Exemple #1
0
    def append_item(self, action_id, text, icon_name=None, size=None,
            pixbuf=None):

        if (icon_name or pixbuf):
            self._icon_renderer = Gtk.CellRendererPixbuf()

            settings = self.get_settings()
            _, w, h = Gtk.icon_size_lookup_for_settings(settings,
                    Gtk.IconSize.MENU)
            self._icon_renderer.props.stock_size = w

            self.pack_start(self._icon_renderer, False)
            self.add_attribute(self._icon_renderer, 'pixbuf', 2)

        #if text:
            #self._text_renderer = Gtk.CellRendererText()
            #self.pack_start(self._text_renderer, True)
            #self.add_attribute(self._text_renderer, 'text', 1)

        if not pixbuf:
            if icon_name:
                if not size:
                    size = Gtk.IconSize.LARGE_TOOLBAR
                    width, height = Gtk.icon_size_lookup(size)
                else:
                    width, height = size
                if icon_name[0:6] == "theme:":
                    icon_name = self._get_real_name_from_theme(icon_name[6:],
                            size)
                pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_name,
                        width, height)
            else:
                pixbuf = None

        self.model.append([action_id, text])
    def append_item(self, action_id, text, icon_name=None, file_name=None):
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = Gtk.CellRendererPixbuf()

            settings = self.get_settings()
            valid_, w, h = Gtk.icon_size_lookup_for_settings(
                settings, Gtk.IconSize.MENU)
            self._icon_renderer.props.stock_size = max(w, h)

            self.pack_start(self._icon_renderer, False)
            self.add_attribute(self._icon_renderer, 'pixbuf', 2)

        if not self._text_renderer and text:
            self._text_renderer = Gtk.CellRendererText()
            self.pack_end(self._text_renderer, True)
            self.add_attribute(self._text_renderer, 'text', 1)

        if icon_name or file_name:
            if text:
                size = Gtk.IconSize.MENU
            else:
                size = Gtk.IconSize.LARGE_TOOLBAR
            valid_, width, height = Gtk.icon_size_lookup(size)

            if icon_name:
                file_name = self._get_real_name_from_theme(icon_name, size)

            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                file_name, width, height)
        else:
            pixbuf = None

        self._model.append([action_id, text, pixbuf, False])
def get_tab_icon_size(tab):
	if log.query(log.INFO):
		debug_plugin_message(log.format("%s", tab))

	is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup_for_settings(tab.get_settings(), Gtk.IconSize.MENU)

	return icon_size_height
Exemple #4
0
def get_tab_icon_size(tab):
    if log.query(log.INFO):
        debug_plugin_message(log.format("%s", tab))

    is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup_for_settings(
        tab.get_settings(), Gtk.IconSize.MENU)

    return icon_size_height
Exemple #5
0
    def __init__(self, iconname, text, onclose):
        Gtk.HBox.__init__(self, homogeneous=False, spacing=4)

        label = Gtk.Label(label=text)
        # FIXME: ideally, we would use custom ellipsization that ellipsized the
        # two paths separately, but that requires significant changes to label
        # generation in many different parts of the code
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
        label.set_single_line_mode(True)
        label.set_alignment(0.0, 0.5)
        label.set_padding(0, 0)

        context = self.get_pango_context()
        font_desc = self.get_style_context().get_font(Gtk.StateFlags.NORMAL)
        metrics = context.get_metrics(font_desc, context.get_language())
        char_width = metrics.get_approximate_char_width() / Pango.SCALE
        valid, w, h = Gtk.icon_size_lookup_for_settings(
            self.get_settings(), Gtk.IconSize.MENU)
        # FIXME: PIXELS replacement
        self.set_size_request(
            self.tab_width_in_chars * char_width + 2 * w, -1)

        button = Gtk.Button()
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.set_focus_on_click(False)
        icon = Gio.ThemedIcon.new_with_default_fallbacks(
            'window-close-symbolic')
        image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.MENU)
        image.set_tooltip_text(_("Close tab"))
        button.add(image)
        button.set_name("meld-tab-close-button")
        button.connect("clicked", onclose)

        context = button.get_style_context()
        provider = Gtk.CssProvider()
        provider.load_from_data(self.css)
        context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        icon = Gtk.Image.new_from_icon_name(iconname, Gtk.IconSize.MENU)

        label_box = Gtk.EventBox()
        label_box.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        label_box.props.visible_window = False
        label_box.connect("button-press-event", self.on_label_clicked)
        label_box.add(label)

        self.pack_start(icon, False, True, 0)
        self.pack_start(label_box, True, True, 0)
        self.pack_start(button, False, True, 0)
        self.set_tooltip_text(text)
        self.show_all()

        self.__label = label
        self.__onclose = onclose
