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])