def _make_plugin_info_widget(self, plugin_id): sources, actions, text_sources = \ plugins.get_plugin_attributes(plugin_id, ( plugins.sources_attribute, plugins.action_decorators_attribute, plugins.text_sources_attribute) ) all_items = list() vbox = gtk.VBox() vbox.set_property("spacing", 5) def make_objects_frame(objs, title): frame_label = gtk.Label() frame_label.set_markup(u"<b>%s</b>" % title) frame_label.set_alignment(0, 0) objvbox = gtk.VBox() objvbox.pack_start(frame_label, False) objvbox.set_property("spacing", 3) for item in objs: plugin_type = plugins.get_plugin_attribute(plugin_id, item) if not plugin_type: continue hbox = gtk.HBox() hbox.set_property("spacing", 3) obj = plugin_type() name = unicode(obj) desc = obj.get_description() or u"" gicon = obj.get_icon() im = gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", 32) hbox.pack_start(im, False) name_label = \ u"%s\n<small>%s</small>" % (name, desc) if desc else \ u"%s" % (name, ) label = wrapped_label() label.set_markup(name_label) hbox.pack_start(label, False) objvbox.pack_start(hbox) # Display information for application content-sources. if not kobject_should_show(obj): continue try: leaf_repr = obj.get_leaf_repr() except AttributeError: continue if leaf_repr is None: continue hbox = gtk.HBox() hbox.set_property("spacing", 3) gicon = leaf_repr.get_icon() im = gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", 16) hbox.pack_start(gtk.Label(_("Content of")), False) hbox.pack_start(im, False) hbox.pack_start(gtk.Label(unicode(leaf_repr)), False) objvbox.pack_start(hbox) return objvbox sources = list(sources or ()) + list(text_sources or ()) if sources: # TRANS: Plugin contents header swid = make_objects_frame(sources, _("Sources")) vbox.pack_start(swid) if actions: # TRANS: Plugin contents header awid = make_objects_frame(actions, _("Actions")) vbox.pack_start(awid) vbox.show_all() return vbox
def plugin_sidebar_update(self, plugin_id): about = gtk.VBox() about.set_property("spacing", 15) about.set_property("border-width", 5) info = self._plugin_info_for_id(plugin_id) title_label = gtk.Label() title_label.set_markup(u"<b><big>%s</big></b>" % info["localized_name"]) version, description, author = plugins.get_plugin_attributes(plugin_id, ( "__version__", "__description__", "__author__", )) about.pack_start(title_label, False) infobox = gtk.VBox() infobox.set_property("spacing", 3) # TRANS: Plugin info fields for field, val in zip((_("Description"), _("Author")), (description, author)): if not val: continue label = gtk.Label() label.set_alignment(0, 0) label.set_markup(u"<b>%s</b>" % field) infobox.pack_start(label, False) label = wrapped_label() label.set_alignment(0, 0) label.set_markup(u"%s" % gobject.markup_escape_text(val)) label.set_selectable(True) infobox.pack_start(label, False) if version: label = wrapped_label() label.set_alignment(0, 0) label.set_markup(u"<b>%s:</b> %s" % (_("Version"), version)) label.set_selectable(True) infobox.pack_start(label, False) about.pack_start(infobox, False) # Check for plugin load exception exc_info = plugins.get_plugin_error(plugin_id) if exc_info is not None: etype, error, tb = exc_info # TRANS: Error message when Plugin needs a Python module to load import_error_localized = _("Python module '%s' is needed") % u"\\1" import_error_pat = u"No module named ([^\s]+)" errmsg = unicode(error) if re.match(import_error_pat, errmsg): errstr = re.sub(import_error_pat, import_error_localized, errmsg, count=1) else: import traceback errstr = "".join(traceback.format_exception(*exc_info)) label = wrapped_label() label.set_alignment(0, 0) label.set_markup(u"<b>%s</b>\n\n%s" % ( _("Plugin could not be read due to an error:"), gobject.markup_escape_text(errstr), )) label.set_selectable(True) about.pack_start(label, False) elif not plugins.is_plugin_loaded(plugin_id): label = gtk.Label() label.set_alignment(0, 0) label.set_text(u"(%s)" % _("disabled")) about.pack_start(label, False) wid = self._make_plugin_info_widget(plugin_id) about.pack_start(wid, False) psettings_wid = self._make_plugin_settings_widget(plugin_id) if psettings_wid: about.pack_start(psettings_wid, False) oldch = self.plugin_about_parent.get_child() if oldch: self.plugin_about_parent.remove(oldch) vp = gtk.Viewport() vp.set_shadow_type(gtk.SHADOW_NONE) vp.add(about) self.plugin_about_parent.add(vp) self.plugin_about_parent.show_all()
def plugin_sidebar_update(self, plugin_id): about = Gtk.VBox() about.set_property("spacing", 15) about.set_property("border-width", 5) info = self._plugin_info_for_id(plugin_id) title_label = Gtk.Label() m_localized_name = GLib.markup_escape_text(info["localized_name"]) title_label.set_markup("<b><big>%s</big></b>" % m_localized_name) version, description, author = plugins.get_plugin_attributes( plugin_id, ( "__version__", "__description__", "__author__", )) about.pack_start(title_label, False, True, 0) infobox = Gtk.VBox() infobox.set_property("spacing", 3) # TRANS: Plugin info fields for field, val in zip((_("Description"), _("Author")), (description, author)): if not val: continue label = Gtk.Label() label.set_alignment(0, 0) label.set_markup("<b>%s</b>" % field) infobox.pack_start(label, False, True, 0) label = wrapped_label() label.set_alignment(0, 0) label.set_markup("%s" % GLib.markup_escape_text(val)) label.set_selectable(True) infobox.pack_start(label, False, True, 0) if version: label = wrapped_label() label.set_alignment(0, 0) m_version = GLib.markup_escape_text(version) label.set_markup("<b>%s:</b> %s" % (_("Version"), m_version)) label.set_selectable(True) infobox.pack_start(label, False, True, 0) about.pack_start(infobox, False, True, 0) # Check for plugin load exception exc_info = plugins.get_plugin_error(plugin_id) if exc_info is not None: etype, error, tb = exc_info # TRANS: Error message when Plugin needs a Python module to load import_error_localized = _("Python module '%s' is needed") % "\\1" import_error_pat = "No module named ([^\s]+)" errmsg = str(error) if re.match(import_error_pat, errmsg): errstr = re.sub(import_error_pat, import_error_localized, errmsg, count=1) elif issubclass(etype, ImportError): errstr = errmsg else: import traceback errstr = "".join(traceback.format_exception(*exc_info)) label = wrapped_label() label.set_alignment(0, 0) label.set_markup("<b>%s</b>\n\n%s" % ( _("Plugin could not be read due to an error:"), GLib.markup_escape_text(errstr), )) label.set_selectable(True) about.pack_start(label, False, True, 0) elif not plugins.is_plugin_loaded(plugin_id): label = Gtk.Label() label.set_alignment(0, 0) label.set_text("(%s)" % _("disabled")) about.pack_start(label, False, True, 0) wid = self._make_plugin_info_widget(plugin_id) about.pack_start(wid, False, True, 0) psettings_wid = self._make_plugin_settings_widget(plugin_id) if psettings_wid: about.pack_start(psettings_wid, False, True, 0) oldch = self.plugin_about_parent.get_child() if oldch: self.plugin_about_parent.remove(oldch) vp = Gtk.Viewport() vp.set_shadow_type(Gtk.ShadowType.NONE) vp.add(about) self.plugin_about_parent.add(vp) self.plugin_about_parent.show_all()
def _make_plugin_info_widget(self, plugin_id): sources, actions, text_sources = \ plugins.get_plugin_attributes(plugin_id, ( plugins.sources_attribute, plugins.action_decorators_attribute, plugins.text_sources_attribute) ) vbox = Gtk.VBox() vbox.set_property("spacing", 5) setctl = settings.GetSettingsController() small_icon_size = setctl.get_config_int("Appearance", "icon_small_size") def make_objects_frame(objs, title): frame_label = Gtk.Label() frame_label.set_markup("<b>%s</b>" % GLib.markup_escape_text(title)) frame_label.set_alignment(0, 0) objvbox = Gtk.VBox() objvbox.pack_start(frame_label, False, True, 0) objvbox.set_property("spacing", 3) for item in objs: plugin_type = plugins.get_plugin_attribute(plugin_id, item) if not plugin_type: continue hbox = Gtk.HBox() hbox.set_property("spacing", 3) obj = plugin_type() name = str(obj) desc = obj.get_description() or "" gicon = obj.get_icon() im = Gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", small_icon_size) hbox.pack_start(im, False, True, 0) m_name = GLib.markup_escape_text(name) m_desc = GLib.markup_escape_text(desc) name_label = \ "%s\n<small>%s</small>" % (m_name, m_desc) if m_desc else \ "%s" % (m_name, ) label = wrapped_label() label.set_markup(name_label) label.set_xalign(0.) hbox.pack_start(label, False, True, 0) objvbox.pack_start(hbox, True, True, 0) # Display information for application content-sources. if not kobject_should_show(obj): continue try: leaf_repr = obj.get_leaf_repr() except AttributeError: continue if leaf_repr is None: continue hbox = Gtk.HBox() hbox.set_property("spacing", 3) gicon = leaf_repr.get_icon() im = Gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", small_icon_size // 2) hbox.pack_start(Gtk.Label.new(_("Content of")), False, True, 0) hbox.pack_start(im, False, True, 0) hbox.pack_start(Gtk.Label.new(str(leaf_repr)), False, True, 0) objvbox.pack_start(hbox, True, True, 0) return objvbox sources = list(sources or ()) + list(text_sources or ()) if sources: # TRANS: Plugin contents header swid = make_objects_frame(sources, _("Sources")) vbox.pack_start(swid, True, True, 0) if actions: # TRANS: Plugin contents header awid = make_objects_frame(actions, _("Actions")) vbox.pack_start(awid, True, True, 0) vbox.show_all() return vbox
def _make_plugin_info_widget(self, plugin_id): sources, actions, text_sources = \ plugins.get_plugin_attributes(plugin_id, ( plugins.sources_attribute, plugins.action_decorators_attribute, plugins.text_sources_attribute) ) vbox = gtk.VBox() vbox.set_property("spacing", 5) def make_objects_frame(objs, title): frame_label = gtk.Label() frame_label.set_markup(u"<b>%s</b>" % gobject.markup_escape_text(title)) frame_label.set_alignment(0, 0) objvbox = gtk.VBox() objvbox.pack_start(frame_label, False) objvbox.set_property("spacing", 3) for item in objs: plugin_type = plugins.get_plugin_attribute(plugin_id, item) if not plugin_type: continue hbox = gtk.HBox() hbox.set_property("spacing", 3) obj = plugin_type() name = unicode(obj) desc = obj.get_description() or u"" gicon = obj.get_icon() im = gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", 32) hbox.pack_start(im, False) m_name = gobject.markup_escape_text(name) m_desc = gobject.markup_escape_text(desc) name_label = \ u"%s\n<small>%s</small>" % (m_name, m_desc) if m_desc else \ u"%s" % (m_name, ) label = wrapped_label() label.set_markup(name_label) hbox.pack_start(label, False) objvbox.pack_start(hbox) # Display information for application content-sources. if not kobject_should_show(obj): continue try: leaf_repr = obj.get_leaf_repr() except AttributeError: continue if leaf_repr is None: continue hbox = gtk.HBox() hbox.set_property("spacing", 3) gicon = leaf_repr.get_icon() im = gtk.Image() im.set_property("gicon", gicon) im.set_property("pixel-size", 16) hbox.pack_start(gtk.Label(_("Content of")), False) hbox.pack_start(im, False) hbox.pack_start(gtk.Label(unicode(leaf_repr)), False) objvbox.pack_start(hbox) return objvbox sources = list(sources or ()) + list(text_sources or ()) if sources: # TRANS: Plugin contents header swid = make_objects_frame(sources, _("Sources")) vbox.pack_start(swid) if actions: # TRANS: Plugin contents header awid = make_objects_frame(actions, _("Actions")) vbox.pack_start(awid) vbox.show_all() return vbox