def tab_label_style_set_cb(tab_label, style):
    context = tab_label.get_pango_context()
    # FIXME: AttributeError: 'function' object has no attribute 'font_desc'
    font_desc = Pango.font_description_from_string(tab_label.label.get_label())
    metrics = context.get_metrics(font_desc, context.get_language())
    char_width = metrics.get_approximate_digit_width()
    (Bool, width, height) = Gtk.icon_size_lookup_for_settings(tab_label.get_settings(),
                                                              Gtk.IconSize.MENU)
    #tab_label.set_size_request(20 * Pango.PIXELS(char_width) + 2 * width, -1)
    tab_label.set_size_request(20 * char_width + 2 * width, -1)
    button = tab_label.get_data("close-button")
    button.set_size_request(width + 4, height + 4)
    def __init__(self, iconname, text, onclose):
        Gtk.HBox.__init__(self, homogeneous=False, spacing=4)

        label = Gtk.Label(label=text)
        # FIXME: ideally, we would use custom ellipsization that ellipsized the
        # two paths separately, but that requires significant changes to label
        # generation in many different parts of the code
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
        label.set_single_line_mode(True)
        label.set_alignment(0.0, 0.5)
        label.set_padding(0, 0)

        context = self.get_pango_context()
        font_desc = self.get_style_context().get_font(Gtk.StateFlags.NORMAL)
        metrics = context.get_metrics(font_desc, context.get_language())
        char_width = metrics.get_approximate_char_width() / Pango.SCALE
        valid, w, h = Gtk.icon_size_lookup_for_settings(
            self.get_settings(), Gtk.IconSize.MENU)
        # FIXME: PIXELS replacement
        self.set_size_request(self.tab_width_in_chars * char_width + 2 * w, -1)

        button = Gtk.Button()
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.set_focus_on_click(False)
        icon = Gio.ThemedIcon.new_with_default_fallbacks(
            'window-close-symbolic')
        image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.MENU)
        image.set_tooltip_text(_("Close tab"))
        button.add(image)
        button.set_name("meld-tab-close-button")
        button.connect("clicked", onclose)

        context = button.get_style_context()
        provider = Gtk.CssProvider()
        provider.load_from_data(self.css)
        context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        icon = Gtk.Image.new_from_icon_name(iconname, Gtk.IconSize.MENU)

        label_box = Gtk.EventBox()
        label_box.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        label_box.props.visible_window = False
        label_box.connect("button-press-event", self.on_label_clicked)
        label_box.add(label)

        self.pack_start(icon, False, True, 0)
        self.pack_start(label_box, True, True, 0)
        self.pack_start(button, False, True, 0)
        self.set_tooltip_text(text)
        self.show_all()

        self.__label = label
        self.__onclose = onclose
Exemple #8
0
	def _add_icon_to_button(self, button):
		icon_box = Gtk.HBox()
		image = Gtk.Image()
		image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
		Gtk.Button.set_relief(button, Gtk.ReliefStyle.NONE)

		settings = Gtk.Widget.get_settings(button)
		valid_, w, h = Gtk.icon_size_lookup_for_settings(settings,
														 Gtk.IconSize.MENU)
		Gtk.Widget.set_size_request(button, w + 4, h + 4)
		image.show()
		icon_box.pack_start(image, True, False, 0)
		button.add(icon_box)
		icon_box.show()
Exemple #9
0
    def _add_icon_to_button(self, button):
        icon_box = Gtk.HBox()
        image = Gtk.Image()
        image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
        Gtk.Button.set_relief(button, Gtk.ReliefStyle.NONE)

        settings = Gtk.Widget.get_settings(button)
        valid_, w, h = Gtk.icon_size_lookup_for_settings(
            settings, Gtk.IconSize.MENU)
        Gtk.Widget.set_size_request(button, w + 4, h + 4)
        image.show()
        icon_box.pack_start(image, True, False, 0)
        button.add(icon_box)
        icon_box.show()
