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/book_detail.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/book_detail.py')
| -rw-r--r-- | src/book_detail.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/book_detail.py b/src/book_detail.py new file mode 100644 index 0000000..168a212 --- /dev/null +++ b/src/book_detail.py @@ -0,0 +1,57 @@ +import gi +gi.require_version('Gtk', '4.0') +from gi.repository import Gtk +import os +import subprocess + +import src.utils as utils +import src.book_files as book_files + +class BookDetail(Gtk.Window): + + def __init__(self, parent_window, library, book_id, data): + Gtk.Window.__init__(self) + + utils.configure_dialog(self, parent_window, data['title'], height=800) + + scrolled_window = Gtk.ScrolledWindow() + self.set_child(scrolled_window) + + box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20) + scrolled_window.set_child(box) + utils.set_margin(box, 20) + + if has_info(data, 'subtitle'): + box.append(utils.label(data['subtitle'])) + + if has_info(data, 'year'): + box.append(utils.label(str(data['year']))) + + if len(data['authors']): + box.append(utils.label(', '.join(data['authors']))) + + if len(data['genres']): + box.append(utils.label(', '.join(data['genres']))) + + picture = Gtk.Picture.new_for_filename(f'{library}/{book_id}/cover.png') + picture.set_can_shrink(False) + box.append(picture) + + box.append(utils.label(data['summary'])) + + for path in book_files.get(library, book_id): + box.append(book_line(path)) + +def has_info(data, key): + return key in data and data[key] + +def book_line(path): + box = Gtk.Box(spacing=20) + box.append(utils.label(os.path.basename(path))) + open_button = Gtk.Button(label='Ouvrir') + open_button.connect('clicked', lambda _: open_book(path)) + box.append(open_button) + return box + +def open_book(path): + subprocess.run(['xdg-open', path]) |
