class SleepTimerPrefs(Configurator): """ Configurator for setting sleep and wake up times. """ ICON = theme.prefs_sleep_timer TITLE = "Sleep Timer" DESCRIPTION = "Fall asleep and wake up with music" def __init__(self): self.__sleep_handler = None self.__wakeup_handler = None self.__sleep_time = config.get_sleep_time() self.__wakeup_time = config.get_wakeup_time() Configurator.__init__(self) self.__list = ThumbableGridView() self.add(self.__list) #img = Image(theme.mb_sleep_timer_sleep) #hbox.add(img, False) chk = CheckBoxItem("Fall asleep and stop playing at", config.get_sleep()) chk.connect_checked(self.__on_check_sleep) self.__list.append_item(chk) btn = ButtonItem("%02d:%02d" % self.__sleep_time) btn.connect_clicked(self.__on_set_sleep, btn) self.__list.append_item(btn) #img = Image(theme.mb_sleep_timer_wakeup) #hbox.add(img, False) chk = CheckBoxItem("Wake up at and start playing at", config.get_wakeup()) chk.connect_checked(self.__on_check_wakeup) self.__list.append_item(chk) btn = ButtonItem("%02d:%02d" % self.__wakeup_time) btn.connect_clicked(self.__on_set_wakeup, btn) self.__list.append_item(btn) lbl = LabelItem("MediaBox will start playing the file that is " \ "selected at the moment of waking up.") lbl.set_icon(theme.mb_sleep_timer_wakeup) self.__list.append_item(lbl) # status icon #self.__status_icon_sleep = Image(theme.mb_status_sleep) #self.__status_icon_sleep.connect_clicked(self.__on_clicked_status_icon) """ def __update_status_icons(self): if (self.__sleep_handler or self.__wakeup_handler): self.emit_message(msgs.UI_ACT_SET_STATUS_ICON, self.__status_icon_sleep) else: self.emit_message(msgs.UI_ACT_UNSET_STATUS_ICON, self.__status_icon_sleep) """ """ def __on_clicked_status_icon(self): if (self.__sleep_handler): sleep_time = "%02d:%02d" % self.__sleep_time else: sleep_time = "- not set -" if (self.__wakeup_handler): wakeup_time = "%02d:%02d" % self.__wakeup_time else: wakeup_time = "- not set -" msg = "Fall asleep at:\t %s\n" \ "\n" \ "Wake up at:\t\t %s" % (sleep_time, wakeup_time) self.call_service(msgs.DIALOG_SVC_INFO, "Sleep and Wake Up Times", msg) """ def __on_check_sleep(self, value): if (self.__sleep_handler): gobject.source_remove(self.__sleep_handler) self.__sleep_handler = None if (value): now = time.time() then = self.__find_next_occurence(*self.__sleep_time) delta = int((then - now) * 1000) self.__sleep_handler = gobject.timeout_add(delta, self.__fall_asleep) config.set_sleep(value) #self.__update_status_icons() def __on_check_wakeup(self, value): if (self.__wakeup_handler): gobject.source_remove(self.__wakeup_handler) self.__wakeup_handler = None if (value): now = time.time() then = self.__find_next_occurence(*self.__wakeup_time) delta = int((then - now) * 1000) self.__wakeup_handler = gobject.timeout_add(delta, self.__wakeup) config.set_wakeup(value) #self.__update_status_icons() def __on_set_sleep(self, btn): dlg = ClockSetter() dlg.set_time(*self.__sleep_time) dlg.run() self.__sleep_time = dlg.get_time() config.set_sleep_time(*self.__sleep_time) btn.set_text("%02d:%02d" % self.__sleep_time) idx = self.__list.get_items().index(btn) self.__list.invalidate_item(idx) if (self.__sleep_handler): self.__on_check_sleep(True) def __on_set_wakeup(self, btn): dlg = ClockSetter() dlg.set_time(*self.__wakeup_time) dlg.run() self.__wakeup_time = dlg.get_time() config.set_wakeup_time(*self.__wakeup_time) btn.set_text("%02d:%02d" % self.__wakeup_time) idx = self.__list.get_items().index(btn) self.__list.invalidate_item(idx) if (self.__wakeup_handler): self.__on_check_wakeup(True) def __fall_asleep(self): self.__sleep_handler = None logging.debug("sleep timer falling asleep") self.emit_message(msgs.MEDIA_ACT_STOP) self.__on_check_sleep(True) def __wakeup(self): self.__wakeup_handler = None logging.debug("wakeup timer waking up") self.emit_message(msgs.MEDIA_ACT_PLAY) self.__on_check_wakeup(True) def __find_next_occurence(self, h, m): now = time.time() now_tuple = list(time.localtime(now)) now_tuple[3] = h now_tuple[4] = m now_tuple[5] = 0 seconds = time.mktime(tuple(now_tuple)) if (seconds <= now): seconds += 24 * 3600 return seconds def handle_COM_EV_APP_STARTED(self): #self.__update_status_icons() self.__on_check_sleep(config.get_sleep()) self.__on_check_wakeup(config.get_wakeup())
class DownloadManager(Dialog): """ Dialog for managing active downloads. """ def __init__(self): # table: download ID -> item self.__items = {} Dialog.__init__(self) self.set_title("Active Downloads") self.__list = ThumbableGridView() self.add(self.__list) def __on_click_item(self, download_id): dlg = OptionDialog("Abort this download?") dlg.add_option(None, "Yes, abort") dlg.add_option(None, "No, continue") if (dlg.run() == dlg.RETURN_OK): choice = dlg.get_choice() if (choice == 0): self.emit_message(msgs.DOWNLOADER_ACT_ABORT, download_id) #end if def handle_DOWNLOADER_EV_STARTED(self, download_id, url, destination): item = DownloadItem(url, destination) self.__items[download_id] = item self.__list.append_item(item) item.connect_clicked(self.__on_click_item, download_id) def handle_DOWNLOADER_EV_FINISHED(self, download_id): item = self.__items.get(download_id) if (item): del self.__items[download_id] pos = self.__list.get_items().index(item) self.__list.remove_item(pos) self.__list.invalidate() self.__list.render() def handle_DOWNLOADER_EV_ABORTED(self, download_id): item = self.__items.get(download_id) if (item): del self.__items[download_id] pos = self.__list.get_items().index(item) self.__list.remove_item(pos) self.__list.invalidate() self.__list.render() def handle_DOWNLOADER_EV_PROGRESS(self, download_id, name, amount, total): item = self.__items.get(download_id) if (item): item.set_amount(amount, total) item.set_destination(name) idx = self.__list.get_items().index(item) self.__list.invalidate_item(idx)
class ConfigTheme(Configurator): """ Configurator for selecting the UI theme. """ ICON = theme.prefs_icon_theme TITLE = "Themes" DESCRIPTION = "Change the look of MediaBox with themes" def __init__(self): Configurator.__init__(self) self.__list = ThumbableGridView() self.add(self.__list) self.__update_list() def set_size(self, w, h): Configurator.set_size(self, w, h) for item in self.__list.get_items(): item.set_size(w, 80) def __on_item_clicked(self, preview, name, title, idx): self.__list.set_hilight(idx) gobject.idle_add(self.__change_theme, name, title, preview) def __update_list(self): w, h = self.get_size() themes = theme.list_themes() self.__themes = [] idx = 0 for name, preview, title, description, author in themes: try: img = gtk.gdk.pixbuf_new_from_file(preview) except: continue item = ThemeListItem(img, title, description, author) item.set_size(w, 80) item.connect_clicked(self.__on_item_clicked, preview, name, title, idx) self.__list.append_item(item) self.__themes.append((name, title)) if (name == config.theme()): self.__list.set_hilight(idx) idx += 1 #end for def __change_theme(self, t, title, preview): #self.set_visible(False) #dlg = InfoDialog(u"Using theme \xbb%s\xab" % title, self) #dlg.run() config.set_theme(t) #config.set_thumbnails_epoch(int(time.time())) theme.set_theme(t) self.propagate_theme_change() w, h = self.get_size() buf = Pixmap(None, w, h) self.render_at(buf) self.fx_slide_vertical(buf, 0, 0, w, h, self.SLIDE_DOWN) self.emit_message(msgs.CORE_EV_THEME_CHANGED)