Пример #1
0
	def _get_icon(self):
		screen = self.get_screen()

		theme = gtk.icon_theme_get_for_screen(screen)
		if theme == None:
			return None

		icon_size = gtk.icon_size_lookup_for_settings(self.get_settings(), gtk.ICON_SIZE_MENU)[1]

		if self._state == TAB_STATE_LOADING:
			pixbuf = get_stock_icon(theme, gtk.STOCK_OPEN, icon_size)
		elif self._state == TAB_STATE_REVERTING:
			pixbuf = get_stock_icon (theme, gtk.STOCK_REVERT_TO_SAVED, icon_size)
		elif self._state == TAB_STATE_SAVING:
			pixbuf = get_stock_icon(theme, gtk.STOCK_SAVE, icon_size)
		elif self._state == TAB_STATE_PRINTING:
			pixbuf = get_stock_icon(theme, gtk.STOCK_PRINT, icon_size)
		elif self._state == TAB_STATE_PRINT_PREVIEWING or self._state == TAB_STATE_SHOWING_PRINT_PREVIEW:
			pixbuf = get_stock_icon (theme, gtk.STOCK_PRINT_PREVIEW, icon_size)
		elif self._state == TAB_STATE_LOADING_ERROR or \
		     self._state == TAB_STATE_REVERTING_ERROR or \
		     self._state == TAB_STATE_SAVING_ERROR or \
		     self._state == TAB_STATE_GENERIC_ERROR:
			pixbuf = get_stock_icon (theme, gtk.STOCK_DIALOG_ERROR, icon_size)
		elif self._state == TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION:
			pixbuf = get_stock_icon(theme, GTK_STOCK_DIALOG_WARNING, icon_size)
		else:
			doc = self.get_document()

			raw_uri = doc.get_uri()
			mime_type = doc.get_mime_type()

			pixbuf = get_icon(theme, raw_uri, mime_type, icon_size)

		return pixbuf
Пример #2
0
    def __add_widget_title(self, w):
        hbox = gtk.HBox()
        label = gtk.Label('<notitle>')
        label.set_selectable(False)
        label.set_ellipsize(pango.ELLIPSIZE_END)
        hbox.pack_start(label, expand=True)

        close = gtk.Button()
        close.set_focus_on_click(False)
        close.set_relief(gtk.RELIEF_NONE)
        close.set_name('hotwire-tab-close')
        img = gtk.Image()
        img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        close.add(img)
        close.connect('clicked', lambda b: self.__close_tab(w))
        (width,
         height) = gtk.icon_size_lookup_for_settings(label.get_settings(),
                                                     gtk.ICON_SIZE_MENU)
        close.set_size_request(width + 2, height + 2)
        hbox.pack_start(close, expand=False)
        hbox.show_all()
        self.__notebook.set_tab_label(w, hbox)
        w.set_data('hotwire-tab-label', label)
        self.__notebook.set_tab_label_packing(w, True, True, gtk.PACK_START)
        self.__sync_tabs_visible()
        return label
Пример #3
0
    def _item_new(self, action_id, text, icon_name, file_name):
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = gtk.CellRendererPixbuf()

            settings = self.get_settings()
            w, h = gtk.icon_size_lookup_for_settings(settings,
                                                     gtk.ICON_SIZE_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.ICON_SIZE_MENU
            else:
                size = gtk.ICON_SIZE_LARGE_TOOLBAR
            width, height = gtk.icon_size_lookup(size)

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

            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                file_name, width, height)
        else:
            pixbuf = None

        return (action_id, text, pixbuf, False)
Пример #4
0
    def tab_get_icon(self, tab):
        theme = gtk.icon_theme_get_for_screen(tab.get_screen())
        icon_size_width, icon_size_height = gtk.icon_size_lookup_for_settings(
            tab.get_settings(), gtk.ICON_SIZE_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 glib.GError:
                pixbuf = None
        else:
            pixbuf = None

        if not pixbuf:
            uri = tab.get_document().get_uri()
            if uri:
                location = gio.File(uri)
            else:
                location = None
            pixbuf = self.get_icon(theme, location, icon_size_height)

        return pixbuf
Пример #5
0
    def init_widgets(self, name):
        #create a custom tab for notebook containing a 
        #label and a button with STOCK_ICON
        tabBox = gtk.HBox(False, 2)
        tabButton=gtk.Button(use_underline=False)
        tabButton.connect('clicked', self.on_clicked)

        self.label = gtk.Label(name)

        #Add a picture on a button
        iconBox = gtk.HBox(False, 0)
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_MENU)
        gtk.Button.set_relief(tabButton,gtk.RELIEF_NONE)
        settings = gtk.Widget.get_settings(tabButton)
        (w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU)
        gtk.Widget.set_size_request(tabButton, w + 4, h + 4);
        iconBox.pack_start(image, True, False, 0)
        tabButton.add(iconBox)

        tabBox.pack_start(self.label, False)
        tabBox.pack_start(tabButton, False)

        self.connect('button-press-event', self.on_button_press)

        # needed, otherwise even calling show_all on the notebook won't
        # make the hbox contents appear.
        tabBox.show_all()
        self.add(tabBox)
