Modified Auto import GUI to allow n-sites based on config file. Added filter option to display. Added option to enable or disable sites in Config

This commit is contained in:
Worros 2008-11-06 18:39:49 +13:00
parent cf714a8ec1
commit 68344b5ec0
2 changed files with 93 additions and 100 deletions

View File

@ -57,6 +57,7 @@ class Site:
self.hudbgcolor = node.getAttribute("bgcolor")
self.hudfgcolor = node.getAttribute("fgcolor")
self.converter = node.getAttribute("converter")
self.enabled = node.getAttribute("enabled")
self.layout = {}
for layout_node in node.getElementsByTagName('layout'):
@ -494,13 +495,14 @@ class Config:
parms["site_path"] = self.supported_sites[site].site_path
parms["table_finder"] = self.supported_sites[site].table_finder
parms["HH_path"] = self.supported_sites[site].HH_path
parms["enabled"] = self.supported_sites[site].enabled
return parms
def set_site_parameters(self, site_name, converter = None, decoder = None,
hudbgcolor = None, hudfgcolor = None,
hudopacity = None, screen_name = None,
site_path = None, table_finder = None,
HH_path = None):
HH_path = None, enabled = None):
"""Sets the specified site parameters for the specified site."""
site_node = self.get_site_node(site_name)
if not db_node == None:
@ -513,6 +515,7 @@ class Config:
if not site_path == None: site_node.setAttribute("site_path", site_path)
if not table_finder == None: site_node.setAttribute("table_finder", table_finder)
if not HH_path == None: site_node.setAttribute("HH_path", HH_path)
if not enabled == None: site_node.setAttribute("enabled", enabled)
if self.supported_databases.has_key(db_name):
if not converter == None: self.supported_sites[site].converter = converter
@ -524,6 +527,7 @@ class Config:
if not site_path == None: self.supported_sites[site].site_path = site_path
if not table_finder == None: self.supported_sites[site].table_finder = table_finder
if not HH_path == None: self.supported_sites[site].HH_path = HH_path
if not enabled == None: self.supported_sites[site].enabled = enabled
return
if __name__== "__main__":

View File

