示例#1
0
def _gtklabel(self, gtkitem):
    debug.mainthreadTest()
    name = utils.underscore2space(self.name)
    # Add ellipsis automatically if there's an automatically generated
    # gui_callback.
    if self.ellipsis or (self.params and not self.gui_callback):
        name = name + '...'
    # Add tooltip.
    if self.helpstr:
        label = gtk.EventBox()
        if self.accel:  # add accelerator too
            l2 = gtk.AccelLabel(name)
            l2.set_accel_widget(gtkitem)
        else:
            l2 = gtk.Label(name)  # don't add accelerator
        l2.set_alignment(0.0, 0.5)
        label.add(l2)
        tooltips.set_tooltip_text(label, self.helpstr)
    else:  # don't add tooltip
        if self.accel:
            label = gtk.AccelLabel(name)
            label.set_accel_widget(gtkitem)
        else:
            label = gtk.Label(name)
        label.set_alignment(0.0, 0.5)
    label.show_all()
    return label
示例#2
0
    def __init__(self, label, stock=None):
        """An menu item with an (option) icon.

        you can use this in three different ways:

        ContextMenuItem('foo')
        ContextMenuItem('foo', gtk.STOCK_PASTE)
        ContextMenuItem(gtk.STOCK_PASTE)

        The first will display an label 'foo'. The second will display the same label with the
        paste icon, and the last will display the paste icon with the default paste label
        """
        gtk.ImageMenuItem.__init__(self)

        if not stock:
            stock = label
            info = gtk.stock_lookup(label)
            if info:
                try:
                    label = info.label
                # For PyGTk
                except AttributeError:
                    label = info[1]

        lbl = gtk.AccelLabel(label)
        lbl.set_alignment(0, 0.5)
        lbl.set_use_underline(True)
        lbl.set_use_markup(True)
        self.add(lbl)

        image = gtk.Image()
        image.set_from_stock(stock, gtk.ICON_SIZE_MENU)
        self.set_image(image)
示例#3
0
    def __init__(self, label, stock=None):
        """An menu item with an (option) icon.

        you can use this in three different ways:

        ContextMenuItem('foo')
        ContextMenuItem('foo', gtk.STOCK_PASTE)
        ContextMenuItem(gtk.STOCK_PASTE)

        The first will display an label 'foo'. The second will display the same label with the
        paste icon, and the last will display the paste icon with the default paste label
        """
        # For some reason I don't know, gtk.ImageMenuItem.__init__(...) does not work. It
        # complains I should use __gobject_init__ instead.
        self.__gobject_init__()

        if not stock:
            stock = label
            info = gtk.stock_lookup(label)
            if info:
                label = info[1]

        lbl = gtk.AccelLabel(label)
        lbl.set_alignment(0, 0.5)
        lbl.set_use_underline(True)
        lbl.set_use_markup(True)
        self.add(lbl)

        image = gtk.Image()
        image.set_from_stock(stock, gtk.ICON_SIZE_MENU)
        self.set_image(image)
