1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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()
|