Пример #6
0
 def add_icon_to_button(self, button, iconpath):
     #"Function that add the icon to the button"
     #Hbox creation
     iconBox = gtk.HBox(False, 0)
     #Empty image creation
     image = gtk.Image()
     #Let's get the default gtk close button
     #image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_BUTTON) #gtk.ICON_SIZE_MENU
     image.set_from_file(iconpath)
     #set the relief off
     gtk.Button.set_relief(button, gtk.RELIEF_NONE)
     #Get the settings of the button
     settings = gtk.Widget.get_settings(button)
     #w and h dimensions of the button
     (w, h) = gtk.icon_size_lookup_for_settings(settings,
                                                gtk.ICON_SIZE_BUTTON)
     #modification of the dimensions
     gtk.Widget.set_size_request(button, w + 15, h + 15)
     image.show()
     #pack the image in the box
     iconBox.pack_start(image, True, False, 0)
     #add the box in the button
     button.add(iconBox)
     iconBox.show()
     return
Пример #7
0
    def on_size_allocate(self, widget, allocation):
        """
            Takes care of resizing the icon if necessary
        """
        screen = widget.get_screen()
        settings = gtk.settings_get_for_screen(screen)
        icon_sizes = (
            gtk.ICON_SIZE_MENU,  # 1
            gtk.ICON_SIZE_SMALL_TOOLBAR,  # 2
            gtk.ICON_SIZE_LARGE_TOOLBAR,  # 3
            gtk.ICON_SIZE_BUTTON,  # 4
            gtk.ICON_SIZE_DND,  # 5
            gtk.ICON_SIZE_DIALOG  # 6
        )
        # Retrieve pixel dimensions of stock icon sizes
        sizes = [(gtk.icon_size_lookup_for_settings(settings, i)[0], i)
                 for i in icon_sizes]
        # Only look at sizes lower than the current dimensions
        sizes = [(s, i) for s, i in sizes if s <= allocation.width]
        # Get the closest fit
        target_size = max(sizes)[1]

        # Avoid setting the same size over and over again
        if self.image.props.icon_size is not target_size.real:
            glib.idle_add(self.image.set_from_icon_name,
                          self.image.props.icon_name, target_size)
Пример #8
0
    def on_size_allocate(self, widget, allocation):
        """
            Takes care of resizing the icon if necessary
        """
        screen = widget.get_screen()
        settings = gtk.settings_get_for_screen(screen)
        icon_sizes = (
            gtk.ICON_SIZE_MENU, # 1
            gtk.ICON_SIZE_SMALL_TOOLBAR, # 2
            gtk.ICON_SIZE_LARGE_TOOLBAR, # 3
            gtk.ICON_SIZE_BUTTON, # 4
            gtk.ICON_SIZE_DND, # 5
            gtk.ICON_SIZE_DIALOG # 6
        )
        # Retrieve pixel dimensions of stock icon sizes
        sizes = [(gtk.icon_size_lookup_for_settings(settings, i)[0], i)
                 for i in icon_sizes]
        # Only look at sizes lower than the current dimensions
        sizes = [(s, i) for s, i in sizes if s <= allocation.width]
        # Get the closest fit
        target_size = max(sizes)[1]

        # Avoid setting the same size over and over again
        if self.image.props.icon_size is not target_size.real:
            glib.idle_add(self.image.set_from_icon_name,
                self.image.props.icon_name, target_size)
