FormulaCalculator¶
-
class
decida.FormulaCalculator.
FormulaCalculator
(parent=None, par_specs=None, recalc_specs=None, title='')¶ synopsis:
Simple formula calculator.
A small calculator can be useful to evaluate a single formula involving a few parameters/variables. This formula calculator class constructs a small calculator which evaluates the formula or its inverse with respect to a particular parameter, according to specified code for each result.
(originally posted as a Tcl/Tk application on wiki.tcl.tk)
constructor arguments:
parent (Tkinter handle, default=None)
handle of frame or other widget to pack plot in. if this is not specified, top-level is created.par_specs (list of lists of parameter specifications)
each list of parameter specifications is: parameter name, text to be displayed for the parameter label in the GUI, units, initial value, key of equation recalculation formula.recalc_specs (list of lists of formula specifications)
each list of recalculation specifications is: recalculation key, formula.results:
- Sets up GUI for formula recalculation.
- Changing and typing return in a parameter entry box re-evaluates the respective formula.
- Emacs-style bindings switch between entry boxes: ^n and ^p focus on next or previous entry windows, respectively
example (from test_FormulaCalculator_1):
from decida.FormulaCalculator import FormulaCalculator fc = FormulaCalculator(None, title="L-C oscillator", par_specs = [ ["L", "Inductance", "pH", 1000.0, "f"], ["C", "Capacitance", "pF", 25.00, "f"], ["freq", "Frequency", "GHz", 1.00, "L"], ], recalc_specs = [ ["f", "freq = 1e3/(2*pi*sqrt(L*C))"], ["L", "L = 1e6/(C*pow(2*pi*freq, 2))"], ["C", "C = 1e6/(L*pow(2*pi*freq, 2))"], ] )
-
recalculate
(par_changed)¶