From 1b03eebf34cd8ab1083a761a749d24c0b1fc45bc Mon Sep 17 00:00:00 2001 From: Adam Schreiber Date: Tue, 21 Apr 2009 16:00:02 +0000 Subject: Initial Commit --- 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 + + 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 . +""" + +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 * 105 + 0 * 104 + 0 * 103 + 0 * 102 + 0 * 101 + 0 * 100 = 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} * 105 + {1} * 104 + {2} * 103 + {3} * 102 + {4} * 101 + {5} * 100 = {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() -- cgit v0.9.1