def _create_technical(self): vbox = Gtk.VBox() vbox.props.spacing = style.DEFAULT_SPACING hbox = Gtk.HBox() kind = _('Kind: ') kindlabel = Gtk.Label() kindlabel.set_markup('<span foreground="%s">%s</span>' % ( style.COLOR_BUTTON_GREY.get_html(), kind)) lines = [ _('Date: %s') % (self._format_date(),), _('Size: %s') % (format_size( int(self._metadata.get( 'filesize', model.get_file_size(self._metadata['uid']))))) ] mimelist = Gtk.ListStore(str) generic_types = mime.get_all_generic_types() mimescombo = Gtk.ComboBox.new_with_model(mimelist) for sub_types in generic_types: for mime_type in sub_types.mime_types: mimelist.append([mime_type]) for index, element in enumerate(mimelist): if element[0] == self._metadata['mime_type']: mimescombo.set_active(index) break mimescombo.connect("changed", self._mime_activated_cb) cell = Gtk.CellRendererText() cell.set_property("xalign", 0.5) cell.set_fixed_size(150, 18) mimescombo.pack_start(cell, True) mimescombo.add_attribute(cell, "text", 0) vbox.pack_start(hbox, False, False, 0) hbox.pack_start(kindlabel, False, False, 0) hbox.pack_start(mimescombo, False, False, 0) for line in lines: linebox = Gtk.HBox() vbox.pack_start(linebox, False, False, 0) text = Gtk.Label() text.set_markup('<span foreground="%s">%s</span>' % ( style.COLOR_BUTTON_GREY.get_html(), line)) linebox.pack_start(text, False, False, 0) return vbox
def _get_icon_for_mime(mime_type): generic_types = mime.get_all_generic_types() for generic_type in generic_types: if mime_type in generic_type.mime_types: file_name = get_icon_file_name(generic_type.icon) if file_name is not None: return file_name icons = Gio.content_type_get_icon(mime_type) logging.debug('icons for this file: %r', icons.props.names) for icon_name in icons.props.names: file_name = get_icon_file_name(icon_name) if file_name is not None: return file_name
def get_icon(self): mime_type = self.get_mime_type() generic_types = mime.get_all_generic_types() for generic_type in generic_types: if mime_type in generic_type.mime_types: return generic_type.icon icons = Gio.content_type_get_icon(mime_type) icon_name = None if icons is not None: icon_theme = Gtk.IconTheme.get_default() for icon_name in icons.props.names: icon_info = icon_theme.lookup_icon(icon_name, Gtk.IconSize.LARGE_TOOLBAR, 0) if icon_info is not None: icon_info.free() return icon_name return 'application-octet-stream'
def get_icon(self): mime_type = self.get_mime_type() generic_types = mime.get_all_generic_types() for generic_type in generic_types: if mime_type in generic_type.mime_types: return generic_type.icon icons = Gio.content_type_get_icon(mime_type) icon_name = None if icons is not None: icon_theme = Gtk.IconTheme.get_default() for icon_name in icons.props.names: icon_info = (icon_theme.lookup_icon(icon_name, Gtk.IconSize.LARGE_TOOLBAR, 0)) if icon_info is not None: icon_info.free() return icon_name return 'application-octet-stream'
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): # 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): 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): # 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()