diff options
Diffstat (limited to 'sugar-toolkit/src/sugar/tutorius/calc.py')
-rw-r--r-- | sugar-toolkit/src/sugar/tutorius/calc.py | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/sugar-toolkit/src/sugar/tutorius/calc.py b/sugar-toolkit/src/sugar/tutorius/calc.py new file mode 100644 index 0000000..56ceba6 --- /dev/null +++ b/sugar-toolkit/src/sugar/tutorius/calc.py @@ -0,0 +1,130 @@ +import logging + +import sys, os +import pygtk +pygtk.require20() +import gtk + +import overlayer + + +#import rpdb2 +#rpdb2.start_embedded_debugger("foo", True, True) + +class TootOriole(): + def hello(self, widget, data=None): + logging.info('Hello World') + + def buttonclicked(self, button, data=None): + evt = button.child.get_text() + if evt not in ("+", "-", "*", "/", "=", "."): + if self.newNum: + self.reg1 = 0 + self.newNum = False + if not self.decimal: + self.reg1 = self.reg1*10+int(evt) + else: + self.reg1 += self.decimal*int(evt) + self.decimal /= 10 + else: + if (evt == "."): + self.decimal = 0.1 + return + + if evt == "=": + evt = None + + self.reg2 = { + "+": lambda a, b: a+b, + "-": lambda a, b: a-b, + "*": lambda a, b: a*b, + "/": lambda a, b: a/b, + None: lambda a, b: b + }[self.lastOp](self.reg2, self.reg1) + self.reg1 = self.reg2 + self.newNum = True + self.decimal = 0 + self.lastOp = evt + self.label.set_label(str(self.reg1)) + + def __init__(self): + self.reg1 = 0 + self.reg2 = 0 + self.lastOp = None + self.decimal = 0 + self.newNum = False + + print "running activity init" + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.window.connect("delete_event", self.delete_event) + self.window.connect("destroy", self.destroy) + print "activity running" + + # Creates the Toolbox. It contains the Activity Toolbar, which is the + # bar that appears on every Sugar window and contains essential + # functionalities, such as the 'Collaborate' and 'Close' buttons. + #toolbox = activity.ActivityToolbox(self) + #self.set_toolbox(toolbox) + #toolbox.show() + + self.vbox = gtk.VBox(homogeneous=False, spacing=20) + + #textbox + self.label = gtk.Label("0") + self.label.show() + self.vbox.pack_start(self.label, False, True, 10) + + table = gtk.Table(rows=4, columns=4, homogeneous=True) + table.show() + self.vbox.pack_start(child=table, expand=True, fill=True, \ + padding=10) + buttonlist = [0, "+", "-", "x", 7, 8, 9, "/", 4, 5, 6, "=", \ + 1, 2, 3, "."] + + for i in range(4): + for j in range(4): + button = gtk.Button("") + button.child.set_markup("<big><b>%s</b></big>" \ + % str(buttonlist.pop(0))) + table.attach(button, j, j+1, i, i+1, gtk.EXPAND|gtk.FILL, + gtk.EXPAND|gtk.FILL, 15, 15) + button.connect("clicked", self.buttonclicked, None) + button.show() + + # Set the button to be our canvas. The canvas is the main section of + # every Sugar Window. It fills all the area below the toolbox. + + + # The final step is to display this newly created widget. + self.vbox.show() + self.window.add(self.vbox) + + self.window.show() + + # proto overlap + # ==================================================================== + # =================================== clip here ====================== + # Create overlay base where all overlayed widgets will reside + overlayBase = overlayer.Overlayer() + overlayBase.inject(self.vbox) + bubble = overlayer.TextBubble(text="Hello,\nI'm a comma.Use me to\nrepresent decimal numbers.", speaker=button) + overlayBase.put(bubble, 40, 50) + # we do not eject the overlay, but it could be done when overlay is not + # needed anymore + # =================================== end clip ======================= + # ==================================================================== + + + def delete_event(self, widget, event, data=None): + print "quitting..." + return False + + def destroy(self, widget, data=None): + gtk.main_quit() + + + + +if __name__ == "__main__": + t = TootOriole() + gtk.main() |