import pygtk pygtk.require("2.0") import gtk def make_menu_item(name, widget): item = gtk.MenuItem(name) item.connect('activate', widget, name) item.show() return item class test: def __init__(self): self.window = gtk.Window(type=gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", lambda w: gtk.main_quit()) self.window.set_title('test') self.window.set_size_request(800, 600) self.window.set_position(gtk.WIN_POS_CENTER) self.create_widgets() self.create_buttons() self.conf1() self.text() self.window.show_all() gtk.main() def create_widgets(self): self.main_box = gtk.HBox(False) self.main_box.set_border_width(10) self.window.add(self.main_box) self.vbox_1 = gtk.VBox('') # To include the buttons self.main_box.pack_start(self.vbox_1, False, True, 0) # Set the Setup frame self.setup_frame = gtk.Frame('Setup') self.vbox_1.pack_start(self.setup_frame, True, True, 0) self.vbox_setup = gtk.VBox(False, 0) self.vbox_setup.set_border_width(10) self.setup_frame.add(self.vbox_setup) # Set the Graphic frame self.graphic_frame = gtk.Frame("Graphic") self.main_box.pack_start(self.graphic_frame, True, True, 0) self.vbox = gtk.VBox(False, 0) self.vbox.set_border_width(5) self.graphic_frame.add(self.vbox) def create_buttons(self): self.vbox_button = gtk.VBox(False, 0) self.vbox_1.pack_start(self.vbox_button, False, True, 0) # Set the button name and size self.btn1 = gtk.Button('Plot') self.vbox_button.pack_start(self.btn1, False, padding=0) self.btn1.set_size_request(60, 60) self.btn2 = gtk.Button('Clear') self.vbox_button.pack_start(self.btn2, False, padding=0) self.btn3 = gtk.Button('Save') self.vbox_button.pack_start(self.btn3, False, padding=0) self.btn4 = gtk.Button("Close") self.btn4.connect("clicked", lambda w: gtk.main_quit()) self.vbox_button.pack_start(self.btn4, False, padding=0) def conf1(self): self.observatory_box = gtk.VBox(False, 0) self.vbox_setup.pack_start(self.observatory_box, False, True, 0) self.label = gtk.Label('Conf1') self.label.set_alignment(.5, .5) self.observatory_box.pack_start(self.label, False, True, 3) self.label_lat = gtk.Label('Latitude: ?') self.label_lat.set_alignment(.0, .5) self.label_lat.set_size_request(150, -1) self.combobox_1 = gtk.ComboBox() self.liststore = gtk.ListStore(str) self.cell = gtk.CellRendererText() self.combobox_1.pack_start(self.cell) self.combobox_1.add_attribute(self.cell, 'text', 0) self.observatory_box.pack_start(self.combobox_1, False, True, 3) self.liststore.append(['Select:']) self.liststore.append(['C1']) self.liststore.append(['C2']) self.combobox_1.set_model(self.liststore) self.combobox_1.connect('changed', self.conf1_choice) self.combobox_1.connect('changed', self.configuration_choice) self.combobox_1.set_active(0) self.observatory_box.pack_start(self.label_lat, False, True, 3) def conf1_choice(self, combobox): model = combobox.get_model() index = combobox.get_active() if model[index][0] == 'C1': self.latitude = -12.12 self.array = model[index][0] elif model[index][0] == 'C2': self.latitude = 23.23 self.array = model[index][0] else : self.latitude = 0 self.array = model[index][0] lat_dgr = int(self.latitude) lat_mn = int((self.latitude %1)*60.) lat_s = ((self.latitude %1)*60. %1)*60. self.label_lat.set_label('Latitude: '+str(lat_dgr)+u'\u00B0 '+ str(lat_mn)+u'\u0027 '+str(round(lat_s,2))+u'\u0027\u0027' ) def configuration_choice(self, widget): self.configuration_box = gtk.VBox(False, 0) self.vbox_setup.pack_start(self.configuration_box, False, True, 0) self.label = gtk.Label('Conf2') self.label.set_alignment(.5, .5) self.configuration_box.pack_start(self.label, False, True, 3) self.label.show() self.combobox_2 = gtk.ComboBox() self.liststore = gtk.ListStore(str) self.cell = gtk.CellRendererText() self.combobox_2.pack_start(self.cell) self.combobox_2.add_attribute(self.cell, 'text', 0) self.configuration_box.pack_start(self.combobox_2, False, True, 3) self.liststore.append(['Select:']) if self.array == 'C1': self.liststore.append(['2']) self.liststore.append(['3']) self.liststore.append(['4']) if self.array == 'C2': self.liststore.append(['2']) self.liststore.append(['3']) self.liststore.append(['4']) self.liststore.append(['6']) self.combobox_2.set_model(self.liststore) self.combobox_2.connect('changed', self.conf2) self.combobox_2.set_active(0) def conf2(self,widget): self.tel_box_1 = gtk.HBox(False, 0) self.vbox_setup.pack_start(self.tel_box_1, False, True, 0) self.tel_box_2 = gtk.HBox(False, 0) self.vbox_setup.pack_start(self.tel_box_2, False, True, 0) self.opt = gtk.OptionMenu() self.menu = gtk.Menu() if self.array == 'C1': if self.listore == 2: self.item = make_menu_item('T1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T2',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T3',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T4',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) if self.listore == 3: self.item = make_menu_item('T1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T2',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T3',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T4',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) if self.listore == 4: self.item = make_menu_item('T1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T2',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T3',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('T4',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_2.pack_start(self.opt, False, True, 0) if self.array == 'C2': if self.listore == 2: self.item = make_menu_item('U1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('U2',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) if self.listore == 3: self.item = make_menu_item('U1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('U2',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) if self.listore == 4: self.item = make_menu_item('U1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('U2',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_2.pack_start(self.opt, False, True, 0) if self.listore == 6: self.item = make_menu_item('U1',self.conf_tel) self.menu.append(self.item) self.item = make_menu_item('U2',self.conf_tel) self.menu.append(self.item) self.opt.set_menu(self.menu) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_1.pack_start(self.opt, False, True, 0) self.tel_box_2.pack_start(self.opt, False, True, 0) self.tel_box_2.pack_start(self.opt, False, True, 0) self.tel_box_2.pack_start(self.opt, False, True, 0) def text(self): self.text_box = gtk.VBox(False, 0) self.vbox_setup.pack_start(self.text_box, False, True, 10) self.label = gtk.Label('text') self.label.set_alignment(.5, .5) self.text_box.pack_start(self.label, False, True, 3) self.text_entry = gtk.Entry(max=4) self.text_entry.set_size_request(70, -1) self.text_entry.add_events(gtk.gdk.KEY_RELEASE_MASK) self.text_entry.connect('key-release-event', self.text_choice) self.text_box.pack_start(self.text_entry, False, True, 0) def text_choice(self, widget, event): self.text = widget.get_text() print self.array, self.text if __name__ == "__main__": te = test()