Пример #9
0
    def __init__(self, textlabel, stockid, size=gtk.ICON_SIZE_MENU):
        gtk.EventBox.__init__(self)
        self.set_property('visible-window', False)
        #gtk.HBox.__init__(self, False, 0)
        self.HBox = gtk.HBox(False, 0)

        self.label = gtk.Label(textlabel)

        iconBox = gtk.HBox(False, 0)
        image = gtk.image_new_from_stock(stockid, size)
        iconBox.pack_start(image, True, False, 0)
        iconBox.show()
        
        self.button = gtk.Button()
        self.button.add(iconBox)
        self.button.set_property('relief', gtk.RELIEF_NONE)
        settings = self.button.get_settings()
        (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
        self.button.set_size_request(w + 4, h + 7)

        self.button.connect('clicked', self.__imgClicked)
       
        self.HBox.pack_start(self.label)
        self.HBox.pack_end(self.button, True, False, 0)        

        self.connect("button-press-event", self.__butoonPressCB)
        self.add(self.HBox)
        self.show_all()
Пример #10
0
    def _item_new(self, action_id, text, icon_name, file_name):
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = gtk.CellRendererPixbuf()

            settings = self.get_settings()
            w, h = gtk.icon_size_lookup_for_settings(
                                            settings, gtk.ICON_SIZE_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.ICON_SIZE_MENU
            else:
                size = gtk.ICON_SIZE_LARGE_TOOLBAR
            width, height = gtk.icon_size_lookup(size)

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

            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                                                file_name, width, height)
        else:
            pixbuf = None

        return (action_id, text, pixbuf, False)
Пример #11
0
def tab_label_style_set_cb (tab_label, style):
    context = tab_label.get_pango_context()
    metrics = context.get_metrics(tab_label.style.font_desc, context.get_language())
    char_width = metrics.get_approximate_digit_width()
    (width, height) = gtk.icon_size_lookup_for_settings(tab_label.get_settings(), gtk.ICON_SIZE_MENU)
    tab_label.set_size_request(20 * pango.PIXELS(char_width) + 2 * width, -1)
    button = tab_label.get_data("close-button")
    button.set_size_request(width + 4, height + 4)
Пример #12
0
    def __init__(self, main_window, flow_graph, file_path=''):
        """
        Page constructor.

        Args:
            main_window: main window
            file_path: path to a flow graph file
        """
        self._flow_graph = flow_graph
        self.process = None
        #import the file
        self.main_window = main_window
        self.file_path = file_path
        initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
        self.state_cache = StateCache(initial_state)
        self.saved = True
        #import the data to the flow graph
        self.get_flow_graph().import_data(initial_state)
        #initialize page gui
        gtk.HBox.__init__(self, False, 0)
        self.show()
        #tab box to hold label and close button
        self.tab = gtk.HBox(False, 0)
        #setup tab label
        self.label = gtk.Label()
        self.tab.pack_start(self.label, False)
        #setup button image
        image = gtk.Image()
        image.set_from_stock('gtk-close', gtk.ICON_SIZE_MENU)
        #setup image box
        image_box = gtk.HBox(False, 0)
        image_box.pack_start(image, True, False, 0)
        #setup the button
        button = gtk.Button()
        button.connect("clicked", self._handle_button)
        button.set_relief(gtk.RELIEF_NONE)
        button.add(image_box)
        #button size
        w, h = gtk.icon_size_lookup_for_settings(button.get_settings(),
                                                 gtk.ICON_SIZE_MENU)
        button.set_size_request(w + 6, h + 6)
        self.tab.pack_start(button, False)
        self.tab.show_all()
        #setup scroll window and drawing area
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH,
                                              MIN_WINDOW_HEIGHT)
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
                                        gtk.POLICY_AUTOMATIC)
        self.scrolled_window.connect('key-press-event',
                                     self._handle_scroll_window_key_press)
        self.drawing_area = DrawingArea(self.get_flow_graph())
        self.scrolled_window.add_with_viewport(self.get_drawing_area())
        self.pack_start(self.scrolled_window)
        #inject drawing area into flow graph
        self.get_flow_graph().drawing_area = self.get_drawing_area()
        self.show_all()
Пример #13
0
    def set_profile(self, profile):
        if profile != self.profile:
            self.profile = profile
            if profile['icon']:
                pixbuf = gtk.gdk.pixbuf_new_from_file(self.profile['icon'])
                settings = gtk.Widget.get_settings (self.tabButton);
                (w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU);

                scaled_buf = pixbuf.scale_simple(w,h,gtk.gdk.INTERP_BILINEAR)
                self.iconImg.set_from_pixbuf(scaled_buf)
