aboutsummaryrefslogtreecommitdiff
path: root/src/application.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/application.py')
-rw-r--r--src/application.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/application.py b/src/application.py
new file mode 100644
index 0000000..46ab901
--- /dev/null
+++ b/src/application.py
@@ -0,0 +1,67 @@
+# To add CSS
+# https://github.com/Taiko2k/GTK4PythonTutorial/blob/main/README.md#adding-your-custom-css-stylesheet
+
+import gi
+gi.require_version('Gtk', '4.0')
+gi.require_version('Adw', '1')
+from gi.repository import Gtk, Adw
+
+from src.book_flow import BookFlow
+from src.filters import Filters
+from src.book_form import BookForm
+import src.utils as utils
+
+class MainWindow(Gtk.ApplicationWindow):
+ def __init__(self, resources, library, ereader, conn, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ utils.set_header_bar(self, 'Books')
+
+ scrolled_window = Gtk.ScrolledWindow()
+ self.set_child(scrolled_window)
+
+ init_progress = 'Reading'
+
+ add_book_button = Gtk.Button(label='Ajouter un livre')
+ add_book_button.connect('clicked', lambda _: BookForm(self, resources, library, conn, self._filters.get_progress(), self._on_book_added).present())
+
+ header = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
+ utils.set_margin(header, 20)
+ self._filters = Filters(init_progress, self._update_book_flow_progress)
+ self._filters.set_hexpand(True)
+ header.append(self._filters)
+ header.append(add_book_button)
+
+ box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
+ box.append(header)
+ self._book_flow = BookFlow(self, resources, library, ereader, conn, init_progress, self._update_filters_progress)
+ box.append(self._book_flow)
+ scrolled_window.set_child(box)
+
+ def _update_book_flow_progress(self, progress):
+ self._book_flow.update_progress(progress)
+
+ def _update_filters_progress(self, progress):
+ self._filters.update_progress(progress)
+
+ def _on_book_added(self, book_id, data):
+ self._update_filters_progress(data['progress'])
+ self._book_flow.add_book(book_id, data)
+
+class Application(Adw.Application):
+ def __init__(self, resources, library, ereader, conn, **kwargs):
+ super().__init__(**kwargs)
+ self.connect('activate', self.on_activate)
+
+ self._resources = resources
+ self._library = library
+ self._ereader = ereader
+ self._conn = conn
+
+ # Dark theme
+ sm = self.get_style_manager()
+ sm.set_color_scheme(Adw.ColorScheme.PREFER_DARK)
+
+ def on_activate(self, app):
+ self.win = MainWindow(self._resources, self._library, self._ereader, self._conn, application=app)
+ self.win.present()