reformatting, pep8 stuff

This commit is contained in:
Eric Blade 2011-03-06 06:08:08 -05:00
parent d0acf8e943
commit 10f098dc18
2 changed files with 175 additions and 155 deletions

View File

@ -56,15 +56,17 @@ class Table(Table_Window):
"""Finds poker client window with the given table name.""" """Finds poker client window with the given table name."""
titles = {} titles = {}
win32gui.EnumWindows(win_enum_handler, titles) win32gui.EnumWindows(win_enum_handler, titles)
for hwnd in titles: for hwnd in titles:
if titles[hwnd] == "": if titles[hwnd] == "":
continue continue
if re.search(self.search_string, titles[hwnd], re.I): if re.search(self.search_string, titles[hwnd], re.I):
if self.check_bad_words(titles[hwnd]): if self.check_bad_words(titles[hwnd]):
continue continue
if not win32gui.IsWindowVisible(hwnd): # if window not visible, probably not a table # if window not visible, probably not a table
if not win32gui.IsWindowVisible(hwnd):
continue continue
if win32gui.GetParent(hwnd) != 0: # if window is a child of another window, probably not a table # if window is a child of another window, probably not a table
if win32gui.GetParent(hwnd) != 0:
continue continue
HasNoOwner = win32gui.GetWindow(hwnd, win32con.GW_OWNER) == 0 HasNoOwner = win32gui.GetWindow(hwnd, win32con.GW_OWNER) == 0
WindowStyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) WindowStyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
@ -72,7 +74,7 @@ class Table(Table_Window):
continue continue
if not HasNoOwner and WindowStyle & win32con.WS_EX_APPWINDOW == 0: if not HasNoOwner and WindowStyle & win32con.WS_EX_APPWINDOW == 0:
continue continue
self.window = hwnd self.window = hwnd
break break

View File