Пример #14
0
    def win_add(self, page, hide_current=False, allow_similar=True):
        if not allow_similar:
            for other_page in self.pages:
                if page == other_page:
                    current_page = self.notebook.get_current_page()
                    page_num = self.notebook.page_num(other_page.widget)
                    other_page.widget.props.visible = True
                    self.notebook.set_current_page(page_num)
                    # In order to focus the page
                    if current_page == page_num:
                        self._sig_page_changt(self.notebook, None, page_num)
                    return
        previous_page_id = self.notebook.get_current_page()
        previous_widget = self.notebook.get_nth_page(previous_page_id)
        if previous_widget and hide_current:
            page_id = previous_page_id + 1
        else:
            page_id = -1
        self.previous_pages[page] = previous_widget
        self.pages.append(page)
        hbox = gtk.HBox(spacing=3)
        icon_w, icon_h = gtk.icon_size_lookup(gtk.ICON_SIZE_SMALL_TOOLBAR)[-2:]
        if page.icon is not None:
            common.ICONFACTORY.register_icon(page.icon)
            image = gtk.Image()
            image.set_from_stock(page.icon, gtk.ICON_SIZE_SMALL_TOOLBAR)
            hbox.pack_start(image, expand=False, fill=False)
        name = page.name
        label = gtk.Label(common.ellipsize(name, 20))
        self.tooltips.set_tip(label, page.name)
        self.tooltips.enable()
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=True, fill=True)

        button = gtk.Button()
        img = gtk.Image()
        img.set_from_stock('tryton-close', gtk.ICON_SIZE_MENU)
        width, height = img.size_request()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_can_focus(False)
        button.add(img)
        self.tooltips.set_tip(button, _('Close Tab'))
        button.connect('clicked', self._sig_remove_book, page.widget)
        hbox.pack_start(button, expand=False, fill=False)
        x, y = gtk.icon_size_lookup_for_settings(button.get_settings(),
                                                 gtk.ICON_SIZE_MENU)[-2:]
        button.set_size_request(x, y)

        hbox.show_all()
        label_menu = gtk.Label(page.name)
        label_menu.set_alignment(0.0, 0.5)
        self.notebook.insert_page_menu(page.widget, hbox, label_menu, page_id)
        self.notebook.set_tab_reorderable(page.widget, True)
        self.notebook.set_current_page(page_id)
Пример #15
0
def tab_label_style_set_cb(tab_label, style):
    context = tab_label.get_pango_context()
    metrics = context.get_metrics(tab_label.style.font_desc,
                                  context.get_language())
    char_width = metrics.get_approximate_digit_width()
    (width,
     height) = gtk.icon_size_lookup_for_settings(tab_label.get_settings(),
                                                 gtk.ICON_SIZE_MENU)
    tab_label.set_size_request(20 * pango.PIXELS(char_width) + 2 * width, -1)
    button = tab_label.get_data("close-button")
    button.set_size_request(width + 4, height + 4)
Пример #16
0
 def add_icon_to_button(self, button, icon):
     iconBox = gtk.HBox(False, 0)
     image = gtk.Image()
     image.set_from_stock(icon,gtk.ICON_SIZE_MENU)
     gtk.Button.set_relief(button,gtk.RELIEF_NONE)
     settings = gtk.Widget.get_settings (button);
     (w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU);
     gtk.Widget.set_size_request (button, w + 4, h + 4);
     image.show()
     iconBox.pack_start(image, True, False, 0)
     button.add(iconBox)
Пример #17
0
	def tabs_add_icon_to_button(self, button):
		image = gtk.Image()
		image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
		iconBox = gtk.HBox(False, 0)
		iconBox.pack_start(image, True, False, 0)
		button.set_relief(gtk.RELIEF_NONE)
		settings = button.get_settings()
		(w,h)=gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
		button.set_size_request(w + 4, h + 4)
		button.add(iconBox)
		button.show_all()
Пример #18
0
    def append(self, document):
        """Append the given document as a new tab in the notebook.
        @document: A document instance to append."""

        # Set tab title, short if is too large.
        if document.path:
            title = os.path.basename(document.path)
            title = self.short_title(title)
        else:
            title = '%s %s' % (_('Unsaved'), main.documents.unsaved)

        # Set label widget.
        label = gtk.Label(title)
        label.set_tooltip_text(document.path)
        label.set_padding(4, 0)

        # Set image box, by this way expand parameter is tuned.
        button_box = gtk.HBox(False, 0)
        button_img = gtk.image_new_from_stock('gtk-close', 1)
        button_box.pack_start(button_img, True, False, 0)

        # Set button widget.
        button = gtk.Button()
        button.add(button_box)
        button.set_relief(gtk.RELIEF_NONE)
        button.set_focus_on_click(False)
        button.connect("clicked", lambda w: main.documents.close(document))
        button.set_name('thick')

        # Set button internal padding to zero.
        gtk.rc_parse_string('\
            style "thick"\
            {\
                xthickness = 0\
                ythickness = 0\
            }\
            widget "*.thick" style "thick"')

        # Adjust button size.
        settings = button.get_settings()
        (w,h) = gtk.icon_size_lookup_for_settings(settings, 1)
        button.set_size_request(w+4, h+4)

        # Add all to tab box.
        hbox = gtk.HBox(False, 3)
        hbox.pack_start(label, False, False, 0)
        hbox.pack_start(button, False, False, 0)
        hbox.show_all()

        # Append to notebook and select the new tab.
        self.notebook.append_page(document.canvas.table, hbox)
        self.notebook.set_tab_reorderable(document.canvas.table, True)
        self.notebook.set_current_page(-1)
