class ListDialog(Window): def __init__(self, title): self.__choice = None Window.__init__(self, Window.TYPE_DIALOG) self.set_flag(windowflags.EXCLUSIVE, True) self.connect_closed(self.__on_close) self.set_title(title) self.__list = ThumbableGridView() self.add(self.__list) def render_this(self): w, h = self.get_size() screen = self.get_screen() self.__list.set_geometry(0, 0, w, h) def __on_close(self): self.set_visible(False) def __on_click_item(self, item): self.__choice = item self.set_visible(False) def add_item(self, item): item.connect_clicked(self.__on_click_item, item) self.__list.append_item(item) def get_choice(self): return self.__choice
class PrefsComponents(Configurator): """ Configurator for listing the currently loaded components. """ ICON = theme.mb_folder_prefs TITLE = "Components" DESCRIPTION = "View the loaded components" def __init__(self): self.__components = [] Configurator.__init__(self) self.__list = ThumbableGridView() self.add(self.__list) def __on_item_clicked(self, item): comp = item.get_component() self.__show_com_interface(comp) def __show_com_interface(self, comp): iface = "" handlers = [ m for m in dir(comp) if m.startswith("handle_") and not m == "handle_message" ] handlers.sort() for h in handlers: msg_name = h[7:] iface += msg_name + "\n" #end for if (not iface): iface = "- no public interface -" self.call_service(msgs.UI_ACT_SHOW_INFO, iface) def render_this(self): x, y = self.get_screen_pos() w, h = self.get_size() screen = self.get_screen() self.__list.set_geometry(0, 0, w, h) screen.fill_area(x, y, w, h, theme.color_mb_background) def __update_list(self): self.__list.clear_items() self.__components.sort( lambda a, b: cmp(a.__class__.__module__, b.__class__.__module__)) for comp in self.__components: item = ComponentListItem(comp) item.connect_clicked(self.__on_item_clicked, item) self.__list.append_item(item) #end for def handle_COM_EV_COMPONENT_LOADED(self, comp): self.__components.append(comp) def handle_COM_EV_APP_STARTED(self): self.__update_list()