def plugins_view_add_items(self, items, insert_pos=None, clear_first=False): for item in items: item.plugins_view = self TreeView.add_items(self.plugins_view, items, insert_pos, clear_first)
class AlbumDetailPage(gtk.VBox): ''' class docs ''' def __init__(self, data_manager, album_info): ''' init docs ''' gtk.VBox.__init__(self) self.treeview = TreeView(enable_drag_drop=False, expand_column=1) items = [] for software_info in album_info['softwares']: items.append(AlbumDetailItem(software_info, data_manager)) self.treeview.add_items(items) self.treeview.draw_mask = self.draw_mask self.pack_start(self.treeview, True, True) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] )
def plugin_widget(self): self.__get_devices() plugin_box = gtk.VBox() adapter_box = gtk.HBox(spacing=5) adapter_image = ImageBox( app_theme.get_pixbuf("bluetooth/enable_open.png")) adapter_label = self.__setup_label(_("Adapter")) adapter_toggle = self.__setup_toggle() if self.my_bluetooth.adapter: adapter_toggle.set_active(self.my_bluetooth.adapter.get_powered()) if self.my_bluetooth.adapter.get_powered(): self.tray_icon.set_icon_theme("enable") else: self.tray_icon.set_icon_theme("enable_disconnect") adapter_toggle.connect("toggled", self.__adapter_toggled) separator_align = self.__setup_align(padding_bottom=0) separator = self.__setup_separator() separator_align.add(separator) ''' devices treeview ''' device_treeview = TreeView() device_separator_align = self.__setup_align() device_separator = self.__setup_separator() device_separator_align.add(device_separator) device_count = len(self.device_items) if device_count: device_treeview.delete_all_items() device_treeview.add_items(self.device_items) device_treeview.set_size_request( self.width, device_count * DeviceItem.ITEM_HEIGHT) else: device_treeview.set_child_visible(False) device_separator_align.set_size_request(-1, 0) device_separator_align.set_child_visible(False) ''' select button ''' select_button_align = self.__setup_align() select_button = SelectButton(_("Advanced options..."), font_size=10, ali_padding=5) select_button.set_size_request(self.width, 25) select_button.connect( "clicked", self.__bluetooth_selected ) # I don't know why, but replacing "button-press-event" with select_button_align.add(select_button) # clicked really works... adapter_box.pack_start(adapter_image, False, False) adapter_box.pack_start(adapter_label, False, False) adapter_box.pack_start(adapter_toggle, False, False) plugin_box.pack_start(adapter_box, False, False) plugin_box.pack_start(separator_align, False, False) plugin_box.pack_start(device_treeview, False, False) plugin_box.pack_start(device_separator_align, False, False) plugin_box.pack_start(select_button_align, False, False) return plugin_box
def plugin_widget(self): self.__get_devices() plugin_box = gtk.VBox() adapter_box = gtk.HBox(spacing = 5) adapter_image = ImageBox(app_theme.get_pixbuf("bluetooth/enable_open.png")) adapter_label = self.__setup_label(_("Adapter")) adapter_toggle = self.__setup_toggle() if self.my_bluetooth.adapter: adapter_toggle.set_active(self.my_bluetooth.adapter.get_powered()) if self.my_bluetooth.adapter.get_powered(): self.tray_icon.set_icon_theme("enable") else: self.tray_icon.set_icon_theme("enable_disconnect") adapter_toggle.connect("toggled", self.__adapter_toggled) separator_align = self.__setup_align(padding_bottom = 0) separator = self.__setup_separator() separator_align.add(separator) ''' devices treeview ''' device_treeview = TreeView() device_separator_align = self.__setup_align() device_separator = self.__setup_separator() device_separator_align.add(device_separator) device_count = len(self.device_items) if device_count: device_treeview.delete_all_items() device_treeview.add_items(self.device_items) device_treeview.set_size_request(self.width, device_count * DeviceItem.ITEM_HEIGHT) else: device_treeview.set_child_visible(False) device_separator_align.set_size_request(-1, 0) device_separator_align.set_child_visible(False) ''' select button ''' select_button_align = self.__setup_align() select_button = SelectButton(_("Advanced options..."), font_size = 10, ali_padding = 5) select_button.set_size_request(self.width, 25) select_button.connect("clicked", self.__bluetooth_selected) # I don't know why, but replacing "button-press-event" with select_button_align.add(select_button) # clicked really works... adapter_box.pack_start(adapter_image, False, False) adapter_box.pack_start(adapter_label, False, False) adapter_box.pack_start(adapter_toggle, False, False) plugin_box.pack_start(adapter_box, False, False) plugin_box.pack_start(separator_align, False, False) plugin_box.pack_start(device_treeview, False, False) plugin_box.pack_start(device_separator_align, False, False) plugin_box.pack_start(select_button_align, False, False) return plugin_box
class AlbumDetailPage(gtk.VBox): ''' class docs ''' def __init__(self, data_manager, album_info): ''' init docs ''' gtk.VBox.__init__(self) self.treeview = TreeView(enable_drag_drop=False, expand_column=1) items = [] album_detail_infos = album_info['softwares'] album_detail_infos = sorted(album_detail_infos, key=lambda info: info.get('order'), reverse=True) for software_info in album_detail_infos: items.append(AlbumDetailItem(software_info, data_manager)) self.treeview.add_items(items) self.treeview.draw_mask = self.draw_mask self.pack_start(self.treeview, True, True) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ])
class CompletionWindow(Window): ''' class docs ''' def __init__(self, window_width, window_height): ''' init docs ''' # Init. Window.__init__( self, shadow_visible=False, shadow_radius = 0, shape_frame_function=self.shape_completion_window_frame, expose_frame_function=self.expose_completion_window_frame, # window_type=gtk.WINDOW_POPUP, ) self.window_width = window_width self.window_height = window_height self.window_offset_x = 0 self.window_offset_y = 0 self.align_size = 2 self.treeview = TreeView( enable_highlight=False, enable_multiple_select=False, enable_drag_drop=False,) self.treeview.draw_mask = self.treeview_draw_mask self.treeview.scrolled_window.tag_by_popup_grab_window = True self.treeview_align = gtk.Alignment() self.treeview_align.set(0.5, 0.5, 1, 1) self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size) self.treeview_align.add(self.treeview) self.window_frame.pack_start(self.treeview_align, True, True) self.connect("realize", self.realize_completion_window) self.get_scrolledwindow = self.get_scrolledwindow wrap_grab_window(completion_grab_window, self) def get_scrolledwindow(self): return self.treeview.scrolled_window def shape_completion_window_frame(self, widget, event): pass def treeview_draw_mask(self, cr, x, y, w, h): cr.set_source_rgba(1, 1, 1, 0.95) cr.rectangle(x, y, w, h) cr.fill() def expose_completion_window_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1,1,1) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo("#c7c7c7")) cr.rectangle(*rect) cr.stroke() def show(self, keyword): self.treeview.delete_all_items() self.treeview.add_items([TextItem(key) for key in ["linux", "deepin", "word", keyword]]) self.treeview.select_first_item() # self.treeview.grab_focus() (x, y) = get_widget_root_coordinate(search_entry, WIDGET_POS_BOTTOM_LEFT, True) self.move(x + self.window_offset_x, y + self.window_offset_y) self.show_all() def realize_completion_window(self, widget): self.set_default_size(self.window_width, self.window_height) self.set_geometry_hints( None, self.window_width, # minimum width self.window_height, # minimum height self.window_width, self.window_height, -1, -1, -1, -1, -1, -1 )
class InstallPage(gtk.VBox): ''' class docs ''' def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.message_bar = MessageBar(32) self.message_box = gtk.HBox() self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) self.cute_message_image = gtk.VBox() self.content_box = gtk.VBox() self.pack_start(self.message_box, False, False) self.pack_start(self.content_box, True, True) self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf("info", "no_download.png") self.content_box.pack_start(self.cute_message_image, True, True) self.treeview.draw_mask = self.draw_mask self.cute_message_image.connect("expose-event", self.expose_cute_message_image) self.treeview.connect("items-change", self.update_message_bar) self.treeview.connect("items-change", lambda treeview: global_event.emit("update-install-notify-number", self.get_installing_pkgs_number())) #self.get_action_item("deepin-webapps-baidu-map") #self.download_failed("deepin-webapps-baidu-map") def expose_cute_message_image(self, widget, event): if self.cute_message_pixbuf: cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_pixbuf( cr, self.cute_message_pixbuf, rect.x + (rect.width - self.cute_message_pixbuf.get_width()) / 2, rect.y + (rect.height - self.cute_message_pixbuf.get_height()) / 2, ) def update_install_status(self): global_event.emit("update-install-notify-number", self.get_installing_pkgs_number()) self.update_message_bar(self.treeview) def get_installing_pkgs_number(self): items = [] for item in self.treeview.visible_items: if not (item.status == item.STATUS_INSTALL_FINISH or \ item.status == item.STATUS_DOWNLOAD_FAILED): items.append(item) return len(items) def get_installed_pkgs_number(self): items = [] for item in self.treeview.visible_items: if item.status == item.STATUS_INSTALL_FINISH: items.append(item) return len(items) def delete_item_match_pkgname(self, pkg_name): for install_item in self.treeview.visible_items: if install_item.pkg_name == pkg_name: self.treeview.delete_items([install_item]) break def update_message_bar(self, treeview): if self.get_installing_pkgs_number() == 0: if self.get_installed_pkgs_number() == 0: container_remove_all(self.message_box) children = self.content_box.get_children() if len(children) == 0 or children[0] == self.treeview: if self.cute_message_pixbuf == None: self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf("info", "no_download.png") container_remove_all(self.content_box) self.content_box.pack_start(self.cute_message_image, True, True) self.show_all() else: self.message_bar.set_message("") else: container_remove_all(self.message_box) self.message_box.pack_start(self.message_bar, True, True) self.message_bar.set_message(_("%s applications are being installed") % self.get_installing_pkgs_number()) children = self.content_box.get_children() if len(children) == 0 or children[0] == self.cute_message_image: if self.cute_message_pixbuf: del self.cute_message_pixbuf self.cute_message_pixbuf = None container_remove_all(self.content_box) self.content_box.pack_start(self.treeview, True, True) self.show_all() def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] ) def update_download_status(self, pkg_infos): pkg_items = [] for (pkg_name, download_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = InstallItem(pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name])[0], self.data_manager) if download_status == "wait": pkg_item.download_wait() elif download_status == "start": pkg_item.download_start() elif download_status == "update": pkg_item.download_update(0, 0) pkg_items.append(pkg_item) pkg_items = filter(lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def update_action_status(self, pkg_infos): pkg_items = [] for (pkg_name, action_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = InstallItem(pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name])[0], self.data_manager) if action_status == "wait": pkg_item.download_finish() elif action_status == "start": pkg_item.action_start() elif action_status == "update": pkg_item.action_update(0) pkg_items.append(pkg_item) pkg_items = filter(lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def add_install_actions(self, pkg_names): for pkg_name in pkg_names: self.get_action_item(pkg_name) def get_action_item(self, pkg_name): action_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: action_item = item break if action_item == None: action_item = InstallItem(pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name])[0], self.data_manager) self.treeview.add_items([action_item]) return action_item def download_ready(self, pkg_name): self.get_action_item(pkg_name).download_ready() def download_wait(self, pkg_name): self.get_action_item(pkg_name).download_wait() def download_start(self, pkg_name): self.get_action_item(pkg_name).download_start() def download_update(self, pkg_name, percent, speed): self.get_action_item(pkg_name).download_update(percent, speed) def download_finish(self, pkg_name): self.get_action_item(pkg_name).download_finish() def download_stop(self, pkg_name): self.get_action_item(pkg_name).download_stop() def download_parse_failed(self, pkg_name): self.get_action_item(pkg_name).download_parse_failed() def download_failed(self, pkg_name): self.get_action_item(pkg_name).download_failed() def action_start(self, pkg_name): self.get_action_item(pkg_name).action_start() def action_update(self, pkg_name, percent): self.get_action_item(pkg_name).action_update(percent) def action_finish(self, pkg_name, pkg_info_list): self.get_action_item(pkg_name).action_finish()
# Set application icon. application.set_icon(os.path.join(get_current_dir(__file__), "icon.ico")) # Set application preview pixbuf. application.set_skin_preview(os.path.join(get_current_dir(__file__), "frame.png")) # Add titlebar. application.add_titlebar( ["theme", "max", "min", "close"], os.path.join(get_current_dir(__file__), "logo.png"), "TreeView demo", "TreeView demo", ) # Add TreeView. treeview = TreeView() treeview.add_items(map(TextItem, ["Node1", "Node2", "Node3"])) treeview.visible_items[0].add_items(map(TextItem, ["Node1 - SubNode1", "Node1 - SubNode2", "Node1 - SubNode3"])) treeview.visible_items[1].add_items(map(TextItem, ["Node2 - SubNode1", "Node2 - SubNode2", "Node2 - SubNode3"])) treeview.visible_items[2].add_items(map(TextItem, ["Node3 - SubNode1", "Node3 - SubNode2", "Node3 - SubNode3"])) treeview_align = gtk.Alignment() treeview_align.set(0.5, 0.5, 1, 1) treeview_align.set_padding(0, 2, 2, 2) treeview_align.add(treeview) application.main_box.pack_start(treeview_align) application.window.connect("show", lambda w: treeview.visible_highlight()) application.run()
class InstallPage(gtk.VBox): ''' class docs ''' def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.message_bar = MessageBar(32) self.message_box = gtk.HBox() self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) self.cute_message_image = gtk.VBox() self.content_box = gtk.VBox() self.pack_start(self.message_box, False, False) self.pack_start(self.content_box, True, True) self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf( "info", "no_download.png") self.content_box.pack_start(self.cute_message_image, True, True) self.treeview.draw_mask = self.draw_mask self.cute_message_image.connect("expose-event", self.expose_cute_message_image) self.treeview.connect("items-change", self.update_message_bar) self.treeview.connect( "items-change", lambda treeview: global_event.emit( "update-install-notify-number", self.get_installing_pkgs_number())) #self.get_action_item("deepin-webapps-baidu-map") #self.download_failed("deepin-webapps-baidu-map") def expose_cute_message_image(self, widget, event): if self.cute_message_pixbuf: cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_pixbuf( cr, self.cute_message_pixbuf, rect.x + (rect.width - self.cute_message_pixbuf.get_width()) / 2, rect.y + (rect.height - self.cute_message_pixbuf.get_height()) / 2, ) def update_install_status(self): global_event.emit("update-install-notify-number", self.get_installing_pkgs_number()) self.update_message_bar(self.treeview) def get_installing_pkgs_number(self): items = [] for item in self.treeview.visible_items: if not (item.status == item.STATUS_INSTALL_FINISH or \ item.status == item.STATUS_DOWNLOAD_FAILED): items.append(item) return len(items) def get_installed_pkgs_number(self): items = [] for item in self.treeview.visible_items: if item.status == item.STATUS_INSTALL_FINISH: items.append(item) return len(items) def delete_item_match_pkgname(self, pkg_name): for install_item in self.treeview.visible_items: if install_item.pkg_name == pkg_name: self.treeview.delete_items([install_item]) break def update_message_bar(self, treeview): if self.get_installing_pkgs_number() == 0: if self.get_installed_pkgs_number() == 0: container_remove_all(self.message_box) children = self.content_box.get_children() if len(children) == 0 or children[0] == self.treeview: if self.cute_message_pixbuf == None: self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf( "info", "no_download.png") container_remove_all(self.content_box) self.content_box.pack_start(self.cute_message_image, True, True) self.show_all() else: self.message_bar.set_message("") else: container_remove_all(self.message_box) self.message_box.pack_start(self.message_bar, True, True) self.message_bar.set_message( _("%s applications are being installed") % self.get_installing_pkgs_number()) children = self.content_box.get_children() if len(children) == 0 or children[0] == self.cute_message_image: if self.cute_message_pixbuf: del self.cute_message_pixbuf self.cute_message_pixbuf = None container_remove_all(self.content_box) self.content_box.pack_start(self.treeview, True, True) self.show_all() def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ]) def update_download_status(self, pkg_infos): pkg_items = [] for (pkg_name, download_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = InstallItem( pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name ])[0], self.data_manager) if download_status == "wait": pkg_item.download_wait() elif download_status == "start": pkg_item.download_start() elif download_status == "update": pkg_item.download_update(0, 0) pkg_items.append(pkg_item) pkg_items = filter( lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def update_action_status(self, pkg_infos): pkg_items = [] for (pkg_name, action_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = InstallItem( pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name ])[0], self.data_manager) if action_status == "wait": pkg_item.download_finish() elif action_status == "start": pkg_item.action_start() elif action_status == "update": pkg_item.action_update(0) pkg_items.append(pkg_item) pkg_items = filter( lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def add_install_actions(self, pkg_names): for pkg_name in pkg_names: self.get_action_item(pkg_name) def get_action_item(self, pkg_name): action_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: action_item = item break if action_item == None: action_item = InstallItem( pkg_name, self.bus_interface.request_pkgs_install_version([pkg_name])[0], self.data_manager) self.treeview.add_items([action_item]) return action_item def download_ready(self, pkg_name): self.get_action_item(pkg_name).download_ready() def download_wait(self, pkg_name): self.get_action_item(pkg_name).download_wait() def download_start(self, pkg_name): self.get_action_item(pkg_name).download_start() def download_update(self, pkg_name, percent, speed): self.get_action_item(pkg_name).download_update(percent, speed) def download_finish(self, pkg_name): self.get_action_item(pkg_name).download_finish() def download_stop(self, pkg_name): self.get_action_item(pkg_name).download_stop() def download_parse_failed(self, pkg_name): self.get_action_item(pkg_name).download_parse_failed() def download_failed(self, pkg_name): self.get_action_item(pkg_name).download_failed() def action_start(self, pkg_name): self.get_action_item(pkg_name).action_start() def action_update(self, pkg_name, percent): self.get_action_item(pkg_name).action_update(percent) def action_finish(self, pkg_name, pkg_info_list): self.get_action_item(pkg_name).action_finish()
class SearchPage(gtk.VBox): ''' class docs ''' def __init__(self, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.data_manager = data_manager self.keywords = [] self.all_pkg_names = [] self.message_bar = MessageBar(18) self.content_box = gtk.VBox() self.treeview = TreeView(enable_drag_drop=False, expand_column=0) global_event.register_event("delete-search-page-items", self.treeview.delete_items) self.cute_message_image = gtk.VBox() self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf("info", "noresult.png") self.cute_message_image.connect("expose-event", self.expose_cute_message_image) self.content_box.pack_start(self.message_bar, False, False) self.content_box.pack_start(self.treeview) self.loading_box = LoadingBox() self.pack_start(self.loading_box, True, True) self.treeview.connect("items-change", self.update_message_bar) self.treeview.draw_mask = self.draw_mask def expose_cute_message_image(self, widget, event): if self.cute_message_pixbuf: cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(1, 1, 1, 0) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_pixbuf( cr, self.cute_message_pixbuf, rect.x + (rect.width - self.cute_message_pixbuf.get_width()) / 2, rect.y + (rect.height - self.cute_message_pixbuf.get_height()) / 2, ) def update_message_bar(self, treeview): if len(treeview.visible_items) > 0: self.message_bar.set_message( " ".join(self.keywords) + ": " + _("%s applications searched") % len(self.all_pkg_names)) container_remove_all(self) self.pack_start(self.content_box) global_event.emit("update-current-status-pkg-page", treeview) else: container_remove_all(self) self.pack_start(self.cute_message_image) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] ) def update(self, keywords): self.keywords = keywords self.treeview.delete_all_items() self.all_pkg_names = self.data_manager.search_query(keywords) if self.all_pkg_names: if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) else: self.update_message_bar(self.treeview) self.treeview.scrolled_window.connect('vscrollbar-state-changed', self.scrolled_window_vscrollbar_handler) def scrolled_window_vscrollbar_handler(self, widget, state): if state == "bottom": current_item_number = len(self.treeview.visible_items) all_pkgs_number = len(self.all_pkg_names) start = current_item_number if current_item_number < all_pkgs_number and (current_item_number+LOAD_ITEMS_NUMBER) < all_pkgs_number: end = current_item_number+LOAD_ITEMS_NUMBER elif current_item_number < all_pkgs_number and (current_item_number+LOAD_ITEMS_NUMBER) >= all_pkgs_number: end = all_pkgs_number else: return self.load_new_items(self.all_pkg_names[start:end]) def load_new_items(self, pkg_names): if pkg_names: items = [] for pkg_name in pkg_names: items.append(SearchItem(pkg_name, self.data_manager, self.keywords)) self.treeview.add_items(items) #global_event.emit("show-pkg-view", self.page_box) else: self.update_message_bar(self.treeview)
class PreferenceDialog(DialogBox): def __init__(self): super(PreferenceDialog, self).__init__(_("Preferences"), 575, 495, mask_type=DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all) self.set_position(gtk.WIN_POS_CENTER) self.main_box = gtk.VBox() close_button = Button(_("Close")) close_button.connect("clicked", lambda w: self.hide_all()) # Init widget. self.general_setting = GeneralSetting() self.hotkey_setting = HotKeySetting() self.desktop_lyrics_setting = DesktopLyricsSetting() self.scroll_lyrics_setting = ScrollLyricsSetting() self.plugins_manager = PluginsManager() # Category bar self.category_bar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.category_bar.set_expand_column(0) self.category_bar.draw_mask = self.draw_treeview_mask self.category_bar.set_size_request(132, 516) self.category_bar.connect("single-click-item", self.on_categorybar_single_click) # Init catagory bar. self.__init_category_bar() category_box = gtk.VBox() background_box = BackgroundBox() background_box.set_size_request(132, 11) background_box.draw_mask = self.draw_treeview_mask category_box.pack_start(background_box, False, False) category_bar_align = gtk.Alignment() category_bar_align.set(0, 0, 1, 1,) category_bar_align.set_padding(0, 1, 0, 0) category_bar_align.add(self.category_bar) category_box.pack_start(category_bar_align, True, True) # Pack widget. left_box = gtk.VBox() self.right_box = gtk.VBox() left_box.add(category_box) self.right_box.add(self.general_setting) right_align = gtk.Alignment() right_align.set_padding(0, 0, 10, 0) right_align.add(self.right_box) body_box = gtk.HBox() body_box.pack_start(left_box, False, False) body_box.pack_start(right_align, False, False) self.main_box.add(body_box) # DialogBox code. self.body_box.pack_start(self.main_box, True, True) self.right_button_box.set_buttons([close_button]) def __init_category_bar(self): general_normal_item = NormalItem(_("General"), self.general_setting) hotkey_normal_item = NormalItem(_("Hotkeys"), self.hotkey_setting) self.lyrics_expand_item = ExpandItem(_("Lyrics"), None) self.lyrics_expand_item.add_childs([(_("Desktop"), self.desktop_lyrics_setting), (_("Window"), self.scroll_lyrics_setting)]) self.plugins_expand_item = NormalItem(_("Plugins"), self.plugins_manager) about_normal_item = NormalItem(_("About"), AboutBox()) items = [general_normal_item, hotkey_normal_item, self.lyrics_expand_item, self.plugins_expand_item, about_normal_item] self.category_bar.add_items(items) self.category_bar.select_items([general_normal_item]) def switch_lyrics_page(self, index=3): self.lyrics_expand_item.try_to_expand() show_item = self.category_bar.visible_items[index] self.category_bar.select_items([show_item]) self.on_categorybar_single_click(self.category_bar, show_item, None, None, None) def show_scroll_lyrics_page(self): self.switch_lyrics_page(4) self.show_all() def show_desktop_lyrics_page(self): self.switch_lyrics_page(3) self.show_all() def draw_treeview_mask(self, cr, x, y, width, height): draw_alpha_mask(cr, x, y, width, height, ("#FFFFFF", 0.9)) def on_categorybar_single_click(self, widget, item, column, x, y): if item.allocate_widget: switch_tab(self.right_box, item.allocate_widget) def load_plugins(self): self.plugins_manager.flush_plugins()
class UninstallPage(gtk.VBox): ''' class docs ''' def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.search_flag = False self.uninstall_change_items = {"add": [], "delete": []} ### init UI widgets self.message_bar = MessageBar(32) self.message_bar.search_entry.entry.connect("changed", self.search_cb) self.message_bar.search_button.connect("clicked", self.search_cb) self.top_hbox = gtk.HBox() self.top_hbox.pack_start(self.message_bar) self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) self.treeview.connect("items-change", self.update_message_bar) self.loading_box = LoadingBox() self.loading_box_align = create_align((0.5, 0.5, 1, 1), (10, 10, 10, 10)) self.loading_box_align.add(self.loading_box) ### init UI widgets self.white_kernel_pkg_names = self.get_white_kernel_pkg_names() global_event.register_event("uninstall-items-filtered", self.load_uninstall_items) self.show_loading_page() self.fetch_uninstall_info() self.treeview.draw_mask = self.draw_mask def show_loading_page(self): container_remove_all(self) self.pack_start(self.loading_box_align, True, True) def show_uninstall_page(self): container_remove_all(self) self.pack_start(self.top_hbox, False, False) self.pack_start(self.treeview, True, True) def search_cb(self, widget, event=None): if not self.search_flag: self.cache_items = [item for item in self.treeview.visible_items] results = [] keywords = self.message_bar.search_entry.get_text().strip() if keywords != "": self.search_flag = True # TODO: comment this search_query api, there are many problems for this api ''' pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" "))) for item in self.cache_items: if item.pkg_name in pkg_names: results.append(item) ''' for item in self.cache_items: if keywords in item.pkg_name: results.append(item) self.treeview.clear() self.treeview.add_items(results) else: self.treeview.clear() self.search_flag = False # for add items if self.uninstall_change_items["add"] != []: for item in self.uninstall_change_items["add"]: self.cache_items.append(item) self.uninstall_change_items["add"] = [] # for delete items if self.uninstall_change_items["delete"] != []: for item in self.uninstall_change_items["delete"]: if item in self.cache_items: self.cache_items.remove(item) self.uninstall_change_items["delete"] = [] self.treeview.add_items(self.cache_items) def normal_search_cb(self, keywords): pass def update_message_bar(self, treeview): self.message_bar.set_message( _("%s applications can be uninstalled") % len(treeview.visible_items)) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ]) def update_action_status(self, pkg_infos): pkg_items = [] for (pkg_name, action_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = UninstallItem( pkg_name, self.bus_interface.request_pkgs_uninstall_version( [pkg_name])[0], self.data_manager) if action_status == "wait": pkg_item.action_wait() elif action_status == "start": pkg_item.action_start() elif action_status == "update": pkg_item.action_update(0) pkg_items.append(pkg_item) pkg_items = filter( lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def fetch_uninstall_info(self): self.bus_interface.request_uninstall_pkgs( reply_handler=lambda r: self.add_uninstall_items(r, True), error_handler=lambda e: self.add_uninstall_items(e, False)) def get_white_kernel_pkg_names(self): version = commands.getoutput("uname -r").split("-generic")[0] white_pkg_names = ["linux-image-generic", "linux-headers-generic"] white_pkg_names.append("linux-image-%s-generic" % version) white_pkg_names.append("linux-image-extra-%s-generic" % version) white_pkg_names.append("linux-headers-%s-generic" % version) white_pkg_names.append("linux-headers-%s" % version) return white_pkg_names def is_uninstallable_kernel(self, pkg_name): if pkg_name.startswith("linux-image") or pkg_name.startswith( "linux-headers"): return pkg_name not in self.white_kernel_pkg_names def add_uninstall_items(self, data, success): if not success: global_logger.error("request_uninstall_pkgs failed: %s" % data) return pkg_infos = str(data) try: uninstall_pkg_infos = json.loads(pkg_infos) except Exception, e: global_logger.error( "Parse uninstall package information failed: %s" % pkg_infos) global_logger.error("Error: %s" % str(e)) uninstall_pkg_infos = [] ThreadMethod(self.filter_uninstall_pkg_infos, (uninstall_pkg_infos, )).start()
class TrayUI(gtk.VBox): def __init__(self): gtk.VBox.__init__(self, spacing=0) self.init_ui() self.active_ap_index = [] self.all_showed = False def init_ui(self): self.wire = Section(app_theme.get_pixbuf("network/cable.png"), _("Wired")) self.wireless = Section(app_theme.get_pixbuf("network/wifi.png"), _("Wireless")) self.mobile = Section(app_theme.get_pixbuf("network/3g.png"), _("Mobile Network")) # vpn self.vpn = Section(app_theme.get_pixbuf("network/vpn.png"), _("VPN Network")) self.dsl = Section(app_theme.get_pixbuf("network/dsl.png"), _("DSL")) self.ssid_list = [] self.tree_box = gtk.VBox(spacing=0) self.button_more = SelectButton(_("Advanced..."), font_size=10, ali_padding=5) self.button_more.set_size_request(-1, 25) #self.pack_start(self.button_more, False, False) self.ap_tree = TreeView(mask_bound_height=0) self.ap_tree.set_expand_column(0) self.vpn_list = ConList() self.dsl_list = DSLConList() self.wire_box = self.section_box([self.wire]) self.wireless_box = self.section_box([self.wireless, self.tree_box]) self.mobile_box = self.section_box([self.mobile]) self.vpn_box = self.section_box([self.vpn, self.vpn_list]) self.dsl_box = self.section_box([self.dsl, self.dsl_list]) self.wire_state = False self.wireless_state = False self.mobile_state = False self.vpn_state = False self.dsl_state = False self.device_tree = None self.pack_start(self.wire_box, False, False) self.pack_start(self.wireless_box, False, False) self.pack_start(self.mobile_box, False, False) self.pack_start(self.vpn_box, False, False) self.pack_start(self.dsl_box, False, False) self.pack_start(self.button_more, False, False) def get_widget_height(self): height = 0 if self.wire_state: height += 35 if self.wireless_state: height += 35 if self.ap_tree.visible_items and self.wireless.get_active(): height += self.ap_tree.get_size_request()[1] if self.device_tree: height += 22 if self.mobile_state: height += 35 if self.vpn_state: height += 35 + len(self.vpn_list.get_children()) * 22 if self.dsl_state: height += 35 + len(self.dsl_list.get_children()) * 22 height += 5 height += 25 return height def section_box(self, widgets): box = gtk.VBox(spacing=0) for w in widgets: box.pack_start(w, False, False) style.add_separator(box, 10) return box def remove_net(self, net_type): #print net_type getattr(self, net_type + "_box").set_no_show_all(True) #getattr(self, net_type).set_active((True, False)) getattr(self, net_type + "_box").hide() setattr(self, net_type + "_state", False) def show_net(self, net_type): getattr(self, net_type + "_box").set_no_show_all(False) getattr(self, net_type + "_box").show() setattr(self, net_type + "_state", True) def set_wired_state(self, widget, new_state, reason): if new_state is 20: self.wire.set_active(0) else: tray_log.debug(__name__, new_state, reason) def set_visible_aps(self, show_all=False): if not self.__ap_list: self.visible_aps = [] return tray_log.debug(len(self.__ap_list)) if show_all: if len(self.__ap_list) <= 10: self.visible_aps = self.__ap_list[:] else: self.visible_aps = self.__ap_list[:10] self.more_button.set_ap_list([]) self.show_all = True else: if len(self.__ap_list) <= 5: self.visible_aps = self.__ap_list[:] self.show_all = True else: self.visible_aps = self.__ap_list[:5] self.more_button.set_ap_list(self.__ap_list[5:]) self.show_all = False def set_ap(self, ap_list, redraw=True): if not ap_list: return self.__set_ap_list(ap_list) #print "DEBUG", len(self.visible_aps), self.show_all self.ap_tree.delete_all_items() container_remove_all(self.tree_box) self.ap_tree.add_items(map(lambda ap: SsidItem(ap), self.__ap_list)) length = len(self.ap_tree.visible_items) if length <= 10: self.ap_tree.set_size_request(-1, WIDGET_HEIGHT * length) else: self.ap_tree.set_size_request(-1, WIDGET_HEIGHT * 10) for item in self.ap_tree.visible_items: item.set_padding(10) self.tree_box.pack_start(self.ap_tree, False, False) self.show_all() if redraw: Dispatcher.request_resize() def __set_ap_list(self, ap_list): self.__ap_list = ap_list def move_active(self, index): if index != [] and self.__ap_list: for i in index: if i < len(self.ap_tree.visible_items): self.ap_tree.delete_item_by_index(i) self.ap_tree.add_items([SsidItem(self.__ap_list[i])], insert_pos=0) else: self.ap_tree.delete_item_by_index(-1) self.ap_tree.add_items([SsidItem(self.__ap_list[i])], insert_pos=0) self.ap_tree.visible_items[0].set_active(True) def set_active_ap(self, index, state): self.active_ap_index = index self.set_ap(self.__ap_list, redraw=False) if index: self.move_active(index) def get_active_ap(self): return self.active_ap_index def add_switcher(self): if not hasattr(self, "device_tree") or not self.device_tree: self.device_tree = TreeView([DeviceItem()], mask_bound_height=0) self.device_tree.set_expand_column(1) self.wireless_box.pack_start(self.device_tree, False, False) self.wireless_box.reorder_child( self.wireless_box.get_children()[-2], len(self.wireless_box.get_children())) tray_log.debug(self.wireless_box.get_children()) net_manager.emit_wifi_switch(0) def remove_switcher(self): if self.device_tree: self.wireless_box.remove(self.device_tree) self.device_tree = None def get_active_in_ui(self): return filter(lambda i: i.get_active() == True, self.ap_tree.visible_items) def reset_tree(self): if len(self.ap_tree.visible_items) >= 5 and self.all_showed: remove_items = self.ap_tree.visible_items[5:] self.ap_tree.delete_items(remove_items) self.ap_tree.set_size_request(-1, WIDGET_HEIGHT * 5) self.tree_box.pack_start(self.more_button, False, False) self.all_showed = False
class SessionView(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) self.open_dialog = False self.tmp_editing_session = None # UI style style.draw_background_color(self) self.tree = TreeView( [], enable_drag_drop=False, enable_hover=True, enable_multiple_select=False, ) self.tree.set_expand_column(3) self.tree.set_column_titles( (_("Active"), _("Application"), _("Description"), _("Exec")), ) self.tree.set_size_request(800, -1) self.tree.connect("right-press-items", self.right_press_item) self.tree.draw_mask = self.draw_mask self.tree.add_items(self.get_list()) align = gtk.Alignment(0, 0, 0, 1) align.set_padding(15, 0, 20, 20) align.add(self.tree) align.connect("expose-event", self.expose_line) add_button = Button(_("New")) self.delete_button = Button(_("Delete")) add_button.connect("clicked", self.add_autostart) self.delete_button.connect("clicked", self.delete_autostart) self.delete_button.set_sensitive(False) foot_box = FootBox(adjustment=15) foot_box.set_buttons([add_button, self.delete_button]) self.pack_start(align, True, True) self.pack_end(foot_box, False, False) #self.pack_end(self.new_box, False, False) self.show_all() self._init_monitor() def disable_delete_button(self, value): self.delete_button.set_sensitive(not value) def _init_monitor(self): self.library_monitor = LibraryMonitor(get_user_config_dir()) self.library_monitor.set_property("monitored", True) self.library_monitor.connect("file-added", self.refresh_list) self.library_monitor.connect("location-removed", self.refresh_list) def right_press_item(self, widget, x_root, y_root, current_item, select_items): self.tmp_editing_session = current_item.item for item in select_items: item.unselect() if current_item != None: current_item.select() if self.open_dialog == False: dialog = NewSessionDialog(confirm_callback=self.edit_done, cancel_callback=self.cancel_callback) dialog.name_entry.set_text(current_item.item.name) dialog.exec_entry.set_text(current_item.item.exec_) dialog.desc_entry.set_text(current_item.item.comment) dialog.place_center() dialog.show_all() self.open_dialog = True def create_session_item(self, dialog): name = dialog.name_entry.get_text() exec_ = dialog.exec_entry.get_text() comment = dialog.desc_entry.get_text() session_manager.add(name, exec_, comment) self.open_dialog = False def expose_line(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation style.draw_out_line(cr, rect, exclude=["left", "right", "top"]) def sort_method(self): pass def add_autostart(self, widget): if self.open_dialog == False: dialog = NewSessionDialog( confirm_callback=self.create_session_item, cancel_callback=self.cancel_callback) dialog.show_all() self.open_dialog = True def delete_autostart(self, widget): items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows) item = items[0].item item.delete() self.tree.delete_select_items() if self.tree.visible_items == []: self.tree.add_items([NothingItem()]) def edit_done(self, dialog): self.tmp_editing_session.set_name(dialog.name_entry.get_text()) self.tmp_editing_session.set_exec(dialog.exec_entry.get_text()) self.tmp_editing_session.set_comment(dialog.desc_entry.get_text()) self.tmp_editing_session.save() self.tmp_editing_session = None items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows) self.tree.redraw_request(items, True) self.open_dialog = False def cancel_callback(self): self.tmp_editing_session = None self.open_dialog = False def pack(self, parent, widget_list, expand=False, fill=False): for w in widget_list: parent.pack_start(w, expand, fill) def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def get_list(self): usr_list = session_manager.list_autostart_items() if usr_list: return map(lambda w: SessionItem(self, w), usr_list) else: return [NothingItem()] def refresh_list(self, widget, gfile): self.tree.clear() self.tree.add_items(self.get_list()) self.tree.show()
class CompletionWindow(Window): ''' class docs ''' def __init__(self, window_width, window_height): ''' init docs ''' # Init. Window.__init__( self, # shadow_visible=False, shape_frame_function=self.shape_completion_window_frame, expose_frame_function=self.expose_completion_window_frame) self.window_width = window_width self.window_height = window_height self.window_offset_x = 8 self.window_offset_y = 34 self.align_size = 2 self.treeview = TreeView( [], enable_highlight=False, enable_multiple_select=False, enable_drag_drop=False, expand_column=0, ) self.treeview.scrolled_window.tag_by_popup_grab_window = True self.treeview_align = gtk.Alignment() self.treeview_align.set(0.5, 0.5, 1, 1) self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size) self.treeview_align.add(self.treeview) self.treeview.connect("press-return", self.treeview_press_return) self.treeview.draw_mask = self.draw_mask self.window_frame.pack_start(self.treeview_align, True, True) self.connect("realize", self.realize_completion_window) self.get_scrolledwindow = self.get_scrolledwindow wrap_grab_window(completion_grab_window, self) completion_grab_window.connect("input-method-focus-in", self.input_method_focus_in) completion_grab_window.connect("input-method-commit", self.input_method_commit) self.keymap = { "Home" : self.treeview.select_first_item, "End" : self.treeview.select_last_item, "Page_Up" : self.treeview.scroll_page_up, "Page_Down" : self.treeview.scroll_page_down, "Up" : self.treeview.select_prev_item, "Down" : self.treeview.select_next_item, } def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#ffffff", 0.9)), (1, ("#ffffff", 0.9)),] ) def treeview_press_return(self, treeview, select_items): if len(select_items) > 0: completion_grab_window.popup_grab_window_focus_out() global_event.emit("switch-to-detail-page", select_items[0].text) def set_input_method_cursor(self): entry_buffer = search_entry.entry.entry_buffer cursor_pos = entry_buffer.get_cursor_pos(entry_buffer.get_insert_index())[0] (entry_x, entry_y) = search_entry.translate_coordinates(search_entry.get_toplevel(), 0, 0) (window_x, window_y) = search_entry.get_toplevel().window.get_origin() completion_grab_window.im.set_cursor_location( gtk.gdk.Rectangle( window_x + entry_x + cursor_pos[0], window_y + entry_y + cursor_pos[1], 1, cursor_pos[3])) def input_method_focus_in(self, grab_window, im): self.set_input_method_cursor() def input_method_commit(self, grab_window, im, input_text): self.set_input_method_cursor() search_entry.set_text("%s%s" % (search_entry.get_text(), input_text)) def get_scrolledwindow(self): return self.treeview.scrolled_window def shape_completion_window_frame(self, widget, event): pass def expose_completion_window_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_frame_outside_3").get_color_info())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_frame_inside_2").get_color_info())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2) cr.fill() def show(self, search_string, pkg_names): search_entry.entry.entry_buffer.grab_focus_flag = True self.treeview.delete_all_items() self.treeview.add_items(map(lambda pkg_name: TextItem(pkg_name, search_string), pkg_names)) self.treeview.draw_area.grab_focus() (x, y) = get_widget_root_coordinate(search_entry, WIDGET_POS_BOTTOM_LEFT, False) self.move(x + self.window_offset_x, y + self.window_offset_y) self.show_all() def realize_completion_window(self, widget): self.set_default_size(self.window_width, self.window_height) self.set_geometry_hints( None, self.window_width, # minimum width self.window_height, # minimum height self.window_width, self.window_height, -1, -1, -1, -1, -1, -1 )
class PluginsManager(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) self.set_spacing(5) self.plugins = utils.get_main_window().plugins self.plugins_view = TreeView() self.plugins_view.add_items = self.plugins_view_add_items self.plugins_view.set_expand_column(0) self.plugins_view.draw_mask = self.plugins_view_draw_mask self.plugins_view.set_size_request(420, 330) self.plugins_view.connect("single-click-item", self.on_plugins_view_single_click) self.plugins_view.connect("press-return", self.on_plugins_view_press_return) self.plugins_view.set_column_titles([_("Name"), _("Version"), _("Enable"), ""], (self.sort_by_title, self.sort_by_title, self.sort_by_title, self.sort_by_title)) plugins_view_align = set_widget_gravity(self.plugins_view, gravity=(1, 1, 1, 1), paddings=(10, 0, 0, 0)) self.plugin_infos = PluginInfos() self.plugin_infos.set_size_request(420, 90) # plugin info self.pack_start(plugins_view_align, False, True) self.pack_start(self.plugin_infos, False, True) def plugins_view_add_items(self, items, insert_pos=None, clear_first=False): for item in items: item.plugins_view = self TreeView.add_items(self.plugins_view, items, insert_pos, clear_first) def sort_by_title(self, items, reverse): return sorted(items, key=lambda item: item.plugin, reverse=reverse) def plugins_view_draw_mask(self, cr, x, y, width, height): draw_alpha_mask(cr, x, y, width, height, "layoutLeft") def flush_plugins(self): self.__load_plugin_list() def __load_plugin_list(self): # clear plugins_view items. self.plugins_view.clear() plugins = self.plugins.list_installed_plugins() plugins_list = [] failed_list = [] for plugin in plugins: try: info = self.plugins.get_plugin_info(plugin) except Exception: failed_list.append(plugin) continue enabled = plugin in self.plugins.enabled_plugins plugins_list.append((plugin, info, enabled)) plugins_list.sort(key=lambda x: locale.strxfrm(x[1]["Name"])) plugins_items = [PluginItem(*args) for args in plugins_list] self.plugins_view.add_items(plugins_items) def on_plugins_view_press_return(self, widget, items): if len(items) > 0: item = items[0] self.toggle_plugin_status(item) def on_plugins_view_single_click(self, widget, item, column, x, y): if column == 2: self.toggle_plugin_status(item) def toggle_plugin_status(self, item): plugin = item.plugin will_enable = not item.enabled if will_enable: try: self.plugins.enable_plugin(plugin) except Exception, e: print e return else:
class MainBox(gtk.HBox): def __init__(self): gtk.HBox.__init__(self) self.connect("expose-event", self.on_page_expose_event) self.aibizhi_cache_page = CachePage(Aibizhi()) self.bizhi360_cache_page = CachePage(Bizhi360()) self.aibizhi_cache_page.cache_view.try_to_fetch() self.bizhi360_cache_page.cache_view.try_to_fetch() self.favorites_page = FavoritePage(get_favorite_dir()) self.pictures_page = LocalPicturePage(get_download_wallpaper_dir()) self.add_item = AddItem() self.pictures_page.select_view.add_items([self.add_item]) self.task_page = TaskPage() self.switch_page = gtk.VBox() self.__init_navigatebar() self.pack_start(self.navigatebar, False, True) self.pack_start(self.switch_page, True, True) event_manager.add_callback("switch-to-local-pictures", self.switch_to_local_pictures) def switch_to_local_pictures(self, name, obj, data=None): item = self.navigatebar.get_items()[2] self.on_navigatebar_single_click(self.navigatebar, item, 0, 0, 0) def __init_navigatebar(self): self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click) self.navigatebar.set_size_request(132, -1) self.navigatebar.draw_mask = self.on_navigatebar_draw_mask local_expand_item = ExpandItem(_("Library")) network_expand_item = ExpandItem(_("Internet")) self.navigatebar.add_items([ local_expand_item, network_expand_item, ]) local_expand_item.add_childs([ (FavoritesTitle, self.favorites_page), (LocalWallpapersTitle, self.pictures_page), ], expand=True) network_expand_item.add_childs([ (_("360 Wallpaper"), self.bizhi360_cache_page), (_("LoveWallpaper"), self.aibizhi_cache_page), ], expand=True) if get_favorite_number() == 0: self.navigatebar.set_highlight_item( self.navigatebar.get_items()[2]) self.switch_page.add(self.pictures_page) else: self.navigatebar.set_highlight_item( self.navigatebar.get_items()[1]) self.switch_page.add(self.favorites_page) def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def on_page_expose_event(self, widget, event): cr = widget.window.cairo_create() width, height = widget.size_request() self.draw_mask(cr, 0, 0, width, height) def on_navigatebar_draw_mask(self, cr, x, y, w, h): self.draw_mask(cr, x, y, w, h) draw_line(cr, (x + w, y), (0, h), "#d6d6d6") def on_navigatebar_single_click(self, widget, item, column, x, y): if item.widget: widget.set_highlight_item(item) switch_box(self.switch_page, item.widget)
class UninstallPage(gtk.VBox): ''' class docs ''' def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.search_flag = False self.uninstall_change_items = {"add": [], "delete": []} self.message_bar = MessageBar(32) self.message_bar.search_entry.entry.connect("changed", self.search_cb) self.message_bar.search_button.connect("clicked", self.search_cb) self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) top_hbox = gtk.HBox() top_hbox.pack_start(self.message_bar) self.pack_start(top_hbox, False, False) self.pack_start(self.treeview, True, True) self.treeview.connect("items-change", self.update_message_bar) self.fetch_uninstall_info() self.treeview.draw_mask = self.draw_mask def search_cb(self, widget, event=None): if not self.search_flag: self.cache_items = [item for item in self.treeview.visible_items] results = [] keywords = self.message_bar.search_entry.get_text().strip() if keywords != "": self.search_flag = True # TODO: comment this search_query api, there are many problems for this api ''' pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" "))) for item in self.cache_items: if item.pkg_name in pkg_names: results.append(item) ''' for item in self.cache_items: if keywords in item.pkg_name: results.append(item) self.treeview.clear() self.treeview.add_items(results) else: self.treeview.clear() self.search_flag = False # for add items if self.uninstall_change_items["add"] != []: for item in self.uninstall_change_items["add"]: self.cache_items.append(item) self.uninstall_change_items["add"] = [] # for delete items if self.uninstall_change_items["delete"] != []: for item in self.uninstall_change_items["delete"]: if item in self.cache_items: self.cache_items.remove(item) self.uninstall_change_items["delete"] = [] self.treeview.add_items(self.cache_items) def normal_search_cb(self, keywords): pass def update_message_bar(self, treeview): self.message_bar.set_message(_("%s applications can be uninstalled") % len(treeview.visible_items)) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] ) def update_action_status(self, pkg_infos): pkg_items = [] for (pkg_name, action_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = UninstallItem(pkg_name, self.bus_interface.request_pkgs_uninstall_version([pkg_name])[0], self.data_manager) if action_status == "wait": pkg_item.action_wait() elif action_status == "start": pkg_item.action_start() elif action_status == "update": pkg_item.action_update(0) pkg_items.append(pkg_item) pkg_items = filter(lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def fetch_uninstall_info(self): self.bus_interface.request_uninstall_pkgs( reply_handler=self.render_uninstall_info, error_handler=lambda e:handle_dbus_error("request_uninstall_pkgs", e)) def render_uninstall_info(self, pkg_infos): self.add_uninstall_items(pkg_infos) def add_uninstall_items(self, pkg_infos): items = [] for pkg_info in pkg_infos: (pkg_name, pkg_version) = eval(pkg_info) if self.data_manager.is_pkg_have_desktop_file(pkg_name) != None \ and self.data_manager.is_pkg_display_in_uninstall_page(pkg_name)[0] == '1': items.append(UninstallItem(pkg_name, pkg_version, self.data_manager)) if self.search_flag: self.uninstall_change_items["add"] += items else: self.treeview.add_items(items) def delete_uninstall_items(self, items): if self.search_flag: self.uninstall_change_items["delete"] += items for item in items: if item in self.treeview.visible_items: self.treeview.delete_items([item]) else: self.treeview.delete_items(items) def action_start(self, pkg_name): for item in self.treeview.visible_items: if item.pkg_name == pkg_name: item.action_start() break def action_update(self, pkg_name, percent): for item in self.treeview.visible_items: if item.pkg_name == pkg_name: item.action_update(percent) break def action_finish(self, pkg_name, pkg_info_list): for item in self.treeview.visible_items: if item.pkg_name == pkg_name: item.action_finish() break
class Region(gtk.Alignment): def __init__(self, connection=None): gtk.Alignment.__init__(self, 0, 0, 0, 0) ################# self.provider_select = None self.connect('expose-event', self.expose_event) self.prop_dict = {} main_table = gtk.Table(2, 2, False) main_table.set_row_spacing(1, 10) main_table.set_col_spacings(4) self.add(main_table) self.country_tree = TreeView(enable_multiple_select=False, enable_drag_drop=False, ) self.country_tree.set_expand_column(1) self.country_tree.set_size_request(365, 380) self.country_tree.draw_mask = self.draw_mask self.country_tree.connect("button-press-item", self.country_selected) left_box_align = gtk.Alignment(0, 0, 0, 0) left_box_align.set_padding(1,1,1,1) left_box_align.add(self.country_tree) left_box_align.show_all() left_box = gtk.VBox() # wrap title country_title = TitleBar(app_theme.get_pixbuf("network/globe-green.png"), _("Country or Region:"), has_separator=False) left_box.pack_start(country_title, False, False) left_box.pack_start(left_box_align, False, False) self.provider_tree = TreeView(enable_multiple_select=False, enable_drag_drop=False, ) self.provider_tree.set_expand_column(0) self.provider_tree.set_size_request(365, 380) self.provider_tree.draw_mask = self.draw_mask self.provider_tree.connect("button-press-item", self.provider_selected) right_box_align = gtk.Alignment(0, 0, 0, 0) right_box_align.set_padding(1,1,1,1) right_box_align.add(self.provider_tree) right_box = gtk.VBox() # wrap title provider_title = TitleBar(app_theme.get_pixbuf("network/building.png"), _("Provider:"), has_separator=False) right_box.pack_start(provider_title, False, False) right_box.pack_start(right_box_align, False, False) main_left_align = gtk.Alignment(0, 0, 0, 0) main_left_align.set_padding(15, 0, 20, 0) main_left_align.add(left_box) main_table.attach(main_left_align, 0, 1, 0, 1) main_right_align = gtk.Alignment(0, 0, 0, 0) main_right_align.set_padding(15, 0, 0, 20) main_right_align.add(right_box) main_table.attach(main_right_align, 1, 2, 0, 1) hints = _("Tips:This assistant helps you easily set up a mobile broadband connection to a cellular network.") left_box_align.connect("expose-event", self.expose_outline) right_box_align.connect("expose-event", self.expose_outline) next_button = Button("Next") next_button.connect("clicked", self.next_button_clicked) self.foot_box = FootBox() self.foot_box.set_buttons([next_button]) self.foot_box.set_tip(hints) main_table.attach(self.foot_box, 0, 2, 1, 2) self.show_all() #self.init() def expose_outline(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*BORDER_COLOR) cr.rectangle(rect.x, rect.y, rect.width , rect.height ) cr.stroke() def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb( 1, 1, 1) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def expose_hint_background(self, widget, event): bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR) cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*bg_color) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() with cairo_disable_antialias(cr): cr.set_source_rgb(*BORDER_COLOR) cr.set_line_width(1) cr.rectangle(rect.x , rect.y, rect.width , rect.height -1) cr.stroke() def next_button_clicked(self, widget): # 检查是否选择了运营商 if not self.provider_select: print "provider has not selected" return try: self.plan_select except: self.plan_select = None def add_keys(settings): self.prop_dict = settings username = self.__sp.get_provider_username(self.code, self.provider_select) password = self.__sp.get_provider_password(self.code, self.provider_select) add_keys({"cdma": { "number": "#777", "username": username, "password": password}}) provider_type = "cdma" if self.plan_select: self.prop_dict.pop("cdma") apn = self.plan_select index = self.__sp.get_provider_apns_name(self.code, self.provider_select).index(apn) (network_id, network_type) = self.__sp.get_provider_networks(self.code, self.provider_select)[index] add_keys({"gsm":{ "number": "*99#", "username": username, "password": password, "apn": apn, #"network_id": network_id, "network_type": network_type}}) provider_type = "gsm" #setting_page = nm_module.slider.get_page_by_name("setting") #broadband = setting_page.setting_group.get_broadband() if self.connection_type == None: new_connection = getattr(nm_module.nm_remote_settings, "new_%s_connection"%provider_type)() Dispatcher.emit("region-back", new_connection, self.prop_dict, provider_type) #setting_page.sidebar.new_connection_list[provider_type].append(new_connection) #setting_page.init(setting_page.sidebar.new_connection_list) #setting_page.sidebar.set_active(new_connection) #broadband.set_new_values(self.prop_dict, provider_type) else: Dispatcher.emit("region-back", self.connection, self.prop_dict, provider_type) #broadband.set_new_values(self.prop_dict, provider_type) nm_module.slider._slide_to_page("setting", "none") def init(self, connection): if connection == None: self.connection_type = None else: self.connection = connection mobile_type = connection.get_setting("connection").type self.connection_type = mobile_type Dispatcher.send_submodule_crumb(_("Region"), 2) from mm.provider import ServiceProviders self.__sp = ServiceProviders() self.country_list = self.__sp.get_country_name_list() self.country_tree.delete_all_items() self.country_tree.add_items([CountryItem(_(country)) for country in self.country_list]) # add a bottom line for last item code = self.__sp.get_country_from_timezone() self.country_codes = self.__sp.get_country_list() try: selected_country = self.country_tree.visible_items[self.country_codes.index(code)] self.country_tree.select_items([selected_country]) self.auto_scroll_to() self.country_tree.emit("button-press-item", selected_country, 0, 1, 1) except: pass def country_selected(self, widget, w, a, b, c): self.provider_tree.delete_all_items() self.code = self.country_codes[widget.select_rows[0]] if self.connection_type: self.provider_names = getattr(self.__sp, "get_country_%s_providers_name"%self.connection_type)(self.code) else: self.provider_names = self.__sp.get_country_providers_name(self.code) self.provider_select = None self.provider_tree.add_items([Item(p, self.__sp, self.code) for p in self.provider_names]) self.provider_tree.show_all() def provider_selected(self, widget, item, column, offset_x, offset_y): if type(item) is Item: self.provider_select = item.content self.plan_select = None else: self.plan_select = item.content def auto_scroll_to(self): vadjust = self.country_tree.scrolled_window.get_vadjustment() upper = vadjust.upper page_size = vadjust.page_size vadjust.set_value(min(upper - page_size, (self.country_tree.select_rows[0]- 4)*30))
class RadioBrowser(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) # Init radiobar. self.__init_radiobar() # is loaded. self.homepage_load_flag = False self.home_page = HomePage() self.hot_page_view, self.hot_page_sw = self.get_radio_icon_view(TAG_HOT, 20) self.fast_page_view, self.fast_page_sw = self.get_radio_icon_view(TAG_FAST, 20) # Genres page self.genre_page = GenrePage() self.page_box = gtk.VBox() self.page_box.add(self.home_page) self.body_paned = HPaned(handle_color=app_theme.get_color("panedHandler")) self.body_paned.add1(self.radiobar) self.body_paned.add2(self.page_box) self.network_failed_box = NetworkConnectFailed(self.check_network_connection) self.check_network_connection(auto=True) def check_network_connection(self, auto=False): if is_network_connected(): switch_tab(self, self.body_paned) if not auto: self.start_fetch_channels() else: switch_tab(self, self.network_failed_box) def __init_radiobar(self): self.radiobar = TreeView(enable_drag_drop=False, enable_multiple_select=False) items = [] items.append(CategroyTreeItem(_("Home"), "home", lambda : switch_tab(self.page_box, self.home_page))) items.append(CategroyTreeItem(_("Hot MHz"), "hot", lambda : switch_tab(self.page_box, self.hot_page_sw))) items.append(CategroyTreeItem(_("Genres MHz"), "genre", lambda : switch_tab(self.page_box, self.genre_page))) items.append(CategroyTreeItem(_("Pop MHz"), "up", lambda : switch_tab(self.page_box, self.fast_page_sw))) self.radiobar.add_items(items) self.radiobar.select_items([self.radiobar.visible_items[0]]) self.radiobar.set_size_request(121, -1) self.radiobar.draw_mask = self.on_radiobar_draw_mask def on_radiobar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h ,"layoutRight") def get_radio_icon_view(self, tag, limit=10, padding_x=0, padding_y=10): icon_view = RadioIconView(tag=tag, limit=limit, padding_x=padding_x, padding_y=padding_y) scrolled_window = icon_view.get_scrolled_window() return icon_view, scrolled_window def start_fetch_channels(self): self.fast_page_view.clear_items() self.hot_page_view.clear_items() self.home_page.start_fetch_channels() self.hot_page_view.start_fetch_channels() self.fast_page_view.start_fetch_channels() self.genre_page.start_fetch_channels()
class SearchUI(DialogBox): def __init__(self): DialogBox.__init__( self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, modal=False, window_hint=None, skip_taskbar_hint=False, window_pos=gtk.WIN_POS_CENTER) self.artist_entry = InputEntry() self.artist_entry.set_size(130, 23) self.title_entry = InputEntry() self.title_entry.set_size(130, 23) artist_label = Label(_("Artist:")) title_label = Label(_("Title:")) right_align = gtk.Alignment() right_align.set(0, 0, 0, 1) self.search_button = Button(_("Search")) self.search_button.connect("clicked", self.search_lyric_cb) self.process_id = 0 info_box = gtk.HBox(spacing=25) control_box = gtk.HBox(spacing=5) title_box = gtk.HBox(spacing=5) title_box.pack_start(title_label, False, False) title_box.pack_start(self.title_entry) artist_box = gtk.HBox(spacing=5) artist_box.pack_start(artist_label, False, False) artist_box.pack_start(self.artist_entry) control_box.pack_start(title_box, False, False) control_box.pack_start(artist_box, False, False) info_box.pack_start(control_box, False, False) info_box.pack_start(self.search_button, False, False) sort_items = [ lambda items, reverse : self.sort_by_key(items, reverse, "title"), lambda items, reverse : self.sort_by_key(items, reverse, "artist")] self.result_view = TreeView() self.result_view.set_expand_column(0) self.result_view.connect("double-click-item", self.double_click_cb) self.result_view.set_column_titles([_("Title"), _("Artist")], sort_items) self.result_view.draw_mask = self.draw_view_mask self.prompt_label = Label("") download_button = Button(_("Download")) download_button.connect("clicked", self.download_lyric_cb) cancel_button = Button(_("Close")) cancel_button.connect("clicked", lambda w: self.hide_all()) info_box_align = gtk.Alignment() info_box_align.set_padding(5, 0, 5, 0) info_box_align.add(info_box) self.body_box.set_spacing(5) self.body_box.pack_start(info_box_align, False, False) self.body_box.pack_start(self.result_view, True, True) self.left_button_box.set_buttons([self.prompt_label]) self.right_button_box.set_buttons([download_button, cancel_button]) self.lrc_manager = LrcManager() def show_window(self): DialogBox.show_window(self) self.present() def draw_view_mask(self, cr, x, y, width, height): draw_alpha_mask(cr, x, y, width, height, "layoutMiddle") def sort_by_key(self, items, sort_reverse, sort_key): return sorted(items, reverse=sort_reverse, key=lambda item: getattr(item, sort_key)) def double_click_cb(self, widget, item, colume, x, y): self.download_lyric_cb(widget) def search_engine(self, artist, title, pid): ting_result = poster.query_lrc_info(artist, title) self.render_lyrics(ting_result, pid=pid) ttplayer_result = TTPlayer().request(artist, title) self.render_lyrics(ttplayer_result, pid=pid) ttpod_result = TTPod().request(artist, title) self.render_lyrics(ttpod_result, pid=pid) duomi_result = DUOMI().request(artist, title) self.render_lyrics(duomi_result, pid=pid, last=True) def search_lyric_cb(self, widget): self.result_view.clear() artist = self.artist_entry.entry.get_text() title = self.title_entry.entry.get_text() # widget.set_sensitive(False) self.prompt_label.set_text(_("Now searching...")) if artist == "" and title == "": self.prompt_label.set_text(_("Not found!")) return self.process_id += 1 utils.ThreadLoad(self.search_engine, artist, title, self.process_id).start() @post_gui def render_lyrics(self, result, last=False, pid=1): '''docs''' if pid != self.process_id: return if result != None: try: items = [SearchItem(each_info) for each_info in result] except: pass else: self.result_view.add_items(items) self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items())) else: if last: if len(self.result_view.get_items()) > 0: self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items())) else: self.prompt_label.set_text(_("Not found!")) def download_lyric_cb(self, widget): select_items = self.result_view.select_rows save_filepath = self.lrc_manager.get_lrc_filepath(Player.song) if len(select_items) > 0: self.prompt_label.set_text(_("Downloading lyrics...")) item = self.result_view.get_items()[select_items[0]] url = item.get_url() net_encode = item.get_netcode() utils.ThreadRun(utils.download, self.render_download, [url, save_filepath, net_encode]).start() @post_gui def render_download(self, result): if result: Dispatcher.reload_lrc(Player.song) self.prompt_label.set_text("%s %s" % (_("File save to"), config.get("lyrics", "save_lrc_path"))) else: self.prompt_label.set_text(_("Download failed."))
class UninstallPage(gtk.VBox): ''' class docs ''' def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.search_flag = False self.uninstall_change_items = {"add": [], "delete": []} self.message_bar = MessageBar(32) self.message_bar.search_entry.entry.connect("changed", self.search_cb) self.message_bar.search_button.connect("clicked", self.search_cb) self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) top_hbox = gtk.HBox() top_hbox.pack_start(self.message_bar) self.pack_start(top_hbox, False, False) self.pack_start(self.treeview, True, True) self.treeview.connect("items-change", self.update_message_bar) self.white_kernel_pkg_names = self.get_white_kernel_pkg_names() self.fetch_uninstall_info() self.treeview.draw_mask = self.draw_mask def search_cb(self, widget, event=None): if not self.search_flag: self.cache_items = [item for item in self.treeview.visible_items] results = [] keywords = self.message_bar.search_entry.get_text().strip() if keywords != "": self.search_flag = True # TODO: comment this search_query api, there are many problems for this api ''' pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" "))) for item in self.cache_items: if item.pkg_name in pkg_names: results.append(item) ''' for item in self.cache_items: if keywords in item.pkg_name: results.append(item) self.treeview.clear() self.treeview.add_items(results) else: self.treeview.clear() self.search_flag = False # for add items if self.uninstall_change_items["add"] != []: for item in self.uninstall_change_items["add"]: self.cache_items.append(item) self.uninstall_change_items["add"] = [] # for delete items if self.uninstall_change_items["delete"] != []: for item in self.uninstall_change_items["delete"]: if item in self.cache_items: self.cache_items.remove(item) self.uninstall_change_items["delete"] = [] self.treeview.add_items(self.cache_items) def normal_search_cb(self, keywords): pass def update_message_bar(self, treeview): self.message_bar.set_message(_("%s applications can be uninstalled") % len(treeview.visible_items)) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] ) def update_action_status(self, pkg_infos): pkg_items = [] for (pkg_name, action_status) in pkg_infos: pkg_item = None for item in self.treeview.visible_items: if item.pkg_name == pkg_name: pkg_item = item break if pkg_item == None: pkg_item = UninstallItem(pkg_name, self.bus_interface.request_pkgs_uninstall_version([pkg_name])[0], self.data_manager) if action_status == "wait": pkg_item.action_wait() elif action_status == "start": pkg_item.action_start() elif action_status == "update": pkg_item.action_update(0) pkg_items.append(pkg_item) pkg_items = filter(lambda item: item not in self.treeview.visible_items, pkg_items) self.treeview.add_items(pkg_items) def fetch_uninstall_info(self): self.bus_interface.request_uninstall_pkgs( reply_handler=lambda r:self.add_uninstall_items(r, True), error_handler=lambda e:self.add_uninstall_items(e, False) ) def get_white_kernel_pkg_names(self): version = commands.getoutput("uname -r").split("-generic")[0] white_pkg_names = ["linux-image-generic", "linux-headers-generic"] white_pkg_names.append("linux-image-%s-generic" % version) white_pkg_names.append("linux-image-extra-%s-generic" % version) white_pkg_names.append("linux-headers-%s-generic" % version) white_pkg_names.append("linux-headers-%s" % version) return white_pkg_names def is_uninstallable_kernel(self, pkg_name): if pkg_name.startswith("linux-image") or pkg_name.startswith("linux-headers"): return pkg_name not in self.white_kernel_pkg_names def add_uninstall_items(self, data, success): if not success: global_logger.logerror("request_uninstall_pkgs failed: %s" % data) return pkg_infos = str(data) items = [] try: uninstall_pkg_infos = json.loads(pkg_infos) for pkg_info in uninstall_pkg_infos: pkg_name, pkg_version = pkg_info if self.is_uninstallable_kernel(pkg_name) or \ self.data_manager.is_pkg_display_in_uninstall_page(pkg_name): items.append(UninstallItem(pkg_name, pkg_version, self.data_manager)) except Exception, e: global_logger.logerror("Parse uninstall package information failed: %s" % pkg_infos) global_logger.logerror("Error: %s" % str(e)) if self.search_flag: self.uninstall_change_items["add"] += items else: self.treeview.add_items(items)
class MainBox(gtk.HBox): def __init__(self): gtk.HBox.__init__(self) self.connect("expose-event", self.on_page_expose_event) self.aibizhi_cache_page = CachePage(Aibizhi()) self.bizhi360_cache_page = CachePage(Bizhi360()) self.aibizhi_cache_page.cache_view.try_to_fetch() self.bizhi360_cache_page.cache_view.try_to_fetch() self.favorites_page = FavoritePage(get_favorite_dir()) self.pictures_page = LocalPicturePage(get_download_wallpaper_dir()) self.add_item = AddItem() self.pictures_page.select_view.add_items([self.add_item]) self.task_page = TaskPage() self.switch_page = gtk.VBox() self.__init_navigatebar() self.pack_start(self.navigatebar, False, True) self.pack_start(self.switch_page, True, True) event_manager.add_callback("switch-to-local-pictures", self.switch_to_local_pictures) def switch_to_local_pictures(self, name, obj, data=None): item = self.navigatebar.get_items()[2] self.on_navigatebar_single_click(self.navigatebar, item, 0, 0, 0) def __init_navigatebar(self): self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click) self.navigatebar.set_size_request(132, -1) self.navigatebar.draw_mask = self.on_navigatebar_draw_mask local_expand_item = ExpandItem(_("Library")) network_expand_item = ExpandItem(_("Internet")) self.navigatebar.add_items([local_expand_item, network_expand_item, ]) local_expand_item.add_childs([ (FavoritesTitle, self.favorites_page), (LocalWallpapersTitle, self.pictures_page), ], expand=True) network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page), (_("LoveWallpaper"), self.aibizhi_cache_page), ], expand=True) if get_favorite_number() == 0: self.navigatebar.set_highlight_item(self.navigatebar.get_items()[2]) self.switch_page.add(self.pictures_page) else: self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1]) self.switch_page.add(self.favorites_page) def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def on_page_expose_event(self, widget, event): cr = widget.window.cairo_create() width, height= widget.size_request() self.draw_mask(cr, 0, 0, width, height) def on_navigatebar_draw_mask(self, cr, x, y, w, h): self.draw_mask(cr, x, y, w, h) draw_line(cr, (x + w, y), (0, h), "#d6d6d6") def on_navigatebar_single_click(self, widget, item, column, x, y): if item.widget: widget.set_highlight_item(item) switch_box(self.switch_page, item.widget)
class WebcastsBrowser(gtk.VBox, SignalContainer): def __init__(self): gtk.VBox.__init__(self) SignalContainer.__init__(self) # Init categorys. self.get_categorys() # load data. self.__load_webcast_query() # Init webcastbar. self.__init_webcastbar() # Init iconview. self.metro_view = self.get_icon_view() self.metro_view_sw = self.metro_view.get_scrolled_window() self.page_box = gtk.VBox() self.page_box.add(self.metro_view_sw) # webcasts view self.webcast_view = self.get_webcast_view() self.webcast_view_sw = self.webcast_view.get_scrolled_window() # collect view self.collected_db_file = get_config_file("favorite_webcasts.db") self.collected_view = self.get_webcast_view() self.collected_view_sw = self.collected_view.get_scrolled_window() # Init collect view. # init listview page. self.init_listview_page() Dispatcher.connect("change-webcast", self.on_dispatcher_change_webcast) WebcastDB.connect("changed", self.on_db_update_songs) body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True) body_paned.add1(self.webcastbar) body_paned.add2(self.page_box) self.add(body_paned) def get_categorys(self): lang = utils.get_system_lang() if lang.startswith("zh"): self.__categorys = ["region", "genre", "composite"] self.current_category = "region" else: self.__categorys = ["region_en", "genre_en"] self.current_category = "region_en" self.__category_gettexts = { "region" : "地域分类", "genre" : "流派分类", "region_en" : _("Region"), "genre_en" : _("Genre"), "composite" : "综合分类", "finance" : "财经", "sports" : "体育", "music" : "音乐", "news" : "新闻", "network" : "网络", } def __load_webcast_query(self): self.__db_query = WebcastQuery() if WebcastDB.isloaded(): self.__on_db_loaded() else: WebcastDB.connect("loaded", lambda obj: self.__on_db_loaded()) def __on_db_loaded(self): self.autoconnect(self.__db_query, "added", self.__on_added_songs) self.autoconnect(self.__db_query, "removed", self.__on_removed_songs) self.autoconnect(self.__db_query, "update-songs", self.__on_update_songs) self.autoconnect(self.__db_query, "full-update", self.__on_full_update) self.__db_query.set_query() def __on_added_songs(self, db_query, songs): self.reload_flag = True def __on_removed_songs(self, db_query, songs): self.reload_flag = True def __on_update_songs(self, db_query, songs): self.reload_flag = True def __on_full_update(self, db_query): self.load_view_data() self.load_collect_data() def __init_webcastbar(self): self.webcastbar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.webcastbar.connect("single-click-item", self.on_webcastbar_single_click_item) items = [] for category in self.__categorys: items.append(CategoryTreeItem(self.__category_gettexts[category], category=category)) items.append(CollectTreeItem(_("Favorites"))) self.webcastbar.add_items(items) self.webcastbar.select_items([self.webcastbar.visible_items[0]]) self.webcastbar.set_size_request(121, -1) self.webcastbar.draw_mask = self.on_webcastbar_draw_mask def on_webcastbar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h ,"layoutRight") def on_webcastbar_single_click_item(self, widget, item, column, x, y): if hasattr(item, "collect_flag"): switch_tab(self.page_box, self.collected_view_sw) else: widget = self.page_box.get_children()[0] if widget != self.metro_view_sw: switch_tab(self.page_box, self.metro_view_sw) if self.current_category != item.category: self.current_category = item.category self.load_view_data() def init_listview_page(self): self.listview_page = gtk.VBox() self.text_prompt = TextPrompt("Default") prompt_align = set_widget_gravity(self.text_prompt, paddings=(10, 10, 0, 0)) prompt_box = gtk.HBox() back_button = BackButton() back_button.connect("clicked", self.on_backbutton_clicked) back_button_align = set_widget_gravity(back_button, gravity=(0.5, 0.5, 0, 0), paddings=(0, 0, 10, 5)) prompt_box.pack_start(back_button_align, False, True) prompt_box.pack_start(prompt_align, False, False) self.listview_page.pack_start(prompt_box, False, True) self.listview_page.pack_start(self.webcast_view_sw, True, True) def on_backbutton_clicked(self, widget): switch_tab(self.page_box, self.metro_view_sw) def switch_to_listview(self, category, title): self.text_prompt.set_text(title) self.webcast_view.clear() songs = self.__db_query.get_songs(category, title) self.webcast_view.add_webcasts(songs) switch_tab(self.page_box, self.listview_page) def load_view_data(self): self.metro_view.clear() if self.current_category == "composite": child_datas = self.__db_query.get_composite_categorys() gettext_datas = [] for child in child_datas: gettext_datas.append((self.__category_gettexts[child], child)) self.metro_view.add_composite_items(gettext_datas) else: child_datas = self.__db_query.get_info(self.current_category)[0] child_datas.sort(key=lambda x: locale.strxfrm(x)) self.metro_view.add_webcast_items(child_datas) def load_collect_data(self): try: collected_objs = utils.load_db(self.collected_db_file) except: collected_objs = None if collected_objs: songs = [ WebcastDB.get_song(uri) for uri in collected_objs] else: songs = None if songs: songs = [ song for song in songs if song.get("collected", False)] if songs: self.collected_view.add_webcasts(songs) def get_icon_view(self): icon_view = WebcastIconView() icon_view.connect("single-click-item", self.on_iconview_single_click_item) icon_view.connect("double-click-item", self.on_iconview_single_click_item) return icon_view def on_iconview_single_click_item(self, widget, item, x, y): if item.is_composited: category = item.category else: category = self.current_category title = item.title if item.is_composited: self.switch_to_listview(category, title) else: self.switch_to_listview(category, title) def get_webcast_view(self): webcast_view = MultiDragWebcastView() webcast_view.keymap.update({"BackSpace" : lambda : self.on_backbutton_clicked(None)}) return webcast_view def on_dispatcher_change_webcast(self, widget, song): item = self.collected_view.get_webcast_item(song) if item and not song.get("collected", False): self.collected_view.delete_items([item]) elif song.get("collected", False): self.collected_view.add_webcasts([song]) def on_db_update_songs(self, db, infos): for song, tags, new_tags in infos: if new_tags.has_key("collected"): item = self.collected_view.get_webcast_item(song) if item: if not new_tags.get("collected", False): self.collected_view.delete_items([item]) else: if new_tags.get("collected", False): self.collected_view.add_webcasts([song]) def save(self): songs = self.collected_view.get_webcasts() uris = [ song.get("uri") for song in songs if song.get("uri")] utils.save_db(uris, self.collected_db_file)
class ListviewFactory(object): ''' class docs ''' def __init__(self, items, owner): ''' init docs ''' self.items = [ListViewItem(x, owner) for x in items] self.owner = owner self.count_per_page = 10 if self.owner == "brief" else 20 self.listview = None self.page_count = 0 self.page_index = 0 self.paged_items = self.get_paged_items() self.init_listview() def prepend_item(self, item): if self.listview: self.listview.add_items([ListViewItem(item, self.owner)], insert_pos=0) def append_item(self, item): if self.listview: self.listview.add_items([ListViewItem(item, self.owner)]) def on_listview_button_pressed(self, widget, event, listview): x = event.x y = event.y if event.button == 1: for item in listview.get_items(): for index, rect in enumerate(item.pointer_hand_rectangles): if is_in_rect((x, y), rect): action = item.message["hints"]["x-deepin-hyperlinks"][index] if action.has_key("href"): webbrowser.open_new_tab(action.get("href")) return def on_listview_motion_notify(self, widget, event, listview): x = event.x y = event.y flag = False for item in listview.get_items(): if flag: break for rect in item.pointer_hand_rectangles: if is_in_rect((x, y), rect): flag = True break if flag: widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1)) else: widget.window.set_cursor(None) def init_listview(self): ''' docs ''' items = self.paged_items[self.page_index] self.listview = TreeView(items) self.listview.draw_mask = self.on_listview_draw_mask self.listview.set_expand_column(0) if self.owner == "detail": self.listview.set_column_titles([_("Content of messages"), _("Time")], [self.sort_by_content, self.sort_by_time]) self.listview.draw_area.connect_after("button-press-event", self.on_listview_button_pressed, self.listview) self.listview.draw_area.connect_after("motion-notify-event", self.on_listview_motion_notify, self.listview) self.listview.connect("right-press-items", self.on_listview_right_press_items) self.listview.scrolled_window.connect("vscrollbar-state-changed", self.update_listview) event_manager.emit("listview-items-added", items) def update_listview(self, widget, state): if state == "bottom": if self.page_index < self.page_count - 1: self.page_index = self.page_index + 1 items = self.paged_items[self.page_index] self.listview.add_items(items) event_manager.emit("listview-items-added", items) def on_listview_draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def on_listview_right_press_items(self, widget, root_x, root_y, current_item, select_items): if self.owner == "detail": def on_delete_selected_record(): def on_ok_clicked(): def _remove_selected(): for item in select_items: db.remove(item.id) db.commit() widget.delete_items(select_items) widget.get_toplevel()._init_data() Thread(target=_remove_selected).run() dialog = ConfirmDialog( _("Delete Item(s)"), _("Are you sure you want to delete the selected item(s)?"), confirm_callback = on_ok_clicked) dialog.show_all() def on_delete_all_record(): def on_ok_clicked(): def _remove_all(): for item in self.items: db.remove(item.id) db.commit() widget.get_toplevel().refresh_view() Thread(target=_remove_all).run() dialog = ConfirmDialog( _("Delete Item(s)"), _("Are you sure delete all items?"), confirm_callback = on_ok_clicked) dialog.show_all() Menu([(None, _("Delete selected item(s)"), on_delete_selected_record), (None, _("Delete all items"), on_delete_all_record)], True).show((root_x, root_y)) def get_paged_items(self): paged_items = {} index = 0 for item in self.items: paged_items.setdefault(index / self.count_per_page, []).append(item) index += 1 self.page_count = len(paged_items) return paged_items def sort_by_content(self, items, reverse): ''' docs ''' return sorted(items, key=lambda item : item.content, reverse=reverse) def sort_by_time(self, items, reverse): ''' docs ''' return sorted(items, key=lambda item : item.time, reverse=reverse)
class SessionView(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) self.open_dialog = False self.tmp_editing_session = None # UI style style.draw_background_color(self) self.tree = TreeView([],enable_drag_drop=False, enable_hover=True, enable_multiple_select=False, ) self.tree.set_expand_column(3) self.tree.set_column_titles((_("Active"), _("Application"), _("Description"), _("Exec")),) self.tree.set_size_request(800, -1) self.tree.connect("right-press-items", self.right_press_item) self.tree.draw_mask = self.draw_mask self.tree.add_items(self.get_list()) align = gtk.Alignment(0, 0, 0, 1) align.set_padding(15, 0, 20, 20) align.add(self.tree) align.connect("expose-event", self.expose_line) add_button = Button(_("New")) self.delete_button = Button(_("Delete")) add_button.connect("clicked", self.add_autostart) self.delete_button.connect("clicked", self.delete_autostart) self.delete_button.set_sensitive(False) foot_box = FootBox(adjustment=15) foot_box.set_buttons([add_button, self.delete_button]) self.pack_start(align, True, True) self.pack_end(foot_box, False, False) #self.pack_end(self.new_box, False, False) self.show_all() self._init_monitor() def disable_delete_button(self, value): self.delete_button.set_sensitive(not value) def _init_monitor(self): self.library_monitor = LibraryMonitor(get_user_config_dir()) self.library_monitor.set_property("monitored", True) self.library_monitor.connect("file-added", self.refresh_list) self.library_monitor.connect("location-removed", self.refresh_list) def right_press_item(self, widget, x_root, y_root, current_item, select_items): self.tmp_editing_session = current_item.item for item in select_items: item.unselect() if current_item != None: current_item.select() if self.open_dialog == False: dialog = NewSessionDialog(confirm_callback = self.edit_done, cancel_callback = self.cancel_callback) dialog.name_entry.set_text(current_item.item.name) dialog.exec_entry.set_text(current_item.item.exec_) dialog.desc_entry.set_text(current_item.item.comment) dialog.place_center() dialog.show_all() self.open_dialog = True def create_session_item(self, dialog): name = dialog.name_entry.get_text() exec_ = dialog.exec_entry.get_text() comment = dialog.desc_entry.get_text() session_manager.add(name, exec_, comment) self.open_dialog = False def expose_line(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation style.draw_out_line(cr, rect, exclude=["left", "right", "top"]) def sort_method(self): pass def add_autostart(self, widget): if self.open_dialog == False: dialog = NewSessionDialog(confirm_callback= self.create_session_item, cancel_callback = self.cancel_callback) dialog.show_all() self.open_dialog = True def delete_autostart(self, widget): items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows) item = items[0].item item.delete() self.tree.delete_select_items() if self.tree.visible_items == []: self.tree.add_items([NothingItem()]) def edit_done(self, dialog): self.tmp_editing_session.set_name(dialog.name_entry.get_text()) self.tmp_editing_session.set_exec(dialog.exec_entry.get_text()) self.tmp_editing_session.set_comment(dialog.desc_entry.get_text()) self.tmp_editing_session.save() self.tmp_editing_session = None items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows) self.tree.redraw_request(items, True) self.open_dialog = False def cancel_callback(self): self.tmp_editing_session = None self.open_dialog = False def pack(self, parent, widget_list, expand=False, fill=False): for w in widget_list: parent.pack_start(w, expand, fill) def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def get_list(self): usr_list = session_manager.list_autostart_items() if usr_list: return map(lambda w: SessionItem(self, w), usr_list) else: return [NothingItem()] def refresh_list(self, widget, gfile): self.tree.clear() self.tree.add_items(self.get_list()) self.tree.show()
wuhan_node = tree_view.add_item(None, TreeViewItem("Linux Deepin")) wuhan_dev_node = tree_view.add_item(wuhan_node, TreeViewItem("test1")) wuhan_des_node = tree_view.add_item(wuhan_node, TreeViewItem("test2")) wuhan_sys_node = tree_view.add_item(wuhan_node, TreeViewItem("test3")) tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Music Player")) tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Media Player")) tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Software Center")) tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin Talk")) tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin IM")) tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin Reader")) tree_view.add_item(wuhan_des_node, TreeViewItem("ZHL")) tree_view.add_item(wuhan_des_node, TreeViewItem("ZHL")) tree_view.add_item(wuhan_des_node, TreeViewItem("zhm")) beijing_node = tree_view.add_item(None, TreeViewItem("深度 Linux")) tree_view.add_items(beijing_node, [TreeViewItem(name) for name in ("开发部", "设计部", "系统部")]) tree_view.set_index_text(1, "深度测试改名") # text_view = TextView("this is line one\nline break is awesome\nblahblahlooooooooooooooooooooooooooooooooooooooooooooooooooooooooog") # sw = ScrolledWindow() # text_viewport = gtk.Viewport() # text_viewport.add(text_view) # sw.add(text_viewport) # tab_5_box.pack_start(sw, True, True) # Run. application.run()
class Region(gtk.Alignment): def __init__(self, connection=None): gtk.Alignment.__init__(self, 0, 0, 0, 0) ################# self.provider_select = None self.connect('expose-event', self.expose_event) self.prop_dict = {} main_table = gtk.Table(2, 2, False) main_table.set_row_spacing(1, 10) main_table.set_col_spacings(4) self.add(main_table) self.country_tree = TreeView( enable_multiple_select=False, enable_drag_drop=False, ) self.country_tree.set_expand_column(1) self.country_tree.set_size_request(365, 380) self.country_tree.draw_mask = self.draw_mask self.country_tree.connect("button-press-item", self.country_selected) left_box_align = gtk.Alignment(0, 0, 0, 0) left_box_align.set_padding(1, 1, 1, 1) left_box_align.add(self.country_tree) left_box_align.show_all() left_box = gtk.VBox() # wrap title country_title = TitleBar( app_theme.get_pixbuf("network/globe-green.png"), _("Country or Region:"), has_separator=False) left_box.pack_start(country_title, False, False) left_box.pack_start(left_box_align, False, False) self.provider_tree = TreeView( enable_multiple_select=False, enable_drag_drop=False, ) self.provider_tree.set_expand_column(0) self.provider_tree.set_size_request(365, 380) self.provider_tree.draw_mask = self.draw_mask self.provider_tree.connect("button-press-item", self.provider_selected) right_box_align = gtk.Alignment(0, 0, 0, 0) right_box_align.set_padding(1, 1, 1, 1) right_box_align.add(self.provider_tree) right_box = gtk.VBox() # wrap title provider_title = TitleBar(app_theme.get_pixbuf("network/building.png"), _("Provider:"), has_separator=False) right_box.pack_start(provider_title, False, False) right_box.pack_start(right_box_align, False, False) main_left_align = gtk.Alignment(0, 0, 0, 0) main_left_align.set_padding(15, 0, 20, 0) main_left_align.add(left_box) main_table.attach(main_left_align, 0, 1, 0, 1) main_right_align = gtk.Alignment(0, 0, 0, 0) main_right_align.set_padding(15, 0, 0, 20) main_right_align.add(right_box) main_table.attach(main_right_align, 1, 2, 0, 1) hints = _( "Tips:This assistant helps you easily set up a mobile broadband connection to a cellular network." ) left_box_align.connect("expose-event", self.expose_outline) right_box_align.connect("expose-event", self.expose_outline) next_button = Button("Next") next_button.connect("clicked", self.next_button_clicked) self.foot_box = FootBox() self.foot_box.set_buttons([next_button]) self.foot_box.set_tip(hints) main_table.attach(self.foot_box, 0, 2, 1, 2) self.show_all() #self.init() def expose_outline(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*BORDER_COLOR) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.stroke() def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def expose_hint_background(self, widget, event): bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR) cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*bg_color) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() with cairo_disable_antialias(cr): cr.set_source_rgb(*BORDER_COLOR) cr.set_line_width(1) cr.rectangle(rect.x, rect.y, rect.width, rect.height - 1) cr.stroke() def next_button_clicked(self, widget): # 检查是否选择了运营商 if not self.provider_select: print "provider has not selected" return try: self.plan_select except: self.plan_select = None def add_keys(settings): self.prop_dict = settings username = self.__sp.get_provider_username(self.code, self.provider_select) password = self.__sp.get_provider_password(self.code, self.provider_select) add_keys({ "cdma": { "number": "#777", "username": username, "password": password } }) provider_type = "cdma" if self.plan_select: self.prop_dict.pop("cdma") apn = self.plan_select index = self.__sp.get_provider_apns_name( self.code, self.provider_select).index(apn) (network_id, network_type) = self.__sp.get_provider_networks( self.code, self.provider_select)[index] add_keys({ "gsm": { "number": "*99#", "username": username, "password": password, "apn": apn, #"network_id": network_id, "network_type": network_type } }) provider_type = "gsm" #setting_page = nm_module.slider.get_page_by_name("setting") #broadband = setting_page.setting_group.get_broadband() if self.connection_type == None: new_connection = getattr(nm_module.nm_remote_settings, "new_%s_connection" % provider_type)() Dispatcher.emit("region-back", new_connection, self.prop_dict, provider_type) #setting_page.sidebar.new_connection_list[provider_type].append(new_connection) #setting_page.init(setting_page.sidebar.new_connection_list) #setting_page.sidebar.set_active(new_connection) #broadband.set_new_values(self.prop_dict, provider_type) else: Dispatcher.emit("region-back", self.connection, self.prop_dict, provider_type) #broadband.set_new_values(self.prop_dict, provider_type) nm_module.slider._slide_to_page("setting", "none") def init(self, connection): if connection == None: self.connection_type = None else: self.connection = connection mobile_type = connection.get_setting("connection").type self.connection_type = mobile_type Dispatcher.send_submodule_crumb(_("Region"), 2) from mm.provider import ServiceProviders self.__sp = ServiceProviders() self.country_list = self.__sp.get_country_name_list() self.country_tree.delete_all_items() self.country_tree.add_items( [CountryItem(_(country)) for country in self.country_list]) # add a bottom line for last item code = self.__sp.get_country_from_timezone() self.country_codes = self.__sp.get_country_list() try: selected_country = self.country_tree.visible_items[ self.country_codes.index(code)] self.country_tree.select_items([selected_country]) self.auto_scroll_to() self.country_tree.emit("button-press-item", selected_country, 0, 1, 1) except: pass def country_selected(self, widget, w, a, b, c): self.provider_tree.delete_all_items() self.code = self.country_codes[widget.select_rows[0]] if self.connection_type: self.provider_names = getattr( self.__sp, "get_country_%s_providers_name" % self.connection_type)(self.code) else: self.provider_names = self.__sp.get_country_providers_name( self.code) self.provider_select = None self.provider_tree.add_items( [Item(p, self.__sp, self.code) for p in self.provider_names]) self.provider_tree.show_all() def provider_selected(self, widget, item, column, offset_x, offset_y): if type(item) is Item: self.provider_select = item.content self.plan_select = None else: self.plan_select = item.content def auto_scroll_to(self): vadjust = self.country_tree.scrolled_window.get_vadjustment() upper = vadjust.upper page_size = vadjust.page_size vadjust.set_value( min(upper - page_size, (self.country_tree.select_rows[0] - 4) * 30))
class WebcastsBrowser(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) # Init data. self.source_data = OrderedDict() self.source_data["internal"] = "国内广播" self.source_data["foreign"] = "国外广播" self.source_data["network"] = "网络广播" self.source_data["genres"] = "流派广播" self.source_data["music"] = "音乐广播" self.source_data["finance"] = "财经广播" self.source_data["sports"] = "体育广播" # Init sourcebar self.__init_sourcebar() # Init webcasts view. self.source_view, self.source_sw = self.get_webcasts_view() self.collect_view, self.collect_sw = self.get_webcasts_view() # self.custom_view, custom_view_sw = self.get_webcasts_view() self.source_view.connect("single-click-item", self.on_source_view_single_click_item) if WebcastsDB.isloaded(): self.on_webcastsdb_loaded() else: self.connect_to_webcastsdb() # Dispatcher Dispatcher.connect("webcast-info", self.on_dispatcher_webcast_info) Dispatcher.connect("clear-sourcebar-status", lambda obj: self.clear_sourcebar_status()) # Used to switch categroy view. self.switch_view_box = gtk.VBox() self.switch_view_box.add(self.source_sw) body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True) body_paned.add1(self.sourcebar) body_paned.add2(self.switch_view_box) self.add(body_paned) self.show_all() def on_dispatcher_webcast_info(self, obj, parent, key): items = WebcastsDB.get_items(parent, key) self.source_view.clear() if items: self.source_view.add_items([WebcastListItem(tag) for tag in items]) switch_tab(self.switch_view_box, self.source_sw) def connect_to_webcastsdb(self): WebcastsDB.connect("loaded", self.on_webcastsdb_loaded) def on_webcastsdb_loaded(self, *args): items = WebcastsDB.get_items("internal", "中央电台") self.source_view.add_items([WebcastListItem(tag) for tag in items]) # load collect webcasts. collect_taglist = WebcastsDB.get_favorite_items() if collect_taglist: self.collect_view.add_items( [WebcastListItem(tag) for tag in collect_taglist]) def __init_sourcebar(self): self.sourcebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) items = [] for index, (key, value) in enumerate(self.source_data.items()): if index == 0: show_icon = True else: show_icon = False items.append( CategroyItem(value, key, self.sourcebar, index, show_icon)) items.append( CustomItem( "我的收藏", lambda: switch_tab(self.switch_view_box, self.collect_sw))) self.sourcebar.add_items(items) self.sourcebar.set_size_request(121, -1) self.sourcebar.draw_mask = self.on_sourcebar_draw_mask self.sourcebar.draw_area.tag_by_poup_panel_grab_window = True popup_grab_window.focus_out_callback = self.handle_focus_out def handle_focus_out(self): self.sourcebar.unhover_row() self.sourcebar.left_button_press = False def get_webcasts_view(self): webcast_view = MultiDragWebcastView() scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.add_child(webcast_view) return webcast_view, scrolled_window def on_sourcebar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h, "layoutRight") return False def on_source_view_single_click_item(self, widget, item, column, x, y): if column == 2: item.toggle_is_collected() if item.is_collected: tags = item.webcast.get_dict() self.collect_view.add_items([WebcastListItem(tags, True)]) else: for c_item in self.collect_view.items: if c_item == item: self.collect_view.delete_items([c_item]) del c_item def save(self): if not self.collect_view.items: return items = [] for item in self.collect_view.items: items.append(item.get_tags()) utils.save_db(items, get_config_file("favorite_webcasts.db")) def clear_sourcebar_status(self): items = self.sourcebar.visible_items if items: [item.unselect() for item in items]
def add_items(self, items, insert_pos=None, clear_first=False): for item in items: song_view = getattr(item, "song_view", None) if song_view: setattr(song_view, "category_view", self) TreeView.add_items(self, items, insert_pos, clear_first)
class WebcastsBrowser(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) # Init data. self.source_data = OrderedDict() self.source_data["internal"] = "国内广播" self.source_data["foreign"] = "国外广播" self.source_data["network"] = "网络广播" self.source_data["genres"] = "流派广播" self.source_data["music"] = "音乐广播" self.source_data["finance"] = "财经广播" self.source_data["sports"] = "体育广播" # Init sourcebar self.__init_sourcebar() # Init webcasts view. self.source_view, self.source_sw = self.get_webcasts_view() self.collect_view, self.collect_sw = self.get_webcasts_view() # self.custom_view, custom_view_sw = self.get_webcasts_view() self.source_view.connect("single-click-item", self.on_source_view_single_click_item) if WebcastsDB.isloaded(): self.on_webcastsdb_loaded() else: self.connect_to_webcastsdb() # Dispatcher Dispatcher.connect("webcast-info", self.on_dispatcher_webcast_info) Dispatcher.connect("clear-sourcebar-status", lambda obj: self.clear_sourcebar_status()) # Used to switch categroy view. self.switch_view_box = gtk.VBox() self.switch_view_box.add(self.source_sw) body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True) body_paned.add1(self.sourcebar) body_paned.add2(self.switch_view_box) self.add(body_paned) self.show_all() def on_dispatcher_webcast_info(self, obj, parent, key): items = WebcastsDB.get_items(parent, key) self.source_view.clear() if items: self.source_view.add_items([WebcastListItem(tag) for tag in items]) switch_tab(self.switch_view_box, self.source_sw) def connect_to_webcastsdb(self): WebcastsDB.connect("loaded", self.on_webcastsdb_loaded) def on_webcastsdb_loaded(self, *args): items = WebcastsDB.get_items("internal", "中央电台") self.source_view.add_items([WebcastListItem(tag) for tag in items]) # load collect webcasts. collect_taglist = WebcastsDB.get_favorite_items() if collect_taglist: self.collect_view.add_items([WebcastListItem(tag) for tag in collect_taglist]) def __init_sourcebar(self): self.sourcebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) items = [] for index, (key, value) in enumerate(self.source_data.items()): if index == 0: show_icon = True else: show_icon = False items.append(CategroyItem(value, key, self.sourcebar, index, show_icon)) items.append(CustomItem("我的收藏", lambda : switch_tab(self.switch_view_box, self.collect_sw))) self.sourcebar.add_items(items) self.sourcebar.set_size_request(121, -1) self.sourcebar.draw_mask = self.on_sourcebar_draw_mask self.sourcebar.draw_area.tag_by_poup_panel_grab_window = True popup_grab_window.focus_out_callback = self.handle_focus_out def handle_focus_out(self): self.sourcebar.unhover_row() self.sourcebar.left_button_press = False def get_webcasts_view(self): webcast_view = MultiDragWebcastView() scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.add_child(webcast_view) return webcast_view, scrolled_window def on_sourcebar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h ,"layoutRight") return False def on_source_view_single_click_item(self, widget, item, column, x, y): if column == 2: item.toggle_is_collected() if item.is_collected: tags = item.webcast.get_dict() self.collect_view.add_items([WebcastListItem(tags, True)]) else: for c_item in self.collect_view.items: if c_item == item: self.collect_view.delete_items([c_item]) del c_item def save(self): if not self.collect_view.items: return items = [] for item in self.collect_view.items: items.append(item.get_tags()) utils.save_db(items, get_config_file("favorite_webcasts.db")) def clear_sourcebar_status(self): items = self.sourcebar.visible_items if items: [item.unselect() for item in items]
class RadioBrowser(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) # Init radiobar. self.__init_radiobar() # is loaded. self.homepage_load_flag = False self.home_page = HomePage() self.hot_page_view, self.hot_page_sw = self.get_radio_icon_view( TAG_HOT, 20) self.fast_page_view, self.fast_page_sw = self.get_radio_icon_view( TAG_FAST, 20) # Genres page self.genre_page = GenrePage() self.page_box = gtk.VBox() self.page_box.add(self.home_page) self.body_paned = HPaned( handle_color=app_theme.get_color("panedHandler")) self.body_paned.add1(self.radiobar) self.body_paned.add2(self.page_box) self.network_failed_box = NetworkConnectFailed( self.check_network_connection) self.check_network_connection(auto=True) def check_network_connection(self, auto=False): if is_network_connected(): switch_tab(self, self.body_paned) if not auto: self.start_fetch_channels() else: switch_tab(self, self.network_failed_box) def __init_radiobar(self): self.radiobar = TreeView(enable_drag_drop=False, enable_multiple_select=False) items = [] items.append( CategroyTreeItem( _("Home"), "home", lambda: switch_tab(self.page_box, self.home_page))) items.append( CategroyTreeItem( _("Hot MHz"), "hot", lambda: switch_tab(self.page_box, self.hot_page_sw))) items.append( CategroyTreeItem( _("Genres"), "genre", lambda: switch_tab(self.page_box, self.genre_page))) items.append( CategroyTreeItem( _("Pop MHz"), "up", lambda: switch_tab(self.page_box, self.fast_page_sw))) self.radiobar.add_items(items) self.radiobar.select_items([self.radiobar.visible_items[0]]) self.radiobar.set_size_request(121, -1) self.radiobar.draw_mask = self.on_radiobar_draw_mask def on_radiobar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h, "layoutRight") def get_radio_icon_view(self, tag, limit=10, padding_x=0, padding_y=10): icon_view = RadioIconView(tag=tag, limit=limit, padding_x=padding_x, padding_y=padding_y) scrolled_window = icon_view.get_scrolled_window() return icon_view, scrolled_window def start_fetch_channels(self): self.fast_page_view.clear_items() self.hot_page_view.clear_items() self.home_page.start_fetch_channels() self.hot_page_view.start_fetch_channels() self.fast_page_view.start_fetch_channels() self.genre_page.start_fetch_channels()
class PlaylistUI(gtk.VBox): '''Playlist UI.''' def __init__(self): '''Init.''' gtk.VBox.__init__(self) # Init catagory list. self.category_list = TreeView() self.category_list.draw_mask = self.draw_category_list_mask self.category_list.connect("single-click-item", self.on_category_single_click) self.category_list.connect("right-press-items", self.on_category_right_press) self.category_list.set_size_request(CATEGROYLIST_WIDTH, -1) # Init SearchEntry. self.entry_box = SearchEntry("") self.entry_box.entry.connect("changed", self.search_cb) self.entry_box.set_no_show_all(True) entry_align = gtk.Alignment() entry_align.set(0, 0, 1, 1) entry_align.set_padding(2, 0, 10, 10) entry_align.add(self.entry_box) entry_align.connect("expose-event", self.expose_entry_mask) # Init toolbar. self.toolbar_box = gtk.HBox(spacing=45) self.search_button = self.__create_simple_toggle_button("search", self.show_text_entry, _("Search in Current Playlist")) self.__create_simple_button("list", self.popup_list_menu, _("Playlist Operations")) self.__create_simple_button("add", self.popup_add_menu, _("Add")) self.playmode_button = PlaymodeButton(config.get("setting", "loop_mode", "list_mode").split("_")[0]) Tooltip.text(self.playmode_button, _("Playback Order")) self.playmode_button.connect("button-press-event", self.popup_sort_menu) self.toolbar_box.pack_start(self.playmode_button, False, False) self.__create_simple_button("delete", self.popup_delete_menu, _("Delete")) toolbar_align = gtk.Alignment() toolbar_align.set_padding(6, 6, 28, 0) toolbar_align.add(self.toolbar_box) toolbar_align.connect("expose-event", self.expose_toolbar_mask) self.right_box = gtk.VBox() self.right_box.connect("size-allocate", self.on_right_box_size_allocate) self.list_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True) self.list_paned.pack1(self.category_list, True, True) self.list_paned.pack2(self.right_box, True, False) bottom_box = gtk.VBox() bottom_box.set_size_request(-1, 22) self.pack_start(self.list_paned, True, True) self.pack_start(entry_align, False, False) self.pack_start(toolbar_align, False, True) # Current self.current_playlist = None self.search_time_source = 0 self.current_item = None self.search_flag = False self.cache_items = None self.delete_source_id = None self.drag_source_id = None self.menu_source_id = None self.song_notify_id = None self.detail_menu = None if MediaDB.isloaded(): self.__on_db_loaded(MediaDB) else: MediaDB.connect("loaded", self.__on_db_loaded) Player.connect("loaded", self.__on_player_loaded) Dispatcher.connect("play-song", self.__play_and_add) Dispatcher.connect("add-songs", self.__add_songs_to_list) Dispatcher.connect("new-cd-playlist", self.__new_audiocd_playlist) Dispatcher.connect("del-cd-playlist", self.delete_audiocd_list) Dispatcher.connect("save-current-list", self.save_current_playlist) config.connect("config-changed", self.on_config_changed) def on_config_changed(self, config, section, option, value): if section == "setting" and option == "loop_mode": icon_name = value.split("_")[0] self.playmode_button.update_dpixbufs(icon_name, True) def on_right_box_size_allocate(self, widget, rect): if self.current_item: if rect.width > HIDE_PLAYLIST_WIDTH: self.current_item.song_view.set_hide_columns(None) else: self.current_item.song_view.set_hide_columns([1]) def expose_toolbar_mask(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(1, 1, 1, 0.95) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_line(cr, (rect.x, rect.y + 1), (rect.x + rect.width, rect.y + 1), "#b0b0b0") return False def expose_entry_mask(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation draw_alpha_mask(cr, rect.x , rect.y, rect.width, rect.height, "toolbarEntry") def draw_category_list_mask(self, cr, x, y, width, height): draw_alpha_mask(cr, x, y, width, height, "layoutLeft") def draw_item_mask(self, cr, x, y, width, height): draw_vlinear(cr, x, y, width, height, app_theme.get_shadow_color("editlistItemPress").get_color_info()) def __on_db_loaded(self, db): if not MediaDB.get_playlists(): MediaDB.create_playlist("local", _("Default List")) # From MediaDB loaded playlists. init_items = [ListTreeItem(pl) for pl in MediaDB.get_playlists()] self.category_list.add_items(init_items) # Init Category_list. self.category_list.set_highlight_item(self.get_categroy_item_by_index(self.get_save_item_index())) self.current_item = self.category_list.get_highlight_item() self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items) self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event) self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu) Player.set_source(self.current_item.song_view) self.right_box.add(self.current_item.get_list_widget()) self.list_paned.show_all() def __on_player_loaded(self, player): if self.current_item: self.current_item.song_view.reset_error_items() self.current_item.song_view.set_highlight_song(Player.song) def __play_and_add(self, widget, song): self.current_item.song_view.add_songs(song, play=True) def __add_songs_to_list(self, widget, songs): if songs and self.current_item.song_view: self.current_item.song_view.add_songs(songs) def get_selected_song_view(self): if self.current_item: return self.current_item.song_view def search_cb(self, widget, text): if not self.search_flag: self.cache_items = self.current_item.song_view.get_items() # Clear song_view select status self.current_item.song_view.clear_highlight() self.current_item.song_view.select_rows = [] if text != "": self.search_flag = True results = filter(lambda item: text.lower().replace(" ", "") in item.get_song().get("search", ""), self.cache_items) self.current_item.song_view.set_song_items(results) else: self.search_flag = False self.current_item.song_view.set_song_items(self.cache_items) if Player.song: self.current_item.song_view.set_highlight_song(Player.song) def parser_delete_items(self, widget, items): if self.search_flag: if self.cache_items != None: [self.cache_items.remove(item) for item in items if item in self.cache_items] def parser_drag_event(self, widget, context, x, y, selection, info, timestamp): if self.search_flag: self.reset_search_entry() def reset_search_entry(self): self.search_button.set_active(False) def __create_simple_toggle_button(self, name, callback, tip_msg=""): toggle_button = ToggleButton( app_theme.get_pixbuf("toolbar/%s_normal.png" % name), app_theme.get_pixbuf("toolbar/%s_press.png" % name), ) toggle_button.connect("toggled", callback) if tip_msg: Tooltip.text(toggle_button, tip_msg) self.toolbar_box.pack_start(toggle_button, False, False) return toggle_button def __create_simple_button(self, name, callback, tip_msg=""): button = ImageButton( app_theme.get_pixbuf("toolbar/%s_normal.png" % name), app_theme.get_pixbuf("toolbar/%s_hover.png" % name), app_theme.get_pixbuf("toolbar/%s_press.png" % name), ) button.connect("button-press-event", callback) if tip_msg: Tooltip.text(button, tip_msg) self.toolbar_box.pack_start(button, False, False) return button def popup_add_menu(self, widget, event): self.current_item.song_view.popup_add_menu(int(event.x_root), int(event.y_root)) def popup_list_menu(self, widget, event): menu_items = [(None, _("New List"), self.new_list), (None, _("Import List"), self.leading_in_list), (None, _("Open List"), self.add_to_list), (None, _("Export List"), self.leading_out_list), (None, _("Remove List"), self.delete_item_list), None, (None, _("Save all Lists"), self.save_all_list)] Menu(menu_items, True).show((int(event.x_root), int(event.y_root))) def new_list(self, items=[], name=None): index = len(self.category_list.get_items()) if name is None: name = "%s%d" % (_("New List"), index) input_dialog = InputDialog(_("New List"), name, 300, 100, lambda name : self.create_new_playlist(name, items)) input_dialog.show_all() def create_new_playlist(self, name, items): self.category_list.add_items([ListTreeItem(Playlist("local", name, items))]) def __new_audiocd_playlist(self, obj, name, songs, udi): self.category_list.add_items([ListTreeItem(CDPlaylist("audiocd", name, songs), udi=udi)]) def get_categroy_other_items(self): other_items = [] highlight_item = self.category_list.get_highlight_item() for item in self.category_list.get_items(): if highlight_item == item: continue other_items.append(item) return other_items def get_categroy_index_by_item(self, item): index = -1 for each_index, each_item in enumerate(self.category_list.get_items()): if item == each_item: index = each_index break return index def get_categroy_item_by_index(self, index): try: return self.category_list.get_items()[index] except: return None def get_edit_sub_menu(self, select_items, move=False): sub_menu_items = [] if len(self.category_list.get_items()) > 1: other_category_items = self.get_categroy_other_items() sub_menu_items = [(None, category_item.get_title(), self.edit_list_item, category_item, select_items ,move) for category_item in other_category_items] if sub_menu_items: sub_menu_items.extend([None, ((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None), _("New List"), self.edit_new_list_item, select_items, move)]) else: sub_menu_items.extend([((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None), _("New List"), self.edit_new_list_item, select_items, move)]) return Menu(sub_menu_items) def edit_list_item(self, category_item, select_items, move): try: category_item.song_view.add_items(select_items) category_item.song_view.update_item_index() category_item.song_view.update_vadjustment() if move: self.current_item.song_view.remove_select_items() except: pass else: self.current_item.song_view.update_item_index() self.current_item.song_view.update_vadjustment() def edit_new_list_item(self, select_items, move): self.new_list([item.get_song().get("uri") for item in select_items]) if move: self.current_item.song_view.remove_select_items() self.current_item.song_view.update_item_index() self.current_item.song_view.update_vadjustment() def leading_in_list(self): uri = WindowLoadPlaylist().run() try: p_name = utils.get_filename(uri) pl = MediaDB.create_playlist("local", p_name, []) new_item = ListTreeItem(pl) self.category_list.add_items([new_item]) new_item.song_view.async_add_uris(uri) except: pass def leading_out_list(self, item): if not item: item = self.current_item WindowExportPlaylist(item.get_songs()).run() def add_to_list(self, item=None): uri = WindowLoadPlaylist().run() if uri: try: if not item: item = self.current_item item.song_view.async_add_uris(uri) except: pass def delete_audiocd_list(self, obj, udi): reset = False for item in self.category_list.get_items(): if item.udi == udi: reset = True self.category_list.delete_items([item]) if reset: self.reset_highlight_item(self.category_list.get_items()[-1]) def delete_item_list(self, item): if len(self.category_list.get_items()) == 1: return index = self.get_categroy_index_by_item(item) self.category_list.delete_items([item]) max_index = len(self.category_list.get_items()) - 1 if index <= max_index: new_index = index else: new_index = index- 1 self.reset_highlight_item(self.category_list.get_items()[new_index]) def save_all_list(self): uri = WinDir().run() if uri: try: save_name_dict = {} dir_name = utils.get_path_from_uri(uri) for item in self.category_list.get_items(): item_name = item.get_title() save_name_dict[item_name] = save_name_dict.get(item_name, -1) + 1 if save_name_dict.get(item_name) > 0: filename = "%s%d.%s" % (os.path.join(dir_name, item_name), save_name_dict.get(item_name), "m3u") else: filename = "%s.%s" % (os.path.join(dir_name, item_name), "m3u") utils.export_playlist(item.get_songs(), filename, "m3u") except: pass def reset_highlight_item(self, item): self.category_list.set_highlight_item(item) self.on_category_single_click(None, item, None, None, None) def get_current_item_index(self): item = self.category_list.get_highlight_item() index = self.get_categroy_index_by_item(item) if index is None: return 0 else: return index def popup_sort_menu(self, widget, event): self.current_item.song_view.get_playmode_menu([int(event.x_root), int(event.y_root)]) def popup_delete_menu(self, widget, event): self.current_item.song_view.popup_delete_menu(int(event.x_root), int(event.y_root)) def get_save_item_index(self): index = config.getint("playlist", "current_index") if index <= len(self.category_list.get_items()) - 1: return index return 0 def on_category_right_press(self, widget, x, y, item, column): if not item: menu_items = [ (None, _("New List"), self.new_list), (None, _("Import List"), self.leading_in_list), None, (None, _("Save all Lists"), self.save_all_list) ] else: menu_items = [ (None, _("Rename"), lambda : self.rename_item_list(item)), (None, _("Remove List"), lambda : self.delete_item_list(item)), (None, _("Open List"), lambda : self.add_to_list(item)), None, (None, _("Save all Lists"), self.save_all_list) ] Menu(menu_items, True).show((x, y)) def rename_item_list(self, item): input_dialog = InputDialog(_("Rename"), item.get_title(), 300, 100, lambda name: item.set_title(name)) input_dialog.show_all() def on_category_button_press(self, widget, event): if event.button == 3: self.popup_list_menu(widget, event) def on_category_single_click(self, widget, item, column, x, y): self.reset_search_entry() if self.drag_source_id != None or self.delete_source_id != None or self.menu_source_id !=None: gobject.source_remove(self.drag_source_id) gobject.source_remove(self.delete_source_id) gobject.source_remove(self.menu_source_id) self.current_item = item self.category_list.set_highlight_item(item) self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items) self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event) self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu) container_remove_all(self.right_box) self.right_box.add(item.get_list_widget()) self.list_paned.show_all() def show_text_entry(self, widget): if widget.get_active(): self.entry_box.set_no_show_all(False) self.entry_box.show_all() self.entry_box.focus_input() else: self.entry_box.hide_all() self.entry_box.set_no_show_all(True) self.entry_box.entry.set_text("") def popup_detail_menu(self, widget, x, y, item, select_items): if self.detail_menu != None: self.detail_menu.destroy() play_mode_menu = self.current_item.song_view.get_playmode_menu(align=True) sort_dict = OrderedDict() sort_dict["file"] = _("By Filename") sort_dict["title"] = _("By Title") sort_dict["artist"] = _("By Artist") sort_dict["album"] = _("By Album") sort_dict["genre"] = _("By Genre") sort_dict["#track"] = _("By Track") sort_dict["#playcount"] = _("By Play Count") sort_dict["#added"] = _("By Date Added") sort_items = [(None, value, self.current_item.song_view.set_sort_keyword, key) for key, value in sort_dict.iteritems()] sort_items.append(None) sort_items.append((None, _("Randomize"), self.current_item.song_view.random_reorder)) sub_sort_menu = Menu(sort_items) add_to_list_menu = self.get_edit_sub_menu(select_items) move_to_list_menu = self.get_edit_sub_menu(select_items, True) self.detail_menu = Menu([(None, _("Play"), self.current_item.song_view.play_select_item), (None, _("Add to List"), add_to_list_menu), (None, _("move to List"), move_to_list_menu), None, (None, _("Remove Track"), self.current_item.song_view.remove_select_items), (None, _("Move to Trash"), self.current_item.song_view.try_move_trash), (None, _("Clear List"), self.current_item.song_view.erase_items), None, (None, _("Playback Order"), play_mode_menu), (None, _("Sort"), sub_sort_menu), (None, _("Convert"), self.current_item.song_view.songs_convert), (None, _("Open directory"), self.current_item.song_view.open_song_dir), (None, _("Properties"), self.current_item.song_view.open_song_editor), ], True) if item and item.song.get_type() == "cue": self.detail_menu.set_menu_item_sensitive_by_index(5, False) self.detail_menu.set_menu_item_sensitive_by_index(10, False) self.detail_menu.show((int(x), int(y))) def save_current_playlist(self, *args): index = self.get_current_item_index() config.set("playlist","current_index", str(index)) def save_to_library(self): if self.search_flag: self.reset_search_entry() MediaDB.full_erase_playlists() for item in self.category_list.get_items(): if item.udi is not None: continue songs = item.get_songs() name = item.get_title() MediaDB.create_playlist("local", name, songs)
class AddPage(gtk.HBox): def __init__(self): gtk.HBox.__init__(self) self.aibizhi_cache_page = CachePage(Aibizhi()) self.bizhi360_cache_page = CachePage(Bizhi360()) self.aibizhi_cache_page.cache_view.try_to_fetch() self.bizhi360_cache_page.cache_view.try_to_fetch() self.system_wallpapers_page = SystemPage(get_system_wallpaper_dirs()[0]) self.picture_wallpapers_page = PicturePage(get_images_dir()) self.download_wallpapaers_page = UserPage(get_download_wallpaper_dir()) self.task_page = TaskPage() self.__init_navigatebar() self.switch_page = gtk.VBox() self.pack_start(self.navigatebar, False, True) self.pack_start(self.switch_page, True, True) self.switch_page.add(self.system_wallpapers_page) event_manager.add_callback("downloading-tasks-number", self.on_download_item_changed) self.connect("expose-event", self.on_addpage_expose_event) def set_theme(self, theme): self.system_wallpapers_page.set_theme(theme) self.picture_wallpapers_page.set_theme(theme) self.download_wallpapaers_page.set_theme(theme) self.aibizhi_cache_page.set_theme(theme) self.bizhi360_cache_page.set_theme(theme) def on_download_item_changed(self, name, obj, data): pass def __init_navigatebar(self): self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click) self.navigatebar.set_size_request(132, -1) self.navigatebar.draw_mask = self.on_navigatebar_draw_mask local_expand_item = ExpandItem(_("Library")) network_expand_item = ExpandItem(_("Internet")) self.navigatebar.add_items([local_expand_item, network_expand_item, ]) local_expand_item.add_childs([(_("System"), self.system_wallpapers_page), (_("Pictures"), self.picture_wallpapers_page), (_("Favorites"), self.download_wallpapaers_page)], expand=True) network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page), (_("LoveWallpaper"), self.aibizhi_cache_page), ], expand=True) self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1]) def on_addpage_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation self.draw_mask(cr, *rect) def on_navigatebar_draw_mask(self, cr, x, y, w, h): self.draw_mask(cr, x, y, w, h) draw_line(cr, (x + w, y), (0, h), "#d6d6d6") def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def on_navigatebar_single_click(self, widget, item, column, x, y): if item.widget: widget.set_highlight_item(item) switch_box(self.switch_page, item.widget)
class WebcastsBrowser(gtk.VBox, SignalContainer): def __init__(self): gtk.VBox.__init__(self) SignalContainer.__init__(self) # Init categorys. self.get_categorys() # load data. self.__load_webcast_query() # Init webcastbar. self.__init_webcastbar() # Init iconview. self.metro_view = self.get_icon_view() self.metro_view_sw = self.metro_view.get_scrolled_window() self.page_box = gtk.VBox() self.page_box.add(self.metro_view_sw) # webcasts view self.webcast_view = self.get_webcast_view() self.webcast_view_sw = self.webcast_view.get_scrolled_window() # collect view self.collected_db_file = get_config_file("favorite_webcasts.db") self.collected_view = self.get_webcast_view() self.collected_view_sw = self.collected_view.get_scrolled_window() # Init collect view. # init listview page. self.init_listview_page() Dispatcher.connect("change-webcast", self.on_dispatcher_change_webcast) WebcastDB.connect("changed", self.on_db_update_songs) body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True) body_paned.add1(self.webcastbar) body_paned.add2(self.page_box) self.add(body_paned) def get_categorys(self): lang = utils.get_system_lang() if lang.startswith("zh"): self.__categorys = ["region", "genre", "composite"] self.current_category = "region" else: self.__categorys = ["region_en", "genre_en"] self.current_category = "region_en" self.__category_gettexts = { "region": "地域分类", "genre": "流派分类", "region_en": _("Region"), "genre_en": _("Genre"), "composite": "综合分类", "finance": "财经", "sports": "体育", "music": "音乐", "news": "新闻", "network": "网络", } def __load_webcast_query(self): self.__db_query = WebcastQuery() if WebcastDB.isloaded(): self.__on_db_loaded() else: WebcastDB.connect("loaded", lambda obj: self.__on_db_loaded()) def __on_db_loaded(self): self.autoconnect(self.__db_query, "added", self.__on_added_songs) self.autoconnect(self.__db_query, "removed", self.__on_removed_songs) self.autoconnect(self.__db_query, "update-songs", self.__on_update_songs) self.autoconnect(self.__db_query, "full-update", self.__on_full_update) self.__db_query.set_query() def __on_added_songs(self, db_query, songs): self.reload_flag = True def __on_removed_songs(self, db_query, songs): self.reload_flag = True def __on_update_songs(self, db_query, songs): self.reload_flag = True def __on_full_update(self, db_query): self.load_view_data() self.load_collect_data() def __init_webcastbar(self): self.webcastbar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.webcastbar.connect("single-click-item", self.on_webcastbar_single_click_item) items = [] for category in self.__categorys: items.append( CategoryTreeItem(self.__category_gettexts[category], category=category)) items.append(CollectTreeItem(_("Favorites"))) self.webcastbar.add_items(items) self.webcastbar.select_items([self.webcastbar.visible_items[0]]) self.webcastbar.set_size_request(121, -1) self.webcastbar.draw_mask = self.on_webcastbar_draw_mask def on_webcastbar_draw_mask(self, cr, x, y, w, h): draw_alpha_mask(cr, x, y, w, h, "layoutRight") def on_webcastbar_single_click_item(self, widget, item, column, x, y): if hasattr(item, "collect_flag"): switch_tab(self.page_box, self.collected_view_sw) else: widget = self.page_box.get_children()[0] if widget != self.metro_view_sw: switch_tab(self.page_box, self.metro_view_sw) if self.current_category != item.category: self.current_category = item.category self.load_view_data() def init_listview_page(self): self.listview_page = gtk.VBox() self.text_prompt = TextPrompt("Default") prompt_align = set_widget_gravity(self.text_prompt, paddings=(10, 10, 0, 0)) prompt_box = gtk.HBox() back_button = BackButton() back_button.connect("clicked", self.on_backbutton_clicked) back_button_align = set_widget_gravity(back_button, gravity=(0.5, 0.5, 0, 0), paddings=(0, 0, 10, 5)) prompt_box.pack_start(back_button_align, False, True) prompt_box.pack_start(prompt_align, False, False) self.listview_page.pack_start(prompt_box, False, True) self.listview_page.pack_start(self.webcast_view_sw, True, True) def on_backbutton_clicked(self, widget): switch_tab(self.page_box, self.metro_view_sw) def switch_to_listview(self, category, title): self.text_prompt.set_text(title) self.webcast_view.clear() songs = self.__db_query.get_songs(category, title) self.webcast_view.add_webcasts(songs) switch_tab(self.page_box, self.listview_page) def load_view_data(self): self.metro_view.clear() if self.current_category == "composite": child_datas = self.__db_query.get_composite_categorys() gettext_datas = [] for child in child_datas: gettext_datas.append((self.__category_gettexts[child], child)) self.metro_view.add_composite_items(gettext_datas) else: child_datas = self.__db_query.get_info(self.current_category)[0] child_datas.sort(key=lambda x: locale.strxfrm(x)) self.metro_view.add_webcast_items(child_datas) def load_collect_data(self): try: collected_objs = utils.load_db(self.collected_db_file) except: collected_objs = None if collected_objs: songs = [WebcastDB.get_song(uri) for uri in collected_objs] else: songs = None if songs: songs = [song for song in songs if song.get("collected", False)] if songs: self.collected_view.add_webcasts(songs) def get_icon_view(self): icon_view = WebcastIconView() icon_view.connect("single-click-item", self.on_iconview_single_click_item) icon_view.connect("double-click-item", self.on_iconview_single_click_item) return icon_view def on_iconview_single_click_item(self, widget, item, x, y): if item.is_composited: category = item.category else: category = self.current_category title = item.title if item.is_composited: self.switch_to_listview(category, title) else: self.switch_to_listview(category, title) def get_webcast_view(self): webcast_view = MultiDragWebcastView() webcast_view.keymap.update( {"BackSpace": lambda: self.on_backbutton_clicked(None)}) return webcast_view def on_dispatcher_change_webcast(self, widget, song): item = self.collected_view.get_webcast_item(song) if item and not song.get("collected", False): self.collected_view.delete_items([item]) elif song.get("collected", False): self.collected_view.add_webcasts([song]) def on_db_update_songs(self, db, infos): for song, tags, new_tags in infos: if new_tags.has_key("collected"): item = self.collected_view.get_webcast_item(song) if item: if not new_tags.get("collected", False): self.collected_view.delete_items([item]) else: if new_tags.get("collected", False): self.collected_view.add_webcasts([song]) def save(self): songs = self.collected_view.get_webcasts() uris = [song.get("uri") for song in songs if song.get("uri")] utils.save_db(uris, self.collected_db_file)
class SearchPage(gtk.VBox): ''' class docs ''' def __init__(self, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.data_manager = data_manager self.keywords = [] self.all_pkg_names = [] self.message_bar = MessageBar(18) self.content_box = gtk.VBox() self.treeview = TreeView(enable_drag_drop=False, expand_column=0) self.cute_message_image = gtk.VBox() self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf("info", "noresult.png") self.cute_message_image.connect("expose-event", self.expose_cute_message_image) self.content_box.pack_start(self.message_bar, False, False) self.content_box.pack_start(self.treeview) self.loading_box = LoadingBox() self.pack_start(self.loading_box, True, True) self.treeview.connect("items-change", self.update_message_bar) self.treeview.draw_mask = self.draw_mask def expose_cute_message_image(self, widget, event): if self.cute_message_pixbuf: cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(1, 1, 1, 0) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_pixbuf( cr, self.cute_message_pixbuf, rect.x + (rect.width - self.cute_message_pixbuf.get_width()) / 2, rect.y + (rect.height - self.cute_message_pixbuf.get_height()) / 2, ) def update_message_bar(self, treeview): if len(treeview.visible_items) > 0: self.message_bar.set_message(_("%s: %s matched applications") % (' '.join(self.keywords), len(self.all_pkg_names))) container_remove_all(self) self.pack_start(self.content_box) global_event.emit("update-current-status-pkg-page", treeview) else: container_remove_all(self) self.pack_start(self.cute_message_image) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] ) def update(self, keywords): self.keywords = keywords self.treeview.delete_all_items() self.all_pkg_names = self.data_manager.search_query(keywords) if self.all_pkg_names: if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) else: self.update_message_bar(self.treeview) self.treeview.scrolled_window.connect('vscrollbar-state-changed', self.scrolled_window_vscrollbar_handler) def scrolled_window_vscrollbar_handler(self, widget, state): if state == "bottom": current_item_number = len(self.treeview.visible_items) all_pkgs_number = len(self.all_pkg_names) start = current_item_number if current_item_number < all_pkgs_number and (current_item_number+LOAD_ITEMS_NUMBER) < all_pkgs_number: end = current_item_number+LOAD_ITEMS_NUMBER elif current_item_number < all_pkgs_number and (current_item_number+LOAD_ITEMS_NUMBER) >= all_pkgs_number: end = all_pkgs_number else: return self.load_new_items(self.all_pkg_names[start:end]) def load_new_items(self, pkg_names): if pkg_names: results = self.data_manager.get_search_pkgs_info(pkg_names) self.data_manager.get_pkgs_install_status( pkg_names, reply_handler=lambda status: self.search_reply_handler(status, results), error_handler=handle_dbus_error) else: self.update_message_bar(self.treeview) def search_reply_handler(self, status, results): for (i, result) in enumerate(results): result.append(status[i]) self.render_search_info(results, self.keywords) def render_search_info(self, pkg_infos, keywords): self.keywords = keywords items = [] for pkg_info in pkg_infos: items.append(SearchItem(pkg_info, self.data_manager, keywords)) self.treeview.add_items(items)
class PluginsManager(gtk.VBox): def __init__(self): gtk.VBox.__init__(self) self.set_spacing(5) self.plugins = utils.get_main_window().plugins self.plugins_view = TreeView() self.plugins_view.set_expand_column(0) self.plugins_view.draw_mask = self.plugins_view_draw_mask self.plugins_view.set_size_request(420, 330) self.plugins_view.connect("single-click-item", self.on_plugins_view_single_click) self.plugins_view.set_column_titles([_("Add-on"), _("Version"), _("Enable"), ""], (self.sort_by_title, self.sort_by_title, self.sort_by_title, self.sort_by_title)) plugins_view_align = set_widget_gravity(self.plugins_view, gravity=(1, 1, 1, 1), paddings=(10, 0, 0, 0)) self.plugin_infos = PluginInfos() self.plugin_infos.set_size_request(420, 90) # plugin info self.pack_start(plugins_view_align, False, True) self.pack_start(self.plugin_infos, False, True) def sort_by_title(self, items, reverse): return sorted(items, key=lambda item: item.plugin, reverse=reverse) def plugins_view_draw_mask(self, cr, x, y, width, height): draw_alpha_mask(cr, x, y, width, height, "layoutLeft") def flush_plugins(self): self.__load_plugin_list() def __load_plugin_list(self): # clear plugins_view items. self.plugins_view.clear() plugins = self.plugins.list_installed_plugins() plugins_list = [] failed_list = [] for plugin in plugins: try: info = self.plugins.get_plugin_info(plugin) except Exception: failed_list.append(plugin) continue enabled = plugin in self.plugins.enabled_plugins plugins_list.append((plugin, info, enabled)) plugins_list.sort(key=lambda x: locale.strxfrm(x[1]["Name"])) plugins_items = [PluginItem(*args) for args in plugins_list] self.plugins_view.add_items(plugins_items) def on_plugins_view_single_click(self, widget, item, column, x, y): if column == 2: plugin = item.plugin will_enable = not item.enabled if will_enable: try: self.plugins.enable_plugin(plugin) except Exception, e: print e return else: try: self.plugins.disable_plugin(plugin) except Exception, e: print e return item.toggle_enabled()
class AddPage(gtk.HBox): def __init__(self): gtk.HBox.__init__(self) self.aibizhi_cache_page = CachePage(Aibizhi()) self.bizhi360_cache_page = CachePage(Bizhi360()) self.aibizhi_cache_page.cache_view.try_to_fetch() self.bizhi360_cache_page.cache_view.try_to_fetch() self.system_wallpapers_page = SystemPage( get_system_wallpaper_dirs()[0]) self.picture_wallpapers_page = PicturePage(get_images_dir()) self.download_wallpapaers_page = UserPage(get_download_wallpaper_dir()) self.task_page = TaskPage() self.__init_navigatebar() self.switch_page = gtk.VBox() self.pack_start(self.navigatebar, False, True) self.pack_start(self.switch_page, True, True) self.switch_page.add(self.system_wallpapers_page) event_manager.add_callback("downloading-tasks-number", self.on_download_item_changed) self.connect("expose-event", self.on_addpage_expose_event) def set_theme(self, theme): self.system_wallpapers_page.set_theme(theme) self.picture_wallpapers_page.set_theme(theme) self.download_wallpapaers_page.set_theme(theme) self.aibizhi_cache_page.set_theme(theme) self.bizhi360_cache_page.set_theme(theme) def on_download_item_changed(self, name, obj, data): pass def __init_navigatebar(self): self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False) self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click) self.navigatebar.set_size_request(132, -1) self.navigatebar.draw_mask = self.on_navigatebar_draw_mask local_expand_item = ExpandItem(_("Library")) network_expand_item = ExpandItem(_("Internet")) self.navigatebar.add_items([ local_expand_item, network_expand_item, ]) local_expand_item.add_childs( [(_("System"), self.system_wallpapers_page), (_("Pictures"), self.picture_wallpapers_page), (_("Favorites"), self.download_wallpapaers_page)], expand=True) network_expand_item.add_childs([ (_("360 Wallpaper"), self.bizhi360_cache_page), (_("LoveWallpaper"), self.aibizhi_cache_page), ], expand=True) self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1]) def on_addpage_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation self.draw_mask(cr, *rect) def on_navigatebar_draw_mask(self, cr, x, y, w, h): self.draw_mask(cr, x, y, w, h) draw_line(cr, (x + w, y), (0, h), "#d6d6d6") def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill() def on_navigatebar_single_click(self, widget, item, column, x, y): if item.widget: widget.set_highlight_item(item) switch_box(self.switch_page, item.widget)
class CompletionWindow(Window): ''' class docs ''' def __init__(self, window_width, window_height): ''' init docs ''' # Init. Window.__init__( self, # shadow_visible=False, shape_frame_function=self.shape_completion_window_frame, expose_frame_function=self.expose_completion_window_frame) self.window_width = window_width self.window_height = window_height self.window_offset_x = 8 self.window_offset_y = 34 self.align_size = 2 self.treeview = TreeView( [], enable_highlight=False, enable_multiple_select=False, enable_drag_drop=False, expand_column=0, ) self.treeview.scrolled_window.tag_by_popup_grab_window = True self.treeview_align = gtk.Alignment() self.treeview_align.set(0.5, 0.5, 1, 1) self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size) self.treeview_align.add(self.treeview) self.treeview.connect("press-return", self.treeview_press_return) self.treeview.draw_mask = self.draw_mask self.window_frame.pack_start(self.treeview_align, True, True) self.connect("realize", self.realize_completion_window) self.get_scrolledwindow = self.get_scrolledwindow wrap_grab_window(completion_grab_window, self) completion_grab_window.connect("input-method-focus-in", self.input_method_focus_in) completion_grab_window.connect("input-method-commit", self.input_method_commit) self.keymap = { "Home": self.treeview.select_first_item, "End": self.treeview.select_last_item, "Page_Up": self.treeview.scroll_page_up, "Page_Down": self.treeview.scroll_page_down, "Up": self.treeview.select_prev_item, "Down": self.treeview.select_next_item, } def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#ffffff", 0.9)), (1, ("#ffffff", 0.9)), ]) def treeview_press_return(self, treeview, select_items): if len(select_items) > 0: completion_grab_window.popup_grab_window_focus_out() global_event.emit("switch-to-detail-page", select_items[0].text) def set_input_method_cursor(self): entry_buffer = search_entry.entry.entry_buffer cursor_pos = entry_buffer.get_cursor_pos( entry_buffer.get_insert_index())[0] (entry_x, entry_y) = search_entry.translate_coordinates( search_entry.get_toplevel(), 0, 0) (window_x, window_y) = search_entry.get_toplevel().window.get_origin() completion_grab_window.im.set_cursor_location( gtk.gdk.Rectangle(window_x + entry_x + cursor_pos[0], window_y + entry_y + cursor_pos[1], 1, cursor_pos[3])) def input_method_focus_in(self, grab_window, im): self.set_input_method_cursor() def input_method_commit(self, grab_window, im, input_text): self.set_input_method_cursor() search_entry.set_text("%s%s" % (search_entry.get_text(), input_text)) def get_scrolledwindow(self): return self.treeview.scrolled_window def shape_completion_window_frame(self, widget, event): pass def expose_completion_window_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*alpha_color_hex_to_cairo( ui_theme.get_alpha_color( "window_frame_outside_3").get_color_info())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() cr.set_source_rgba(*alpha_color_hex_to_cairo( ui_theme.get_alpha_color( "window_frame_inside_2").get_color_info())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2) cr.fill() def show(self, search_string, pkg_names): search_entry.entry.entry_buffer.grab_focus_flag = True self.treeview.delete_all_items() self.treeview.add_items( map(lambda pkg_name: TextItem(pkg_name, search_string), pkg_names)) self.treeview.draw_area.grab_focus() (x, y) = get_widget_root_coordinate(search_entry, WIDGET_POS_BOTTOM_LEFT, False) self.move(x + self.window_offset_x, y + self.window_offset_y) self.show_all() def realize_completion_window(self, widget): self.set_default_size(self.window_width, self.window_height) self.set_geometry_hints( None, self.window_width, # minimum width self.window_height, # minimum height self.window_width, self.window_height, -1, -1, -1, -1, -1, -1)