Пример #19
0
    def __init__(self, main_window, flow_graph, file_path=""):
        """
        Page constructor.

        Args:
            main_window: main window
            file_path: path to a flow graph file
        """
        self._flow_graph = flow_graph
        self.process = None
        # import the file
        self.main_window = main_window
        self.file_path = file_path
        initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
        self.state_cache = StateCache(initial_state)
        self.saved = True
        # import the data to the flow graph
        self.get_flow_graph().import_data(initial_state)
        # initialize page gui
        gtk.HBox.__init__(self, False, 0)
        self.show()
        # tab box to hold label and close button
        self.tab = gtk.HBox(False, 0)
        # setup tab label
        self.label = gtk.Label()
        self.tab.pack_start(self.label, False)
        # setup button image
        image = gtk.Image()
        image.set_from_stock("gtk-close", gtk.ICON_SIZE_MENU)
        # setup image box
        image_box = gtk.HBox(False, 0)
        image_box.pack_start(image, True, False, 0)
        # setup the button
        button = gtk.Button()
        button.connect("clicked", self._handle_button)
        button.set_relief(gtk.RELIEF_NONE)
        button.add(image_box)
        # button size
        w, h = gtk.icon_size_lookup_for_settings(button.get_settings(), gtk.ICON_SIZE_MENU)
        button.set_size_request(w + 6, h + 6)
        self.tab.pack_start(button, False)
        self.tab.show_all()
        # setup scroll window and drawing area
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.scrolled_window.connect("key-press-event", self._handle_scroll_window_key_press)
        self.drawing_area = DrawingArea(self.get_flow_graph())
        self.scrolled_window.add_with_viewport(self.get_drawing_area())
        self.pack_start(self.scrolled_window)
        # inject drawing area into flow graph
        self.get_flow_graph().drawing_area = self.get_drawing_area()
        self.show_all()
Пример #20
0
 def tabs_add_icon_to_button(self, button):
     image = gtk.Image()
     image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
     iconBox = gtk.HBox(False, 0)
     iconBox.pack_start(image, True, False, 0)
     button.set_relief(gtk.RELIEF_NONE)
     settings = button.get_settings()
     (w, h) = gtk.icon_size_lookup_for_settings(settings,
                                                gtk.ICON_SIZE_MENU)
     button.set_size_request(w + 4, h + 4)
     button.add(iconBox)
     button.show_all()
Пример #21
0
 def __add_close_icon(self, button):
     box = gtk.HBox(False, 0)
     self.close_img = gtk.Image()
     self.close_img.show()
     self.close_img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
     self.set_modified(False)
     button.set_relief(gtk.RELIEF_NONE)
     settings = button.get_settings()
     (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
     button.set_size_request(w + 4, h + 4)
     box.pack_start(self.close_img, True, False, 0)
     button.add(box)
     box.show()
     return
Пример #22
0
 def add_icon_to_button(self, button):
   iconBox = gtk.HBox(False, 0)
   image = gtk.Image()
   image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
   gtk.Button.set_relief(button, gtk.RELIEF_NONE)
   #gtk.Button.set_focus_on_click(button,False)
   settings = gtk.Widget.get_settings (button)
   (w,h) = gtk.icon_size_lookup_for_settings (settings, gtk.ICON_SIZE_MENU)
   gtk.Widget.set_size_request (button, w + 4, h + 4)
   image.show()
   iconBox.pack_start(image, True, False, 0)
   button.add(iconBox)
   iconBox.show()
   return
Пример #23
0
def add_icon_to_button(button,buttonType=gtk.STOCK_CLOSE):
	"Fonction pour ajouter un bouton fermer"
	iconBox = gtk.HBox(False, 0)
	image = gtk.Image()
	image.set_from_stock(buttonType,gtk.ICON_SIZE_MENU)
	gtk.Button.set_relief(button,gtk.RELIEF_NONE)
	settings = gtk.Widget.get_settings(button)
	(w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU)
	gtk.Widget.set_size_request(button, w + 12, h + 12)
	image.show()
	iconBox.pack_start(image, True, False, 0)
	button.add(iconBox)
	iconBox.show()
	return
Пример #24
0
 def create_tab_close_button(self):
     button = gtk.Button()
     iconBox = gtk.HBox(False, 0)
     image = gtk.Image()
     image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
     gtk.Button.set_relief(button, gtk.RELIEF_NONE)
     settings = gtk.Widget.get_settings(button)
     (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
     gtk.Widget.set_size_request(button, w + 4, h + 4)
     image.show()
     iconBox.pack_start(image, True, False, 0)
     button.add(iconBox)
     iconBox.show()
     return button
Пример #25
0
    def __init__(self, iconname, text, onclose):
        gtk.HBox.__init__(self, False, 4)

        label = gtk.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.ELLIPSIZE_MIDDLE)
        label.set_single_line_mode(True)
        label.set_alignment(0.0, 0.5)
        label.set_padding(0, 0)

        context = self.get_pango_context()
        metrics = context.get_metrics(self.style.font_desc,
                                      context.get_language())
        char_width = metrics.get_approximate_digit_width()
        (w, h) = gtk.icon_size_lookup_for_settings(self.get_settings(),
                                                   gtk.ICON_SIZE_MENU)
        self.set_size_request(
            self.tab_width_in_chars * pango.PIXELS(char_width) + 2 * w, -1)

        button = gtk.Button()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_focus_on_click(False)
        image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        if gtk.pygtk_version >= (2, 12, 0):
            image.set_tooltip_text(_("Close tab"))
        button.add(image)
        button.set_name("meld-tab-close-button")
        button.set_size_request(w + 2, h + 2)
        button.connect("clicked", onclose)

        icon = gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_MENU)

        label_box = gtk.EventBox()
        label_box.add_events(gtk.gdk.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, expand=False)
        self.pack_start(label_box)
        self.pack_start(button, expand=False)
        if gtk.pygtk_version >= (2, 12, 0):
            self.set_tooltip_text(text)
        self.show_all()

        self.__label = label
        self.__onclose = onclose
