summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jfr_playoff/gui/__init__.py3
-rw-r--r--jfr_playoff/gui/frames/network.py8
-rw-r--r--jfr_playoff/gui/frames/team.py23
-rw-r--r--jfr_playoff/gui/tabs.py29
4 files changed, 60 insertions, 3 deletions
diff --git a/jfr_playoff/gui/__init__.py b/jfr_playoff/gui/__init__.py
index b654456..00f3292 100644
--- a/jfr_playoff/gui/__init__.py
+++ b/jfr_playoff/gui/__init__.py
@@ -22,3 +22,6 @@ class PlayoffGUI(tk.Tk):
def getTeams(self):
return self.tabs['TeamsTab'].getTeams()
+
+ def getDBs(self):
+ return self.tabs['NetworkTab'].getDBList()
diff --git a/jfr_playoff/gui/frames/network.py b/jfr_playoff/gui/frames/network.py
index 249cb1c..961ee21 100644
--- a/jfr_playoff/gui/frames/network.py
+++ b/jfr_playoff/gui/frames/network.py
@@ -43,24 +43,31 @@ class MySQLConfigurationFrame(tk.Frame):
if self.dbError is not None:
tkmb.showerror('Błąd połączenia z bazą danych', self.dbError)
+ def _changeNotify(self, *args):
+ self.winfo_toplevel().event_generate(
+ '<<DBSettingsChanged>>', when='tail')
+
def renderContent(self, container):
(ttk.Label(container, text='Ustawienia MySQL')).grid(
row=0, column=0, columnspan=4, sticky=tk.E+tk.W)
(ttk.Label(container, text='Host:')).grid(
row=1, column=0, sticky=tk.E)
self.host = tk.StringVar()
+ self.host.trace('w', self._changeNotify)
(ttk.Entry(container, textvariable=self.host)).grid(
row=1, column=1, sticky=tk.E+tk.W)
(ttk.Label(container, text='Port:')).grid(
row=1, column=2, sticky=tk.E)
self.port = tk.StringVar()
self.port.set(3306)
+ self.port.trace('w', self._changeNotify)
(tk.Spinbox(
container, textvariable=self.port, width=5,
from_=0, to=65535)).grid(row=1, column=3, sticky=tk.W)
(ttk.Label(container, text='Użytkownik:')).grid(
row=2, column=0, sticky=tk.E)
self.user = tk.StringVar()
+ self.user.trace('w', self._changeNotify)
(ttk.Entry(container, textvariable=self.user)).grid(
row=2, column=1, sticky=tk.E+tk.W)
(ttk.Button(
@@ -73,6 +80,7 @@ class MySQLConfigurationFrame(tk.Frame):
(ttk.Label(container, text='Hasło:')).grid(
row=3, column=0, sticky=tk.E)
self.pass_ = tk.StringVar()
+ self.pass_.trace('w', self._changeNotify)
(ttk.Entry(container, textvariable=self.pass_, show='*')).grid(
row=3, column=1, sticky=tk.E+tk.W)
diff --git a/jfr_playoff/gui/frames/team.py b/jfr_playoff/gui/frames/team.py
index 78b2be0..e7eb83d 100644
--- a/jfr_playoff/gui/frames/team.py
+++ b/jfr_playoff/gui/frames/team.py
@@ -139,19 +139,38 @@ class TeamFetchSettingsFrame(tk.Frame):
teams['max_teams'] = maxTeams
return teams
+ def _createDBList(self, values):
+ self.fetchDBField = ttk.OptionMenu(
+ self, self.fetchDB, *([''] + values))
+ self.fetchDBField.grid(row=0, column=3, sticky=tk.W+tk.E)
+
+ def _onDBListChange(self, *args):
+ self.fetchDBField.destroy()
+ self._createDBList(self.winfo_toplevel().getDBs())
+
+ def _sourceChange(self, *args):
+ self.fetchDBField.configure(state=tk.DISABLED)
+ self.fetchLink.configure(state=tk.DISABLED)
+ if self.fetchSource.get() == self.SOURCE_LINK:
+ self.fetchLink.configure(state=tk.NORMAL)
+ elif self.fetchSource.get() == self.SOURCE_DB:
+ self.fetchDBField.configure(state=tk.NORMAL)
+
def renderContent(self):
(ttk.Label(self, text=' ')).grid(row=0, column=0, rowspan=2)
self.fetchSource = tk.IntVar()
self.fetchSource.set(self.SOURCE_LINK)
+ self.fetchSource.trace('w', self._sourceChange)
(ttk.Radiobutton(
self, text='Baza danych',
variable=self.fetchSource, value=self.SOURCE_DB)).grid(
row=0, column=1, columnspan=2, sticky=tk.W)
self.fetchDB = tk.StringVar()
self.fetchDB.trace('w', self._changeNotify)
- (ttk.OptionMenu(self, self.fetchDB, '')).grid(
- row=0, column=3, sticky=tk.W+tk.E)
+ self._createDBList([])
+ self.winfo_toplevel().bind(
+ '<<DBListChanged>>', self._onDBListChange, add='+')
(ttk.Radiobutton(
self, text='Strona wyników',
diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py
index 2d96ce7..7cb908a 100644
--- a/jfr_playoff/gui/tabs.py
+++ b/jfr_playoff/gui/tabs.py
@@ -134,7 +134,9 @@ class TeamsTab(PlayoffTab):
if dbConfig is not None:
config['database'] = dbConfig
data = PlayoffData()
- self._teamList = data.fetch_team_list(config['teams'], dbConfig)
+ self._teamList = data.fetch_team_list(
+ config['teams'],
+ PlayoffDB(dbConfig) if dbConfig is not None else None)
self.winfo_toplevel().event_generate(
'<<TeamListChanged>>', when='tail')
@@ -166,6 +168,26 @@ class NetworkTab(PlayoffTab):
def title(self):
return 'Sieć'
+ def _onDBSettingsChange(self, event):
+ if self.dbFetchTimer is not None:
+ self.after_cancel(self.dbFetchTimer)
+ self.dbFetchTimer = self.after(1500, self._fetchDBList)
+
+ def _fetchDBList(self):
+ self._dbList = []
+ try:
+ db = PlayoffDB(self.getDB())
+ for row in db.fetch_all(
+ 'information_schema',
+ 'SELECT TABLE_SCHEMA FROM information_schema.COLUMNS WHERE TABLE_NAME = "admin" AND COLUMN_NAME = "teamcnt" ORDER BY TABLE_SCHEMA;', {}):
+ self._dbList.append(row[0])
+ except Exception as e:
+ pass
+ self.winfo_toplevel().event_generate('<<DBListChanged>>', when='tail')
+
+ def getDBList(self):
+ return self._dbList
+
def getDB(self):
return self.mysqlFrame.getConfig()
@@ -185,6 +207,11 @@ class NetworkTab(PlayoffTab):
self.remoteFrame = RemoteConfigurationFrame(container, vertical=True)
self.remoteFrame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
+ self._dbList = []
+ self.dbFetchTimer = None
+ self.winfo_toplevel().bind(
+ '<<DBSettingsChanged>>', self._onDBSettingsChange, add='+')
+
class VisualTab(PlayoffTab):
@property
def title(self):