def __init__(self, aModelEditor, aDuration): self.theModelEditor = aModelEditor # Sets the return number self.___num = CANCEL_PRESSED self.__off = False self.win = gtk.Dialog('AutosaveWindow', None) self.win.connect("destroy", self.destroy) # Sets size and position self.win.set_border_width(2) self.win.set_default_size(300, 75) self.win.set_position(gtk.WIN_POS_MOUSE) # appends ok button ok_button = gtk.Button(" OK ") self.win.action_area.pack_start( ok_button, False, False, ) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default() ok_button.show() ok_button.connect("clicked", self.okButtonClicked) # appends cancel button cancel_button = gtk.Button(" Cancel ") self.win.action_area.pack_start(cancel_button, False, False) cancel_button.show() cancel_button.connect("clicked", self.cancelButtonClicked) # Sets title self.win.set_title('Preferences') self.ViewComponentObject = ViewComponent(self.win.vbox, 'attachment_box', 'AutosaveWindow.glade') self.ViewComponentObject['duration'] aPixbuf16 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor.png")) aPixbuf32 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor32.png")) self.win.set_icon_list(aPixbuf16, aPixbuf32) self.win.show_all() self.__setAutosaveDuration(aDuration) self.ViewComponentObject.addHandlers({ "on_duration_toggled": self.__buttonChosen, "on_operations_toggled": self.__buttonChosen, "on_turn_off_toggled": self.__buttonChosen }) gtk.main()
def __init__(self, aModelEditor, aDuration): self.theModelEditor = aModelEditor # Sets the return number self.___num = CANCEL_PRESSED self.__off = False self.win = gtk.Dialog('AutosaveWindow' , None) self.win.connect("destroy",self.destroy) # Sets size and position self.win.set_border_width(2) self.win.set_default_size(300,75) self.win.set_position(gtk.WIN_POS_MOUSE) # appends ok button ok_button = gtk.Button(" OK ") self.win.action_area.pack_start(ok_button,False,False,) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default() ok_button.show() ok_button.connect("clicked",self.okButtonClicked) # appends cancel button cancel_button = gtk.Button(" Cancel ") self.win.action_area.pack_start(cancel_button,False,False) cancel_button.show() cancel_button.connect("clicked",self.cancelButtonClicked) # Sets title self.win.set_title('Preferences') self.ViewComponentObject = ViewComponent( self.win.vbox, 'attachment_box', 'AutosaveWindow.glade' ) self.ViewComponentObject['duration'] aPixbuf16 = gtk.gdk.pixbuf_new_from_file( os.path.join( config.GLADEFILE_PATH, "modeleditor.png") ) aPixbuf32 = gtk.gdk.pixbuf_new_from_file( os.path.join( config.GLADEFILE_PATH, "modeleditor32.png") ) self.win.set_icon_list(aPixbuf16, aPixbuf32) self.win.show_all() self.__setAutosaveDuration ( aDuration ) self.ViewComponentObject.addHandlers({ "on_duration_toggled" : self.__buttonChosen, "on_operations_toggled" : self.__buttonChosen, "on_turn_off_toggled" : self.__buttonChosen }) gtk.main()
def __init__(self, aModelEditor): """ sets up a modal dialogwindow displaying the AboutModelEditor window """ self.theModelEditor = aModelEditor # Create the Dialog self.win = gtk.Dialog('AboutModelEditor', None) self.win.connect("destroy", self.destroy) # Sets size and position self.win.set_border_width(2) self.win.set_default_size(300, 75) self.win.set_position(gtk.WIN_POS_MOUSE) # appends ok button ok_button = gtk.Button(" OK ") self.win.action_area.pack_start( ok_button, False, False, ) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default() ok_button.show() ok_button.connect("clicked", self.destroy) # Sets title self.win.set_title('About Model Editor') ViewComponent(self.win.vbox, 'attachment_box', 'AboutModelEditor.glade') aPixbuf16 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor.png")) aPixbuf32 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor32.png")) self.win.set_icon_list(aPixbuf16, aPixbuf32) self.win.show_all() self.theModelEditor.toggleAboutModelEditor(True, self)
class AutosaveWindow: # ========================================================================== def __init__(self, aModelEditor, aDuration): self.theModelEditor = aModelEditor # Sets the return number self.___num = CANCEL_PRESSED self.__off = False self.win = gtk.Dialog('AutosaveWindow' , None) self.win.connect("destroy",self.destroy) # Sets size and position self.win.set_border_width(2) self.win.set_default_size(300,75) self.win.set_position(gtk.WIN_POS_MOUSE) # appends ok button ok_button = gtk.Button(" OK ") self.win.action_area.pack_start(ok_button,False,False,) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default() ok_button.show() ok_button.connect("clicked",self.okButtonClicked) # appends cancel button cancel_button = gtk.Button(" Cancel ") self.win.action_area.pack_start(cancel_button,False,False) cancel_button.show() cancel_button.connect("clicked",self.cancelButtonClicked) # Sets title self.win.set_title('Preferences') self.ViewComponentObject = ViewComponent( self.win.vbox, 'attachment_box', 'AutosaveWindow.glade' ) self.ViewComponentObject['duration'] aPixbuf16 = gtk.gdk.pixbuf_new_from_file( os.path.join( config.GLADEFILE_PATH, "modeleditor.png") ) aPixbuf32 = gtk.gdk.pixbuf_new_from_file( os.path.join( config.GLADEFILE_PATH, "modeleditor32.png") ) self.win.set_icon_list(aPixbuf16, aPixbuf32) self.win.show_all() self.__setAutosaveDuration ( aDuration ) self.ViewComponentObject.addHandlers({ "on_duration_toggled" : self.__buttonChosen, "on_operations_toggled" : self.__buttonChosen, "on_turn_off_toggled" : self.__buttonChosen }) gtk.main() def __setAutosaveDuration ( self, aDuration ): if aDuration[0]>0: self.ViewComponentObject['set_duration'].set_active(True) self.ViewComponentObject['duration'].set_text(str(aDuration[0])) self.ViewComponentObject['operations'].set_sensitive(False) self.ViewComponentObject['duration'].set_sensitive(True) elif aDuration[1]>0: self.ViewComponentObject['set_operations'].set_active(True) self.ViewComponentObject['operations'].set_text(str(aDuration[1])) self.ViewComponentObject['operations'].set_sensitive(True) self.ViewComponentObject['duration'].set_sensitive(False) else: self.ViewComponentObject['turn_off'].set_active( True) self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(False) def cancelButtonClicked( self, *arg ): """ If Cancel button clicked or the return pressed, this method is called. """ # set the return number self.___num = None self.destroy() def destroy( self, *arg ): """destroy dialog """ self.win.hide() gtk.main_quit() def __saveAutosaveDuration ( self ): aDuration = [1000,5] if self.__off == True: aDuration = [0,0] else: #radiobutton(set_duration) is selected if self.ViewComponentObject['set_duration'].get_active() == True: try: num = self.ViewComponentObject['duration'].get_text() aDuration[0] = int(num) if aDuration[0]<1: a=1/0 aDuration[1] = 0 except: self.theModelEditor.openConfirmWindow( "Please enter valid positive integer for time duration", "Invalid number format", 0) return None else: try: num = self.ViewComponentObject['operations'].get_text() aDuration[1] = int(num) if aDuration[1]<0: a=1/0 aDuration[0] = 0 except: self.theModelEditor.openConfirmWindow( "Please enter valid positive integer for number of operations", "Invalid number format" , 0) return None return aDuration def okButtonClicked ( self, *arg ): aDuration = self.__saveAutosaveDuration() if aDuration == None: return self.___num = aDuration self.destroy() def return_result( self ): """Returns result """ return self.___num def __buttonChosen(self, *args): aName = args[0].get_name() if aName == "turn_off": self.__off = True self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(False) else: self.__off = False if aName == "set_duration": self.ViewComponentObject['duration'].set_sensitive(True) self.ViewComponentObject['operations'].set_sensitive(False) else: self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(True)
class AutosaveWindow: # ========================================================================== def __init__(self, aModelEditor, aDuration): self.theModelEditor = aModelEditor # Sets the return number self.___num = CANCEL_PRESSED self.__off = False self.win = gtk.Dialog('AutosaveWindow', None) self.win.connect("destroy", self.destroy) # Sets size and position self.win.set_border_width(2) self.win.set_default_size(300, 75) self.win.set_position(gtk.WIN_POS_MOUSE) # appends ok button ok_button = gtk.Button(" OK ") self.win.action_area.pack_start( ok_button, False, False, ) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default() ok_button.show() ok_button.connect("clicked", self.okButtonClicked) # appends cancel button cancel_button = gtk.Button(" Cancel ") self.win.action_area.pack_start(cancel_button, False, False) cancel_button.show() cancel_button.connect("clicked", self.cancelButtonClicked) # Sets title self.win.set_title('Preferences') self.ViewComponentObject = ViewComponent(self.win.vbox, 'attachment_box', 'AutosaveWindow.glade') self.ViewComponentObject['duration'] aPixbuf16 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor.png")) aPixbuf32 = gtk.gdk.pixbuf_new_from_file( os.path.join(config.GLADEFILE_PATH, "modeleditor32.png")) self.win.set_icon_list(aPixbuf16, aPixbuf32) self.win.show_all() self.__setAutosaveDuration(aDuration) self.ViewComponentObject.addHandlers({ "on_duration_toggled": self.__buttonChosen, "on_operations_toggled": self.__buttonChosen, "on_turn_off_toggled": self.__buttonChosen }) gtk.main() def __setAutosaveDuration(self, aDuration): if aDuration[0] > 0: self.ViewComponentObject['set_duration'].set_active(True) self.ViewComponentObject['duration'].set_text(str(aDuration[0])) self.ViewComponentObject['operations'].set_sensitive(False) self.ViewComponentObject['duration'].set_sensitive(True) elif aDuration[1] > 0: self.ViewComponentObject['set_operations'].set_active(True) self.ViewComponentObject['operations'].set_text(str(aDuration[1])) self.ViewComponentObject['operations'].set_sensitive(True) self.ViewComponentObject['duration'].set_sensitive(False) else: self.ViewComponentObject['turn_off'].set_active(True) self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(False) def cancelButtonClicked(self, *arg): """ If Cancel button clicked or the return pressed, this method is called. """ # set the return number self.___num = None self.destroy() def destroy(self, *arg): """destroy dialog """ self.win.hide() gtk.main_quit() def __saveAutosaveDuration(self): aDuration = [1000, 5] if self.__off == True: aDuration = [0, 0] else: #radiobutton(set_duration) is selected if self.ViewComponentObject['set_duration'].get_active() == True: try: num = self.ViewComponentObject['duration'].get_text() aDuration[0] = int(num) if aDuration[0] < 1: a = 1 / 0 aDuration[1] = 0 except: self.theModelEditor.openConfirmWindow( "Please enter valid positive integer for time duration", "Invalid number format", 0) return None else: try: num = self.ViewComponentObject['operations'].get_text() aDuration[1] = int(num) if aDuration[1] < 0: a = 1 / 0 aDuration[0] = 0 except: self.theModelEditor.openConfirmWindow( "Please enter valid positive integer for number of operations", "Invalid number format", 0) return None return aDuration def okButtonClicked(self, *arg): aDuration = self.__saveAutosaveDuration() if aDuration == None: return self.___num = aDuration self.destroy() def return_result(self): """Returns result """ return self.___num def __buttonChosen(self, *args): aName = args[0].get_name() if aName == "turn_off": self.__off = True self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(False) else: self.__off = False if aName == "set_duration": self.ViewComponentObject['duration'].set_sensitive(True) self.ViewComponentObject['operations'].set_sensitive(False) else: self.ViewComponentObject['duration'].set_sensitive(False) self.ViewComponentObject['operations'].set_sensitive(True)