Пример #26
0
    def append_item(self, action_id, text, icon_name=None, file_name=None):
        """
        Parameters
        ----------
        action_id :

        text :

        icon_name=None :

        file_name=None :

        Returns
        -------
        None

        """
        if not self._icon_renderer and (icon_name or file_name):
            self._icon_renderer = gtk.CellRendererPixbuf()

            settings = self.get_settings()
            w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_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.ICON_SIZE_MENU
            else:
                size = gtk.ICON_SIZE_LARGE_TOOLBAR
            width, height = gtk.icon_size_lookup(size)

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

            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(file_name, width, height)
        else:
            pixbuf = None

        self._model.append([action_id, text, pixbuf, False])
Пример #27
0
    def __init__(self, iconname, text, onclose):
        gtk.HBox.__init__(self, False, 4)

        label = gtk.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.ELLIPSIZE_MIDDLE)
        label.set_single_line_mode(True)
        label.set_alignment(0.0, 0.5)
        label.set_padding(0, 0)

        context = self.get_pango_context()
        metrics = context.get_metrics(self.style.font_desc, context.get_language())
        char_width = metrics.get_approximate_digit_width()
        (w, h) = gtk.icon_size_lookup_for_settings (self.get_settings(), gtk.ICON_SIZE_MENU)
        self.set_size_request(self.tab_width_in_chars * pango.PIXELS(char_width) + 2 * w, -1)

        button = gtk.Button()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_focus_on_click(False)
        image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        if gtk.pygtk_version >= (2, 12, 0):
            image.set_tooltip_text(_("Close tab"))
        button.add(image)
        button.set_name("meld-tab-close-button")
        button.set_size_request(w + 2, h + 2)
        button.connect("clicked", onclose)

        icon = gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_MENU)

        label_box = gtk.EventBox()
        label_box.add_events(gtk.gdk.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, expand=False)
        self.pack_start(label_box)
        self.pack_start(button, expand=False)
        if gtk.pygtk_version >= (2, 12, 0):
            self.set_tooltip_text(text)
        self.show_all()

        self.__label = label
        self.__onclose = onclose
