def set_book(self, book): """ Display the given book in the book overview. """ if self.book and self.book.id == book.id: self.update_time() return self.book = db.Book.get_by_id(book.id) if self.ui.is_playing and self.ui.titlebar.current_book and self.book.id == self.ui.titlebar.current_book.id: self.play_book_button.set_image(self.pause_img) else: self.play_book_button.set_image(self.play_img) self.name_label.set_text(book.name) self.author_label.set_text(book.author) self.update_offline_status() pixbuf = artwork_cache.get_cover_pixbuf( book, self.ui.window.get_scale_factor(), 250) if pixbuf: surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.ui.window.get_scale_factor(), None) self.cover_img.set_from_surface(surface) else: self.cover_img.set_from_icon_name("book-open-variant-symbolic", Gtk.IconSize.DIALOG) self.cover_img.props.pixel_size = 250 self.duration = db.get_book_duration(book) self.speed = self.book.playback_speed self.total_label.set_text( tools.seconds_to_human_readable(self.duration / self.speed)) self.last_played_label.set_text( tools.past_date_to_human_readable(book.last_played)) self.published_label.set_visible(False) self.published_text.set_visible(False) # track list # This box contains all track content self.track_box = Gtk.Box() self.track_box.set_orientation(Gtk.Orientation.VERTICAL) self.track_box.set_halign(Gtk.Align.START) self.track_box.set_valign(Gtk.Align.START) self.track_box.props.margin = 8 for track in db.tracks(book): self.track_box.add(TrackElement(track, self)) tools.remove_all_children(self.track_list_container) self.track_box.show_all() self.track_list_container.add(self.track_box) self._mark_current_track() self.update_time()
def set_book(self, book): if self.book is not None and self.book.id == book.id: self.update_time() return self.book = book if self.ui.is_playing and self.ui.titlebar.current_book is not None and self.book.id == self.ui.titlebar.current_book.id: self.play_book_button.set_image(self.pause_img) else: self.play_book_button.set_image(self.play_img) self.name_label.set_text(book.name) self.author_label.set_text(book.author) pixbuf = artwork_cache.get_cover_pixbuf( book, self.ui.window.get_scale_factor(), 250) surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.ui.window.get_scale_factor(), None) self.cover_img.set_from_surface(surface) self.duration = db.get_book_duration(book) self.speed = db.Book.select().where( db.Book.id == self.book.id).get().playback_speed self.total_label.set_text( tools.seconds_to_human_readable(self.duration / self.speed)) self.last_played_label.set_text( tools.past_date_to_human_readable(book.last_played)) self.published_label.set_visible(False) self.published_text.set_visible(False) # track list # This box contains all track content self.track_box = Gtk.Box() self.track_box.set_orientation(Gtk.Orientation.VERTICAL) self.track_box.set_halign(Gtk.Align.START) self.track_box.set_valign(Gtk.Align.START) self.track_box.props.margin = 8 count = 0 for track in db.tracks(book): self.track_box.add(TrackElement(track, self.ui, self)) count += 1 tools.remove_all_children(self.track_list_container) self.track_box.show_all() self.track_list_container.add(self.track_box) self._mark_current_track() self.update_time()
def __player_changed(self, event, message): """ """ if self.book is None or self.ui.titlebar.current_book is None or self.ui.titlebar.current_book.id != self.book.id: return if event == "play": self.play_book_button.set_image(self.pause_img) self.current_track_element.set_playing(True) self.last_played_label.set_text( tools.past_date_to_human_readable(message.book.last_played)) elif event == "pause": self.play_book_button.set_image(self.play_img) self.current_track_element.set_playing(False) elif event == "stop": self._mark_current_track() elif event == "track-changed": track = player.get_current_track() self.select_track(track, self.ui.is_playing)
def set_book(self, book): """ Display the given book in the book overview. """ if self.book and self.book.id == book.id: self.update_time() return self.book = Book.get(Book.id == book.id) if player.is_playing( ) and self.ui.titlebar.current_book and self.book.id == self.ui.titlebar.current_book.id: self.play_book_button.set_image(self.pause_img) else: self.play_book_button.set_image(self.play_img) self.name_label.set_text(book.name) self.author_label.set_text(book.author) self.update_offline_status() pixbuf = self._artwork_cache.get_cover_pixbuf( book, self.ui.window.get_scale_factor(), 250) if pixbuf: surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.ui.window.get_scale_factor(), None) self.cover_img.set_from_surface(surface) else: self.cover_img.set_from_icon_name("book-open-variant-symbolic", Gtk.IconSize.DIALOG) self.cover_img.props.pixel_size = 250 self.duration = get_book_duration(book) self.speed = self.book.playback_speed self.total_label.set_text( tools.seconds_to_human_readable(self.duration / self.speed)) self.last_played_label.set_text( tools.past_date_to_human_readable(book.last_played)) self.published_label.set_visible(False) self.published_text.set_visible(False) # track list # This box contains all track content self.track_box = Gtk.Box() self.track_box.set_orientation(Gtk.Orientation.VERTICAL) self.track_box.set_halign(Gtk.Align.START) self.track_box.set_valign(Gtk.Align.START) self.track_box.props.margin = 8 disk_number = -1 first_disk_element = None disk_count = 0 for track in get_tracks(book): # Insert disk headers if track.disk != disk_number: disc_element = DiskElement(track.disk) self.track_box.add(disc_element) if disk_number == -1: first_disk_element = disc_element if track.disk < 2: first_disk_element.set_hidden(True) else: first_disk_element.show_all() disc_element.show_all() disk_number = track.disk disk_count += 1 track_element = TrackElement(track, self) self.track_box.add(track_element) track_element.show_all() self.track_list_container.remove_all_children() self.track_box.show() self.track_box.set_halign(Gtk.Align.FILL) self.track_list_container.add(self.track_box) self._mark_current_track() self.update_time()
def last_played_text(self) -> Optional[str]: if not self._book: return None return tools.past_date_to_human_readable(self._book.last_played)