Exemple #10
0
    def get_icon_pixbuf(self):
        screen = self.get_screen()
        icon_theme = Gtk.IconTheme.get_for_screen(screen)
        settings = Gtk.Settings.get_for_screen(screen)
        success, width, height = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.DIALOG)
        if not success:
            width = 48
            height = 48

        flags = Gtk.IconLookupFlags.USE_BUILTIN | Gtk.IconLookupFlags.GENERIC_FALLBACK
        info = icon_theme.lookup_icon("gnome-dvb-setup", min(width, height), flags)
        if info != None:
            context = self.get_style_context()
            pixbuf, symbolic = info.load_symbolic_for_context(context)
            return pixbuf
    def append_item(self, value, text, icon_name=None, file_name=None):
        '''
        This function adds another item to the bottom of the combo box list.

        If either `icon_name` or `file_name` are supplied and icon column
        will be added to the combo box list.

        Args:
            value (object):  the value that will be returned by `get_value`,
                when this item is selected
            text (str):  the user visible label for the item
            icon_name (str):  the name of the icon in the theme to use for
                this item, optional and conflicting with `file_name`
            file_name (str):  the path to a sugar (svg) icon to use for this
                item, optional and conflicting with `icon_name`
        '''
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = Gtk.CellRendererPixbuf()

            settings = self.get_settings()
            valid_, w, h = Gtk.icon_size_lookup_for_settings(
                settings, Gtk.IconSize.MENU)
            self._icon_renderer.props.stock_size = max(w, h)

            self.pack_start(self._icon_renderer, False)
            self.add_attribute(self._icon_renderer, 'pixbuf', 2)

        if not self._text_renderer and text:
            self._text_renderer = Gtk.CellRendererText()
            self.pack_end(self._text_renderer, True)
            self.add_attribute(self._text_renderer, 'text', 1)

        if icon_name or file_name:
            if text:
                size = Gtk.IconSize.MENU
            else:
                size = Gtk.IconSize.LARGE_TOOLBAR
            valid_, width, height = Gtk.icon_size_lookup(size)

            if icon_name:
                file_name = self._get_real_name_from_theme(icon_name, size)

            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                file_name, width, height)
        else:
            pixbuf = None

        self._model.append([value, text, pixbuf, False])
    def append_item(self, value, text, icon_name=None, file_name=None):
        '''
        This function adds another item to the bottom of the combo box list.

        If either `icon_name` or `file_name` are supplied and icon column
        will be added to the combo box list.

        Args:
            value (object):  the value that will be returned by `get_value`,
                when this item is selected
            text (str):  the user visible label for the item
            icon_name (str):  the name of the icon in the theme to use for
                this item, optional and conflicting with `file_name`
            file_name (str):  the path to a sugar (svg) icon to use for this
                item, optional and conflicting with `icon_name`
        '''
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = Gtk.CellRendererPixbuf()

            settings = self.get_settings()
            valid_, w, h = Gtk.icon_size_lookup_for_settings(
                settings, Gtk.IconSize.MENU)
            self._icon_renderer.props.stock_size = max(w, h)

            self.pack_start(self._icon_renderer, False)
            self.add_attribute(self._icon_renderer, 'pixbuf', 2)

        if not self._text_renderer and text:
            self._text_renderer = Gtk.CellRendererText()
            self.pack_end(self._text_renderer, True)
            self.add_attribute(self._text_renderer, 'text', 1)

        if icon_name or file_name:
            if text:
                size = Gtk.IconSize.MENU
            else:
                size = Gtk.IconSize.LARGE_TOOLBAR
            valid_, width, height = Gtk.icon_size_lookup(size)

            if icon_name:
                file_name = self._get_real_name_from_theme(icon_name, size)

            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                file_name, width, height)
        else:
            pixbuf = None

        self._model.append([value, text, pixbuf, False])
Exemple #13
0
def register_stock_icons(icon_dir, icon_names, prefix=""):
    """
    Register stock icons. The directory containing the icons should provide a
    scalable SVG icon for the default source as well as sizes for any possible
    Gtk.IconSize (16, 18, 24, 20, 32, 48). At bare minimum, an SVG and a 48x48
    pixel icon should be provided.
    
    Icon directory structure:
    
        <icon_dir>/scalable/<icon_name>.svg
        <icon_dir>/16x16/<icon_name>.png
        ... etc.
    
    Args:
        icon_dir: The directory containing icon source images.
        icon_names: A list of icon names which correspond both to the stock ID
            as well as the filename without the extension. 
        prefix: A prefix to add to the stock_id.
    """
    factory = Gtk.IconFactory()
    for name in icon_names:
        svg_file = os.path.join(icon_dir, "scalable", name + ".svg")
        try:
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(svg_file)
            icon_set = Gtk.IconSet.new_from_pixbuf(pixbuf)
            logger.debug("Registered stock icon (scalable) from %s" % svg_file)
        except Exception as e:
            logger.warn(str(e))
            continue

        for icon_size in xrange(1, 7):
            settings = Gtk.Settings.get_default()
            found, width, height = Gtk.icon_size_lookup_for_settings(
                settings, icon_size)
            if found:
                folder = "%sx%s" % (str(width), str(height))
                icon_file = os.path.join(icon_dir, folder, name + ".png")

                if os.path.exists(icon_file):
                    source = Gtk.IconSource()
                    source.set_filename(icon_file)
                    source.set_size_wildcarded(False)
                    source.set_size(icon_size)
                    icon_set.add_source(source)
                    logger.debug("Registered stock icon (%s) from %s" %
                                 (icon_size, icon_file))
        factory.add(prefix + name, icon_set)
    factory.add_default()
