From e5782dd7360ad00980d49f588bc41c9d1ab71e5f Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Sun, 28 Nov 2010 20:00:56 -0500 Subject: [PATCH] some cleanups and comments --- pyfpdb/GuiAutoImport.py | 10 ++++-- pyfpdb/fpdb.pyw | 67 ++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 3cc816ed..b6d7bcaf 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -204,15 +204,19 @@ class GuiAutoImport (threading.Thread): # That is not correct. It should open another dir for importing while piping the # results to the same pipe. This means that self.path should be a a list of dirs # to watch. - if widget.get_active() or data == "autostart": # toggled on + if data == "autostart": + self.startButton.set_active(True) + return + + if widget == self.startButton and self.startButton.get_active(): # - Does the lock acquisition need to be more sophisticated for multiple dirs? # (see comment above about what to do if pipe already open) # - Ideally we want to release the lock if the auto-import is killed by some # kind of exception - is this possible? - if self.settings['global_lock'].acquire(False): # returns false immediately if lock not acquired + if self.settings['global_lock'].acquire(False, source="AutoImport"): # returns false immediately if lock not acquired self.addText(_("\nGlobal lock taken ... Auto Import Started.\n")) self.doAutoImportBool = True - widget.set_label(_(u' _Stop Auto Import ')) + self.startButton.set_label(_(u' _Stop Auto Import ')) while gtk.events_pending(): # change the label NOW don't wait for the pipe to open gtk.main_iteration(False) if self.pipe_to_hud is None: diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 83463e36..53f74aa4 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -964,8 +964,8 @@ class fpdb: self.quitting = True # TODO: check if current settings differ from profile, if so offer to save or abort - if self.db!=None: - if self.db.backend==self.db.MYSQL_INNODB: + if self.db is not None: + if self.db.backend == self.db.MYSQL_INNODB: try: import _mysql_exceptions if self.db is not None and self.db.is_connected(): @@ -991,7 +991,7 @@ class fpdb: """opens the auto import tab""" new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql, self.window) self.threads.append(new_aimp_thread) - aimp_tab=new_aimp_thread.get_vbox() + aimp_tab = new_aimp_thread.get_vbox() self.add_and_display_tab(aimp_tab, _("Auto Import")) if options.autoimport: new_aimp_thread.startClicked(new_aimp_thread.startButton, "autostart") @@ -1096,8 +1096,11 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.db = None self.status_bar = None self.quitting = False - self.visible = False + self.threads = [] # objects used by tabs - no need for threads, gtk handles it + self.closeq = Queue.Queue(20) # used to signal ending of a thread (only logviewer for now) + + # create window, move it to specific location on command line self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) if options.xloc is not None or options.yloc is not None: if options.xloc is None: @@ -1106,9 +1109,11 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an options.yloc = 0 self.window.move(options.xloc,options.yloc) + # connect to required events self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) self.window.set_title("Free Poker DB - v%s" % (VERSION, )) + # set a default x/y size for the window self.window.set_border_width(1) defx, defy = 900, 720 sx, sy = gtk.gdk.screen_width(), gtk.gdk.screen_height() @@ -1117,30 +1122,31 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.window.set_default_size(defx, defy) self.window.set_resizable(True) + # main area of window self.main_vbox = gtk.VBox(False, 1) self.main_vbox.set_border_width(1) self.window.add(self.main_vbox) self.main_vbox.show() + # create our Main Menu Bar menubar = self.get_menu(self.window) self.main_vbox.pack_start(menubar, False, True, 0) menubar.show() - #done menubar - - self.threads = [] # objects used by tabs - no need for threads, gtk handles it - self.closeq = Queue.Queue(20) # used to signal ending of a thread (only logviewer for now) + # create a tab bar self.nb = gtk.Notebook() self.nb.set_show_tabs(True) self.nb.show() self.main_vbox.pack_start(self.nb, True, True, 0) - self.tabs=[] # the event_boxes forming the actual tabs - self.tab_names=[] # names of tabs used since program started, not removed if tab is closed - self.pages=[] # the contents of the page, not removed if tab is closed - self.nb_tab_names=[] # list of tab names currently displayed in notebook + self.tabs = [] # the event_boxes forming the actual tabs + self.tab_names = [] # names of tabs used since program started, not removed if tab is closed + self.pages = [] # the contents of the page, not removed if tab is closed + self.nb_tab_names = [] # list of tab names currently displayed in notebook + # create the first tab self.tab_main_help(None, None) + # determine window visibility from command line options if options.minimized: self.window.iconify() if options.hidden: @@ -1148,9 +1154,11 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an if not options.hidden: self.window.show() - self.visible = True # Flip on + self.visible = True # Flip on + self.load_profile(create_db = True) + # setup error logging if not options.errorsToConsole: fileName = os.path.join(self.config.dir_log, 'fpdb-errors.txt') print (_("\nNote: error output is being diverted to fpdb-errors.txt and HUD-errors.txt in: %s") % self.config.dir_log) \ @@ -1158,6 +1166,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an errorFile = open(fileName, 'w', 0) sys.stderr = errorFile + # set up tray-icon and menu self.statusIcon = gtk.StatusIcon() # use getcwd() here instead of sys.path[0] so that py2exe works: cards = os.path.join(os.getcwd(), '..','gfx','fpdb-cards.png') @@ -1173,13 +1182,10 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.statusIcon.set_tooltip("Free Poker Database") self.statusIcon.connect('activate', self.statusicon_activate) self.statusMenu = gtk.Menu() - menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT) - menuItem.connect('activate', self.dia_about) - self.statusMenu.append(menuItem) - - menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) - menuItem.connect('activate', self.quit) - self.statusMenu.append(menuItem) + + # set default menu options + self.addImageToTrayMenu(gtk.STOCK_ABOUT, self.dia_about) + self.addImageToTrayMenu(gtk.STOCK_QUIT, self.quit) self.statusIcon.connect('popup-menu', self.statusicon_menu, self.statusMenu) self.statusIcon.set_visible(True) @@ -1189,7 +1195,26 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an if options.autoimport: self.tab_auto_import(None) - + + def addImageToTrayMenu(self, image, event=None): + menuItem = gtk.ImageMenuItem(image) + if event is not None: + menuItem.connect('activate', event) + self.statusMenu.append(menuItem) + menuItem.show() + return menuItem + + def addLabelToTrayMenu(self, label, event=None): + menuItem = gtk.MenuItem(label) + if event is not None: + menuItem.connect('activate', event) + self.statusMenu.append(menuItem) + menuItem.show() + return menuItem + + def removeFromTrayMenu(self, menuItem): + menuItem.destroy() + menuItem = None def __iconify(self): self.visible = False