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
|
#!/usr/bin/env python
"""
Copyright 2009 Adam Schreiber <sadam@gnome.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import gtk
import math
def main():
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("delete_event", delete_event)
window.connect("destroy", gtk.main_quit)
window.set_border_width(10)
window.set_default_size(640, 480)
window.set_title("Deci")
vbox = gtk.VBox (False, 10)
window.add(vbox)
# Scrollbar Value Label
hbox = gtk.HBox()
spinbut = gtk.SpinButton()
spinbut.set_range(0.01,1)
spinbut.set_increments(0.01,0.1)
spinbut.set_numeric(True)
hbox.pack_start(spinbut, True, False)
vbox.pack_start(hbox, False)
# Scrollbar
hscrollbar = gtk.HScrollbar()
hscrollbar.set_range(0,999999)
hscrollbar.set_increments(1,100)
vbox.pack_start(hscrollbar, False)
# Equivalent Label
equivlab = gtk.Label("0 * 100000 + 0 * 10000 + 0 * 1000 + 0 * 100 + 0 * 10 + 0 * 1 = 0")
vbox.pack_start(equivlab, False)
# Power of 10 Equivalent Label
powequivlab = gtk.Label("0 * 10<sup>5</sup> + 0 * 10<sup>4</sup> + 0 * 10<sup>3</sup> + 0 * 10<sup>2</sup> + 0 * 10<sup>1</sup> + 0 * 10<sup>0</sup> = 0")
powequivlab.set_use_markup(True)
vbox.pack_start(powequivlab, False)
# Start Figure Box
drawshapesarea = DrawShapesArea()
vbox.add(drawshapesarea)
spinbut.connect("value-changed", scrollbar_changed, [spinbut, hscrollbar, equivlab, powequivlab, drawshapesarea])
hscrollbar.connect("value-changed", scrollbar_changed, [spinbut, hscrollbar, equivlab, powequivlab, drawshapesarea])
window.show_all()
gtk.main()
def scrollbar_changed(range, data=None):
spinbut = data[0]
hscrollbar = data[1]
equivlab = data[2]
powequivlab = data[3]
drawshapesarea = data[4]
val = round(range.get_value())
if abs(val) < abs(1e-2):
val = 0
val = int(val)
val5 = int(math.floor(val/math.pow(10,5)))
val4 = int(math.floor(math.fmod(val,math.pow(10,5))/math.pow(10,4)))
val3 = int(math.floor(math.fmod(val,math.pow(10,4))/math.pow(10,3)))
val2 = int(math.floor(math.fmod(val,math.pow(10,3))/math.pow(10,2)))
val1 = int(math.floor(math.fmod(val,math.pow(10,2))/math.pow(10,1)))
val0 = int(math.floor(math.fmod(val,math.pow(10,1))))
spinbut.set_value(int(val))
hscrollbar.set_value(int(val))
equivlab.set_text("{0} * 100000 + {1} * 10000 + {2} * 1000 + {3} * 100 + {4} * 10 + {5} * 1 = {6}".format(val5, val4, val3, val2, val1, val0, val))
powequivlab.set_markup("{0} * 10<sup>5</sup> + {1} * 10<sup>4</sup> + {2} * 10<sup>3</sup> + {3} * 10<sup>2</sup> + {4} * 10<sup>1</sup> + {5} * 10<sup>0</sup> = {6}".format(val5, val4, val3, val2, val1, val0, val))
drawshapesarea.set_count (val)
def delete_event(widget, event, data=None):
return False
if __name__ == "__main__":
main()
|