Exemple #14
0
def register_stock_icons(icon_dir, icon_names, prefix=""):
    """
    Register stock icons. The directory containing the icons should provide a
    scalable SVG icon for the default source as well as sizes for any possible
    Gtk.IconSize (16, 18, 24, 20, 32, 48). At bare minimum, an SVG and a 48x48
    pixel icon should be provided.
    
    Icon directory structure:
    
        <icon_dir>/scalable/<icon_name>.svg
        <icon_dir>/16x16/<icon_name>.png
        ... etc.
    
    Args:
        icon_dir: The directory containing icon source images.
        icon_names: A list of icon names which correspond both to the stock ID
            as well as the filename without the extension. 
        prefix: A prefix to add to the stock_id.
    """
    factory = Gtk.IconFactory()
    for name in icon_names:
        svg_file = os.path.join(icon_dir, "scalable", name + ".svg")
        try:
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(svg_file)
            icon_set = Gtk.IconSet.new_from_pixbuf(pixbuf)
            logger.debug("Registered stock icon (scalable) from %s" % svg_file)
        except Exception as e:
            logger.warn(str(e))
            continue

        for icon_size in xrange(1, 7):
            settings = Gtk.Settings.get_default()
            found, width, height = Gtk.icon_size_lookup_for_settings(settings, 
                                                                     icon_size)
            if found:
                folder = "%sx%s" % (str(width), str(height))
                icon_file = os.path.join(icon_dir, folder, name + ".png")
                
                if os.path.exists(icon_file):
                    source = Gtk.IconSource()
                    source.set_filename(icon_file)
                    source.set_size_wildcarded(False)
                    source.set_size(icon_size)
                    icon_set.add_source(source)
                    logger.debug("Registered stock icon (%s) from %s" % (icon_size, icon_file))
        factory.add(prefix+name, icon_set)
    factory.add_default()
	def tab_get_icon(self, tab):
		theme = Gtk.IconTheme.get_for_screen(tab.get_screen())
		is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup_for_settings(tab.get_settings(), Gtk.IconSize.MENU)
		state = tab.get_state()

		if state in self.TAB_STATE_TO_ICON:
			try:
				pixbuf = self.get_stock_icon(theme, self.TAB_STATE_TO_ICON[state], icon_size_height)
			except GObject.GError:
				pixbuf = None
		else:
			pixbuf = None

		if not pixbuf:
			pixbuf = self.get_icon(theme, tab.get_document().get_location(), icon_size_height)

		return pixbuf
Exemple #16
0
	def tab_get_icon(self, tab):
		theme = Gtk.IconTheme.get_for_screen(tab.get_screen())
		is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup_for_settings(tab.get_settings(), Gtk.IconSize.MENU)
		state = tab.get_state()

		if state in self.TAB_STATE_TO_ICON:
			try:
				pixbuf = self.get_stock_icon(theme, self.TAB_STATE_TO_ICON[state], icon_size_height)
			except GObject.GError:
				pixbuf = None
		else:
			pixbuf = None

		if not pixbuf:
			pixbuf = self.get_icon(theme, tab.get_document().get_location(), icon_size_height)

		return pixbuf
    def get_icon_pixbuf(self):
        screen = self.get_screen()
        icon_theme = Gtk.IconTheme.get_for_screen(screen)
        settings = Gtk.Settings.get_for_screen(screen)
        success, width, height = Gtk.icon_size_lookup_for_settings(
            settings, Gtk.IconSize.DIALOG)
        if not success:
            width = 48
            height = 48

        flags = Gtk.IconLookupFlags.USE_BUILTIN | Gtk.IconLookupFlags.GENERIC_FALLBACK
        info = icon_theme.lookup_icon("gnome-dvb-setup", min(width, height),
                                      flags)
        if info != None:
            context = self.get_style_context()
            pixbuf, symbolic = info.load_symbolic_for_context(context)
            return pixbuf