@ -26,11 +26,56 @@ import os
import time
import fpdb_import
class GuiAutoImport (threading.Thread):
def starsBrowseClicked(self, widget, data):
"""runs when user clicks browse on auto import tab"""
#print "start of GuiAutoImport.starsBrowseClicked"
current_path=self.starsDirPath.get_text()
def __init__(self, settings, config):
"""Constructor for GuiAutoImport"""
self.settings=settings
self.config=config
self.input_settings = {}
self.importer = fpdb_import.Importer(self,self.settings)
self.importer.setCallHud(True)
self.importer.setMinPrint(30)
self.importer.setQuiet(False)
self.importer.setFailOnError(False)
self.importer.setHandCount(0)
# self.importer.setWatchTime()
self.server=settings['db-host']
self.user=settings['db-user']
self.password=settings['db-password']
self.database=settings['db-databaseName']
self.mainVBox=gtk.VBox(False,1)
self.mainVBox.show()
self.settingsHBox = gtk.HBox(False, 0)
self.mainVBox.pack_start(self.settingsHBox, False, True, 0)
self.settingsHBox.show()
self.intervalLabel = gtk.Label("Interval (ie. break) between imports in seconds:")
self.settingsHBox.pack_start(self.intervalLabel)
self.intervalLabel.show()
self.intervalEntry=gtk.Entry()
self.intervalEntry.set_text(str(self.settings['hud-defaultInterval']))
self.settingsHBox.pack_start(self.intervalEntry)
self.intervalEntry.show()
self.addSites(self.mainVBox)
self.startButton=gtk.Button("Start Autoimport")
self.startButton.connect("clicked", self.startClicked, "start clicked")
self.mainVBox.add(self.startButton)
self.startButton.show()
#end of GuiAutoImport.__init__
def browseClicked(self, widget, data):
"""runs when user clicks one of the browse buttons in the auto import tab"""
current_path=data[1].get_text()
dia_chooser = gtk.FileChooserDialog(title="Please choose the path that you want to auto import",
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
@ -42,32 +87,12 @@ class GuiAutoImport (threading.Thread):
response = dia_chooser.run()
if response == gtk.RESPONSE_OK:
#print dia_chooser.get_filename(), 'selected'
self.starsDirPath.set_text(dia_chooser.get_filename())
data[1].set_text(dia_chooser.get_filename())
self.input_settings[data[0]][0] = dia_chooser.get_filename()
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dia_chooser.destroy()
#end def GuiAutoImport.starsBrowseClicked
def tiltBrowseClicked(self, widget, data):
"""runs when user clicks browse on auto import tab"""
#print "start of GuiAutoImport.tiltBrowseClicked"
current_path=self.tiltDirPath.get_text()
dia_chooser = gtk.FileChooserDialog(title="Please choose the path that you want to auto import",
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
#dia_chooser.set_current_folder(pathname)
dia_chooser.set_filename(current_path)
#dia_chooser.set_select_multiple(select_multiple) #not in tv, but want this in bulk import
response = dia_chooser.run()
if response == gtk.RESPONSE_OK:
#print dia_chooser.get_filename(), 'selected'
self.tiltDirPath.set_text(dia_chooser.get_filename())
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dia_chooser.destroy()
#end def GuiAutoImport.tiltBrowseClicked
#end def GuiAutoImport.browseClicked
def do_import(self):
"""Callback for timer to do an import iteration."""
@ -106,12 +131,10 @@ class GuiAutoImport (threading.Thread):
# command = command + " %s" % (self.database)
# print "command = ", command
# self.pipe_to_hud = os.popen(command, 'w')
self.starspath=self.starsDirPath.get_text()
self.tiltpath=self.tiltDirPath.get_text()
# Add directory to importer object.
self.importer.addImportDirectory(self.starspath, True, "PokerStars", "passthrough")
self.importer.addImportDirectory(self.tiltpath, True, "FullTilt", "passthrough")
# Add directories to importer object.
for site in self.input_settings:
self.importer.addImportDirectory(self.input_settings[site][0], True, site, self.input_settings[site][1])
self.do_import()
interval=int(self.intervalEntry.get_text())
@ -123,78 +146,44 @@ class GuiAutoImport (threading.Thread):
return self.mainVBox
#end def get_vbox
def __init__(self, settings, config, debug=True):
"""Constructor for GuiAutoImport"""
self.settings=settings
self.config=config
self.importer = fpdb_import.Importer(self,self.settings)
self.importer.setCallHud(True)
self.importer.setMinPrint(30)
self.importer.setQuiet(False)
self.importer.setFailOnError(False)
self.importer.setHandCount(0)
# self.importer.setWatchTime()
#Create the site line given required info and setup callbacks
#enabling and disabling sites from this interface not possible
#expects a box to layout the line horizontally
def createSiteLine(self, hbox, site, iconpath, hhpath, filter_name, active = True):
label = gtk.Label(site + " auto-import:")
hbox.pack_start(label, False, False, 0)
label.show()
self.server=settings['db-host']
self.user=settings['db-user']
self.password=settings['db-password']
self.database=settings['db-databaseName']
dirPath=gtk.Entry()
dirPath.set_text(hhpath)
hbox.pack_start(dirPath, False, True, 0)
dirPath.show()
self.mainVBox=gtk.VBox(False,1)
self.mainVBox.show()
browseButton=gtk.Button("Browse...")
browseButton.connect("clicked", self.browseClicked, [site] + [dirPath])
hbox.pack_start(browseButton, False, False, 0)
browseButton.show()
self.settingsHBox = gtk.HBox(False, 0)
self.mainVBox.pack_start(self.settingsHBox, False, True, 0)
self.settingsHBox.show()
label = gtk.Label(site + " filter:")
hbox.pack_start(label, False, False, 0)
label.show()
self.intervalLabel = gtk.Label("Interval (ie. break) between imports in seconds:")
self.settingsHBox.pack_start(self.intervalLabel)
self.intervalLabel.show()
filter=gtk.Entry()
filter.set_text(filter_name)
hbox.pack_start(filter, False, True, 0)
filter.show()
self.intervalEntry=gtk.Entry()
self.intervalEntry.set_text(str(self.settings['hud-defaultInterval']))
self.settingsHBox.pack_start(self.intervalEntry)
self.intervalEntry.show()
def addSites(self, vbox):
for site in self.config.supported_sites.keys():
pathHBox = gtk.HBox(False, 0)
vbox.pack_start(pathHBox, False, True, 0)
pathHBox.show()
self.pathHBox = gtk.HBox(False, 0)
self.mainVBox.pack_start(self.pathHBox, False, True, 0)
self.pathHBox.show()
paths = self.config.get_default_paths(site)
params = self.config.get_site_parameters(site)
self.createSiteLine(pathHBox, site, False, paths['hud-defaultPath'], params['converter'], params['enabled'])
self.input_settings[site] = [paths['hud-defaultPath']] + [params['converter']]
self.pathStarsLabel = gtk.Label("Path to PokerStars auto-import:")
self.pathHBox.pack_start(self.pathStarsLabel, False, False, 0)
self.pathStarsLabel.show()
self.starsDirPath=gtk.Entry()
paths = self.config.get_default_paths("PokerStars")
self.starsDirPath.set_text(paths['hud-defaultPath'])
self.pathHBox.pack_start(self.starsDirPath, False, True, 0)
self.starsDirPath.show()
self.browseButton=gtk.Button("Browse...")
self.browseButton.connect("clicked", self.starsBrowseClicked, "Browse clicked")
self.pathHBox.pack_start(self.browseButton, False, False, 0)
self.browseButton.show()
self.pathTiltLabel = gtk.Label("Path to Full Tilt auto-import:")
self.pathHBox.pack_start(self.pathTiltLabel, False, False, 0)
self.pathTiltLabel.show()
self.tiltDirPath=gtk.Entry()
paths = self.config.get_default_paths("Full Tilt")
self.tiltDirPath.set_text(paths['hud-defaultPath'])
self.pathHBox.pack_start(self.tiltDirPath, False, True, 0)
self.tiltDirPath.show()
self.browseButton=gtk.Button("Browse...")
self.browseButton.connect("clicked", self.tiltBrowseClicked, "Browse clicked")
self.pathHBox.pack_start(self.browseButton, False, False, 0)
self.browseButton.show()
self.startButton=gtk.Button("Start Autoimport")
self.startButton.connect("clicked", self.startClicked, "start clicked")
self.mainVBox.add(self.startButton)
self.startButton.show()
#end of GuiAutoImport.__init__
if __name__== "__main__":
def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit()