Пример #1
0
 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
Пример #2
0
		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
Пример #3
0
	def activate(self, leaf):
		# Try to find the __file__ attribute for the plugin
		# It will fail for files inside zip packages, but that is
		# uncommon for now.
		# Additionally, it will fail for fake plugins
		plugin_id = leaf.object["name"]
		filename = plugins.get_plugin_attribute(plugin_id, "__file__")
		if not filename:
			return leaf
		root, ext = os.path.splitext(filename)
		if ext.lower() == ".pyc" and os.path.exists(root + ".py"):
			return FileLeaf(root + ".py")

		if not os.path.exists(filename):
			# handle modules in zip or eggs
			import pkgutil
			pfull = "kupfer.plugin." + plugin_id
			loader = pkgutil.get_loader(pfull)
			if loader:
				return TextLeaf(loader.get_source(pfull))
		return FileLeaf(filename)
Пример #4
0
    def activate(self, leaf):
        # Try to find the __file__ attribute for the plugin
        # It will fail for files inside zip packages, but that is
        # uncommon for now.
        # Additionally, it will fail for fake plugins
        plugin_id = leaf.object["name"]
        filename = plugins.get_plugin_attribute(plugin_id, "__file__")
        if not filename:
            return leaf
        root, ext = os.path.splitext(filename)
        if ext.lower() == ".pyc" and os.path.exists(root + ".py"):
            return FileLeaf(root + ".py")

        if not os.path.exists(filename):
            # handle modules in zip or eggs
            import pkgutil
            pfull = "kupfer.plugin." + plugin_id
            loader = pkgutil.get_loader(pfull)
            if loader:
                return TextLeaf(loader.get_source(pfull))
        return FileLeaf(filename)
Пример #5
0
	def _make_plugin_settings_widget(self, plugin_id):
		plugin_settings = plugins.get_plugin_attribute(plugin_id,
				plugins.settings_attribute)
		if not plugin_settings:
			return None

		info = self._plugin_info_for_id(plugin_id)
		title_label = gtk.Label()
		# TRANS: Plugin-specific configuration (header)
		title_label.set_markup(u"<b>%s</b>" % _("Configuration"))
		title_label.set_alignment(0, 0)

		vbox = gtk.VBox()
		vbox.pack_start(title_label, False)
		#vbox.set_property("spacing", 5)

		plugin_settings_keys = iter(plugin_settings) if plugin_settings else ()
		for setting in plugin_settings_keys:
			typ = plugin_settings.get_value_type(setting)
			alternatives = plugin_settings.get_alternatives(setting)
			tooltip = plugin_settings.get_tooltip(setting)
			wid = None
			hbox = gtk.HBox()
			hbox.set_property("spacing", 10)
			if tooltip:
				hbox.set_tooltip_text(tooltip)
			label = plugin_settings.get_label(setting)

			if issubclass(typ, plugin_support.UserNamePassword):
				wid = gtk.Button(label or _("Set username and password"))
				wid.connect("clicked", self._get_plugin_credentials_callback(
						plugin_id, setting))
				hbox.pack_start(wid, False)
				vbox.pack_start(hbox, False)
				continue

			label_wid = wrapped_label(label, maxwid=200)
			if issubclass(typ, basestring):
				if alternatives:
					wid = gtk.combo_box_new_text()
					val = plugin_settings[setting]
					active_index = -1
					for idx, text in enumerate(alternatives):
						wid.append_text(text)
						if text == val:
							active_index = idx
					if active_index < 0:
						wid.prepend_text(val)
						active_index = 0
					wid.set_active(active_index)
					wid.connect("changed", self._get_plugin_change_callback(
						plugin_id, setting, typ, "get_active_text"))
				else:
					wid = gtk.Entry()
					wid.set_text(plugin_settings[setting])
					wid.connect("changed", self._get_plugin_change_callback(
						plugin_id, setting, typ, "get_text",
						no_false_values=True))
				hbox.pack_start(label_wid, False)
				hbox.pack_start(wid, True)

			elif issubclass(typ, bool):
				wid = gtk.CheckButton(label)
				wid.set_active(plugin_settings[setting])
				hbox.pack_start(wid, False)
				wid.connect("toggled", self._get_plugin_change_callback(
					plugin_id, setting, typ, "get_active"))
			elif issubclass(typ, int):
				wid = gtk.SpinButton()
				wid.set_increments(1, 1)
				wid.set_range(0, 1000)
				wid.set_value(plugin_settings[setting])
				hbox.pack_start(label_wid, False)
				hbox.pack_start(wid, False)
				wid.connect("changed", self._get_plugin_change_callback(
					plugin_id, setting, typ, "get_text", no_false_values=True))
			vbox.pack_start(hbox, False)

		vbox.show_all()
		return vbox
