def create_palette(self): primary_text = glib.markup_escape_text(self._model.bundle.get_name()) secondary_text = glib.markup_escape_text(self._model.get_name()) palette_icon = Icon(file=self._model.bundle.get_icon(), xo_color=self._model.get_color()) palette_icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR palette = Palette(None, primary_text=primary_text, secondary_text=secondary_text, icon=palette_icon) private = self._model.props.private joined = get_owner_instance() in self._model.props.buddies if joined: item = MenuItem(_('Resume'), 'activity-start') item.connect('activate', self.__palette_item_clicked_cb) item.show() palette.menu.append(item) elif not private: item = MenuItem(_('Join'), 'activity-start') item.connect('activate', self.__palette_item_clicked_cb) item.show() palette.menu.append(item) self.connect_to_palette_pop_events(palette) return palette
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 __init__(self, default_icon, default_value, options, palette_title): self._palette_invoker = ToolInvoker() self._options = options self._palette_title = palette_title Gtk.ToolButton.__init__(self) 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(self._palette_title) self.palette.set_invoker(self._palette_invoker) self.props.palette.set_content(self.set_palette_list(options))
def addBlock(self, data, name, block): # tooltip invoker = WidgetInvoker(block) invoker._position_hint = WidgetInvoker.AT_CURSOR invoker.set_palette(Palette(name)) block.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK) block.connect("button-press-event", self.on_button_press) block.connect("button-release-event", self.on_button_release) block.connect("motion-notify-event", self.on_motion_notify) block.data = data self.blocks.append(block) if self._testAgainstFilter(block): self.pickerBox.pack_start(block, False, False, 3) block.show_all() return block
def setup_rollover_options(self, info): palette = Palette(info, text_maxlen=50) self.set_palette(palette) box = PaletteMenuBox() palette.set_content(box) box.show() menu_item = PaletteMenuItem(_('Remove'), 'list-remove') menu_item.connect('activate', self.item_remove_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() textview = Gtk.TextView() textview.props.height_request = style.GRID_CELL_SIZE * 2 textview.props.width_request = style.GRID_CELL_SIZE * 3 textview.props.hexpand = True textview.props.vexpand = True box.append_item(textview) textview.show() buffer = textview.get_buffer() if self.notes is None: buffer.set_text(_('Take notes on this page')) else: buffer.set_text(self.notes) buffer.connect('changed', self.__buffer_changed_cb)
def __init__(self, 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(style.ELLIPSIZE_MODE_DEFAULT) self._label_widget.set_max_width_chars(_LABEL_MAX_WIDTH) 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(_('Select filter')) self.palette.set_invoker(self._palette_invoker) self.props.palette.set_content(palette_content)
def __init__(self, font_name): Gtk.ToolItem.__init__(self) self._palette_invoker = ToolInvoker() self._font_label = FontLabel(font_name) self._font_name = font_name bt = Gtk.Button("") bt.set_can_focus(False) bt.set_valign(Gtk.Align.CENTER) bt.remove(bt.get_children()[0]) box = Gtk.HBox() icon = Icon(icon_name="font-text") box.pack_start(icon, False, False, 10) box.pack_start(self._font_label, False, False, 10) bt.add(box) self.add(bt) self.show_all() 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) 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) 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 setup_rollover_options(self, info): palette = Palette(info, text_maxlen=50) self.set_palette(palette) menu_item = Gtk.MenuItem(_('Remove')) menu_item.connect('activate', self.item_remove_cb) palette.menu.append(menu_item) menu_item.show()
def set_tooltip(self, tooltip): """ Set a simple palette with just a single label. """ if self.palette is None or self._tooltip is None: self.palette = Palette(tooltip) elif self.palette is not None: self.palette.set_primary_text(tooltip) self._tooltip = tooltip
def set_tooltip(self, text): ''' Sets the tooltip of the toogle tool button. Displays when user hovers over the button with cursor. Args: tooltip (string): tooltip to be added to the button ''' self.set_palette(Palette(text))
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 create_palette(self, text, help_cb): p = Palette(text) if help_cb is not None: item = MenuItem(_('Help'), 'action-help') item.connect('activate', help_cb) item.show() p.menu.append(item) self.set_palette(p)
def set_options(self, options): self._options = options self.palette = Palette(self._palette_title) self.palette.set_invoker(self._palette_invoker) self.props.palette.set_content(self.set_palette_list(options)) if self._value not in list(self._options.keys()): new_value = list(self._options.keys())[0] self._value = new_value self._set_widget_label(self._options[new_value]) self.emit('changed', new_value)
def set_tooltip(self, tooltip): if self.palette is None or self._tooltip is None: self.palette = Palette(tooltip) elif self.palette is not None: self.palette.set_primary_text(tooltip) self._tooltip = tooltip # Set label, shows up when toolbar overflows Gtk.RadioToolButton.set_label(self, tooltip)
def set_tooltip(self, text): ''' Creates a palette with the tooltip text. This will override any current palette set through :any:`set_palette` or that will ever be returned by :any:`create_palette`. Args: text (str): tooltip text ''' from sugar3.graphics.palette import Palette self.set_palette(Palette(text))
def set_tooltip(self, tooltip): """ Set a simple palette with just a single label. """ if self.palette is None or self._tooltip is None: self.palette = Palette(tooltip) elif self.palette is not None: self.palette.set_primary_text(tooltip) self._tooltip = tooltip # Set label, shows up when toolbar overflows Gtk.ToolButton.set_label(self, tooltip)
def _set_up_documents_button(self): documents_path = model.get_documents_path() if documents_path is not None: button = DocumentsButton(documents_path) button.props.group = self._volume_buttons[0] button.set_palette(Palette(_('Documents'))) button.connect('toggled', self._button_toggled_cb) button.show() position = self.get_item_index(self._volume_buttons[-1]) + 1 self.insert(button, position) self._volume_buttons.append(button) self.show()
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 setup_rollover_options(self, title, info): palette = Palette(title, text_maxlen=50) palette.set_secondary_text(info) self.set_palette(palette) menu_item = Gtk.MenuItem(_('Go to Bookmark')) menu_item.connect('activate', self.go_to_bookmark_cb) palette.menu.append(menu_item) menu_item.show() menu_item = Gtk.MenuItem(_('Remove')) menu_item.connect('activate', self.item_remove_cb) palette.menu.append(menu_item) menu_item.show()
def add_button(self, icon_name, description, clicked_cb=None): icon = EventIcon(icon_name=icon_name, pixel_size=(style.GRID_CELL_SIZE*2)/5, xo_color=XoColor('#ffffff,#ffffff')) icon.props.palette = Palette(description) self._top_bar.add(icon) if clicked_cb: def closure(widget, event): alloc = widget.get_allocation() if 0 < event.x < alloc.width and 0 < event.y < alloc.height: clicked_cb(widget) icon.connect('button-release-event', closure) icon.show() return icon
def set_tooltip(self, tooltip): ''' Set the tooltip. Args: tooltip (string): tooltip to be set. ''' if self.palette is None or self._tooltip is None: self.palette = Palette(tooltip) elif self.palette is not None: self.palette.set_primary_text(tooltip) self._tooltip = tooltip # Set label, shows up when toolbar overflows Gtk.ToolButton.set_label(self, tooltip)
def set_tooltip(self, tooltip): ''' Sets the tooltip of the radiotoolbutton. Displays when user hovers over the button with cursor. Args: tooltip (string): tooltip to be added to the button ''' if self.palette is None or self._tooltip is None: self.palette = Palette(tooltip) elif self.palette is not None: self.palette.set_primary_text(tooltip) self._tooltip = tooltip # Set label, shows up when toolbar overflows Gtk.RadioToolButton.set_label(self, tooltip)
def _add_button(self, icon_name, label, accelerator, zoom_level): if self.get_children(): group = self.get_children()[0] else: group = None button = RadioToolButton(icon_name=icon_name, group=group, accelerator=accelerator) button.connect('clicked', self.__level_clicked_cb, zoom_level) self.add(button) button.show() palette = Palette(GLib.markup_escape_text(label)) palette.props.invoker = FrameWidgetInvoker(button) palette.set_group_id('frame') button.set_palette(palette) return button
def setup_rollover_options(self): palette = Palette(Constants.istr_saved_map) self.set_palette(palette) self.tag_menu_item = Gtk.MenuItem(Constants.istr_tag_map) self.ACTIVATE_TAG_ID = self.tag_menu_item.connect( 'activate', self._tag_cb) palette.menu.append(self.tag_menu_item) self.tag_menu_item.show() self.rem_menu_item = Gtk.MenuItem(Constants.istr_remove) self.ACTIVATE_REMOVE_ID = self.rem_menu_item.connect( 'activate', self._item_remove_cb) palette.menu.append(self.rem_menu_item) self.rem_menu_item.show() self.copy_menu_item = Gtk.MenuItem(Constants.istr_copy_to_clipboard) self.ACTIVATE_COPY_ID = self.copy_menu_item.connect( 'activate', self._item_copy_to_clipboard_cb) self.get_palette().menu.append(self.copy_menu_item) self.copy_menu_item.show()
def __init__(self, recd): TrayButton.__init__(self) self._recd = recd self.set_icon_widget(self.get_image()) self._copy_menu_item_handler = None palette = Palette(recd.title) self.set_palette(palette) self._box = PaletteMenuBox() palette.set_content(self._box) self._box.show() self._rem_menu_item = PaletteMenuItem(_('Erase'), icon_name='edit-delete') self._rem_menu_item_handler = self._rem_menu_item.connect( 'activate', self._remove_clicked) self._box.append_item(self._rem_menu_item) self._rem_menu_item.show() self._add_copy_menu_item()
def create_palette(self): primary_text = self._model.bundle.get_name() secondary_text = self._model.get_name() palette_icon = Icon(file=self._model.bundle.get_icon(), pixel_size=style.STANDARD_ICON_SIZE, xo_color=self._model.get_color()) palette = Palette(None, primary_text=primary_text, secondary_text=secondary_text, icon=palette_icon) private = self._model.props.private joined = get_owner_instance() in self._model.props.buddies is_joinable = self._is_joinable is None or self._is_joinable() menu_box = PaletteMenuBox() if joined: item = PaletteMenuItem(_('Resume')) icon = Icon( pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start') item.set_image(icon) item.connect('activate', self.__palette_item_clicked_cb) menu_box.append_item(item) elif not private and is_joinable: item = PaletteMenuItem(_('Join')) icon = Icon( pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start') item.set_image(icon) item.connect('activate', self.__palette_item_clicked_cb) menu_box.append_item(item) palette.set_content(menu_box) menu_box.show_all() self.connect_to_palette_pop_events(palette) return palette
def create_palette(self): primary_text = GLib.markup_escape_text(self._model.bundle.get_name()) secondary_text = GLib.markup_escape_text(self._model.get_name()) palette_icon = Icon(file=self._model.bundle.get_icon(), xo_color=self._model.get_color()) palette_icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR palette = Palette(None, primary_text=primary_text, secondary_text=secondary_text, icon=palette_icon) private = self._model.props.private joined = get_owner_instance() in self._model.props.buddies menu_box = PaletteMenuBox() if joined: item = PaletteMenuItem(_('Resume')) icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start') item.set_image(icon) item.connect('activate', self.__palette_item_clicked_cb) menu_box.append_item(item) elif not private: item = PaletteMenuItem(_('Join')) icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start') item.set_image(icon) item.connect('activate', self.__palette_item_clicked_cb) menu_box.append_item(item) palette.set_content(menu_box) menu_box.show_all() self.connect_to_palette_pop_events(palette) return palette
def _add_tooltip(self, widget, tooltip): #self._add_palette(widget, Palette(tooltip), Palette.DEFAULT) self._add_palette(widget, Palette(tooltip))
def set_tooltip(self, text): from sugar3.graphics.palette import Palette self.set_palette(Palette(text))
def create_palette(self): palette = Palette(_('Show my keyboard')) palette.set_group_id('frame') return palette