@ -28,7 +28,7 @@ if os.name == 'nt' and sys.version[0:3] not in ('2.5', '2.6', '2.7') and '-r' no
#print "old path =", os.environ['PATH'] #print "old path =", os.environ['PATH']
dirs = re.split(os.pathsep, os.environ['PATH']) dirs = re.split(os.pathsep, os.environ['PATH'])
# remove any trailing / or \ chars from dirs: # remove any trailing / or \ chars from dirs:
dirs = [re.sub('[\\/]$','',p) for p in dirs] dirs = [re.sub('[\\/]$', '', p) for p in dirs]
# remove any dirs containing 'python' apart from those ending in 'python25', 'python26' or 'python': # remove any dirs containing 'python' apart from those ending in 'python25', 'python26' or 'python':
dirs = [p for p in dirs if not re.search('python', p, re.I) or re.search('python25$', p, re.I) or re.search('python26$', p, re.I) or re.search('python27$', p, re.I)] dirs = [p for p in dirs if not re.search('python', p, re.I) or re.search('python25$', p, re.I) or re.search('python26$', p, re.I) or re.search('python27$', p, re.I)]
tmppath = ";".join(dirs) tmppath = ";".join(dirs)
@ -37,10 +37,10 @@ if os.name == 'nt' and sys.version[0:3] not in ('2.5', '2.6', '2.7') and '-r' no
os.environ['PATH'] = tmppath os.environ['PATH'] = tmppath
print "Python " + sys.version[0:3] + _(' - press return to continue\n') print "Python " + sys.version[0:3] + _(' - press return to continue\n')
sys.stdin.readline() sys.stdin.readline()
if os.name=='nt': if os.name == 'nt':
os.execvpe('pythonw.exe', ('pythonw.exe', 'fpdb.pyw', '-r'), os.environ) # first arg is ignored (name of program being run) os.execvpe('pythonw.exe', ('pythonw.exe', 'fpdb.pyw', '-r'), os.environ)
else: else:
os.execvpe('python', ('python', 'fpdb.pyw', '-r'), os.environ) # first arg is ignored (name of program being run) os.execvpe('python', ('python', 'fpdb.pyw', '-r'), os.environ)
else: else:
print _("\npython 2.5-2.7 not found, please install python 2.5, 2.6 or 2.7 for fpdb\n") print _("\npython 2.5-2.7 not found, please install python 2.5, 2.6 or 2.7 for fpdb\n")
raw_input(_("Press ENTER to continue.")) raw_input(_("Press ENTER to continue."))
@ -67,7 +67,8 @@ import string
cl_options = string.join(sys.argv[1:]) cl_options = string.join(sys.argv[1:])
(options, argv) = Options.fpdb_options() (options, argv) = Options.fpdb_options()
import logging, logging.config import logging
import logging.config
log = logging.getLogger("fpdb") log = logging.getLogger("fpdb")
try: try:
@ -141,9 +142,9 @@ class fpdb:
def add_tab(self, new_page, new_tab_name): def add_tab(self, new_page, new_tab_name):
"""adds a tab, namely creates the button and displays it and appends all the relevant arrays""" """adds a tab, namely creates the button and displays it and appends all the relevant arrays"""
for name in self.nb_tab_names: #todo: check this is valid for name in self.nb_tab_names: # todo: check this is valid
if name == new_tab_name: if name == new_tab_name:
return # if tab already exists, just go to it return # if tab already exists, just go to it
used_before = False used_before = False
for i, name in enumerate(self.tab_names): for i, name in enumerate(self.tab_names):
@ -205,9 +206,9 @@ class fpdb:
image = gtk.Image() image = gtk.Image()
image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR) image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR)
gtk.Button.set_relief(button, gtk.RELIEF_NONE) gtk.Button.set_relief(button, gtk.RELIEF_NONE)
settings = gtk.Widget.get_settings(button); settings = gtk.Widget.get_settings(button)
(w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_SMALL_TOOLBAR); (w, h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_SMALL_TOOLBAR)
gtk.Widget.set_size_request(button, w + 4, h + 4); gtk.Widget.set_size_request(button, w + 4, h + 4)
image.show() image.show()
iconBox.pack_start(image, True, False, 0) iconBox.pack_start(image, True, False, 0)
button.add(iconBox) button.add(iconBox)
@ -245,7 +246,7 @@ class fpdb:
dia.set_comments(_("You are free to change, and distribute original or changed versions of fpdb within the rules set out by the license")) dia.set_comments(_("You are free to change, and distribute original or changed versions of fpdb within the rules set out by the license"))
dia.set_license(_("Please see fpdb's start screen for license information")) dia.set_license(_("Please see fpdb's start screen for license information"))
dia.set_website("http://fpdb.sourceforge.net/") dia.set_website("http://fpdb.sourceforge.net/")
dia.set_authors(['Steffen', 'Eratosthenes', 'Carl Gherardi', dia.set_authors(['Steffen', 'Eratosthenes', 'Carl Gherardi',
'Eric Blade', '_mt', 'sqlcoder', 'Bostik', _('and others')]) 'Eric Blade', '_mt', 'sqlcoder', 'Bostik', _('and others')])
dia.set_program_name("Free Poker Database (FPDB)") dia.set_program_name("Free Poker Database (FPDB)")
@ -253,27 +254,27 @@ class fpdb:
db_version = "" db_version = ""
#if self.db is not None: #if self.db is not None:
# db_version = self.db.get_version() # db_version = self.db.get_version()
nums = [ (_('Operating System'), os.name) nums = [(_('Operating System'), os.name),
, ('Python', sys.version[0:3]) ('Python', sys.version[0:3]),
, ('GTK+', '.'.join([str(x) for x in gtk.gtk_version])) ('GTK+', '.'.join([str(x) for x in gtk.gtk_version])),
, ('PyGTK', '.'.join([str(x) for x in gtk.pygtk_version])) ('PyGTK', '.'.join([str(x) for x in gtk.pygtk_version])),
, ('matplotlib', matplotlib_version) ('matplotlib', matplotlib_version),
, ('numpy', numpy_version) ('numpy', numpy_version),
, ('sqlite', sqlite_version) ('sqlite', sqlite_version),
, ('fpdb version', VERSION) ('fpdb version', VERSION),
, ('database used', self.settings['db-server']) ('database used', self.settings['db-server'])
] ]
versions = gtk.TextBuffer() versions = gtk.TextBuffer()
w = 20 # width used for module names and version numbers w = 20 # width used for module names and version numbers
versions.set_text( '\n'.join( [x[0].rjust(w)+' '+ x[1].ljust(w) for x in nums] ) ) versions.set_text('\n'.join([x[0].rjust(w) + ' ' + x[1].ljust(w) for x in nums]))
view = gtk.TextView(versions) view = gtk.TextView(versions)
view.set_editable(False) view.set_editable(False)
view.set_justification(gtk.JUSTIFY_CENTER) view.set_justification(gtk.JUSTIFY_CENTER)
view.modify_font(pango.FontDescription('monospace 10')) view.modify_font(pango.FontDescription('monospace 10'))
view.show() view.show()
dia.vbox.pack_end(view, True, True, 2) dia.vbox.pack_end(view, True, True, 2)
l = gtk.Label(_("Your config file is: ")+self.config.file) l = gtk.Label(_("Your config file is: ") + self.config.file)
l.set_alignment(0.5, 0.5) l.set_alignment(0.5, 0.5)
l.show() l.show()
dia.vbox.pack_end(l, True, True, 2) dia.vbox.pack_end(l, True, True, 2)
@ -282,7 +283,7 @@ class fpdb:
l.set_alignment(0.5, 0.5) l.set_alignment(0.5, 0.5)
l.show() l.show()
dia.vbox.pack_end(l, True, True, 2) dia.vbox.pack_end(l, True, True, 2)
dia.run() dia.run()
dia.destroy() dia.destroy()
log.debug(_("Threads: ")) log.debug(_("Threads: "))
@ -332,10 +333,10 @@ class fpdb:
# save updated config # save updated config
self.config.save() self.config.save()
self.load_profile() self.load_profile()
for name in self.config.supported_databases: #db_ip/db_user/db_pass/db_server for name in self.config.supported_databases: # db_ip/db_user/db_pass/db_server
log.info('fpdb: name,desc='+name+','+self.config.supported_databases[name].db_desc) log.info('fpdb: name,desc=' + name + ',' + self.config.supported_databases[name].db_desc)
else: else:
log.info(_('guidb response was ')+str(response)) log.info(_('guidb response was ') + str(response))
self.release_global_lock() self.release_global_lock()
@ -344,72 +345,75 @@ class fpdb:
self.warning_box(_("Cannot open Database Maintenance window because other windows have been opened. Re-start fpdb to use this option.")) self.warning_box(_("Cannot open Database Maintenance window because other windows have been opened. Re-start fpdb to use this option."))
def dia_database_stats(self, widget, data=None): def dia_database_stats(self, widget, data=None):
self.warning_box(str=_("Number of Hands: ")+str(self.db.getHandCount())+ self.warning_box(str=_("Number of Hands: ") + str(self.db.getHandCount()) +
_("\nNumber of Tourneys: ")+str(self.db.getTourneyCount())+ _("\nNumber of Tourneys: ") + str(self.db.getTourneyCount()) +
_("\nNumber of TourneyTypes: ")+str(self.db.getTourneyTypeCount()), _("\nNumber of TourneyTypes: ") + str(self.db.getTourneyTypeCount()),
diatitle=_("Database Statistics")) diatitle=_("Database Statistics"))
#end def dia_database_stats #end def dia_database_stats
def diaHudConfigurator(self, widget, data=None): def diaHudConfigurator(self, widget, data=None):
"""Opens dialog to set parameters (game category, row count, column count for HUD stat configurator""" """Opens dialog to set parameters (game category, row count, column count for HUD stat configurator"""
self.hudConfiguratorRows=None self.hudConfiguratorRows = None
self.hudConfiguratorColumns=None self.hudConfiguratorColumns = None
self.hudConfiguratorGame=None self.hudConfiguratorGame = None
diaSelections = gtk.Dialog(_("HUD Configurator - choose category"), diaSelections = gtk.Dialog(_("HUD Configurator - choose category"),
self.window, self.window,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
label=gtk.Label(_("Please select the game category for which you want to configure HUD stats:")) label = gtk.Label(_("Please select the game category for which you want to configure HUD stats:"))
diaSelections.vbox.add(label) diaSelections.vbox.add(label)
label.show() label.show()
comboGame = gtk.combo_box_new_text() comboGame = gtk.combo_box_new_text()
comboGame.connect("changed", self.hudConfiguratorComboSelection) comboGame.connect("changed", self.hudConfiguratorComboSelection)
diaSelections.vbox.add(comboGame) diaSelections.vbox.add(comboGame)
games=self.config.get_supported_games() games = self.config.get_supported_games()
for game in games: for game in games:
comboGame.append_text(game) comboGame.append_text(game)
comboGame.set_active(0) comboGame.set_active(0)
comboGame.show() comboGame.show()
comboRows = gtk.combo_box_new_text() comboRows = gtk.combo_box_new_text()
comboRows.connect("changed", self.hudConfiguratorComboSelection) comboRows.connect("changed", self.hudConfiguratorComboSelection)
diaSelections.vbox.add(comboRows) diaSelections.vbox.add(comboRows)
for i in range(1,8): for i in range(1, 8):
comboRows.append_text(str(i)+" rows") comboRows.append_text(str(i) + " rows")
comboRows.set_active(0) comboRows.set_active(0)
comboRows.show() comboRows.show()
comboColumns = gtk.combo_box_new_text() comboColumns = gtk.combo_box_new_text()
comboColumns.connect("changed", self.hudConfiguratorComboSelection) comboColumns.connect("changed", self.hudConfiguratorComboSelection)
diaSelections.vbox.add(comboColumns) diaSelections.vbox.add(comboColumns)
for i in range(1,8): for i in range(1, 8):
comboColumns.append_text(str(i)+" columns") comboColumns.append_text(str(i) + " columns")
comboColumns.set_active(0) comboColumns.set_active(0)
comboColumns.show() comboColumns.show()
response=diaSelections.run() response = diaSelections.run()
diaSelections.destroy() diaSelections.destroy()
if response == gtk.RESPONSE_ACCEPT and self.hudConfiguratorRows!=None and self.hudConfiguratorColumns!=None and self.hudConfiguratorGame!=None: if (response == gtk.RESPONSE_ACCEPT and
self.hudConfiguratorRows != None and
self.hudConfiguratorColumns != None and
self.hudConfiguratorGame != None):
#print "clicked ok and selected:", self.hudConfiguratorGame,"with", str(self.hudConfiguratorRows), "rows and", str(self.hudConfiguratorColumns), "columns" #print "clicked ok and selected:", self.hudConfiguratorGame,"with", str(self.hudConfiguratorRows), "rows and", str(self.hudConfiguratorColumns), "columns"
self.diaHudConfiguratorTable() self.diaHudConfiguratorTable()
#end def diaHudConfigurator #end def diaHudConfigurator
def hudConfiguratorComboSelection(self, widget): def hudConfiguratorComboSelection(self, widget):
#TODO: remove this and handle it directly in diaHudConfigurator #TODO: remove this and handle it directly in diaHudConfigurator
result=widget.get_active_text() result = widget.get_active_text()
if result.endswith(" rows"): if result.endswith(" rows"):
self.hudConfiguratorRows=int(result[0]) self.hudConfiguratorRows = int(result[0])
elif result.endswith(" columns"): elif result.endswith(" columns"):
self.hudConfiguratorColumns=int(result[0]) self.hudConfiguratorColumns = int(result[0])
else: else:
self.hudConfiguratorGame=result self.hudConfiguratorGame = result
#end def hudConfiguratorComboSelection #end def hudConfiguratorComboSelection
def diaHudConfiguratorTable(self): def diaHudConfiguratorTable(self):
"""shows dialogue with Table of ComboBoxes to allow choosing of HUD stats""" """shows dialogue with Table of ComboBoxes to allow choosing of HUD stats"""
#TODO: add notices to hud configurator: no duplicates, no empties, display options #TODO: add notices to hud configurator: no duplicates, no empties, display options
@ -419,92 +423,103 @@ class fpdb:
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT, (gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT,
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
label=gtk.Label(_("Please choose the stats you wish to use in the below table.")) label = gtk.Label(_("Please choose the stats you wish to use in the below table."))
diaHudTable.vbox.add(label) diaHudTable.vbox.add(label)
label.show() label.show()
label=gtk.Label(_("Note that you may not select any stat more than once or it will crash.")) label = gtk.Label(_("Note that you may not select any stat more than once or it will crash."))
diaHudTable.vbox.add(label) diaHudTable.vbox.add(label)
label.show() label.show()
label=gtk.Label(_("It is not currently possible to select \"empty\" or anything else to that end.")) label = gtk.Label(_("It is not currently possible to select \"empty\" or anything else to that end."))
diaHudTable.vbox.add(label) diaHudTable.vbox.add(label)
label.show() label.show()
label=gtk.Label(_("To configure things like colouring you will still have to use the Preferences dialogue or manually edit your HUD_config.xml.")) label = gtk.Label(_("To configure things like colouring you will still have to use the Preferences dialogue or manually edit your HUD_config.xml."))
diaHudTable.vbox.add(label) diaHudTable.vbox.add(label)
label.show() label.show()
self.hudConfiguratorTableContents=[] self.hudConfiguratorTableContents = []
table= gtk.Table(rows=self.hudConfiguratorRows+1, columns=self.hudConfiguratorColumns+1, homogeneous=True) table = gtk.Table(rows=self.hudConfiguratorRows + 1, columns=self.hudConfiguratorColumns + 1, homogeneous=True)
statDir=dir(Stats) statDir = dir(Stats)
statDict={} statDict = {}
for attr in statDir: for attr in statDir:
if attr.startswith('__'): continue if attr.startswith('__'):
continue
if attr in ("Charset", "Configuration", "Database", "GInitiallyUnowned", "gtk", "pygtk", if attr in ("Charset", "Configuration", "Database", "GInitiallyUnowned", "gtk", "pygtk",
"player", "c", "db_connection", "do_stat", "do_tip", "stat_dict", "player", "c", "db_connection", "do_stat", "do_tip", "stat_dict",
"h", "re", "re_Percent", "re_Places", ): continue "h", "re", "re_Percent", "re_Places", ):
statDict[attr]=eval("Stats.%s.__doc__" % (attr)) continue
statDict[attr] = eval("Stats.%s.__doc__" % (attr))
for rowNumber in range(self.hudConfiguratorRows+1):
newRow=[] for rowNumber in range(self.hudConfiguratorRows + 1):
for columnNumber in range(self.hudConfiguratorColumns+1): newRow = []
if rowNumber==0: for columnNumber in range(self.hudConfiguratorColumns + 1):
if columnNumber==0: if rowNumber == 0:
if columnNumber == 0:
pass pass
else: else:
label=gtk.Label("column "+str(columnNumber)) label = gtk.Label("column " + str(columnNumber))
table.attach(child=label, left_attach=columnNumber, right_attach=columnNumber+1, top_attach=rowNumber, bottom_attach=rowNumber+1) table.attach(child=label, left_attach=columnNumber,
right_attach=columnNumber + 1,
top_attach=rowNumber,
bottom_attach=rowNumber + 1)
label.show() label.show()
elif columnNumber==0: elif columnNumber == 0:
label=gtk.Label("row "+str(rowNumber)) label = gtk.Label("row " + str(rowNumber))
table.attach(child=label, left_attach=columnNumber, right_attach=columnNumber+1, top_attach=rowNumber, bottom_attach=rowNumber+1) table.attach(child=label, left_attach=columnNumber,
right_attach=columnNumber + 1,
top_attach=rowNumber,
bottom_attach=rowNumber + 1)
label.show() label.show()
else: else:
comboBox = gtk.combo_box_new_text() comboBox = gtk.combo_box_new_text()
for stat in statDict.keys(): for stat in statDict.keys():
comboBox.append_text(stat) comboBox.append_text(stat)
comboBox.set_active(0) comboBox.set_active(0)
newRow.append(comboBox) newRow.append(comboBox)
table.attach(child=comboBox, left_attach=columnNumber, right_attach=columnNumber+1, top_attach=rowNumber, bottom_attach=rowNumber+1) table.attach(child=comboBox, left_attach=columnNumber,
right_attach=columnNumber + 1,
top_attach=rowNumber,
bottom_attach=rowNumber + 1)
comboBox.show() comboBox.show()
if rowNumber!=0: if rowNumber != 0:
self.hudConfiguratorTableContents.append(newRow) self.hudConfiguratorTableContents.append(newRow)
diaHudTable.vbox.add(table) diaHudTable.vbox.add(table)
table.show() table.show()
response=diaHudTable.run() response = diaHudTable.run()
diaHudTable.destroy() diaHudTable.destroy()
if response == gtk.RESPONSE_ACCEPT: if response == gtk.RESPONSE_ACCEPT:
self.storeNewHudStatConfig() self.storeNewHudStatConfig()
#end def diaHudConfiguratorTable #end def diaHudConfiguratorTable
def storeNewHudStatConfig(self): def storeNewHudStatConfig(self):
"""stores selections made in diaHudConfiguratorTable""" """stores selections made in diaHudConfiguratorTable"""
self.obtain_global_lock("diaHudConfiguratorTable") self.obtain_global_lock("diaHudConfiguratorTable")
statTable=[] statTable = []
for row in self.hudConfiguratorTableContents: for row in self.hudConfiguratorTableContents:
newRow=[] newRow = []
for column in row: for column in row:
newField = column.get_active_text() newField = column.get_active_text()
newRow.append(newField) newRow.append(newField)
statTable.append(newRow) statTable.append(newRow)
self.config.editStats(self.hudConfiguratorGame,statTable) self.config.editStats(self.hudConfiguratorGame, statTable)
self.config.save() #TODO: make it not store in horrible formatting self.config.save() # TODO: make it not store in horrible formatting
self.release_global_lock() self.release_global_lock()
#end def storeNewHudStatConfig #end def storeNewHudStatConfig
def dia_dump_db(self, widget, data=None): def dia_dump_db(self, widget, data=None):
filename = "database-dump.sql" filename = "database-dump.sql"
result = self.db.dumpDatabase() result = self.db.dumpDatabase()
dumpFile = open(filename, 'w') dumpFile = open(filename, 'w')
dumpFile.write(result) dumpFile.write(result)
dumpFile.close() dumpFile.close()
@ -543,7 +558,7 @@ class fpdb:
diastring = _("Please confirm that you want to (re-)create the tables.") \ diastring = _("Please confirm that you want to (re-)create the tables.") \
+ (_(" If there already are tables in the database %s on %s they will be deleted and you will have to re-import your histories.\n") % (self.db.database, self.db.host)) \ + (_(" If there already are tables in the database %s on %s they will be deleted and you will have to re-import your histories.\n") % (self.db.database, self.db.host)) \
+ _("This may take a while.") + _("This may take a while.")
dia_confirm.format_secondary_text(diastring)#todo: make above string with bold for db, host and deleted dia_confirm.format_secondary_text(diastring) # todo: make above string with bold for db, host and deleted
# disable windowclose, do not want the the underlying processing interrupted mid-process # disable windowclose, do not want the the underlying processing interrupted mid-process
dia_confirm.set_deletable(False) dia_confirm.set_deletable(False)
@ -581,7 +596,7 @@ class fpdb:
hb1 = gtk.HBox(True, 1) hb1 = gtk.HBox(True, 1)
self.h_start_date = gtk.Entry(max=12) self.h_start_date = gtk.Entry(max=12)
self.h_start_date.set_text( self.db.get_hero_hudcache_start() ) self.h_start_date.set_text(self.db.get_hero_hudcache_start())
lbl = gtk.Label(_(" Hero's cache starts: ")) lbl = gtk.Label(_(" Hero's cache starts: "))
btn = gtk.Button() btn = gtk.Button()
btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)) btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
@ -595,7 +610,7 @@ class fpdb:
hb2 = gtk.HBox(True, 1) hb2 = gtk.HBox(True, 1)
self.start_date = gtk.Entry(max=12) self.start_date = gtk.Entry(max=12)
self.start_date.set_text( self.db.get_hero_hudcache_start() ) self.start_date.set_text(self.db.get_hero_hudcache_start())
lbl = gtk.Label(_(" Villains' cache starts: ")) lbl = gtk.Label(_(" Villains' cache starts: "))
btn = gtk.Button() btn = gtk.Button()
btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)) btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
@ -615,7 +630,7 @@ class fpdb:
while gtk.events_pending(): while gtk.events_pending():
gtk.main_iteration_do(False) gtk.main_iteration_do(False)
self.db.rebuild_hudcache( self.h_start_date.get_text(), self.start_date.get_text() ) self.db.rebuild_hudcache(self.h_start_date.get_text(), self.start_date.get_text())
elif response == gtk.RESPONSE_NO: elif response == gtk.RESPONSE_NO:
print _('User cancelled rebuilding hud cache') print _('User cancelled rebuilding hud cache')
@ -625,11 +640,11 @@ class fpdb:
def dia_rebuild_indexes(self, widget, data=None): def dia_rebuild_indexes(self, widget, data=None):
if self.obtain_global_lock("dia_rebuild_indexes"): if self.obtain_global_lock("dia_rebuild_indexes"):
self.dia_confirm = gtk.MessageDialog(parent=self.window self.dia_confirm = gtk.MessageDialog(parent=self.window,
,flags=gtk.DIALOG_DESTROY_WITH_PARENT flags=gtk.DIALOG_DESTROY_WITH_PARENT,
,type=gtk.MESSAGE_WARNING type=gtk.MESSAGE_WARNING,
,buttons=(gtk.BUTTONS_YES_NO) buttons=(gtk.BUTTONS_YES_NO),
,message_format=_("Confirm rebuilding database indexes")) message_format=_("Confirm rebuilding database indexes"))
diastring = _("Please confirm that you want to rebuild the database indexes.") diastring = _("Please confirm that you want to rebuild the database indexes.")
self.dia_confirm.format_secondary_text(diastring) self.dia_confirm.format_secondary_text(diastring)
# disable windowclose, do not want the the underlying processing interrupted mid-process # disable windowclose, do not want the the underlying processing interrupted mid-process
@ -693,7 +708,6 @@ class fpdb:
self.logbuffer.insert(end_iter, text) self.logbuffer.insert(end_iter, text)
self.logview.scroll_to_mark(self.logbuffer.get_insert(), 0) self.logview.scroll_to_mark(self.logbuffer.get_insert(), 0)
def process_close_messages(self): def process_close_messages(self):
# check for close messages # check for close messages
try: try:
@ -847,29 +861,28 @@ class fpdb:
window.add_accel_group(accel_group) window.add_accel_group(accel_group)
return menubar return menubar
#end def get_menu #end def get_menu
def load_profile(self, create_db = False): def load_profile(self, create_db=False):
"""Loads profile from the provided path name.""" """Loads profile from the provided path name."""
self.config = Configuration.Config(file=options.config, dbname=options.dbname) self.config = Configuration.Config(file=options.config, dbname=options.dbname)
if self.config.file_error: if self.config.file_error:
self.warning_box(_("There is an error in your config file\n") + self.config.file self.warning_box(_("There is an error in your config file\n") + self.config.file
+ _("\n\nError is: ") + str(self.config.file_error) + _("\n\nError is: ") + str(self.config.file_error),
, diatitle=_("CONFIG FILE ERROR")) diatitle=_("CONFIG FILE ERROR"))
sys.exit() sys.exit()
log = Configuration.get_logger("logging.conf", "fpdb", log_dir=self.config.dir_log) log = Configuration.get_logger("logging.conf", "fpdb", log_dir=self.config.dir_log)
print (_("Logfile is %s\n") % os.path.join(self.config.dir_log, self.config.log_file)) print (_("Logfile is %s\n") % os.path.join(self.config.dir_log, self.config.log_file))
if self.config.example_copy: if self.config.example_copy:
self.info_box(_("Config file") self.info_box(_("Config file"),
, _("has been created at:\n%s.\n") % self.config.file _("has been created at:\n%s.\n") % self.config.file
+ _("Edit your screen_name and hand history path in the supported_sites section of the Preferences window (Main menu) before trying to import hands.")) + _("Edit your screen_name and hand history path in the supported_sites section of the Preferences window (Main menu) before trying to import hands."))
self.settings = {} self.settings = {}
self.settings['global_lock'] = self.lock self.settings['global_lock'] = self.lock
if (os.sep=="/"): if (os.sep == "/"):
self.settings['os']="linuxmac" self.settings['os'] = "linuxmac"
else: else:
self.settings['os']="windows" self.settings['os'] = "windows"
self.settings.update({'cl_options': cl_options}) self.settings.update({'cl_options': cl_options})
self.settings.update(self.config.get_db_parameters()) self.settings.update(self.config.get_db_parameters())
@ -879,10 +892,10 @@ class fpdb:
if self.db is not None and self.db.is_connected(): if self.db is not None and self.db.is_connected():
self.db.disconnect() self.db.disconnect()
self.sql = SQL.Sql(db_server = self.settings['db-server']) self.sql = SQL.Sql(db_server=self.settings['db-server'])
err_msg = None err_msg = None
try: try:
self.db = Database.Database(self.config, sql = self.sql) self.db = Database.Database(self.config, sql=self.sql)
if self.db.get_backend_name() == 'SQLite': if self.db.get_backend_name() == 'SQLite':
# tell sqlite users where the db file is # tell sqlite users where the db file is
print (_("Connected to SQLite: %s") % self.db.db_path) print (_("Connected to SQLite: %s") % self.db.db_path)
@ -919,7 +932,8 @@ class fpdb:
# sys.stderr.write("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user'])) # sys.stderr.write("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']))
if self.db is not None and self.db.wrongDbVersion: if self.db is not None and self.db.wrongDbVersion:
diaDbVersionWarning = gtk.Dialog(title=_("Strong Warning - Invalid database version"), parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) diaDbVersionWarning = gtk.Dialog(title=_("Strong Warning - Invalid database version"),
parent=None, flags=0, buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
label = gtk.Label(_("An invalid DB version or missing tables have been detected.")) label = gtk.Label(_("An invalid DB version or missing tables have been detected."))
diaDbVersionWarning.vbox.add(label) diaDbVersionWarning.vbox.add(label)
@ -944,14 +958,14 @@ class fpdb:
if self.db is not None and self.db.is_connected(): if self.db is not None and self.db.is_connected():
self.status_bar.set_text(_("Status: Connected to %s database named %s on host %s") self.status_bar.set_text(_("Status: Connected to %s database named %s on host %s")
% (self.db.get_backend_name(),self.db.database, self.db.host)) % (self.db.get_backend_name(), self.db.database, self.db.host))
# rollback to make sure any locks are cleared: # rollback to make sure any locks are cleared:
self.db.rollback() self.db.rollback()
self.validate_config() self.validate_config()
def obtain_global_lock(self, source): def obtain_global_lock(self, source):
ret = self.lock.acquire(source=source) # will return false if lock is already held ret = self.lock.acquire(source=source) # will return false if lock is already held
if ret: if ret:
print (_("\nGlobal lock taken by %s") % source) print (_("\nGlobal lock taken by %s") % source)
self.lockTakenBy=source self.lockTakenBy=source
@ -969,14 +983,14 @@ class fpdb:
print _("Quitting normally") print _("Quitting normally")
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 is not 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():
self.db.disconnect() self.db.disconnect()
except _mysql_exceptions.OperationalError: # oh, damn, we're already disconnected except _mysql_exceptions.OperationalError: # oh, damn, we're already disconnected
pass pass
else: else:
if self.db is not None and self.db.is_connected(): if self.db is not None and self.db.is_connected():
@ -985,12 +999,12 @@ class fpdb:
pass pass
self.statusIcon.set_visible(False) self.statusIcon.set_visible(False)
self.window.destroy() # explicitly destroy to allow child windows to close cleanly self.window.destroy() # explicitly destroy to allow child windows to close cleanly
gtk.main_quit() gtk.main_quit()
def release_global_lock(self): def release_global_lock(self):
self.lock.release() self.lock.release()
self.lockTakenBy=None self.lockTakenBy = None
print _("Global lock released.\n") print _("Global lock released.\n")
def tab_auto_import(self, widget, data=None): def tab_auto_import(self, widget, data=None):
@ -1023,7 +1037,7 @@ class fpdb:
tab=new_thread.get_vbox() tab=new_thread.get_vbox()
self.add_and_display_tab(tab, _("eMail Import")) self.add_and_display_tab(tab, _("eMail Import"))
#end def tab_import_imap_summaries #end def tab_import_imap_summaries
def tab_ring_player_stats(self, widget, data=None): def tab_ring_player_stats(self, widget, data=None):
new_ps_thread = GuiRingPlayerStats.GuiRingPlayerStats(self.config, self.sql, self.window) new_ps_thread = GuiRingPlayerStats.GuiRingPlayerStats(self.config, self.sql, self.window)
self.threads.append(new_ps_thread) self.threads.append(new_ps_thread)
@ -1110,7 +1124,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
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.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) 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 # create window, move it to specific location on command line
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
@ -1119,7 +1133,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
options.xloc = 0 options.xloc = 0
if options.yloc is None: if options.yloc is None:
options.yloc = 0 options.yloc = 0
self.window.move(options.xloc,options.yloc) self.window.move(options.xloc, options.yloc)
# connect to required events # connect to required events
self.window.connect("delete_event", self.delete_event) self.window.connect("delete_event", self.delete_event)
@ -1129,8 +1143,10 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
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()
if sx < defx: defx = sx if sx < defx:
if sy < defy: defy = sy defx = sx
if sy < defy:
defy = sy
self.window.set_default_size(defx, defy) self.window.set_default_size(defx, defy)
self.window.set_resizable(True) self.window.set_resizable(True)
@ -1162,13 +1178,13 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
if options.minimized: if options.minimized:
self.window.iconify() self.window.iconify()
if options.hidden: if options.hidden:
self.window.hide() self.window.hide()
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 # setup error logging
if not options.errorsToConsole: if not options.errorsToConsole:
@ -1181,7 +1197,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
# set up tray-icon and menu # 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')
if os.path.exists(cards): if os.path.exists(cards):
self.statusIcon.set_from_file(cards) self.statusIcon.set_from_file(cards)
self.window.set_icon_from_file(cards) self.window.set_icon_from_file(cards)
@ -1195,7 +1211,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
self.statusIcon.connect('activate', self.statusicon_activate) self.statusIcon.connect('activate', self.statusicon_activate)
self.statusMenu = gtk.Menu() self.statusMenu = gtk.Menu()
# set default menu options # set default menu options
self.addImageToTrayMenu(gtk.STOCK_ABOUT, self.dia_about) self.addImageToTrayMenu(gtk.STOCK_ABOUT, self.dia_about)
self.addImageToTrayMenu(gtk.STOCK_QUIT, self.quit) self.addImageToTrayMenu(gtk.STOCK_QUIT, self.quit)
@ -1255,7 +1271,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
# Tell GTK not to propagate this signal any further # Tell GTK not to propagate this signal any further
return True return True
def statusicon_menu(self, widget, button, time, data = None): def statusicon_menu(self, widget, button, time, data=None):
# we don't need to pass data here, since we do keep track of most all # we don't need to pass data here, since we do keep track of most all
# our variables .. the example code that i looked at for this # our variables .. the example code that i looked at for this
# didn't use any long scope variables.. which might be an alright # didn't use any long scope variables.. which might be an alright
@ -1266,7 +1282,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
data.popup(None, None, None, 3, time) data.popup(None, None, None, 3, time)
pass pass
def statusicon_activate(self, widget, data = None): def statusicon_activate(self, widget, data=None):
# Let's allow the tray icon to toggle window visibility, the way # Let's allow the tray icon to toggle window visibility, the way
# most other apps work # most other apps work
if self.visible: if self.visible:
@ -1275,15 +1291,17 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
self.window.present() self.window.present()
def info_box(self, str1, str2): def info_box(self, str1, str2):
diapath = gtk.MessageDialog( parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_INFO diapath = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_INFO,
, buttons=(gtk.BUTTONS_OK), message_format=str1 ) buttons=(gtk.BUTTONS_OK), message_format=str1)
diapath.format_secondary_text(str2) diapath.format_secondary_text(str2)
response = diapath.run() response = diapath.run()
diapath.destroy() diapath.destroy()
return response return response
def warning_box(self, str, diatitle=_("FPDB WARNING")): def warning_box(self, str, diatitle=_("FPDB WARNING")):
diaWarning = gtk.Dialog(title=diatitle, parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) diaWarning = gtk.Dialog(title=diatitle, parent=self.window,
flags=gtk.DIALOG_DESTROY_WITH_PARENT,
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
label = gtk.Label(str) label = gtk.Label(str)
diaWarning.vbox.add(label) diaWarning.vbox.add(label)
@ -1296,10 +1314,10 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
def validate_config(self): def validate_config(self):
# can this be removed now? # can this be removed now?
if self.config.get_import_parameters().get('saveStarsHH'): if self.config.get_import_parameters().get('saveStarsHH'):
hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = self.config.get_import_parameters().get("hhArchiveBase")
hhbase = os.path.expanduser(hhbase) hhbase = os.path.expanduser(hhbase)
#hhdir = os.path.join(hhbase,site) #hhdir = os.path.join(hhbase,site)
hhdir = hhbase hhdir = hhbase
if not os.path.isdir(hhdir): if not os.path.isdir(hhdir):
diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir") diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir")
diastring = _("WARNING: Unable to find output hand history directory %s\n\n Press YES to create this directory, or NO to select a new one.") % hhdir diastring = _("WARNING: Unable to find output hand history directory %s\n\n Press YES to create this directory, or NO to select a new one.") % hhdir
@ -1318,7 +1336,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
for site in self.config.get_supported_sites(True): # get site names from config file for site in self.config.get_supported_sites(True): # get site names from config file
try: try:
self.config.get_site_id(site) # and check against list from db self.config.get_site_id(site) # and check against list from db
except KeyError , exc: except KeyError, exc:
log.warning("site %s missing from db" % site) log.warning("site %s missing from db" % site)
dia = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Unknown Site") dia = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Unknown Site")
diastring = _("WARNING: Unable to find site '%s'\n\nPress YES to add this site to the database.") % site diastring = _("WARNING: Unable to find site '%s'\n\nPress YES to add this site to the database.") % site
@ -1329,15 +1347,15 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
self.add_site(site) self.add_site(site)
def add_site(self, site): def add_site(self, site):
dia = gtk.Dialog( title="Add Site", parent=self.window dia = gtk.Dialog(title="Add Site", parent=self.window,
, flags=gtk.DIALOG_DESTROY_WITH_PARENT flags=gtk.DIALOG_DESTROY_WITH_PARENT,
, buttons=(gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT buttons=(gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT,
,gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT) gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
) )
h = gtk.HBox() h = gtk.HBox()
dia.vbox.pack_start(h, padding=5) # sets horizontal padding dia.vbox.pack_start(h, padding=5) # sets horizontal padding
label = gtk.Label( _("\nEnter short code for %s\n(up to 3 characters):\n") % site ) label = gtk.Label(_("\nEnter short code for %s\n(up to 3 characters):\n") % site)
h.pack_start(label, padding=20) # sets horizontal padding h.pack_start(label, padding=20) # sets horizontal padding
#label.set_alignment(1.0, 0.5) #label.set_alignment(1.0, 0.5)
@ -1347,8 +1365,8 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an
e_code.set_width_chars(5) e_code.set_width_chars(5)
h.pack_start(e_code, True, False, padding=5) h.pack_start(e_code, True, False, padding=5)
label = gtk.Label( "" ) label = gtk.Label("")
dia.vbox.add(label) # create space below entry, maybe padding arg above makes this redundant? dia.vbox.add(label) # create space below entry, maybe padding arg above makes this redundant?
dia.show_all() dia.show_all()
response = dia.run() response = dia.run()