Пример #6
0
    def _make_plugin_settings_widget(self, plugin_id):
        plugin_settings = plugins.get_plugin_attribute(
            plugin_id, plugins.settings_attribute)
        if not plugin_settings:
            return None

        title_label = Gtk.Label()
        # TRANS: Plugin-specific configuration (header)
        title_label.set_markup("<b>%s</b>" % _("Configuration"))
        title_label.set_alignment(0, 0)

        vbox = Gtk.VBox()
        vbox.pack_start(title_label, False, True, 0)
        #vbox.set_property("spacing", 5)

        plugin_settings_keys = iter(plugin_settings) if plugin_settings else ()
        for setting in plugin_settings_keys:
            typ = plugin_settings.get_value_type(setting)
            alternatives = plugin_settings.get_alternatives(setting)
            tooltip = plugin_settings.get_tooltip(setting)
            wid = None
            hbox = Gtk.HBox()
            hbox.set_property("spacing", 10)
            if tooltip:
                hbox.set_tooltip_text(tooltip)
            label = plugin_settings.get_label(setting)

            if issubclass(typ, plugin_support.UserNamePassword):
                wid = Gtk.Button(label or _("Set username and password"))
                wid.connect(
                    "clicked",
                    self._get_plugin_credentials_callback(plugin_id, setting))
                hbox.pack_start(wid, False, True, 0)
                vbox.pack_start(hbox, False, True, 0)
                continue

            label_wid = wrapped_label(label, maxwid=200)
            label_wid.set_xalign(0.)
            if issubclass(typ, str):
                if alternatives:
                    wid = Gtk.ComboBoxText.new()
                    val = plugin_settings[setting]
                    active_index = -1
                    for idx, text in enumerate(alternatives):
                        wid.append_text(text)
                        if text == val:
                            active_index = idx
                    if active_index < 0:
                        wid.prepend_text(val)
                        active_index = 0
                    wid.set_active(active_index)
                    wid.connect(
                        "changed",
                        self._get_plugin_change_callback(
                            plugin_id, setting, typ, "get_active_text"))
                else:
                    wid = Gtk.Entry()
                    wid.set_text(plugin_settings[setting])
                    wid.connect(
                        "changed",
                        self._get_plugin_change_callback(plugin_id,
                                                         setting,
                                                         typ,
                                                         "get_text",
                                                         no_false_values=True))
                hbox.pack_start(label_wid, False, True, 0)
                hbox.pack_start(wid, True, True, 0)

            elif issubclass(typ, bool):
                wid = Gtk.CheckButton.new_with_label(label)
                wid.set_active(plugin_settings[setting])
                hbox.pack_start(wid, False, True, 0)
                wid.connect(
                    "toggled",
                    self._get_plugin_change_callback(plugin_id, setting, typ,
                                                     "get_active"))
            elif issubclass(typ, int):
                wid = Gtk.SpinButton()
                wid.set_increments(1, 1)
                wid.set_range(0, 1000)
                wid.set_value(plugin_settings[setting])
                hbox.pack_start(label_wid, False, True, 0)
                hbox.pack_start(wid, False, True, 0)
                wid.connect(
                    "changed",
                    self._get_plugin_change_callback(plugin_id,
                                                     setting,
                                                     typ,
                                                     "get_text",
                                                     no_false_values=True))
            vbox.pack_start(hbox, False, True, 0)

        vbox.show_all()
        return vbox