#!/usr/bin/env python
# -*- coding: utf-8 -*- import pygtk
pygtk.require('2.0')
import gtk
class main_win:
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def keypressed(self, widget, kid):
print kid
def __init__(self): # definition de la fenetre
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("rpl calc" )
self.window.set_border_width(0)
# contenaire principal
self.box_main = gtk.HBox(False, 5)
#################################################
# pile et ligne de saisie #
#################################################
#definition du contenaire self.box_stack = gtk.VBox(True, 5)
#definition de la pile
self.sw_stack = gtk.ScrolledWindow()
self.sw_stack.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.stack = gtk.TextView(buffer=None)
self.stack_buffer = self.stack.get_buffer()
self.sw_stack.add(self.stack)
#mise en place
#de la pile
self.box_main.pack_start(self.sw_stack, True, True, 0)
#de la ligne de saisie
#affichage
#de la pile
self.stack.show()
self.sw_stack.show()
#################################################
# pavé numérique #
#################################################
# definition de la table de boutons
self.table_pad_numeric = gtk.Table(5, 4, True)
# definition des boutons
self.button0 = gtk.Button("0" )
self.button1 = gtk.Button("1" )
self.button2 = gtk.Button("2" )
self.button3 = gtk.Button("3" )
self.button4 = gtk.Button("4" )
self.button5 = gtk.Button("5" )
self.button6 = gtk.Button("6" )
self.button7 = gtk.Button("7" )
self.button8 = gtk.Button("8" )
self.button9 = gtk.Button("9" )
self.button_dec = gtk.Button("." )
self.button_div = gtk.Button("/" )
self.button_mul = gtk.Button("*" )
self.button_sub = gtk.Button("-" )
self.button_add = gtk.Button("+" )
self.button_enter = gtk.Button("enter" )
self.button0.connect("clicked", self.keypressed, "bt_0" ) self.button1.connect("clicked", self.keypressed, "bt_1" )
self.button2.connect("clicked", self.keypressed, "bt_2" )
self.button3.connect("clicked", self.keypressed, "bt_3" )
self.button4.connect("clicked", self.keypressed, "bt_4" )
self.button5.connect("clicked", self.keypressed, "bt_5" )
self.button6.connect("clicked", self.keypressed, "bt_6" )
self.button7.connect("clicked", self.keypressed, "bt_7" )
self.button8.connect("clicked", self.keypressed, "bt_8" )
self.button9.connect("clicked", self.keypressed, "bt_9" )
self.button_dec.connect("clicked", self.keypressed, "bt_dec" )
self.button_div.connect("clicked", self.keypressed, "bt_div" )
self.button_mul.connect("clicked", self.keypressed, "bt_mul" )
self.button_sub.connect("clicked", self.keypressed, "bt_sub" )
self.button_add.connect("clicked", self.keypressed, "bt_add" )
self.button_enter.connect("clicked", self.keypressed, "bt_enter" )
# mise en place
# des boutons
self.table_pad_numeric.attach(self.button_div, 1, 2, 0, 1, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button_mul, 2, 3, 0, 1, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button_sub, 3, 4, 0, 1, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button7, 0, 1, 1, 2, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button8, 1, 2, 1, 2, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button9, 2, 3, 1, 2, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button_add, 3, 4, 1, 3, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button4, 0, 1, 2, 3, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button5, 1, 2, 2, 3, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button6, 2, 3, 2, 3, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button1, 0, 1, 3, 4, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button2, 1, 2, 3, 4, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button3, 2, 3, 3, 4, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button_enter, 3, 4, 3, 5, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button0, 0, 2, 4, 5, xpadding = 3, ypadding = 3)
self.table_pad_numeric.attach(self.button_dec, 2, 3, 4, 5, xpadding = 3, ypadding = 3)
# de la table
self.box_main.pack_start(self.table_pad_numeric, True, True, 0)
# affichages
# des boutons
self.button0.show()
self.button1.show()
self.button2.show()
self.button3.show()
self.button4.show()
self.button5.show()
self.button6.show()
self.button7.show()
self.button8.show()
self.button9.show()
self.button_dec.show()
self.button_div.show()
self.button_mul.show() self.button_sub.show() self.button_add.show() self.button_enter.show() # de la table
self.table_pad_numeric.show()
#################################################
# pavé manipulation de la pile #
#################################################
#definition de la table
self.table_pad_stack = gtk.Table(5, 1, False)
#definition des boutons
self.button_rot = gtk.Button("rot" )
self.button_dup = gtk.Button("dup" )
self.button_drop = gtk.Button("drop" )
self.button_clr = gtk.Button("clr" )
self.button_edit = gtk.Button("edit" )
self.button_rot.connect("clicked", self.keypressed, "bt_rot" )
self.button_dup.connect("clicked", self.keypressed, "bt_dup" )
self.button_drop.connect("clicked", self.keypressed, "bt_drop" )
self.button_clr.connect("clicked", self.keypressed, "bt_clr" )
self.button_edit.connect("clicked", self.keypressed, "bt_edit" )
#mise en place
#des boutons
self.table_pad_stack.attach(self.button_rot, 0, 1, 0, 1, xpadding = 3, ypadding = 3)
self.table_pad_stack.attach(self.button_dup, 0, 1, 1, 2, xpadding = 3, ypadding = 3)
self.table_pad_stack.attach(self.button_drop, 0, 1, 2, 3, xpadding = 3, ypadding = 3)
self.table_pad_stack.attach(self.button_clr, 0, 1, 3, 4, xpadding = 3, ypadding = 3)
self.table_pad_stack.attach(self.button_edit, 0, 1, 4, 5, xpadding = 3, ypadding = 3)
# de la table
self.box_main.pack_start(self.table_pad_stack, True, True, 0)
#affichage
#des boutons
self.button_rot.show()
self.button_dup.show()
self.button_drop.show()
self.button_clr.show()
self.button_edit.show()
#de la table
self.table_pad_stack.show()
self.window.add(self.box_main)
self.box_main.show()
# evenements
self.window.connect("delete_event", self.delete_event)
# affichage de la fenetre
self.window.show() # de la fenetre
def main():
gtk.main()
if __name__ == "__main__":
hello = main_win()
main()
|