some cleanups and comments

This commit is contained in:
Eric Blade 2010-11-28 20:00:56 -05:00
parent 336fee0f3d
commit e5782dd736
2 changed files with 53 additions and 24 deletions

View File

@ -204,15 +204,19 @@ class GuiAutoImport (threading.Thread):
# That is not correct. It should open another dir for importing while piping the # 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 # results to the same pipe. This means that self.path should be a a list of dirs
# to watch. # 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? # - Does the lock acquisition need to be more sophisticated for multiple dirs?
# (see comment above about what to do if pipe already open) # (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 # - Ideally we want to release the lock if the auto-import is killed by some
# kind of exception - is this possible? # 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.addText(_("\nGlobal lock taken ... Auto Import Started.\n"))
self.doAutoImportBool = True 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 while gtk.events_pending(): # change the label NOW don't wait for the pipe to open
gtk.main_iteration(False) gtk.main_iteration(False)
if self.pipe_to_hud is None: if self.pipe_to_hud is None:

View File

@ -964,8 +964,8 @@ class fpdb:
self.quitting = True self.quitting = True
# TODO: check if current settings differ from profile, if so offer to save or abort # TODO: check if current settings differ from profile, if so offer to save or abort
if self.db!=None: if self.db is not None:
if self.db.backend==self.db.MYSQL_INNODB: if self.db.backend == self.db.MYSQL_INNODB:
try: try:
import _mysql_exceptions import _mysql_exceptions
if self.db is not None and self.db.is_connected(): if self.db is not None and self.db.is_connected():
@ -991,7 +991,7 @@ class fpdb:
"""opens the auto import tab""" """opens the auto import tab"""
new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql, self.window) new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql, self.window)
self.threads.append(new_aimp_thread) 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")) self.add_and_display_tab(aimp_tab, _("Auto Import"))
if options.autoimport: if options.autoimport:
new_aimp_thread.startClicked(new_aimp_thread.startButton, "autostart") 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.db = None
self.status_bar = None self.status_bar = None
self.quitting = False self.quitting = False
self.visible = 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) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
if options.xloc is not None or options.yloc is not None: if options.xloc is not None or options.yloc is not None:
if options.xloc is 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 options.yloc = 0
self.window.move(options.xloc,options.yloc) self.window.move(options.xloc,options.yloc)
# connect to required events
self.window.connect("delete_event", self.delete_event) self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy) self.window.connect("destroy", self.destroy)
self.window.set_title("Free Poker DB - v%s" % (VERSION, )) 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) self.window.set_border_width(1)
defx, defy = 900, 720 defx, defy = 900, 720
sx, sy = gtk.gdk.screen_width(), gtk.gdk.screen_height() 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_default_size(defx, defy)
self.window.set_resizable(True) self.window.set_resizable(True)
# main area of window
self.main_vbox = gtk.VBox(False, 1) self.main_vbox = gtk.VBox(False, 1)
self.main_vbox.set_border_width(1) self.main_vbox.set_border_width(1)
self.window.add(self.main_vbox) self.window.add(self.main_vbox)
self.main_vbox.show() self.main_vbox.show()
# create our Main Menu Bar
menubar = self.get_menu(self.window) menubar = self.get_menu(self.window)
self.main_vbox.pack_start(menubar, False, True, 0) self.main_vbox.pack_start(menubar, False, True, 0)
menubar.show() 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 = gtk.Notebook()
self.nb.set_show_tabs(True) self.nb.set_show_tabs(True)
self.nb.show() self.nb.show()
self.main_vbox.pack_start(self.nb, True, True, 0) self.main_vbox.pack_start(self.nb, True, True, 0)
self.tabs=[] # the event_boxes forming the actual tabs 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.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.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.nb_tab_names = [] # list of tab names currently displayed in notebook
# create the first tab
self.tab_main_help(None, None) self.tab_main_help(None, None)
# determine window visibility from command line options
if options.minimized: if options.minimized:
self.window.iconify() self.window.iconify()
if options.hidden: if options.hidden:
@ -1149,8 +1155,10 @@ 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: if not options.hidden:
self.window.show() self.window.show()
self.visible = True # Flip on self.visible = True # Flip on
self.load_profile(create_db = True) self.load_profile(create_db = True)
# setup error logging
if not options.errorsToConsole: if not options.errorsToConsole:
fileName = os.path.join(self.config.dir_log, 'fpdb-errors.txt') 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) \ 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) errorFile = open(fileName, 'w', 0)
sys.stderr = errorFile sys.stderr = errorFile
# set up tray-icon and menu
self.statusIcon = gtk.StatusIcon() self.statusIcon = gtk.StatusIcon()
# use getcwd() here instead of sys.path[0] so that py2exe works: # use getcwd() here instead of sys.path[0] so that py2exe works:
cards = os.path.join(os.getcwd(), '..','gfx','fpdb-cards.png') 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.set_tooltip("Free Poker Database")
self.statusIcon.connect('activate', self.statusicon_activate) self.statusIcon.connect('activate', self.statusicon_activate)
self.statusMenu = gtk.Menu() 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) # set default menu options
menuItem.connect('activate', self.quit) self.addImageToTrayMenu(gtk.STOCK_ABOUT, self.dia_about)
self.statusMenu.append(menuItem) self.addImageToTrayMenu(gtk.STOCK_QUIT, self.quit)
self.statusIcon.connect('popup-menu', self.statusicon_menu, self.statusMenu) self.statusIcon.connect('popup-menu', self.statusicon_menu, self.statusMenu)
self.statusIcon.set_visible(True) self.statusIcon.set_visible(True)
@ -1190,6 +1196,25 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
if options.autoimport: if options.autoimport:
self.tab_auto_import(None) 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): def __iconify(self):
self.visible = False self.visible = False