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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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()
|