def on_open_cdv_menu_activate(self, widget, data=None): """ Open menu """ dialog = gtk.FileChooserDialog( "Open..", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*.cdv") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: self.cdv = CarnetDeVol(xmlfilename=dialog.get_filename()) self.fillListFlies() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy()
class Gcdv(object): # windows signals def on_window_destroy(self, widget, data=None): gtk.main_quit() # menu items signals def on_open_cdv_menu_activate(self, widget, data=None): """ Open menu """ dialog = gtk.FileChooserDialog( "Open..", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*.cdv") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: self.cdv = CarnetDeVol(xmlfilename=dialog.get_filename()) self.fillListFlies() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() def on_imagemenuitem3_activate(self, widget, data=None): """ Save menu """ self.cdv.save() def on_save_as_menu_activate(self, widget, data=None): """ Save as menu """ dialog = gtk.FileChooserDialog( "Save as ...", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*.cdv") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() self.cdv.setXmlFilename(filename) self.cdv.setName(filename.split(".")[0].split("/")[-1]) self.cdv.save() self.window.set_title("CarnetDeVol - "+str(self.cdv.getName())) elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() def on_quit_menu_item_activate(self, widget, data=None): """ Quit menu """ gtk.main_quit() # edit menu def on_add_fly_activate(self, widget, data=None): """ Add menu """ new_num = self.cdv.getMaxFlightNum()+1 self.cdv.addFlight(new_num) self.listFlies.appendFly(self.cdv.getFlight(new_num)) def on_del_fly_activate(self, widget, data=None): """ Delete menu """ try: fly_activated = self.listFlies.selected() self.listFlies.suppressFly(fly_activated) except: pass # track menu def on_add_track_activate(self, widget, data=None): """ add track menu """ # about menu def on_about_menu_activate(self, widget, data=None): """ About menu """ about = gtk.AboutDialog() about.set_name("GCarnetDeVol") about.set_version(__VERSION__) about.set_website(__WEB__) about.set_license(__LICENSE__) about.set_authors(__AUTHORS__) about.run() about.destroy() # right clic def on_treeview_button_release_event(self, widget, data=None): if data.button == 3: print "fly selected "+str(self.listFlies.selected().getNumber()) # list signals def on_treeview_row_activated(self, widget, data, col): """ data = (row_number,) """ print "data : "+str(data)+" col : "+str(col) fly = self.listFlies.getFly(data[0]) # init windows def __init__(self, cdv=None): self.cdv = cdv self.builder = gtk.Builder() self.builder.add_from_file("gui_cdv.xml") self.builder.connect_signals(self) self.window = self.builder.get_object("window") if cdv.getName()==None: self.window.set_title("CarnetDeVol - New*") else: self.window.set_title("CarnetDeVol - "+str(cdv.getName())) self.fillListFlies() self.statusbar = self.builder.get_object("statusbar1") self.statusbar.contextid = self.statusbar.get_context_id("time status") self.statusbar.push(self.statusbar.contextid, "Duree totale de vol : "+second2time(CDV.getTotalDuration())+\ " - Temps moyen d'un vol: "+\ second2time(CDV.getTotalDuration()/CDV.getNumberOfFlights())+\ " - Nombre total de vol : "+str(CDV.getNumberOfFlights())) def fillListFlies(self): self.listFlies = ListFly(self.cdv, self.builder) if self.cdv != None: for fly in self.cdv.getFlights(): self.listFlies.appendFly(fly)
"Duree totale de vol : "+second2time(CDV.getTotalDuration())+\ " - Temps moyen d'un vol: "+\ second2time(CDV.getTotalDuration()/CDV.getNumberOfFlights())+\ " - Nombre total de vol : "+str(CDV.getNumberOfFlights())) def fillListFlies(self): self.listFlies = ListFly(self.cdv, self.builder) if self.cdv != None: for fly in self.cdv.getFlights(): self.listFlies.appendFly(fly) if __name__ == "__main__": try: os.popen("gtk-builder-convert gui_cdv.glade gui_cdv.xml") except: pass if len(sys.argv) == 2: CDV = CarnetDeVol(xmlfilename=sys.argv[1]) else: CDV = CarnetDeVol() print("Duree totale de vol : "+second2time(CDV.getTotalDuration())) print("Temps moyen d'un vol: "+\ second2time(CDV.getTotalDuration()/CDV.getNumberOfFlights())) print("Nombre total de vol : "+str(CDV.getNumberOfFlights())) app = Gcdv(CDV) app.window.show() gtk.main()