Пример #28
0
    def __add_icon_to_button(self, button):
        """
        Add the close image to a button.
        
        @param button: Reference to a button.
        @type button: A Button object.
        """
        iconBox = gtk.HBox(False, 0)
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        gtk.Button.set_relief(button, gtk.RELIEF_NONE)
        settings = gtk.Widget.get_settings(button)
        (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
        gtk.Widget.set_size_request(button, w + 0, h + 2)
        image.show()
        iconBox.pack_start(image, True, False, 0)
        button.add(iconBox)

        iconBox.show()
Пример #29
0
 def __add_icon_to_button(self):
     """
     Add the close image to this button.
     """
     
     self.set_relief(gtk.RELIEF_NONE)
     
     icon_box = gtk.HBox(False, 0)
     image = gtk.Image()
     image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
     
     settings = gtk.Widget.get_settings(self)
     width, height = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
     gtk.Widget.set_size_request(self, width + 0, height + 2)
     
     icon_box.pack_start(image, True, False, 0)
     self.add(icon_box)
     
     image.show()
     icon_box.show()
Пример #30
0
    def __add_close_icon_to_button(self, button):
        """
        Adds a close image to the page title close button.
        """
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        image.show()

        gtk.Button.set_relief(button, gtk.RELIEF_NONE)
        settings = gtk.Widget.get_settings(button)

        (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)

        gtk.Widget.set_size_request(button, w + 4, h + 4)

        icon_hbox = gtk.HBox(False, 0)
        icon_hbox.pack_start(image, True, False, 0)
        icon_hbox.show()

        button.add(icon_hbox)
Пример #31
0
    def append_item(self, action_id, text,
        icon_name=None, size=None, pixbuf=None):

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

            settings = self.get_settings()
            
            w, h = gtk.icon_size_lookup_for_settings(
                settings, gtk.ICON_SIZE_MENU)
                
            self._icon_renderer.props.stock_size = w

            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 not pixbuf:
            if icon_name:
                if not size:
                    size = gtk.ICON_SIZE_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 = gtk.gdk.pixbuf_new_from_file_at_size(
                    icon_name, width, height)
                    
            else:
                pixbuf = None

        self._model.append([action_id, text, pixbuf, False])
Пример #32
0
 def init_label(self):
     hbox = gtk.HBox()
     if self.fq_filename:
         self.notebook_label = gtk.Label( pango_escape(os.path.basename(self.fq_filename)) )
     else:
         self.notebook_label = gtk.Label('untitled')
     hbox.add( self.notebook_label )
     close_button = gtk.Button()
     close_button.connect('clicked', self.close)
     close_button.set_focus_on_click(False)
     close_button_image = gtk.Image()
     close_button_image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
     close_button.set_image(close_button_image)
     close_button.set_relief(gtk.RELIEF_NONE)
     style = close_button.get_style().copy()
     settings = gtk.Widget.get_settings (close_button);
     (w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU);
     gtk.Widget.set_size_request (close_button, w + 4, h + 4);
     hbox.add( close_button )
     hbox.show_all()
     self.notebook.set_tab_label( self.scrolled_window, hbox )
    def __add_close_icon_to_button(self, button):
        """
        Adds a close image to the page title close button.
        """
        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        image.show()

        gtk.Button.set_relief(button, gtk.RELIEF_NONE)
        settings = gtk.Widget.get_settings(button)

        (w, h) = gtk.icon_size_lookup_for_settings(settings,
                                                   gtk.ICON_SIZE_MENU)

        gtk.Widget.set_size_request(button, w + 4, h + 4)

        icon_hbox = gtk.HBox(False, 0)
        icon_hbox.pack_start(image, True, False, 0)
        icon_hbox.show()

        button.add(icon_hbox)
Пример #34
0
    def win_add(self, page, hide_current=False):
        previous_page_id = self.notebook.get_current_page()
        previous_widget = self.notebook.get_nth_page(previous_page_id)
        if previous_widget and hide_current:
            page_id = previous_page_id + 1
        else:
            page_id = -1
        self.previous_pages[page] = previous_widget
        self.pages.append(page)
        hbox = gtk.HBox(spacing=3)
        if page.icon:
            hbox.pack_start(common.IconFactory.get_image(
                page.icon, gtk.ICON_SIZE_SMALL_TOOLBAR),
                            expand=False,
                            fill=False)
        name = page.name
        label = gtk.Label(common.ellipsize(name, 20))
        self.tooltips.set_tip(label, page.name)
        self.tooltips.enable()
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=True, fill=True)

        button = gtk.Button()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_can_focus(False)
        button.add(
            common.IconFactory.get_image('tryton-close', gtk.ICON_SIZE_MENU))
        self.tooltips.set_tip(button, _('Close Tab'))
        button.connect('clicked', self._sig_remove_book, page.widget)
        hbox.pack_start(button, expand=False, fill=False)
        x, y = gtk.icon_size_lookup_for_settings(button.get_settings(),
                                                 gtk.ICON_SIZE_MENU)[-2:]
        button.set_size_request(x, y)

        hbox.show_all()
        label_menu = gtk.Label(page.name)
        label_menu.set_alignment(0.0, 0.5)
        self.notebook.insert_page_menu(page.widget, hbox, label_menu, page_id)
        self.notebook.set_tab_reorderable(page.widget, True)
        self.notebook.set_current_page(page_id)
	def tab_get_icon(self, tab):
		theme = gtk.icon_theme_get_for_screen(tab.get_screen())
		icon_size_width, icon_size_height = gtk.icon_size_lookup_for_settings(tab.get_settings(), gtk.ICON_SIZE_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 glib.GError:
				pixbuf = None
		else:
			pixbuf = None

		if not pixbuf:
			uri = tab.get_document().get_uri()
			if uri:
				location = gio.File(uri)
			else:
				location = None
			pixbuf = self.get_icon(theme, location, icon_size_height)

		return pixbuf
Пример #36
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()
            w, h = gtk.icon_size_lookup_for_settings(settings,
                    gtk.ICON_SIZE_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.ELLIPSIZE_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.ICON_SIZE_LARGE_TOOLBAR
                    width, height = gtk.icon_size_lookup(size)
                else:
                    width, height = size
                pixbuf = gtk.gdk.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])
Пример #37
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.ICON_SIZE_MENU)
    #On enlève le relief au bouton (donné en attribut)
    gtk.Button.set_relief(button, gtk.RELIEF_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.ICON_SIZE_MENU)
    #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()
