diff options
| author | Joris Guyonvarch | 2025-12-26 18:41:26 +0100 |
|---|---|---|
| committer | Joris Guyonvarch | 2025-12-27 20:41:44 +0100 |
| commit | a110c200e86d2325af07167531fac0f61d9681a0 (patch) | |
| tree | 90e843f915a2e153ba735849afd83710d90560bf /src/application.py | |
| parent | a26d92ad5055fa057647158eb79511e7b1841162 (diff) | |
Switch to GUI to manage the library
Allow to regroup the CLI and the view into one unique tool.
Diffstat (limited to 'src/application.py')
| -rw-r--r-- | src/application.py | 67 |
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() |