Exemple #18
0
    def append_item(self,
                    action_id,
                    text=None,
                    icon_name=None,
                    size=None,
                    pixbuf=None,
                    position=None):

        if not self._icon_renderer and (icon_name or pixbuf):
            self._icon_renderer = Gtk.CellRendererPixbuf()

            settings = self.get_settings()
            zxx, w, h = Gtk.icon_size_lookup_for_settings(
                settings, Gtk.IconSize.MENU)
            self._icon_renderer.props.stock_size = w

            self._icon_renderer.props.xpad = 4
            self._icon_renderer.props.ypad = 4

            self.pack_start(self._icon_renderer, False)
            self.add_attribute(self._icon_renderer, 'pixbuf', 2)

        if not self._text_renderer and text:
            self._text_renderer = Gtk.CellRendererText()
            self._text_renderer.props.ellipsize = Pango.EllipsizeMode.END
            self.pack_end(self._text_renderer, True)
            self.add_attribute(self._text_renderer, 'text', 1)

        if not pixbuf:
            if icon_name:
                if not size:
                    size = Gtk.IconSize.LARGE_TOOLBAR
                    width, height = Gtk.icon_size_lookup(size)
                else:
                    width, height = size
                pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                    icon_name, width, height)
            else:
                pixbuf = None

        if position:
            self._model.insert(position, [action_id, text, pixbuf, False])
        else:
            self._model.append([action_id, text, pixbuf, False])
Exemple #19
0
def add_icon_to_button(button, id):
    """Fonction pour ajouter un bouton fermer dans l'onglet du notebook"""
    #création d'une boite horizontale
    iconBox = Gtk.HBox(False, 0)
    #Création d'une image vide
    image = Gtk.Image()
    #On récupère l'icone du bouton "fermer"
    image.set_from_stock(id, Gtk.IconSize.MENU)
    #On enlève le relief au bouton (donné en attribut)
    Gtk.Button.set_relief(button, Gtk.ReliefStyle.NONE)
    #On récupère les propriétés du bouton
    settings = Gtk.Widget.get_settings(button)
    #On affecte à w et h les dimensions
    w, h = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.MENU)[1:]
    #On modifie ces dimensions
    Gtk.Widget.set_size_request(button, w + 8, h + 8)
    image.show()
    #On met l'image dans la boite
    iconBox.pack_start(image, True, False, 0)
    #On ajoute la boite dans le bouton
    button.add(iconBox)
    iconBox.show()
Exemple #20
0
def add_icon_to_button(button, id):
    """Fonction pour ajouter un bouton fermer dans l'onglet du notebook"""
    #création d'une boite horizontale
    iconBox = Gtk.HBox(False, 0)
    #Création d'une image vide
    image = Gtk.Image()
    #On récupère l'icone du bouton "fermer"
    image.set_from_stock(id, Gtk.IconSize.MENU)
    #On enlève le relief au bouton (donné en attribut)
    Gtk.Button.set_relief(button, Gtk.ReliefStyle.NONE)
    #On récupère les propriétés du bouton
    settings = Gtk.Widget.get_settings(button)
    #On affecte à w et h les dimensions
    w, h = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.MENU)[1:]
    #On modifie ces dimensions
    Gtk.Widget.set_size_request(button, w + 8, h + 8)
    image.show()
    #On met l'image dans la boite
    iconBox.pack_start(image, True, False, 0)
    #On ajoute la boite dans le bouton
    button.add(iconBox)
    iconBox.show()
    def _setup(self, window, tab, notebooks, view):
        if self._is_side_panel_stack:
            is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup(
                Gtk.IconSize.MENU)
        else:
            is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup_for_settings(
                tab.get_settings(), Gtk.IconSize.MENU)

        self._icon_cell.set_fixed_size(icon_size_height, icon_size_height)
        self._space_cell.set_fixed_size(icon_size_height, icon_size_height)

        multi = self._get_multi_notebook(tab)

        if multi:
            self._multi = multi

            for doc in window.get_documents():
                self.on_multi_notebook_notebook_added(
                    multi,
                    Gedit.Tab.get_from_document(doc).get_parent(), notebooks,
                    view)

            connect_handlers(self, multi, [
                'notebook-added', 'notebook-removed', 'tab-added',
                'tab-removed'
            ], 'multi_notebook', notebooks, view)
            connect_handlers(self, window, [
                'tabs-reordered', 'active-tab-changed', 'key-press-event',
                'key-release-event', 'focus-out-event', 'configure-event'
            ], 'window', notebooks, view)

        else:
            try:
                Gedit.debug_plugin_message(
                    "cannot find multi notebook from %s", tab)
            except AttributeError:
                pass