def update_time(self): if self.book is None: return # update book object # TODO: optimize usage by only asking from the db on track change self.book = db.Book.select().where(db.Book.id == self.book.id).get() if self.ui.titlebar.current_book and self.book.id == self.ui.titlebar.current_book.id: progress = db.get_book_progress(self.book, False) progress += (player.get_current_duration() / 1000000000) remaining = (self.duration - progress) else: progress = db.get_book_progress(self.book) remaining = db.get_book_remaining(self.book) percentage = progress / self.duration self.total_label.set_text( tools.seconds_to_human_readable(self.duration / self.speed)) if percentage > 0.005: self.remaining_text.set_visible(True) self.remaining_label.set_visible(True) self.remaining_label.set_text( tools.seconds_to_human_readable(remaining / self.speed)) else: self.remaining_text.set_visible(False) self.remaining_label.set_visible(False) self.progress_bar.set_fraction(percentage)
def update_track_ui(self): # set data of new stream in ui track = player.get_current_track() if track is None: return self.title_label.set_text(track.book.name) self.subtitle_label.set_text(track.name) self.block_ui_buttons(False) self.progress_scale.set_sensitive(True) self.progress_scale.set_visible(True) # only change cover when book has changed if self.current_book is not track.book: self.current_book = track.book if tools.is_elementary(): size = 28 else: size = 40 self.set_title_cover( artwork_cache.get_cover_pixbuf( track.book, self.ui.window.get_scale_factor(), size), size) self.current_remaining = db.get_book_remaining(self.current_book, False) self.current_elapsed = db.get_book_progress(self.current_book, False) self.__update_progress_scale_range() if tools.get_glib_settings().get_boolean("titlebar-remaining-time"): self.progress_scale.set_value(self.current_elapsed / self.ui.speed.get_speed()) else: self.progress_scale.set_value(0) self.update_ui_time(None) self.current_label.set_visible(True) self.remaining_label.set_visible(True)