示例#4
0
    def __init__(self,
                 text_label=None,
                 icon_name=None,
                 text_maxlen=60,
                 xo_color=None,
                 file_name=None):
        gobject.GObject.__init__(self)
        self._accelerator = None

        label = gtk.AccelLabel(text_label)
        label.set_alignment(0.0, 0.5)
        label.set_accel_widget(self)
        if text_maxlen > 0:
            label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
            label.set_max_width_chars(text_maxlen)
        self.add(label)
        label.show()

        if icon_name is not None:
            icon = Icon(icon_name=icon_name,
                        icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
            if xo_color is not None:
                icon.props.xo_color = xo_color
            self.set_image(icon)
            icon.show()

        elif file_name is not None:
            icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
            if xo_color is not None:
                icon.props.xo_color = xo_color
            self.set_image(icon)
            icon.show()

        self.connect('can-activate-accel', self.__can_activate_accel_cb)
        self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
示例#5
0
    def __init__(self,
                 text_label=None,
                 icon_name=None,
                 text_maxlen=60,
                 xo_color=None,
                 file_name=None,
                 image=None):
        super(MenuItem, self).__init__()
        self._accelerator = None
        self.props.submenu = None

        label = gtk.AccelLabel(text_label)
        label.set_alignment(0.0, 0.5)
        label.set_accel_widget(self)
        if text_maxlen > 0:
            label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
            label.set_max_width_chars(text_maxlen)
        self.add(label)
        label.show()

        if image is not None:
            self.set_image(image)
            image.show()

        elif icon_name is not None:
            icon = Icon(icon_name=icon_name,
                        icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
            if xo_color is not None:
                icon.props.xo_color = xo_color
            self.set_image(icon)
            icon.show()

        elif file_name is not None:
            icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
            if xo_color is not None:
                icon.props.xo_color = xo_color
            self.set_image(icon)
            icon.show()
示例#6
0
    def __init__(self,
                 label=None,
                 accel_path=None,
                 menu_after_content=False,
                 text_maxlen=60,
                 **kwargs):
        # DEPRECATED: label is passed with the primary-text property,
        # accel_path is set via the invoker property, and menu_after_content
        # is not used

        self._primary_text = None
        self._secondary_text = None
        self._icon = None
        self._icon_visible = True
        self._palette_state = self.PRIMARY

        palette_box = gtk.VBox()

        primary_box = gtk.HBox()
        palette_box.pack_start(primary_box, expand=False)
        primary_box.show()

        self._icon_box = gtk.HBox()
        self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1)
        primary_box.pack_start(self._icon_box, expand=False)

        labels_box = gtk.VBox()
        self._label_alignment = gtk.Alignment(xalign=0,
                                              yalign=0.5,
                                              xscale=1,
                                              yscale=0.33)
        self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
                                          style.DEFAULT_SPACING)
        self._label_alignment.add(labels_box)
        self._label_alignment.show()
        primary_box.pack_start(self._label_alignment, expand=True)
        labels_box.show()

        self._label = gtk.AccelLabel('')
        self._label.set_alignment(0, 0.5)

        if text_maxlen > 0:
            self._label.set_max_width_chars(text_maxlen)
            self._label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        labels_box.pack_start(self._label, expand=True)

        self._secondary_label = gtk.Label()
        self._secondary_label.set_alignment(0, 0.5)

        if text_maxlen > 0:
            self._secondary_label.set_max_width_chars(text_maxlen)
            self._secondary_label.set_ellipsize(pango.ELLIPSIZE_END)

        labels_box.pack_start(self._secondary_label, expand=True)

        self._secondary_box = gtk.VBox()
        palette_box.pack_start(self._secondary_box)

        self._separator = gtk.HSeparator()
        self._secondary_box.pack_start(self._separator)

        self._menu_content_separator = gtk.HSeparator()

        self._secondary_anim = animator.Animator(2.0, 10)
        self._secondary_anim.add(_SecondaryAnimation(self))

        # we init after initializing all of our containers
        PaletteWindow.__init__(self, **kwargs)

        primary_box.set_size_request(
            -1, style.GRID_CELL_SIZE - 2 * self.get_border_width())

        self._full_request = [0, 0]
        self._menu_box = None
        self._content = None

        # we set these for backward compatibility
        if label is not None:
            self.props.primary_text = label

        self._add_menu()
        self._secondary_box.pack_start(self._menu_content_separator)
        self._add_content()

        self.action_bar = PaletteActionBar()
        self._secondary_box.pack_start(self.action_bar)
        self.action_bar.show()

        self.add(palette_box)
        palette_box.show()

        # The menu is not shown here until an item is added
        self.menu = _Menu(self)
        self.menu.connect('item-inserted', self.__menu_item_inserted_cb)

        self.connect('realize', self.__realize_cb)
        self.connect('show', self.__show_cb)
        self.connect('hide', self.__hide_cb)
        self.connect('notify::invoker', self.__notify_invoker_cb)
        self.connect('destroy', self.__destroy_cb)
 def connect_proxy(self, widget):
     _pact = widget.get_data('gtk-action')
     if _pact is not None:
         _pact.disconnect_proxy(widget)
     _hids = self.__hids.setdefault(id(widget),[])
     widget.set_data('gtk-action', self)
     self.__proxies.insert(0, widget)
     _hid = widget.connect('destroy', self._remove_proxy)
     _hids.append(_hid)
     _hid = self.connect_object('notify::sensitive',
                                self._sync_sensitivity,
                                widget)
     _hids.append(_hid)
     widget.set_sensitive(self.is_sensitive())
     _hid = self.connect_object('notify::visible',
                                self._sync_visibility,
                                widget)
     _hids.append(_hid)
     if self.is_visible():
         widget.show()
     else:
         widget.hide()
     if hasattr(widget, 'set_no_show_all'):
         widget.set_no_show_all(True)
     if isinstance(widget, gtk.MenuItem):
         if self.__accelpath is not None:
             self.connect_accelerator()
             widget.set_accel_path(self.__accelpath)
         _label = widget.child
         if _label is None:
             _label = gtk.AccelLabel('')
             _label.set_property('use_underline', True)
             _label.set_property('xalign', 0.0)
             _label.set_property('visible', True)
             _label.set_property('parent', widget)
             _label.set_accel_widget(widget)
         _label.set_label(self.label)
         _hid = self.connect_object('notify::label',
                                    self._sync_label,
                                    widget)
         _hids.append(_hid)
         if isinstance(widget, gtk.ImageMenuItem):
             _image = widget.get_image()
             if _image is not None and not isinstance(_image, gtk.Image):
                 widget.set_image(None)
                 _image = None
             if _image is None:
                 _image = gtk.image_new_from_stock(self.stock_id,
                                                   gtk.ICON_SIZE_MENU)
                 widget.set_image(_image)
                 _image.show()
             _image.set_from_stock(self.stock_id, gtk.ICON_SIZE_MENU)
             _hid = self.connect_object('notify::stock-id',
                                        self._sync_stock_id,
                                        widget)
             _hids.append(_hid)
         if widget.get_submenu() is None:
             _hid = widget.connect_object('activate',
                                          stdAction.activate,
                                          self)
             _hids.append(_hid)
     else:
         raise TypeError, "Unexpected proxy widget type: " + `type(widget)`
     if self.action_group is not None:
         self.action_group.emit('connect-proxy', self, widget)