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, primary_text, output_text, input_text, output_model, input_model): Palette.__init__(self, label=primary_text) self._capture_manager = AudioManagerWidget(input_text, 'media-audio-input', input_model) self._capture_manager.show() separator = PaletteMenuItemSeparator() separator.show() self._speaker_manager = AudioManagerWidget(output_text, 'speaker-100', output_model) self._speaker_manager.show() self._box = PaletteMenuBox() self._box.append_item(self._capture_manager, 0, 0) self._box.append_item(separator, 0, 0) self._box.append_item(self._speaker_manager, 0, 0) self._box.show() self.set_content(self._box) self.connect('popup', self.__popup_cb)
def __init__(self, activity_info, journal_entries): ActivityPalette.__init__(self, activity_info) if not journal_entries: xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(), style.COLOR_WHITE.get_svg())) else: xo_color = misc.get_icon_color(journal_entries[0]) self.props.icon = Icon(file=activity_info.get_icon(), xo_color=xo_color, pixel_size=style.STANDARD_ICON_SIZE) if journal_entries: self.props.secondary_text = journal_entries[0]['title'] menu_items = [] for entry in journal_entries: icon_file_name = misc.get_icon_name(entry) color = misc.get_icon_color(entry) menu_item = PaletteMenuItem(text_label=entry['title'], file_name=icon_file_name, xo_color=color) menu_item.connect('activate', self.__resume_entry_cb, entry) menu_items.append(menu_item) menu_item.show() if journal_entries: separator = PaletteMenuItemSeparator() menu_items.append(separator) separator.show() for i in range(0, len(menu_items)): self.menu_box.pack_start(menu_items[i], True, True, 0)
def setup_palette(self): activity_name = self._home_activity.get_activity_name() if activity_name: self.props.primary_text = glib.markup_escape_text(activity_name) title = self._home_activity.get_title() if title and title != activity_name: self.props.secondary_text = glib.markup_escape_text(title) self.menu_box = PaletteMenuBox() menu_item = PaletteMenuItem(_('Resume'), 'activity-start') menu_item.connect('activate', self.__resume_activate_cb) self.menu_box.append_item(menu_item) # TODO: share-with, keep menu_item = PaletteMenuItem(_('View Source'), 'view-source') menu_item.connect('activate', self.__view_source__cb) self.menu_box.append_item(menu_item) separator = PaletteMenuItemSeparator() self.menu_box.append_item(separator) separator.show() menu_item = PaletteMenuItem(_('Stop'), 'activity-stop') menu_item.connect('activate', self.__stop_activate_cb) self.menu_box.append_item(menu_item) self.set_content(self.menu_box) self.menu_box.show_all()
def __init__(self, name): Gtk.VBox.__init__(self) self._name = name self._notifications_box = Gtk.VBox() self._notifications_box.show() self._scrolled_window = Gtk.ScrolledWindow() self._scrolled_window.add_with_viewport(self._notifications_box) self._scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self._scrolled_window.show() separator = PaletteMenuItemSeparator() separator.show() clear_item = PaletteMenuItem(_('Clear notifications'), 'dialog-cancel') clear_item.connect('activate', self.__clear_cb) clear_item.show() self.add(self._scrolled_window) self.add(separator) self.add(clear_item) self._service = notifications.get_service() entries = self._service.retrieve_by_name(self._name) if entries: for entry in entries: self._add(entry['summary'], entry['body']) self._service.notification_received.connect( self.__notification_received_cb) self.connect('destroy', self.__destroy_cb)
def _add_brightness_manager(self): self._brightness_manager = BrightnessManagerWidget(_('Brightness'), 'brightness-100') self._brightness_manager.show() separator = PaletteMenuItemSeparator() separator.show() self._box.append_item(self._brightness_manager, 0, 0) self._box.append_item(separator, 0, 0)
def _add_brightness_manager(self): self._brightness_manager = BrightnessManagerWidget( _('Brightness'), 'brightness-100') self._brightness_manager.show() separator = PaletteMenuItemSeparator() separator.show() self._box.append_item(self._brightness_manager, 0, 0) self._box.append_item(separator, 0, 0)
def __init__(self, primary_text, model): Palette.__init__(self, label=primary_text) self._model = model box = PaletteMenuBox() self.set_content(box) box.show() self._mute_item = PaletteMenuItem('') self._mute_icon = Icon(pixel_size=style.SMALL_ICON_SIZE) self._mute_item.set_image(self._mute_icon) box.append_item(self._mute_item) self._mute_item.show() self._mute_item.connect('activate', self.__mute_activate_cb) separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() vol_step = sound.VOLUME_STEP self._adjustment = Gtk.Adjustment(value=self._model.props.level, lower=0, upper=100 + vol_step, step_incr=vol_step, page_incr=vol_step, page_size=vol_step) hscale = Gtk.HScale() hscale.props.draw_value = False hscale.set_adjustment(self._adjustment) hscale.set_digits(0) box.append_item(hscale, vertical_padding=0) hscale.show() self._adjustment_handler_id = \ self._adjustment.connect('value_changed', self.__adjustment_changed_cb) self._model_notify_level_handler_id = \ self._model.connect('notify::level', self.__level_changed_cb) self._model.connect('notify::muted', self.__muted_changed_cb) self.connect('popup', self.__popup_cb)
def setup_palette(self): activity_name = self._home_activity.get_activity_name() if activity_name: self.props.primary_text = activity_name title = self._home_activity.get_title() if title and title != activity_name: self.props.secondary_text = title self.menu_box = PaletteMenuBox() menu_item = PaletteMenuItem(_('Resume'), 'activity-start') menu_item.connect('activate', self.__resume_activate_cb) self.menu_box.append_item(menu_item) menu_item.show() # TODO: share-with, keep menu_item = PaletteMenuItem(_('View Source'), 'view-source') menu_item.connect('activate', self.__view_source__cb) menu_item.set_accelerator('Shift+Alt+V') self.menu_box.append_item(menu_item) menu_item.show() help_url_and_title = get_help_url_and_title(self._home_activity) if help_url_and_title: menu_item = PaletteMenuItem(_('View Help'), 'toolbar-help') menu_item.connect('activate', self.__view_help__cb) menu_item.set_accelerator('Shift+Alt+H') self.menu_box.append_item(menu_item) menu_item.show() # avoid circular importing reference from jarabe.frame.notification import NotificationBox menu_item = NotificationBox(self._home_activity.get_activity_id()) self.menu_box.append_item(menu_item, 0, 0) separator = PaletteMenuItemSeparator() menu_item.add(separator) menu_item.reorder_child(separator, 0) separator.show() separator = PaletteMenuItemSeparator() self.menu_box.append_item(separator) separator.show() menu_item = PaletteMenuItem(_('Stop'), 'activity-stop') menu_item.connect('activate', self.__stop_activate_cb) self.menu_box.append_item(menu_item) menu_item.show() self.set_content(self.menu_box) self.menu_box.show()
def __init__(self, primary_text, model): Palette.__init__(self, label=primary_text) self._model = model box = PaletteMenuBox() self.set_content(box) box.show() self._mute_item = PaletteMenuItem('') self._mute_icon = Icon(icon_size=Gtk.IconSize.MENU) self._mute_item.set_image(self._mute_icon) box.append_item(self._mute_item) self._mute_item.show() self._mute_item.connect('activate', self.__mute_activate_cb) separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() vol_step = sound.VOLUME_STEP self._adjustment = Gtk.Adjustment(value=self._model.props.level, lower=0, upper=100 + vol_step, step_incr=vol_step, page_incr=vol_step, page_size=vol_step) hscale = Gtk.HScale() hscale.props.draw_value = False hscale.set_adjustment(self._adjustment) hscale.set_digits(0) box.append_item(hscale, vertical_padding=0) hscale.show() self._adjustment_handler_id = \ self._adjustment.connect('value_changed', self.__adjustment_changed_cb) self._model_notify_level_handler_id = \ self._model.connect('notify::level', self.__level_changed_cb) self._model.connect('notify::muted', self.__muted_changed_cb) self.connect('popup', self.__popup_cb)
def __init__(self, mount): Palette.__init__(self, label=mount.get_name()) self._mount = mount path = mount.get_root().get_path() self.props.secondary_text = GLib.markup_escape_text(path) self.content_box = PaletteMenuBox() self.set_content(self.content_box) self.content_box.show() menu_item = PaletteMenuItem(pgettext('Volume', 'Remove')) icon = Icon(icon_name='media-eject', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__unmount_activate_cb) self.content_box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() self.content_box.append_item(separator) separator.show() free_space_box = Gtk.VBox() free_space_box.set_spacing(style.DEFAULT_PADDING) self.content_box.append_item(free_space_box, vertical_padding=0) free_space_box.show() self._progress_bar = Gtk.ProgressBar() free_space_box.pack_start(self._progress_bar, True, True, 0) self._progress_bar.show() self._free_space_label = Gtk.Label() self._free_space_label.set_alignment(0.5, 0.5) free_space_box.pack_start(self._free_space_label, True, True, 0) self._free_space_label.show() self.connect('popup', self.__popup_cb)
def setup_palette(self): title = self._home_activity.get_title() self.set_primary_text(GLib.markup_escape_text(title)) box = PaletteMenuBox() self.set_content(box) box.show() menu_item = PaletteMenuItem(_("Show contents")) icon = Icon( file=self._home_activity.get_icon_path(), pixel_size=style.SMALL_ICON_SIZE, xo_color=self._home_activity.get_icon_color(), ) menu_item.set_image(icon) icon.show() menu_item.connect("activate", self.__open_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() self._progress_bar = Gtk.ProgressBar() inner_box.add(self._progress_bar) self._progress_bar.show() self._free_space_label = Gtk.Label() self._free_space_label.set_alignment(0.5, 0.5) inner_box.add(self._free_space_label) self._free_space_label.show() self.connect("popup", self.__popup_cb)
def __init__(self, mount): Palette.__init__(self, label=mount.get_name()) self._mount = mount path = mount.get_root().get_path() self.props.secondary_text = glib.markup_escape_text(path) self.content_box = PaletteMenuBox() self.set_content(self.content_box) self.content_box.show() menu_item = PaletteMenuItem(pgettext('Volume', 'Remove')) icon = Icon(icon_name='media-eject', icon_size=Gtk.IconSize.MENU) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__unmount_activate_cb) self.content_box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() self.content_box.append_item(separator) separator.show() free_space_box = Gtk.VBox() free_space_box.set_spacing(style.DEFAULT_PADDING) self.content_box.append_item(free_space_box, vertical_padding=0) free_space_box.show() self._progress_bar = Gtk.ProgressBar() free_space_box.pack_start(self._progress_bar, True, True, 0) self._progress_bar.show() self._free_space_label = Gtk.Label() self._free_space_label.set_alignment(0.5, 0.5) free_space_box.pack_start(self._free_space_label, True, True, 0) self._free_space_label.show() self.connect('popup', self.__popup_cb)
def setup_palette(self): title = self._home_activity.get_title() self.set_primary_text(GLib.markup_escape_text(title)) box = PaletteMenuBox() self.set_content(box) box.show() menu_item = PaletteMenuItem(_('Show contents')) icon = Icon(file=self._home_activity.get_icon_path(), pixel_size=style.SMALL_ICON_SIZE, xo_color=self._home_activity.get_icon_color()) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__open_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() self._progress_bar = Gtk.ProgressBar() inner_box.add(self._progress_bar) self._progress_bar.show() self._free_space_label = Gtk.Label() self._free_space_label.set_alignment(0.5, 0.5) inner_box.add(self._free_space_label) self._free_space_label.show() self.connect('popup', self.__popup_cb)
def __init__(self, activity_info, journal_entries): ActivityPalette.__init__(self, activity_info) if not journal_entries: xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(), style.COLOR_TRANSPARENT.get_svg())) else: xo_color = misc.get_icon_color(journal_entries[0]) self.props.icon = Icon(file=activity_info.get_icon(), xo_color=xo_color, icon_size=Gtk.IconSize.LARGE_TOOLBAR) if journal_entries: title = journal_entries[0]['title'] self.props.secondary_text = glib.markup_escape_text(title) menu_items = [] for entry in journal_entries: icon_file_name = misc.get_icon_name(entry) color = misc.get_icon_color(entry) menu_item = PaletteMenuItem(text_label=entry['title'], file_name=icon_file_name, xo_color=color) menu_item.connect('activate', self.__resume_entry_cb, entry) menu_items.append(menu_item) menu_item.show() if journal_entries: separator = PaletteMenuItemSeparator() menu_items.append(separator) separator.show() for i in range(0, len(menu_items)): self.menu_box.pack_start(menu_items[i], True, True, 0)
def __init__(self, primary_text): Palette.__init__(self, label=primary_text) self._disconnect_item = None self._channel_label = Gtk.Label() self._channel_label.props.xalign = 0.0 self._channel_label.show() self._ip_address_label = Gtk.Label() self._ip_address_label.props.xalign = 0.0 self._ip_address_label.show() self._info = Gtk.VBox() self._disconnect_item = PaletteMenuItem(_('Disconnect')) icon = Icon(pixel_size=style.SMALL_ICON_SIZE, icon_name='media-eject') self._disconnect_item.set_image(icon) self._disconnect_item.connect('activate', self.__disconnect_activate_cb) self._info.add(self._disconnect_item) separator = PaletteMenuItemSeparator() self._info.pack_start(separator, True, True, 0) def _padded(child, xalign=0, yalign=0.5): padder = Gtk.Alignment.new(xalign=xalign, yalign=yalign, xscale=1, yscale=0.33) padder.set_padding(style.DEFAULT_SPACING, style.DEFAULT_SPACING, style.DEFAULT_SPACING, style.DEFAULT_SPACING) padder.add(child) return padder self._info.pack_start(_padded(self._channel_label), True, True, 0) self._info.pack_start(_padded(self._ip_address_label), True, True, 0) self._info.show_all()
def set_palette_list(palette_list): if 'icon' in palette_list[0]: _menu_item = PaletteMenuItem(icon_name=palette_list[0]['icon'], text_label=palette_list[0]['label']) else: _menu_item = PaletteMenuItem(text_label=palette_list[0]['label']) req2 = _menu_item.get_preferred_size()[1] menuitem_width = req2.width menuitem_height = req2.height palette_width = Gdk.Screen.width() - style.GRID_CELL_SIZE palette_height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 3 nx = min(_MAXIMUM_PALETTE_COLUMNS, int(palette_width / menuitem_width)) ny = min(int(palette_height / menuitem_height), len(palette_list) + 1) if ny >= len(palette_list): nx = 1 ny = len(palette_list) grid = Gtk.Grid() grid.set_row_spacing(style.DEFAULT_PADDING) grid.set_column_spacing(0) grid.set_border_width(0) grid.show() x = 0 y = 0 xo_color = XoColor('white') for item in palette_list: if 'separator' in item: menu_item = PaletteMenuItemSeparator() elif 'icon' in item: menu_item = PaletteMenuItem(icon_name=item['icon'], text_label=item['label'], xo_color=xo_color) elif 'file' in item: menu_item = PaletteMenuItem(file_name=item['file'], text_label=item['label'], xo_color=xo_color) else: menu_item = PaletteMenuItem() menu_item.set_label(item['label']) menu_item.set_size_request(style.GRID_CELL_SIZE * 3, -1) if 'separator' in item: y += 1 grid.attach(menu_item, 0, y, nx, 1) x = 0 y += 1 else: menu_item.connect('button-release-event', item['callback'], item) grid.attach(menu_item, x, y, 1, 1) x += 1 if x == nx: x = 0 y += 1 menu_item.show() if palette_height < (y * menuitem_height + style.GRID_CELL_SIZE): # if the grid is bigger than the palette, put in a scrolledwindow scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.set_size_request(nx * menuitem_width, (ny + 1) * menuitem_height) scrolled_window.add_with_viewport(grid) return scrolled_window else: return grid
def _update(self): new_state = self.file_transfer.props.state logging.debug('_update state: %r', new_state) box = PaletteMenuBox() self.set_content(box) box.show() if new_state == filetransfer.FT_STATE_PENDING: menu_item = PaletteMenuItem(_('Cancel')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__cancel_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() if self.file_transfer.description: label = Gtk.Label(label=self.file_transfer.description) inner_box.add(label) label.show() mime_type = self.file_transfer.mime_type type_description = mime.get_mime_description(mime_type) size = self._format_size(self.file_transfer.file_size) label = Gtk.Label(label='%s (%s)' % (size, type_description)) inner_box.add(label) label.show() elif new_state in [filetransfer.FT_STATE_ACCEPTED, filetransfer.FT_STATE_OPEN]: menu_item = PaletteMenuItem(_('Cancel')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__cancel_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() self.progress_bar = Gtk.ProgressBar() inner_box.add(self.progress_bar) self.progress_bar.show() self.progress_label = Gtk.Label(label='') inner_box.add(self.progress_label) self.progress_label.show() self.update_progress() elif new_state in [filetransfer.FT_STATE_COMPLETED, filetransfer.FT_STATE_CANCELLED]: menu_item = PaletteMenuItem(_('Dismiss')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__dismiss_activate_cb) box.append_item(menu_item) menu_item.show() self.update_progress()
def _update(self): box = PaletteMenuBox() self.set_content(box) box.show() logging.debug('_update state: %r', self.file_transfer.props.state) if self.file_transfer.props.state == filetransfer.FT_STATE_PENDING: menu_item = PaletteMenuItem(_('Accept')) icon = Icon(icon_name='dialog-ok', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__accept_activate_cb) box.append_item(menu_item) menu_item.show() menu_item = PaletteMenuItem(_('Decline')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__decline_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() if self.file_transfer.description: text = self.file_transfer.description.replace('\n', ' ') label = Gtk.Label(label=text) label.set_max_width_chars(style.MENU_WIDTH_CHARS) label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT) inner_box.add(label) label.show() mime_type = self.file_transfer.mime_type type_description = mime.get_mime_description(mime_type) size = self._format_size(self.file_transfer.file_size) label = Gtk.Label(label='%s (%s)' % (size, type_description)) inner_box.add(label) label.show() elif self.file_transfer.props.state in \ [filetransfer.FT_STATE_ACCEPTED, filetransfer.FT_STATE_OPEN]: menu_item = PaletteMenuItem(_('Cancel')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__cancel_activate_cb) box.append_item(menu_item) menu_item.show() separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() self.progress_bar = Gtk.ProgressBar() inner_box.add(self.progress_bar) self.progress_bar.show() self.progress_label = Gtk.Label(label='') inner_box.add(self.progress_label) self.progress_label.show() self.update_progress() elif self.file_transfer.props.state == filetransfer.FT_STATE_COMPLETED: menu_item = PaletteMenuItem(_('Dismiss')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__dismiss_activate_cb) box.append_item(menu_item) menu_item.show() self.update_progress() elif self.file_transfer.props.state == filetransfer.FT_STATE_CANCELLED: if self.file_transfer.reason_last_change == \ filetransfer.FT_REASON_REMOTE_STOPPED: menu_item = PaletteMenuItem(_('Dismiss')) icon = Icon(icon_name='dialog-cancel', pixel_size=style.SMALL_ICON_SIZE) menu_item.set_image(icon) icon.show() menu_item.connect('activate', self.__dismiss_activate_cb) box.append_item(menu_item) menu_item.show() inner_box = Gtk.VBox() inner_box.set_spacing(style.DEFAULT_PADDING) box.append_item(inner_box, vertical_padding=0) inner_box.show() text = _('The other participant canceled the file transfer') label = Gtk.Label(label=text) inner_box.add(label) label.show()
def __after_get_text_cb(self, browser, async_result, user_data): self._all_text = self._browser.props.title self._browser.run_javascript( 'document.title = document.SugarBrowseOldTitle') self._link_text = self._hit.props.link_label \ or self._hit.props.link_title self._title = self._link_text or self._all_text self._url = self._hit.props.link_uri or self._hit.props.image_uri \ or self._hit.props.media_uri self._image_url = self._hit.props.image_uri \ or self._hit.props.media_uri if self._title not in (None, ''): self.props.primary_text = GLib.markup_escape_text(self._title) if self._url is not None: self.props.secondary_text = GLib.markup_escape_text(self._url) else: if self._url is not None: self.props.primary_text = GLib.markup_escape_text(self._url) if not self._all_text and not self._url: self.popdown(immediate=True) return # Nothing to see here! menu_box = Gtk.VBox() self.set_content(menu_box) menu_box.show() self._content.set_border_width(1) first_section_added = False if self._hit.context_is_link(): first_section_added = True menu_item = PaletteMenuItem(_('Follow link'), 'browse-follow-link') menu_item.connect('activate', self.__follow_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Follow link in new tab'), 'browse-follow-link-new-tab') menu_item.connect('activate', self.__follow_activate_cb, True) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() # Add "keep link" only if it is not an image. "Keep # image" will be shown in that case. if not self._hit.context_is_image(): menu_item = PaletteMenuItem(_('Keep link'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__download_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Copy link'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_cb, self._url) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() if self._link_text: menu_item = PaletteMenuItem(_('Copy link text'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_cb, self._link_text) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() if self._hit.context_is_image(): if not first_section_added: first_section_added = True else: separator = PaletteMenuItemSeparator() menu_box.pack_start(separator, False, False, 0) separator.show() # FIXME: Copy image is broken menu_item = PaletteMenuItem(_('Copy image'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_image_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Keep image'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__download_activate_cb, self._image_url) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() if self._hit.context_is_selection() and self._all_text: if not first_section_added: first_section_added = True else: separator = PaletteMenuItemSeparator() menu_box.pack_start(separator, False, False, 0) separator.show() menu_item = PaletteMenuItem(_('Copy text'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_cb, self._all_text) menu_box.pack_start(menu_item, False, False, 0) menu_item.show()
def __init__(self, browser, title, url, hit_info): Palette.__init__(self) self._browser = browser self._url = url # FIXME: this sometimes fails for links because Gtk tries # to parse it as markup text and some URLs has # "?template=gallery&page=gallery" for example if title not in (None, ''): self.props.primary_text = title if url is not None: self.props.secondary_text = url else: if url is not None: self.props.primary_text = url menu_box = Gtk.VBox() self.set_content(menu_box) menu_box.show() self._content.set_border_width(1) first_section_added = False if hit_info['is link']: first_section_added = True menu_item = PaletteMenuItem(_('Follow link'), 'browse-follow-link') menu_item.connect('activate', self.__follow_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Follow link in new tab'), 'browse-follow-link-new-tab') menu_item.connect('activate', self.__follow_activate_cb, True) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() # Add "keep link" only if it is not an image. "Keep # image" will be shown in that case. if not hit_info['is image']: menu_item = PaletteMenuItem(_('Keep link'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__download_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Copy link'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_link_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() if hit_info['is image']: if not first_section_added: first_section_added = True else: separator = PaletteMenuItemSeparator() menu_box.pack_start(separator, False, False, 0) separator.show() menu_item = PaletteMenuItem(_('Copy image'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_image_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() menu_item = PaletteMenuItem(_('Keep image'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__download_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() if hit_info['is selection']: if not first_section_added: first_section_added = True else: separator = PaletteMenuItemSeparator() menu_box.pack_start(separator, False, False, 0) separator.show() menu_item = PaletteMenuItem(_('Copy text'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() menu_item.connect('activate', self.__copy_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show()
def set_palette_list(palette_list): if 'icon' in palette_list[0]: _menu_item = PaletteMenuItem(icon_name=palette_list[0]['icon'], text_label=palette_list[0]['label']) else: _menu_item = PaletteMenuItem(text_label=palette_list[0]['label']) req2 = _menu_item.get_preferred_size()[1] menuitem_width = req2.width menuitem_height = req2.height palette_width = Gdk.Screen.width() - style.GRID_CELL_SIZE palette_height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 3 nx = min(_MAXIMUM_PALETTE_COLUMNS, int(palette_width / menuitem_width)) ny = min(int(palette_height / menuitem_height), len(palette_list) + 1) if ny >= len(palette_list): nx = 1 ny = len(palette_list) grid = Gtk.Grid() grid.set_row_spacing(style.DEFAULT_PADDING) grid.set_column_spacing(0) grid.set_border_width(0) grid.show() x = 0 y = 0 xo_color = XoColor('white') for item in palette_list: if 'separator' in item: menu_item = PaletteMenuItemSeparator() elif 'icon' in item: menu_item = PaletteMenuItem(icon_name=item['icon'], text_label=item['label'], xo_color=xo_color) elif 'file' in item: menu_item = PaletteMenuItem(file_name=item['file'], text_label=item['label'], xo_color=xo_color) else: menu_item = PaletteMenuItem() menu_item.set_label(item['label']) menu_item.set_size_request(style.GRID_CELL_SIZE * 3, -1) if 'separator' in item: y += 1 grid.attach(menu_item, 0, y, nx, 1) x = 0 y += 1 else: menu_item.connect('button-release-event', item['callback'], item) grid.attach(menu_item, x, y, 1, 1) x += 1 if x == nx: x = 0 y += 1 menu_item.show() if palette_height < (y * menuitem_height + style.GRID_CELL_SIZE): # if the grid is bigger than the palette, put in a scrolledwindow scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.set_size_request(nx * menuitem_width, (ny + 1) * menuitem_height) scrolled_window.add_with_viewport(grid) return scrolled_window return grid
def __init__(self, primary_text, manager): Palette.__init__(self, label=primary_text) self._manager = manager self._manager.connect('play', self._set_menu_state, 'play') self._manager.connect('stop', self._set_menu_state, 'stop') self._manager.connect('pause', self._set_menu_state, 'pause') box = PaletteMenuBox() self.set_content(box) box.show() self._play_icon = Icon(icon_name='player_play') self._pause_icon = Icon(icon_name='player_pause') self._play_pause_menu = PaletteMenuItem( icon_name='player_play', text_label=_('Say selected text'), accelerator='Shift+Alt+S') self._play_pause_menu.set_image(self._play_icon) self._play_pause_menu.connect('activate', self.__play_activated_cb) box.append_item(self._play_pause_menu) self._play_pause_menu.show() self._stop_menu = PaletteMenuItem(icon_name='player_stop', text_label=_('Stop playback')) self._stop_menu.connect('activate', self.__stop_activated_cb) self._stop_menu.set_sensitive(False) box.append_item(self._stop_menu) separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() pitch_label = Gtk.Label(_('Pitch')) box.append_item(pitch_label, vertical_padding=0) pitch_label.show() self._adj_pitch = Gtk.Adjustment(value=self._manager.get_pitch(), lower=self._manager.MIN_PITCH, upper=self._manager.MAX_PITCH) hscale_pitch = Gtk.HScale() hscale_pitch.set_adjustment(self._adj_pitch) hscale_pitch.set_draw_value(False) box.append_item(hscale_pitch, vertical_padding=0) hscale_pitch.show() rate_label = Gtk.Label(_('Rate')) box.append_item(rate_label, vertical_padding=0) rate_label.show() self._adj_rate = Gtk.Adjustment(value=self._manager.get_rate(), lower=self._manager.MIN_RATE, upper=self._manager.MAX_RATE) hscale_rate = Gtk.HScale() hscale_rate.set_adjustment(self._adj_rate) hscale_rate.set_draw_value(False) box.append_item(hscale_rate, vertical_padding=0) hscale_rate.show() self._adj_pitch.connect('value_changed', self.__adj_pitch_changed_cb) self._adj_rate.connect('value_changed', self.__adj_rate_changed_cb)
def __init__(self, primary_text, manager): Palette.__init__(self, label=primary_text) self._manager = manager self._manager.connect('play', self._set_menu_state, 'play') self._manager.connect('stop', self._set_menu_state, 'stop') self._manager.connect('pause', self._set_menu_state, 'pause') box = PaletteMenuBox() self.set_content(box) box.show() self._play_icon = Icon(icon_name='player_play') self._pause_icon = Icon(icon_name='player_pause') self._play_pause_menu = PaletteMenuItem( icon_name='player_play', text_label=_('Say selected text')) self._play_pause_menu.set_image(self._play_icon) self._play_pause_menu.connect('activate', self.__play_activated_cb) box.append_item(self._play_pause_menu) self._play_pause_menu.show() self._stop_menu = PaletteMenuItem(icon_name='player_stop', text_label=_('Stop playback')) self._stop_menu.connect('activate', self.__stop_activated_cb) self._stop_menu.set_sensitive(False) box.append_item(self._stop_menu) separator = PaletteMenuItemSeparator() box.append_item(separator) separator.show() pitch_label = Gtk.Label(_('Pitch')) box.append_item(pitch_label, vertical_padding=0) pitch_label.show() self._adj_pitch = Gtk.Adjustment(value=self._manager.get_pitch(), lower=self._manager.MIN_PITCH, upper=self._manager.MAX_PITCH) hscale_pitch = Gtk.HScale() hscale_pitch.set_adjustment(self._adj_pitch) hscale_pitch.set_draw_value(False) box.append_item(hscale_pitch, vertical_padding=0) hscale_pitch.show() rate_label = Gtk.Label(_('Rate')) box.append_item(rate_label, vertical_padding=0) rate_label.show() self._adj_rate = Gtk.Adjustment(value=self._manager.get_rate(), lower=self._manager.MIN_RATE, upper=self._manager.MAX_RATE) hscale_rate = Gtk.HScale() hscale_rate.set_adjustment(self._adj_rate) hscale_rate.set_draw_value(False) box.append_item(hscale_rate, vertical_padding=0) hscale_rate.show() self._adj_pitch.connect('value_changed', self.__adj_pitch_changed_cb) self._adj_rate.connect('value_changed', self.__adj_rate_changed_cb)