summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/frames/network.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-06-02 21:01:41 +0200
committeremkael <emkael@tlen.pl>2019-06-02 21:01:41 +0200
commit82fb45bac50bd740ed4118621027ec63582a51fe (patch)
tree3ef8627388821d3d6aac9fd27efbbd2cd6722b61 /jfr_playoff/gui/frames/network.py
parentbec32a9f57abdf0ba20e2e64920648f2d7e993d4 (diff)
Moving MySQL configuration frame to separate widget
Diffstat (limited to 'jfr_playoff/gui/frames/network.py')
-rw-r--r--jfr_playoff/gui/frames/network.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/jfr_playoff/gui/frames/network.py b/jfr_playoff/gui/frames/network.py
new file mode 100644
index 0000000..14deaa0
--- /dev/null
+++ b/jfr_playoff/gui/frames/network.py
@@ -0,0 +1,76 @@
+#coding=utf-8
+
+import tkinter as tk
+from tkinter import ttk
+import tkMessageBox as tkmb
+
+from ...db import PlayoffDB
+from ..frames import getIntVal
+
+class MySQLConfigurationFrame(tk.Frame):
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.renderContent(self)
+
+ def getConfig(self):
+ if len(self.host.get().strip()):
+ return {
+ 'host': self.host.get().strip(),
+ 'port': getIntVal(self.port, default=3306),
+ 'user': self.user.get().strip(),
+ 'pass': self.pass_.get().strip()
+ }
+ return None
+
+ def _testDB(self):
+ try:
+ dbConfig = self.getConfig()
+ if dbConfig is None:
+ raise AttributeError('Database not configured')
+ db = PlayoffDB(dbConfig)
+ self.dbError = None
+ self.dbTestLabel.configure(text='✓')
+ self.dbTestLabel.configure(foreground='green')
+ except Exception as e:
+ self.dbError = unicode(e)
+ self.dbTestLabel.configure(text='✗')
+ self.dbTestLabel.configure(foreground='red')
+
+ def _dbError(self, event):
+ if self.dbError is not None:
+ tkmb.showerror('Błąd połączenia z bazą danych', self.dbError)
+
+ 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()
+ (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)
+ (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()
+ (ttk.Entry(container, textvariable=self.user)).grid(
+ row=2, column=1, sticky=tk.E+tk.W)
+ (ttk.Button(
+ container, text='Testuj ustawienia', command=self._testDB)).grid(
+ row=2, column=3)
+ self.dbError = None
+ self.dbTestLabel = ttk.Label(container)
+ self.dbTestLabel.grid(row=2, column=4)
+ self.dbTestLabel.bind('<Button-1>', self._dbError)
+ (ttk.Label(container, text='Hasło:')).grid(
+ row=3, column=0, sticky=tk.E)
+ self.pass_ = tk.StringVar()
+ (ttk.Entry(container, textvariable=self.pass_, show='*')).grid(
+ row=3, column=1, sticky=tk.E+tk.W)
+
+__all__ = ['MySQLConfigurationFrame']