本文整理汇总了Python中sugar3.graphics.palette.Palette.set_invoker方法的典型用法代码示例。如果您正苦于以下问题:Python Palette.set_invoker方法的具体用法?Python Palette.set_invoker怎么用?Python Palette.set_invoker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.palette.Palette
的用法示例。
在下文中一共展示了Palette.set_invoker方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FontComboBox
# 需要导入模块: from sugar3.graphics.palette import Palette [as 别名]
# 或者: from sugar3.graphics.palette.Palette import set_invoker [as 别名]
class FontComboBox(Gtk.ToolItem):
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_LAST, None, ([])), }
def __init__(self):
self._palette_invoker = ToolInvoker()
Gtk.ToolItem.__init__(self)
self._font_label = FontLabel()
bt = Gtk.Button('')
bt.set_can_focus(False)
bt.remove(bt.get_children()[0])
box = Gtk.HBox()
bt.add(box)
icon = Icon(icon_name='font-text')
box.pack_start(icon, False, False, 10)
box.pack_start(self._font_label, False, False, 10)
self.add(bt)
self.show_all()
self._font_name = 'Sans'
# theme the button, can be removed if add the style to the sugar css
if style.zoom(100) == 100:
subcell_size = 15
else:
subcell_size = 11
radius = 2 * subcell_size
theme = "GtkButton {border-radius: %dpx;}" % radius
css_provider = Gtk.CssProvider()
css_provider.load_from_data(theme)
style_context = bt.get_style_context()
style_context.add_provider(css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
# init palette
self._hide_tooltip_on_click = True
self._palette_invoker.attach_tool(self)
self._palette_invoker.props.toggle_palette = True
self.palette = Palette(_('Select font'))
self.palette.set_invoker(self._palette_invoker)
# load the fonts in the palette menu
self._menu_box = PaletteMenuBox()
self.props.palette.set_content(self._menu_box)
self._menu_box.show()
context = self.get_pango_context()
self._init_font_list()
tmp_list = []
for family in context.list_families():
name = family.get_name()
if name in self._font_white_list:
tmp_list.append(name)
for name in sorted(tmp_list):
self._add_menu(name, self.__font_selected_cb)
self._font_label.set_font(self._font_name)
def _init_font_list(self):
self._font_white_list = []
self._font_white_list.extend(DEFAULT_FONTS)
# check if there are a user configuration file
if not os.path.exists(USER_FONTS_FILE_PATH):
# verify if exists a file in /etc
if os.path.exists(GLOBAL_FONTS_FILE_PATH):
shutil.copy(GLOBAL_FONTS_FILE_PATH, USER_FONTS_FILE_PATH)
if os.path.exists(USER_FONTS_FILE_PATH):
# get the font names in the file to the white list
fonts_file = open(USER_FONTS_FILE_PATH)
# get the font names in the file to the white list
for line in fonts_file:
self._font_white_list.append(line.strip())
# monitor changes in the file
gio_fonts_file = Gio.File.new_for_path(USER_FONTS_FILE_PATH)
self.monitor = gio_fonts_file.monitor_file(
Gio.FileMonitorFlags.NONE, None)
self.monitor.set_rate_limit(5000)
self.monitor.connect('changed', self._reload_fonts)
def _reload_fonts(self, monitor, gio_file, other_file, event):
if event != Gio.FileMonitorEvent.CHANGES_DONE_HINT:
return
self._font_white_list = []
self._font_white_list.extend(DEFAULT_FONTS)
fonts_file = open(USER_FONTS_FILE_PATH)
for line in fonts_file:
self._font_white_list.append(line.strip())
# update the menu
for child in self._menu_box.get_children():
self._menu_box.remove(child)
child = None
context = self.get_pango_context()
tmp_list = []
for family in context.list_families():
#.........这里部分代码省略.........
示例2: FilterToolItem
# 需要导入模块: from sugar3.graphics.palette import Palette [as 别名]
# 或者: from sugar3.graphics.palette.Palette import set_invoker [as 别名]
class FilterToolItem(Gtk.ToolButton):
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_LAST, None, ([])), }
def __init__(self, tagline, default_icon, default_label, palette_content):
self._palette_invoker = ToolInvoker()
Gtk.ToolButton.__init__(self)
self._label = default_label
self.set_is_important(False)
self.set_size_request(style.GRID_CELL_SIZE, -1)
self._label_widget = Gtk.Label()
self._label_widget.set_alignment(0.0, 0.5)
self._label_widget.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
self._label_widget.set_max_width_chars(10)
self._label_widget.set_use_markup(True)
self._label_widget.set_markup(default_label)
self.set_label_widget(self._label_widget)
self._label_widget.show()
self.set_widget_icon(icon_name=default_icon)
self._hide_tooltip_on_click = True
self._palette_invoker.attach_tool(self)
self._palette_invoker.props.toggle_palette = True
self._palette_invoker.props.lock_palette = True
self.palette = Palette(tagline)
self.palette.set_invoker(self._palette_invoker)
self.props.palette.set_content(palette_content)
def set_widget_icon(self, icon_name=None, file_name=None):
if file_name is not None:
icon = Icon(file=file_name,
pixel_size=style.SMALL_ICON_SIZE,
xo_color=XoColor('white'))
else:
icon = Icon(icon_name=icon_name,
pixel_size=style.SMALL_ICON_SIZE,
xo_color=XoColor('white'))
self.set_icon_widget(icon)
icon.show()
def set_widget_label(self, label=None):
# FIXME: Ellipsis is not working on these labels.
if label is None:
label = self._label
"""
if len(label) > 10:
label = label[0:7] + '...' + label[-7:]
"""
self._label_widget.set_markup(label)
self._label = label
def __destroy_cb(self, icon):
if self._palette_invoker is not None:
self._palette_invoker.detach()
def create_palette(self):
return None
def get_palette(self):
return self._palette_invoker.palette
def set_palette(self, palette):
self._palette_invoker.palette = palette
palette = GObject.Property(
type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self):
return self._palette_invoker
def set_palette_invoker(self, palette_invoker):
self._palette_invoker.detach()
self._palette_invoker = palette_invoker
palette_invoker = GObject.Property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def do_draw(self, cr):
if self.palette and self.palette.is_up():
allocation = self.get_allocation()
# draw a black background, has been done by the engine before
cr.set_source_rgb(0, 0, 0)
cr.rectangle(0, 0, allocation.width, allocation.height)
cr.paint()
Gtk.ToolButton.do_draw(self, cr)
if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker
invoker.draw_rectangle(cr, self.palette)
return False
示例3: FilterToolItem
# 需要导入模块: from sugar3.graphics.palette import Palette [as 别名]
# 或者: from sugar3.graphics.palette.Palette import set_invoker [as 别名]
class FilterToolItem(Gtk.ToolButton):
_LABEL_MAX_WIDTH = 18
_MAXIMUM_PALETTE_COLUMNS = 4
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_LAST, None, ([str])), }
def __init__(self, default_icon, default_value, options):
self._palette_invoker = ToolInvoker()
self._options = options
Gtk.ToolButton.__init__(self)
logging.debug('filter options %s', options)
self._value = default_value
self._label = self._options[default_value]
self.set_is_important(True)
self.set_size_request(style.GRID_CELL_SIZE, -1)
self._label_widget = Gtk.Label()
self._label_widget.set_alignment(0.0, 0.5)
self._label_widget.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
self._label_widget.set_max_width_chars(self._LABEL_MAX_WIDTH)
self._label_widget.set_use_markup(True)
self._label_widget.set_markup(self._label)
self.set_label_widget(self._label_widget)
self._label_widget.show()
self.set_widget_icon(icon_name=default_icon)
self._hide_tooltip_on_click = True
self._palette_invoker.attach_tool(self)
self._palette_invoker.props.toggle_palette = True
self._palette_invoker.props.lock_palette = True
self.palette = Palette(_('Select language'))
self.palette.set_invoker(self._palette_invoker)
self.props.palette.set_content(self.set_palette_list(options))
def set_options(self, options):
self._options = options
self.palette = Palette(_('Select language'))
self.palette.set_invoker(self._palette_invoker)
self.props.palette.set_content(self.set_palette_list(options))
if self._value not in self._options.keys():
new_value = self._options.keys()[0]
self._value = new_value
self._set_widget_label(self._options[new_value])
self.emit('changed', new_value)
def set_widget_icon(self, icon_name=None):
icon = Icon(icon_name=icon_name,
pixel_size=style.SMALL_ICON_SIZE)
self.set_icon_widget(icon)
icon.show()
def _set_widget_label(self, label=None):
# FIXME: Ellipsis is not working on these labels.
if label is None:
label = self._label
if len(label) > self._LABEL_MAX_WIDTH:
label = label[0:7] + '...' + label[-7:]
self._label_widget.set_markup(label)
self._label = label
def __destroy_cb(self, icon):
if self._palette_invoker is not None:
self._palette_invoker.detach()
def create_palette(self):
return None
def get_palette(self):
return self._palette_invoker.palette
def set_palette(self, palette):
self._palette_invoker.palette = palette
palette = GObject.property(
type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self):
return self._palette_invoker
def set_palette_invoker(self, palette_invoker):
self._palette_invoker.detach()
self._palette_invoker = palette_invoker
palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def do_draw(self, cr):
if self.palette and self.palette.is_up():
allocation = self.get_allocation()
# draw a black background, has been done by the engine before
cr.set_source_rgb(0, 0, 0)
cr.rectangle(0, 0, allocation.width, allocation.height)
cr.paint()
Gtk.ToolButton.do_draw(self, cr)
#.........这里部分代码省略.........
示例4: PaletteBox
# 需要导入模块: from sugar3.graphics.palette import Palette [as 别名]
# 或者: from sugar3.graphics.palette.Palette import set_invoker [as 别名]
class PaletteBox(Gtk.ToolItem):
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_LAST, None, ([])), }
def __init__(self, default, options):
self._palette_invoker = ToolInvoker()
Gtk.ToolItem.__init__(self)
self._label = Gtk.Label()
bt = Gtk.Button('')
bt.set_can_focus(False)
bt.remove(bt.get_children()[0])
self._box = Gtk.HBox()
bt.add(self._box)
self._icon = Icon(icon_name='')
self._box.pack_start(self._icon, False, False, 5)
self._box.pack_end(self._label, False, False, 5)
self.add(bt)
self.show_all()
# theme the button, can be removed if add the style to the sugar css
if style.zoom(100) == 100:
subcell_size = 15
else:
subcell_size = 11
radius = 2 * subcell_size
theme = "GtkButton {border-radius: %dpx;}" % radius
css_provider = Gtk.CssProvider()
css_provider.load_from_data(theme)
style_context = bt.get_style_context()
style_context.add_provider(css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
# init palette
self._hide_tooltip_on_click = True
self._palette_invoker.attach_tool(self)
self._palette_invoker.props.toggle_palette = True
self.palette = Palette(_('Select option'))
self.palette.set_invoker(self._palette_invoker)
# load the fonts in the palette menu
self._menu_box = PaletteMenuBox()
self.props.palette.set_content(self._menu_box)
self._menu_box.show()
for option in options:
if option.__class__ is str:
self._add_menu(option, activate_cb=self.__option_selected_cb)
else:
self._add_menu(option[0], icon=option[1],
activate_cb=self.__option_selected_cb)
self.set_value(default)
def _set_icon(self, icon_name):
self._box.remove(self._box.get_children()[0])
self._icon = Icon(icon_name=icon_name,
pixel_size=style.STANDARD_ICON_SIZE)
self._icon.show()
self._box.pack_start(self._icon, False, False, 5)
def __option_selected_cb(self, menu, option):
self.set_value(option)
self.emit('changed')
def _add_menu(self, option, icon=None, activate_cb=None):
if icon is not None:
menu_item = PaletteMenuItem(icon_name=icon)
if activate_cb is not None:
menu_item.connect('activate', activate_cb, [option, icon])
else:
menu_item = PaletteMenuItem()
if activate_cb is not None:
menu_item.connect('activate', activate_cb, option)
menu_item.set_label(option)
self._menu_box.append_item(menu_item)
menu_item.show()
def __destroy_cb(self, icon):
if self._palette_invoker is not None:
self._palette_invoker.detach()
def create_palette(self):
return None
def get_palette(self):
return self._palette_invoker.palette
def set_palette(self, palette):
self._palette_invoker.palette = palette
palette = GObject.property(
type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self):
return self._palette_invoker
def set_palette_invoker(self, palette_invoker):
self._palette_invoker.detach()
#.........这里部分代码省略.........