From 75a0034798d7f2d9befa9cdfd755dc12870bfc1b Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Tue, 6 Feb 2024 19:41:45 +0100 Subject: [PATCH 1/4] Disabled buttons on MacOS On MacOS disabled buttons are not grey. Set some color style for that case. --- src/neknihy.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/neknihy.py b/src/neknihy.py index 16232d7..583d52c 100755 --- a/src/neknihy.py +++ b/src/neknihy.py @@ -79,9 +79,10 @@ def createGUI(self): self._window.minsize(600, 400) self._icon = tk.PhotoImage(file=os.path.join(resources, 'neknihy.png')) self._window.iconphoto(True, self._icon) + style = ttk.Style(self._window) if sys.platform == "darwin": - style = ttk.Style(self._window) style.theme_use('default') + style.map('TButton', background=[('disabled', '#BBBBBB')]) nb = ttk.Notebook(self._window) p1 = ttk.Frame(nb) @@ -111,28 +112,31 @@ def createGUI(self): length=70) self._toolbarButtons = [] - button = ttk.Button(toolbar, image=self._img_refresh, command=self.onRefreshBooks) + button = ttk.Button(toolbar, image=self._img_refresh, + command=self.onRefreshBooks, style="TButton") button.pack(side="left", padx=5, pady=5) self.addTooltip(button, "Načíst nové výpůjčky") self._toolbarButtons.append(button) - button = ttk.Button(toolbar, image=self._img_download, command=self.onDownloadBooks) + button = ttk.Button(toolbar, image=self._img_download, + command=self.onDownloadBooks, style="TButton") button.pack(side="left", padx=5, pady=5) self.addTooltip(button, "Stáhnout nově zapůjčené knihy") self._toolbarButtons.append(button) - button = ttk.Button(toolbar, image=self._img_return, command=self.onReturnBooks) + button = ttk.Button(toolbar, image=self._img_return, + command=self.onReturnBooks, style="TButton") button.pack(side="left", padx=5, pady=5) self.addTooltip(button, "Smazat knihy, u kterých\nvypršela výpůjční doba") self._toolbarButtons.append(button) - self._sync_button = ttk.Button(toolbar, - image=self._img_to_reader, - command=self.onSyncReader) + self._sync_button = ttk.Button(toolbar, image=self._img_to_reader, + command=self.onSyncReader, style="TButton") self._sync_button.pack(side="left", padx=5, pady=5) self.addTooltip(self._sync_button, "Synchronizovat výpůjčky s čtečkou") - button = ttk.Button(toolbar, image=self._img_open, command=self.onShowBooks) + button = ttk.Button(toolbar, image=self._img_open, + command=self.onShowBooks, style="TButton") button.pack(side="left", padx=5, pady=5) self.addTooltip(button, "Otevřít složku s knihami") From 56ca25f69b2fede1ff3d0949c18f45700ce6d24b Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Tue, 6 Feb 2024 19:46:07 +0100 Subject: [PATCH 2/4] Refresh book list also when user clicks on download --- src/neknihy.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/neknihy.py b/src/neknihy.py index 583d52c..e7d701e 100755 --- a/src/neknihy.py +++ b/src/neknihy.py @@ -323,6 +323,9 @@ def onRefreshBooks(self): self.backgroundTaskMonitor() def downloadBooks(self): + self.refreshBooks() + if self._error is not None: + return try: self.app.downloadBooks() self._error = None From 852307ace9b085fb1b88fb078966a87dfa045534 Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Tue, 6 Feb 2024 19:51:28 +0100 Subject: [PATCH 3/4] Improve books download Iterate trough all books, even when exception happend on some of them. --- src/neknihy/app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/neknihy/app.py b/src/neknihy/app.py index c9c5490..0ac2a6a 100644 --- a/src/neknihy/app.py +++ b/src/neknihy/app.py @@ -116,11 +116,17 @@ def downloadBooks(self): if not self.settings.configured(): return self.api.login(self.settings.email, self.settings.password) + exc = None for i in range(len(self.books)): - if not self.bookDownloaded(i): - self.downloadBook(i) + try: + if not self.bookDownloaded(i): + self.downloadBook(i) + except Exception as e: + exc = e self.saveBooks() self.updateStatus() + if exc is not None: + raise exc def returnBooks(self): books = [] From 4fcd33f5f44234d408ac5dca9f943426b4b68526 Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Tue, 6 Feb 2024 20:33:34 +0100 Subject: [PATCH 4/4] Import message improvement --- src/neknihy.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/neknihy.py b/src/neknihy.py index e7d701e..ef6cce4 100755 --- a/src/neknihy.py +++ b/src/neknihy.py @@ -36,6 +36,24 @@ def __init__(self, configfile, debug=False): self.updateBookList() self.syncButtonMonitor() + self.gettext_map = { + "pridano": [ + "Do čtečky byla přidána %i kniha, ", + "Do čtečky byly přidány %i knihy, ", + "Do čtečky bylo přidáno %i knih, " + ], + "odstraneno": [ + "odstraněna byla %i kniha, ", + "odstraněny byly %i knihy, ", + "odstraněno bylo %i knih, " + ], + "celkem": [ + "ve čtečce je %i vypůjčená kniha.", + "ve čtečce jsou %i vypůjčené knihy.", + "ve čtečce je %i vypůjčených knih." + ] + } + def _resourcesFolder(self): for resources in [ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources'), @@ -74,6 +92,7 @@ def addTooltip(self, button, tip): def createGUI(self): resources = self._resourcesFolder() self._window = tk.Tk() + self._window.option_add('*Dialog.msg.font', 'Helvetica 12') self._window.title("Neknihy") self._window.geometry("800x600") self._window.minsize(600, 400) @@ -343,6 +362,14 @@ def onReturnBooks(self): self.app.returnBooks() self.updateBookList() + def gettext(self, sentence, amount): + idx = 0 + if amount > 1: + idx = 1 + if amount >= 5 or amount == 0: + idx = 2 + return self.gettext_map[sentence][idx] % (amount) + def syncReader(self): try: self._message = None @@ -350,10 +377,9 @@ def syncReader(self): result = self.app.syncReader() if result is not None: self._message = ( - "Přidáno/odstraněno/zůstává ve čtečce: %i/%i/%i" % ( - len(result["added"]), - len(result["removed"]), - result["total"]) + self.gettext("pridano", len(result["added"])) + + self.gettext("odstraneno", len(result["removed"])) + + self.gettext("celkem", result["total"]) ) except Exception as e: self._error = str(e)