blob: da00919f5cb1ac8679aaaf97b06833679664b3c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
"""Widgets for equation input."""
from gettext import gettext as _
import gtk
import plotter.parse
_FILE_VERSION = 1
class EquationInput(gtk.HBox):
"""A text box..."""
# unique identifier for this input type
CLASS = "text"
def __init__(self, app, equation="x"):
"""Creates input..."""
gtk.HBox.__init__(self)
# add f(x) rather than y, to imply this is a function
self.pack_start(gtk.Label(_("f(x) =")), expand=False,
padding=5)
# create equation entry w/ default text
self._equation = gtk.Entry()
self._equation.set_text(equation)
self.pack_start(self._equation)
self.show_all()
@staticmethod
def load(app, settings):
"""Creates new equation entry from saved state."""
if settings["version"] > _FILE_VERSION:
return EquationInput(app)
return EquationInput(app, settings["text"])
def save(self):
"""Returns settings dictionary with current state."""
settings = {
"version": _FILE_VERSION,
"text": self._equation.get_text()
}
return settings
def get_model(self):
"""Returns function with entry."""
return plotter.parse.parse(self._equation.get_text())
|