def refresh_filters(self): current_value = self._what_search_combo.props.value current_value_index = 0 self._what_search_combo.handler_block(self._what_combo_changed_sid) try: self._what_search_combo.remove_all() # TRANS: Item in a combo box that filters by entry type. self._what_search_combo.append_item(_ACTION_ANYTHING, _('Anything')) registry = bundleregistry.get_registry() appended_separator = False types = mime.get_all_generic_types() for generic_type in types: if not appended_separator: self._what_search_combo.append_separator() appended_separator = True self._what_search_combo.append_item( generic_type.type_id, generic_type.name, generic_type.icon) if generic_type.type_id == current_value: current_value_index = \ len(self._what_search_combo.get_model()) - 1 self._what_search_combo.set_active(current_value_index) self._what_search_combo.append_separator() for service_name in model.get_unique_values('activity'): activity_info = registry.get_bundle(service_name) if activity_info is None: continue if service_name == current_value: combo_model = self._what_search_combo.get_model() current_value_index = len(combo_model) # try activity-provided icon if os.path.exists(activity_info.get_icon()): try: self._what_search_combo.append_item( service_name, activity_info.get_name(), file_name=activity_info.get_icon()) except GObject.GError, exception: logging.warning('Falling back to default icon for' ' "what" filter because %r (%r) has an' ' invalid icon: %s', activity_info.get_name(), str(service_name), exception) else: continue # fall back to generic icon self._what_search_combo.append_item( service_name, activity_info.get_name(), icon_name='application-octet-stream') finally: self._what_search_combo.handler_unblock( self._what_combo_changed_sid)
def refresh_filters(self): current_value = self._what_search_combo.props.value current_value_index = 0 self._what_search_combo.handler_block(self._what_combo_changed_sid) try: self._what_search_combo.remove_all() # TRANS: Item in a combo box that filters by entry type. self._what_search_combo.append_item(_ACTION_ANYTHING, _('Anything')) registry = bundleregistry.get_registry() appended_separator = False types = mime.get_all_generic_types() for generic_type in types: if not appended_separator: self._what_search_combo.append_separator() appended_separator = True self._what_search_combo.append_item(generic_type.type_id, generic_type.name, generic_type.icon) if generic_type.type_id == current_value: current_value_index = \ len(self._what_search_combo.get_model()) - 1 self._what_search_combo.set_active(current_value_index) self._what_search_combo.append_separator() for service_name in model.get_unique_values('activity'): activity_info = registry.get_bundle(service_name) if activity_info is None: continue if service_name == current_value: combo_model = self._what_search_combo.get_model() current_value_index = len(combo_model) # try activity-provided icon if os.path.exists(activity_info.get_icon()): try: self._what_search_combo.append_item( service_name, activity_info.get_name(), file_name=activity_info.get_icon()) except glib.GError, exception: logging.warning( 'Falling back to default icon for' ' "what" filter because %r (%r) has an' ' invalid icon: %s', activity_info.get_name(), str(service_name), exception) else: continue # fall back to generic icon self._what_search_combo.append_item( service_name, activity_info.get_name(), icon_name='application-octet-stream') finally: self._what_search_combo.handler_unblock( self._what_combo_changed_sid)
def refresh_filters(self): # refresh_what_filters self._what_list = [] what_list_activities = [] try: # TRANS: Item on a palette that filters by entry type. self._what_list.append({ 'label': _('Anything'), 'icon': 'application-octet-stream', 'callback': self._what_palette_cb, 'id': _ACTION_ANYTHING }) registry = bundleregistry.get_registry() appended_separator = False types = mime.get_all_generic_types() for generic_type in types: if not appended_separator: self._what_list.append({'separator': True}) appended_separator = True self._what_list.append({ 'label': generic_type.name, 'icon': generic_type.icon, 'callback': self._what_palette_cb, 'id': generic_type.type_id }) self._what_list.append({'separator': True}) for bundle_id in model.get_unique_values('activity'): activity_info = registry.get_bundle(bundle_id) if activity_info is None: continue # try activity-provided icon if os.path.exists(activity_info.get_icon()): try: what_list_activities.append({ 'label': activity_info.get_name(), 'file': activity_info.get_icon(), 'callback': self._what_palette_cb, 'id': bundle_id }) except GLib.GError as exception: # fall back to generic icon logging.warning( 'Falling back to default icon for' ' "what" filter because %r (%r) has an' ' invalid icon: %s', activity_info.get_name(), str(bundle_id), exception) what_list_activities.append({ 'label': activity_info.get_name(), 'icon': 'application-octet-stream', 'callback': self._what_palette_cb, 'id': bundle_id }) finally: for item in sorted(what_list_activities, key=lambda x: x['label']): self._what_list.append(item) if self._what_widget_contents is not None: self._what_widget.remove(self._what_widget_contents) self._what_widget_contents = set_palette_list(self._what_list) self._what_widget.add(self._what_widget_contents) self._what_widget_contents.show()
def refresh_filters(self): # refresh_what_filters self._what_list = [] what_list_activities = [] try: # TRANS: Item on a palette that filters by entry type. self._what_list.append({'label': _('Anything'), 'icon': 'application-octet-stream', 'callback': self._what_palette_cb, 'id': _ACTION_ANYTHING}) registry = bundleregistry.get_registry() appended_separator = False types = mime.get_all_generic_types() for generic_type in types: if not appended_separator: self._what_list.append({'separator': True}) appended_separator = True self._what_list.append({'label': generic_type.name, 'icon': generic_type.icon, 'callback': self._what_palette_cb, 'id': generic_type.type_id}) self._what_list.append({'separator': True}) for bundle_id in model.get_unique_values('activity'): activity_info = registry.get_bundle(bundle_id) if activity_info is None: continue # try activity-provided icon if os.path.exists(activity_info.get_icon()): try: what_list_activities.append( {'label': activity_info.get_name(), 'file': activity_info.get_icon(), 'callback': self._what_palette_cb, 'id': bundle_id}) except GObject.GError as exception: # fall back to generic icon logging.warning('Falling back to default icon for' ' "what" filter because %r (%r) has an' ' invalid icon: %s', activity_info.get_name(), str(bundle_id), exception) what_list_activities.append( {'label': activity_info.get_name(), 'icon': 'application-octet-stream', 'callback': self._what_palette_cb, 'id': bundle_id}) finally: def _cmp(a, b): if a['label'] < b['label']: return -1 else: return 1 for item in sorted(what_list_activities, _cmp): self._what_list.append(item) if self._what_widget_contents is not None: self._what_widget.remove(self._what_widget_contents) self._what_widget_contents = set_palette_list(self._what_list) self._what_widget.add(self._what_widget_contents) self._what_widget_contents.show()