Exemplo n.º 1
0
class GraphingInterface(Core.Object):
    enter_function = Core.InputEvent(KEYBOARD, PRESS, ord(' '))

    def __init__(self):
        Core.Object.__init__(self)
        self.graph = StringFunctionGrapher()
        self.prompt = Prompt()
        self.flash = OnScreenMessage()

        self.flash.position = (-310, 230)
        self.flash.text_size = 25
        self.flash.delay = 5.0
        self.flash.color = (0, 0.2, 0.7)
        self.prompt.position = (-310, 230)
        self.prompt.text_size = 25
        self.prompt.color = (0, 0.2, 0.7)
        self.prompt.set_callback(self.update_function)
        self.graph.position = (-320, 0)
        self.graph.set(DRAW)

    def input(self, evt):
        if (evt == self.enter_function) and not self.prompt.active():
            self.flash.hide()
            self.prompt.ask("Function: ")

    def update_function(self, new_func, context = None):
        try:
            self.graph.set_string_function(new_func)
        except Exception as e:            
            self.flash.show("Invalid function '%s':\n%s" % (new_func, e))
        else:
            self.flash.show("Graphing\nf(x) = %s" % new_func)        
Exemplo n.º 2
0
    def __init__(self):
        Core.Object.__init__(self)
        self.graph = StringFunctionGrapher()
        self.prompt = Prompt()
        self.flash = OnScreenMessage()

        self.flash.position = (-310, 230)
        self.flash.text_size = 25
        self.flash.delay = 5.0
        self.flash.color = (0, 0.2, 0.7)
        self.prompt.position = (-310, 230)
        self.prompt.text_size = 25
        self.prompt.color = (0, 0.2, 0.7)
        self.prompt.set_callback(self.update_function)
        self.graph.position = (-320, 0)
        self.graph.set(DRAW)