def populate_author_reader(self): tools.remove_all_children(self.author_box) tools.remove_all_children(self.reader_box) # Add the special All element all_row = ListBoxRowWithData(_("All"), False) all_row.set_tooltip_text(_("Display all books")) self.author_box.add(all_row) self.author_box.add(ListBoxSeparatorRow()) self.author_box.select_row(all_row) all_row = ListBoxRowWithData(_("All"), False) all_row.set_tooltip_text(_("Display all books")) self.reader_box.add(all_row) self.reader_box.add(ListBoxSeparatorRow()) self.reader_box.select_row(all_row) for book in authors(): row = ListBoxRowWithData(book.author, False) self.author_box.add(row) for book in readers(): row = ListBoxRowWithData(book.reader, False) self.reader_box.add(row) # this is required to see the new items self.author_box.show_all() self.reader_box.show_all()
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 _init_storage(self): """ Display settings from the database in the ui. """ found_default = False tools.remove_all_children(self.storage_list_box) for location in Storage.select(): row = StorageListBoxRow(self, location.id, location.path, location.external, location.default) self.storage_list_box.add(row) if location.default: if found_default: row.set_default(False) else: found_default = True self.storage_list_box.select_row(row) self.__on_storage_box_changed(None, None)
def __on_search_changed(self, sender): """ Reset the search if running and start a new async search. """ self.search_thread_stop.set() #self.throbber.set_visible(True) #self.throbber.start() # we want to avoid flickering of the search box size # as we remove widgets and add them again # so we get the current search popup size and set it as # the preferred size until the search is finished # this helps only a bit, the widgets are still flickering self.popover.set_size_request(self.popover.get_allocated_width(), self.popover.get_allocated_height()) # hide nothing found self.stack.set_visible_child_name("main") # First clear the boxes tools.remove_all_children(self.book_box) tools.remove_all_children(self.author_box) tools.remove_all_children(self.reader_box) # Hide all the labels & separators self.book_label.set_visible(False) self.author_label.set_visible(False) self.reader_label.set_visible(False) self.book_separator.set_visible(False) self.author_separator.set_visible(False) self.reader_separator.set_visible(False) self.track_label.set_visible(False) user_search = self.entry.get_text() if user_search: if self.search_thread.is_alive(): self.search_thread.join(timeout=0.2) self.search_thread_stop.clear() self.search_thread = Thread(target=self.search, args=(user_search, )) self.search_thread.start() else: #self.throbber.stop() #self.throbber.set_visible(False) self.stack.set_visible_child_name("start") self.popover.set_size_request(-1, -1)