2012-09-12 21:53:56 +02:00
|
|
|
# Copyright 2012 One Laptop Per Child
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
The palettemenu module is the main port of call for making palettes. It
|
|
|
|
covers creating menu items, seperators and placing them in a box.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
Create a palette menu with 2 items with a seperator in the middle.
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
from sugar3.graphics.palette import Palette
|
|
|
|
from sugar3.graphics.palettemenu import PaletteMenuBox
|
|
|
|
from sugar3.graphics.palettemenu import PaletteMenuItem
|
|
|
|
from sugar3.graphics.palettemenu import PaletteMenuItemSeparator
|
|
|
|
|
|
|
|
|
|
|
|
class ItemPalette(Palette):
|
|
|
|
def __init__(self):
|
|
|
|
Palette.__init__(
|
|
|
|
self, primary_text='List Item')
|
|
|
|
box = PaletteMenuBox()
|
|
|
|
self.set_content(box)
|
|
|
|
box.show()
|
|
|
|
|
|
|
|
menu_item = PaletteMenuItem(
|
|
|
|
_('Edit'), icon_name='toolbar-edit')
|
|
|
|
menu_item.connect('activate', self.__edit_cb)
|
|
|
|
box.append_item(menu_item)
|
|
|
|
menu_item.show()
|
|
|
|
|
|
|
|
sep = PaletteMenuItemSeparator()
|
|
|
|
box.append_item(sep)
|
|
|
|
sep.show()
|
|
|
|
|
|
|
|
menu_item = PaletteMenuItem(
|
|
|
|
_('Delete'), icon_name='edit-delete')
|
|
|
|
box.append_item(menu_item)
|
|
|
|
menu_item.show()
|
|
|
|
|
|
|
|
def __edit_cb(self, menu_item):
|
2018-03-01 12:58:56 +01:00
|
|
|
print('Edit...')
|
2015-09-15 12:48:48 +02:00
|
|
|
|
|
|
|
# Usually the Palette instance is returned in a create_palette function
|
|
|
|
p = ItemPalette()
|
|
|
|
p.popup()
|
|
|
|
Gtk.main()
|
|
|
|
|
|
|
|
Add a palettebox to a toolbutton:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
image = ToolButton('insert-picture')
|
|
|
|
image.set_tooltip(_('Insert Image'))
|
|
|
|
self._image_id = image.connect('clicked', self.__image_cb)
|
|
|
|
toolbar_box.toolbar.insert(image, -1)
|
|
|
|
|
|
|
|
palette = image.get_palette()
|
|
|
|
box = PaletteMenuBox()
|
|
|
|
palette.set_content(box)
|
|
|
|
box.show()
|
|
|
|
|
|
|
|
menu_item = PaletteMenuItem(_('Floating'))
|
|
|
|
menu_item.connect('activate', self.__image_cb, True)
|
|
|
|
box.append_item(menu_item)
|
|
|
|
menu_item.show()
|
|
|
|
'''
|
2012-09-12 21:53:56 +02:00
|
|
|
|
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
from sugar3.graphics.icon import Icon
|
|
|
|
from sugar3.graphics import style
|
|
|
|
|
|
|
|
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
class PaletteMenuBox(Gtk.VBox):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
The PaletteMenuBox is a box that is useful for making palettes. It
|
|
|
|
supports adding :class:`sugar3.graphics.palettemenu.PaletteMenuItem`,
|
|
|
|
:class:`sugar3.graphics.palettemenu.PaletteMenuItemSeparator` and
|
|
|
|
it automatically adds padding to other widgets.
|
|
|
|
'''
|
|
|
|
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
def __init__(self):
|
|
|
|
Gtk.VBox.__init__(self)
|
|
|
|
|
|
|
|
def append_item(self, item_or_widget, horizontal_padding=None,
|
|
|
|
vertical_padding=None):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Add a menu item, seperator or other widget to the end of the palette
|
|
|
|
(simmilar to `Gtk.Box.pack_start`).
|
|
|
|
|
|
|
|
If an item is appended
|
|
|
|
(a :class:`sugar3.graphics.palettemenu.PaletteMenuItem` or a
|
|
|
|
:class:`sugar3.graphics.palettemenu.PaletteMenuItemSeparator`) no
|
|
|
|
padding will be added, as that is handled by the item. If a widget is
|
|
|
|
appended (:class:`Gtk.Widget` subclass) padding will be added.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
item_or_widget (:class:`Gtk.Widget` or menu item or seperator):
|
|
|
|
item or widget to add the the palette
|
|
|
|
horizontal_padding (int): by default,
|
2017-01-02 05:22:51 +01:00
|
|
|
:class:`sugar3.graphics.style.DEFAULT_SPACING` is applied
|
2015-09-15 12:48:48 +02:00
|
|
|
vertical_padding (int): by default,
|
2017-01-02 05:22:51 +01:00
|
|
|
:class:`sugar3.graphics.style.DEFAULT_SPACING` is applied
|
2015-09-15 12:48:48 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
'''
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
item = None
|
|
|
|
if (isinstance(item_or_widget, PaletteMenuItem) or
|
2013-05-18 04:27:04 +02:00
|
|
|
isinstance(item_or_widget, PaletteMenuItemSeparator)):
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
item = item_or_widget
|
|
|
|
else:
|
|
|
|
item = self._wrap_widget(item_or_widget, horizontal_padding,
|
|
|
|
vertical_padding)
|
|
|
|
|
|
|
|
self.pack_start(item, False, False, 0)
|
|
|
|
|
|
|
|
def _wrap_widget(self, widget, horizontal_padding, vertical_padding):
|
|
|
|
vbox = Gtk.VBox()
|
|
|
|
vbox.show()
|
|
|
|
|
|
|
|
if horizontal_padding is None:
|
|
|
|
horizontal_padding = style.DEFAULT_SPACING
|
|
|
|
|
|
|
|
if vertical_padding is None:
|
|
|
|
vertical_padding = style.DEFAULT_SPACING
|
|
|
|
|
|
|
|
hbox = Gtk.HBox()
|
|
|
|
vbox.pack_start(hbox, True, True, vertical_padding)
|
|
|
|
hbox.show()
|
|
|
|
|
|
|
|
hbox.pack_start(widget, True, True, horizontal_padding)
|
|
|
|
return vbox
|
|
|
|
|
|
|
|
|
|
|
|
class PaletteMenuItemSeparator(Gtk.EventBox):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Horizontal seperator to put in a palette
|
|
|
|
'''
|
2012-09-12 21:53:56 +02:00
|
|
|
|
|
|
|
__gtype_name__ = 'SugarPaletteMenuItemSeparator'
|
|
|
|
|
|
|
|
def __init__(self):
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
Gtk.EventBox.__init__(self)
|
|
|
|
separator = Gtk.HSeparator()
|
|
|
|
self.add(separator)
|
|
|
|
separator.show()
|
|
|
|
self.set_size_request(-1, style.DEFAULT_SPACING * 2)
|
2012-09-12 21:53:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PaletteMenuItem(Gtk.EventBox):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
A palette menu item is a line of text, and optionally an icon, that the
|
|
|
|
user can activate.
|
2012-09-12 21:53:56 +02:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
The `activate` signal is usually emitted when the item is clicked. It has
|
|
|
|
no arguments. When a menu item is activated, the palette is also closed.
|
2012-09-12 21:53:56 +02:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
Args:
|
|
|
|
text_label (str): a text to display in the menu
|
2012-09-12 21:53:56 +02:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
icon_name (str): the name of a sugar icon to be displayed. Takse
|
|
|
|
precedence over file_name
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
text_maxlen (int): the desired maximum width of the label, in
|
|
|
|
characters. By default set to 60 chars
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
xo_color (:class:`sugar.graphics.XoColor`): the color to be applied to
|
|
|
|
the icon
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
file_name (str): the path to a svg file used as icon
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
accelerator (str): a text used to display the keyboard shortcut
|
|
|
|
associated to the menu
|
|
|
|
'''
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
__gtype_name__ = 'SugarPaletteMenuItem'
|
2014-01-31 22:51:15 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
__gsignals__ = {
|
|
|
|
'activate': (GObject.SignalFlags.RUN_FIRST, None, [])
|
|
|
|
}
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
|
2015-09-15 12:48:48 +02:00
|
|
|
def __init__(self, text_label=None, icon_name=None, text_maxlen=60,
|
|
|
|
xo_color=None, file_name=None, accelerator=None):
|
2012-09-12 21:53:56 +02:00
|
|
|
Gtk.EventBox.__init__(self)
|
|
|
|
self.set_above_child(True)
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
|
2012-09-12 21:53:56 +02:00
|
|
|
self.icon = None
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
self._hbox = Gtk.HBox()
|
2012-09-12 21:53:56 +02:00
|
|
|
|
|
|
|
vbox = Gtk.VBox()
|
Set correct padding and size for the palette, window implementation - SL #4144
A new API is provided: PaletteMenuBox is a container to be used in
Palette.set_content(). This is to hide the implementation details and
set the corresponding paddings and sizes.
Usage:
box = PaletteMenuBox()
palette.set_content(box)
Then we can append items to it, like:
item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
box.append_child(item)
separator = PaletteMenuItemSeparator()
box.append_child(item)
We can also append any widget, and the box will handle the paddings:
box.append_child(widget)
style.DEFAULT_PADDING for horizontal and vertical padding is the
default. But can be overriden:
box.append_child(widget, horizontal_padding=0, vertical_padding=0)
Details:
- move palettemenuitem.py to palettemenu.py
- Width of palette: make it a minimun size of 3 Sugar grid cells.
- Padding of content, secondary box: we need top and bottom padding,
which can be set when packing the items container inside the
secondary box.
- Padding of menu items: needs to be just for left and right, so move
the padding to a new horizontal box.
- Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
doesn't support padding. But we can wrap it in a GtkEventBox and
force the height of the widget there.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
2012-11-01 21:45:37 +01:00
|
|
|
self.add(vbox)
|
|
|
|
vbox.show()
|
|
|
|
|
|
|
|
hbox = Gtk.HBox()
|
|
|
|
vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING)
|
|
|
|
hbox.show()
|
|
|
|
|
|
|
|
hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING)
|
|
|
|
|
2012-09-12 21:53:56 +02:00
|
|
|
if icon_name is not None:
|
|
|
|
self.icon = Icon(icon_name=icon_name,
|
2015-06-29 17:12:58 +02:00
|
|
|
pixel_size=style.SMALL_ICON_SIZE)
|
2012-09-12 21:53:56 +02:00
|
|
|
if xo_color is not None:
|
|
|
|
self.icon.props.xo_color = xo_color
|
|
|
|
self._hbox.pack_start(self.icon, expand=False, fill=False,
|
|
|
|
padding=style.DEFAULT_PADDING)
|
|
|
|
elif file_name is not None:
|
|
|
|
self.icon = Icon(file=file_name,
|
2015-06-29 17:12:58 +02:00
|
|
|
pixel_size=style.SMALL_ICON_SIZE)
|
2012-09-12 21:53:56 +02:00
|
|
|
if xo_color is not None:
|
|
|
|
self.icon.props.xo_color = xo_color
|
|
|
|
self._hbox.pack_start(self.icon, expand=False, fill=False,
|
|
|
|
padding=style.DEFAULT_PADDING)
|
|
|
|
|
|
|
|
align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
|
|
|
|
self.label = Gtk.Label(text_label)
|
2012-12-18 16:18:16 +01:00
|
|
|
if text_maxlen > 0:
|
|
|
|
self.label.set_max_width_chars(text_maxlen)
|
2014-12-17 00:39:50 +01:00
|
|
|
self.label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT)
|
2012-09-12 21:53:56 +02:00
|
|
|
align.add(self.label)
|
|
|
|
self._hbox.pack_start(align, expand=True, fill=True,
|
2013-05-18 04:27:04 +02:00
|
|
|
padding=style.DEFAULT_PADDING)
|
2012-09-12 21:53:56 +02:00
|
|
|
|
2014-01-31 22:51:15 +01:00
|
|
|
self._accelerator_label = Gtk.AccelLabel('')
|
|
|
|
if accelerator is not None:
|
|
|
|
self._accelerator_label.set_text(accelerator)
|
|
|
|
self._hbox.pack_start(self._accelerator_label, expand=False,
|
|
|
|
fill=False, padding=style.DEFAULT_PADDING)
|
|
|
|
|
2012-09-12 21:53:56 +02:00
|
|
|
self.id_bt_release_cb = self.connect('button-release-event',
|
2013-05-18 04:27:04 +02:00
|
|
|
self.__button_release_cb)
|
2012-09-12 21:53:56 +02:00
|
|
|
self.id_enter_notify_cb = self.connect('enter-notify-event',
|
|
|
|
self.__enter_notify_cb)
|
|
|
|
self.id_leave_notify_cb = self.connect('leave-notify-event',
|
|
|
|
self.__leave_notify_cb)
|
|
|
|
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
def __button_release_cb(self, widget, event):
|
2015-07-24 13:32:05 +02:00
|
|
|
alloc = self.get_allocation()
|
|
|
|
if 0 < event.x < alloc.width and 0 < event.y < alloc.height:
|
|
|
|
self.emit('activate')
|
2012-09-12 21:53:56 +02:00
|
|
|
|
|
|
|
def __enter_notify_cb(self, widget, event):
|
|
|
|
self.modify_bg(Gtk.StateType.NORMAL,
|
|
|
|
style.COLOR_BUTTON_GREY.get_gdk_color())
|
|
|
|
|
|
|
|
def __leave_notify_cb(self, widget, event):
|
|
|
|
self.modify_bg(Gtk.StateType.NORMAL,
|
|
|
|
style.COLOR_BLACK.get_gdk_color())
|
|
|
|
|
|
|
|
def set_label(self, text_label):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Sets the text to display in the menu.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
text_label (str): text label
|
|
|
|
'''
|
2012-09-12 21:53:56 +02:00
|
|
|
text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \
|
2013-05-18 04:27:04 +02:00
|
|
|
text_label + '</span>'
|
2012-09-12 21:53:56 +02:00
|
|
|
self.label.set_markup(text)
|
|
|
|
|
|
|
|
def set_image(self, icon):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Sets the icon widget. Usually this will be a
|
|
|
|
:class:`sugar3.graphics.icon.Icon`.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
icon (:class:`Gtk.Widget`): icon widget
|
|
|
|
'''
|
2012-09-12 21:53:56 +02:00
|
|
|
self._hbox.pack_start(icon, expand=False, fill=False,
|
|
|
|
padding=style.DEFAULT_PADDING)
|
|
|
|
self._hbox.reorder_child(icon, 0)
|
|
|
|
|
2014-01-31 22:51:15 +01:00
|
|
|
def set_accelerator(self, text):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Sets the text used to display the keyboard shortcut associated with
|
|
|
|
the menu.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
text (str): accelerator text
|
|
|
|
'''
|
2014-01-31 22:51:15 +01:00
|
|
|
self._accelerator_label.set_text(text)
|
|
|
|
|
2012-09-12 21:53:56 +02:00
|
|
|
def set_sensitive(self, sensitive):
|
2015-09-15 12:48:48 +02:00
|
|
|
'''
|
|
|
|
Sets whether the widget should be activateable by the user and changes
|
|
|
|
the widget's appearence to the appropriate state.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
sensitive (bool): if `True`, the widget will be activateable by
|
|
|
|
the user. Otherwise, it will not be activateable
|
|
|
|
'''
|
2013-05-18 04:27:04 +02:00
|
|
|
is_sensitive = bool(not self.get_state_flags() &
|
|
|
|
Gtk.StateFlags.INSENSITIVE)
|
2012-11-05 13:33:00 +01:00
|
|
|
if is_sensitive == sensitive:
|
2012-09-12 21:53:56 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if sensitive:
|
|
|
|
self.handler_unblock(self.id_bt_release_cb)
|
|
|
|
self.handler_unblock(self.id_enter_notify_cb)
|
|
|
|
self.handler_unblock(self.id_leave_notify_cb)
|
2012-11-05 13:33:00 +01:00
|
|
|
self.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
|
2012-09-12 21:53:56 +02:00
|
|
|
else:
|
|
|
|
self.handler_block(self.id_bt_release_cb)
|
|
|
|
self.handler_block(self.id_enter_notify_cb)
|
|
|
|
self.handler_block(self.id_leave_notify_cb)
|
2013-05-18 04:27:04 +02:00
|
|
|
self.set_state_flags(self.get_state_flags() |
|
|
|
|
Gtk.StateFlags.INSENSITIVE,
|
2012-11-05 13:33:00 +01:00
|
|
|
clear=True)
|