Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Schreiber <sadam@gnome.org>2009-04-21 16:00:02 (GMT)
committer Adam Schreiber <sadam@gnome.org>2009-04-21 16:00:02 (GMT)
commit1b03eebf34cd8ab1083a761a749d24c0b1fc45bc (patch)
tree6dad4d50e91bff69303d9a4006b68b26ca10f622
Initial Commit
-rw-r--r--deci.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/deci.py b/deci.py
new file mode 100644
index 0000000..a36cf94
--- /dev/null
+++ b/deci.py
@@ -0,0 +1,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()