Пример #38
0
    def _get_icon(self):
        screen = self.get_screen()

        theme = gtk.icon_theme_get_for_screen(screen)
        if theme == None:
            return None

        icon_size = gtk.icon_size_lookup_for_settings(self.get_settings(),
                                                      gtk.ICON_SIZE_MENU)[1]

        if self._state == TAB_STATE_LOADING:
            pixbuf = get_stock_icon(theme, gtk.STOCK_OPEN, icon_size)
        elif self._state == TAB_STATE_REVERTING:
            pixbuf = get_stock_icon(theme, gtk.STOCK_REVERT_TO_SAVED,
                                    icon_size)
        elif self._state == TAB_STATE_SAVING:
            pixbuf = get_stock_icon(theme, gtk.STOCK_SAVE, icon_size)
        elif self._state == TAB_STATE_PRINTING:
            pixbuf = get_stock_icon(theme, gtk.STOCK_PRINT, icon_size)
        elif self._state == TAB_STATE_PRINT_PREVIEWING or self._state == TAB_STATE_SHOWING_PRINT_PREVIEW:
            pixbuf = get_stock_icon(theme, gtk.STOCK_PRINT_PREVIEW, icon_size)
        elif self._state == TAB_STATE_LOADING_ERROR or \
             self._state == TAB_STATE_REVERTING_ERROR or \
             self._state == TAB_STATE_SAVING_ERROR or \
             self._state == TAB_STATE_GENERIC_ERROR:
            pixbuf = get_stock_icon(theme, gtk.STOCK_DIALOG_ERROR, icon_size)
        elif self._state == TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION:
            pixbuf = get_stock_icon(theme, GTK_STOCK_DIALOG_WARNING, icon_size)
        else:
            doc = self.get_document()

            raw_uri = doc.get_uri()
            mime_type = doc.get_mime_type()

            pixbuf = get_icon(theme, raw_uri, mime_type, icon_size)

        return pixbuf
Пример #39
0
    def __add_widget_title(self, w):
        hbox = gtk.HBox()
        label = gtk.Label("<notitle>")
        label.set_selectable(False)
        label.set_ellipsize(pango.ELLIPSIZE_END)
        hbox.pack_start(label, expand=True)

        close = gtk.Button()
        close.set_focus_on_click(False)
        close.set_relief(gtk.RELIEF_NONE)
        close.set_name("hotwire-tab-close")
        img = gtk.Image()
        img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        close.add(img)
        close.connect("clicked", lambda b: self.__close_tab(w))
        (width, height) = gtk.icon_size_lookup_for_settings(label.get_settings(), gtk.ICON_SIZE_MENU)
        close.set_size_request(width + 2, height + 2)
        hbox.pack_start(close, expand=False)
        hbox.show_all()
        self.__notebook.set_tab_label(w, hbox)
        w.set_data("hotwire-tab-label", label)
        self.__notebook.set_tab_label_packing(w, True, True, gtk.PACK_START)
        self.__sync_tabs_visible()
        return label
Пример #40
0
 def add_icon_to_button(self,button,iconpath):
 #"Function that add the icon to the button"
 #Hbox creation
     iconBox = gtk.HBox(False, 0)
 #Empty image creation
     image = gtk.Image()
 #Let's get the default gtk close button
     #image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_BUTTON) #gtk.ICON_SIZE_MENU
     image.set_from_file(iconpath)
 #set the relief off
     gtk.Button.set_relief(button,gtk.RELIEF_NONE)
 #Get the settings of the button
     settings = gtk.Widget.get_settings(button)
 #w and h dimensions of the button
     (w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_BUTTON)
 #modification of the dimensions
     gtk.Widget.set_size_request(button, w + 15, h + 15)
     image.show()
 #pack the image in the box
     iconBox.pack_start(image, True, False, 0)
 #add the box in the button
     button.add(iconBox)
     iconBox.show()
     return
Пример #41
0
 def __button_style_set(self, widget, prev_style):
     w, h = gtk.icon_size_lookup_for_settings(widget.get_settings(),
                                              gtk.ICON_SIZE_MENU)
     widget.set_size_request(w + 2, h + 2)
 def __on_button_style_set(self, widget, prev_style):
     w, h = gtk.icon_size_lookup_for_settings(self.image.get_settings(),
                                              gtk.ICON_SIZE_MENU)
     self.image.set_size_request(w, h)
 def __button_style_set(self, widget, prev_style):
     w, h = gtk.icon_size_lookup_for_settings(widget.get_settings(),
                                              gtk.ICON_SIZE_MENU)
     widget.set_size_request(w + 2, h + 2)
Пример #44
0
 def on_style_set(self, widget, prevstyle):
     settings = widget.get_settings()
     x, y = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
     widget.set_size_request(x + 2, y + 2)