Esempio n. 1
0
    def __init__(self):
        ToolButton.__init__(self)

        self._property = 'timestamp'
        self._order = Gtk.SortType.ASCENDING

        self.props.tooltip = _('Sort view')
        self.props.icon_name = 'view-lastedit'

        self.props.hide_tooltip_on_click = False
        self.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self.props.palette.set_content(menu_box)
        menu_box.show()

        for property_, icon, label in self._SORT_OPTIONS:
            button = PaletteMenuItem(label)
            button_icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name=icon)
            button.set_image(button_icon)
            button_icon.show()
            button.connect('activate',
                           self.__sort_type_changed_cb,
                           property_,
                           icon)
            button.show()
            menu_box.append_item(button)
Esempio n. 2
0
    def __init__(self, file_name, document_path, activity_name, title,
                 bundle=False):
        RadioToolButton.__init__(self)

        self._document_path = document_path
        self._title = title
        self._jobject = None
        self._activity_name = activity_name

        self.props.tooltip = _('Instance Source')

        settings = Gio.Settings('org.sugarlabs.user')
        self._color = settings.get_string('color')
        icon = Icon(file=file_name,
                    pixel_size=style.STANDARD_ICON_SIZE,
                    xo_color=XoColor(self._color))
        self.set_icon_widget(icon)
        icon.show()

        box = PaletteMenuBox()
        self.props.palette.set_content(box)
        box.show()

        if bundle:
            menu_item = PaletteMenuItem(_('Duplicate'), 'edit-duplicate',
                                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__show_duplicate_alert)
        else:
            menu_item = PaletteMenuItem(_('Keep'), 'document-save',
                                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        box.append_item(menu_item)
        menu_item.show()
Esempio n. 3
0
    def __init__(self):
        ToolButton.__init__(self)

        self._property = 'timestamp'
        self._order = Gtk.SortType.ASCENDING

        self.props.tooltip = _('Sort view')
        self.props.icon_name = 'view-lastedit'

        self.props.hide_tooltip_on_click = False
        self.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self.props.palette.set_content(menu_box)
        menu_box.show()

        sort_options = [
            ('timestamp', 'view-lastedit', _('Sort by date modified')),
            ('creation_time', 'view-created', _('Sort by date created')),
            ('filesize', 'view-size', _('Sort by size')),
        ]

        for property_, icon, label in sort_options:
            button = PaletteMenuItem(label)
            button_icon = Icon(pixel_size=style.SMALL_ICON_SIZE,
                               icon_name=icon)
            button.set_image(button_icon)
            button_icon.show()
            button.connect('activate',
                           self.__sort_type_changed_cb,
                           property_,
                           icon)
            button.show()
            menu_box.append_item(button)
Esempio n. 4
0
    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)
Esempio n. 5
0
class DrawToolButton(RadioToolButton):
    def __init__(self, icon_name, tool_group, tooltip):
        RadioToolButton.__init__(self, icon_name=icon_name)
        self.props.group = tool_group
        self.set_active(False)
        self.set_tooltip(tooltip)

        self.selected_button = None

        self.palette_invoker.props.toggle_palette = True
        self.props.hide_tooltip_on_click = False

        if self.props.palette:
            self.__palette_cb(None, None)

        self.menu_box = PaletteMenuBox()
        self.props.palette.set_content(self.menu_box)
        self.menu_box.show()

        self.connect('notify::palette', self.__palette_cb)

    def __palette_cb(self, widget, pspec):
        if not isinstance(self.props.palette, RadioPalette):
            return
        self.props.palette.update_button()
Esempio n. 6
0
class DrawToolButton(RadioToolButton):

    def __init__(self, icon_name, tool_group, tooltip):
        RadioToolButton.__init__(self, icon_name=icon_name)
        self.props.group = tool_group
        self.set_active(False)
        self.set_tooltip(tooltip)

        self.selected_button = None

        self.palette_invoker.props.toggle_palette = True
        self.props.hide_tooltip_on_click = False

        if self.props.palette:
            self.__palette_cb(None, None)

        self.menu_box = PaletteMenuBox()
        self.props.palette.set_content(self.menu_box)
        self.menu_box.show()

        self.connect('notify::palette', self.__palette_cb)

    def __palette_cb(self, widget, pspec):
        if not isinstance(self.props.palette, RadioPalette):
            return
        self.props.palette.update_button()
Esempio n. 7
0
    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)
Esempio n. 8
0
    def __init__(self, file_name, document_path, activity_name, title,
                 bundle=False):
        RadioToolButton.__init__(self)

        self._document_path = document_path
        self._title = title
        self._jobject = None
        self._activity_name = activity_name

        self.props.tooltip = _('Instance Source')

        settings = Gio.Settings('org.sugarlabs.user')
        self._color = settings.get_string('color')
        icon = Icon(file=file_name,
                    pixel_size=style.STANDARD_ICON_SIZE,
                    xo_color=XoColor(self._color))
        self.set_icon_widget(icon)
        icon.show()

        box = PaletteMenuBox()
        self.props.palette.set_content(box)
        box.show()

        if bundle:
            menu_item = PaletteMenuItem(_('Duplicate'), 'edit-duplicate',
                                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__show_duplicate_alert)
        else:
            menu_item = PaletteMenuItem(_('Keep'), 'document-save',
                                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        box.append_item(menu_item)
        menu_item.show()
Esempio n. 9
0
    def __init__(self):
        ToolButton.__init__(self)

        self._property = 'timestamp'
        self._order = Gtk.SortType.ASCENDING

        self.props.tooltip = _('Sort view')
        self.props.icon_name = 'view-lastedit'

        self.props.hide_tooltip_on_click = False
        self.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self.props.palette.set_content(menu_box)
        menu_box.show()

        for property_, icon, label in self._SORT_OPTIONS:
            button = PaletteMenuItem(label)
            button_icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name=icon)
            button.set_image(button_icon)
            button_icon.show()
            button.connect('activate', self.__sort_type_changed_cb, property_,
                           icon)
            button.show()
            menu_box.append_item(button)
Esempio n. 10
0
class AudioPalette(Palette):
    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 __popup_cb(self, palette):
        self._speaker_manager.update_level()
        self._speaker_manager.update_muted()
        self._capture_manager.update_level()
        self._capture_manager.update_muted()
Esempio n. 11
0
    def __init__(self):
        ToolButton.__init__(self)

        self._property = 'timestamp'
        self._order = Gtk.SortType.ASCENDING

        self.props.tooltip = _('Sort view')
        self.props.icon_name = 'view-lastedit'

        self.props.hide_tooltip_on_click = False
        self.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self.props.palette.set_content(menu_box)
        menu_box.show()

        sort_options = [
            ('timestamp', 'view-lastedit', _('Sort by date modified')),
            ('creation_time', 'view-created', _('Sort by date created')),
            ('filesize', 'view-size', _('Sort by size')),
        ]

        for property_, icon, label in sort_options:
            button = PaletteMenuItem(label)
            button_icon = Icon(pixel_size=style.SMALL_ICON_SIZE,
                               icon_name=icon)
            button.set_image(button_icon)
            button_icon.show()
            button.connect('activate', self.__sort_type_changed_cb, property_,
                           icon)
            button.show()
            menu_box.append_item(button)
Esempio n. 12
0
class AudioPalette(Palette):

    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 __popup_cb(self, palette):
        self._speaker_manager.update_level()
        self._speaker_manager.update_muted()
        self._capture_manager.update_level()
        self._capture_manager.update_muted()
Esempio n. 13
0
class DisplayPalette(Palette):

    def __init__(self):
        Palette.__init__(self, label=_('My Display'))

        self._screenshot = PaletteMenuItem(_('Take a screenshot'))
        icon = Icon(icon_name='camera-external',
                    pixel_size=style.SMALL_ICON_SIZE)
        self._screenshot.set_image(icon)
        icon.show()
        self._screenshot.connect('activate', self.__screenshot_cb)
        self._screenshot.show()

        self._box = PaletteMenuBox()

        self._brightness_manager = None
        # only add this widget if device available
        if brightness.get_instance().get_path():
            self._add_brightness_manager()

        self._box.append_item(self._screenshot, 0, 0)
        self._box.show()

        self.set_content(self._box)
        self.connect('popup', self.__popup_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 __popup_cb(self, palette):
        if self._brightness_manager is not None:
            self._brightness_manager.update()

    def __screenshot_cb(self, palette):
        frame_ = frame.get_view()
        frame_.hide()
        GLib.idle_add(self.__take_screenshot_cb, frame_)

    @staticmethod
    def __take_screenshot_cb(frame_):
        if frame_.is_visible():
            return True
        take_screenshot()
        frame_.show()
        return False
Esempio n. 14
0
    def _setup_quality_palette(self):
        self._quality_palette = self._quality_button.get_palette()
        box = PaletteMenuBox()
        self._quality_palette.set_content(box)
        box.show()

        for quality in QUALITY_VALUES:
            text = _('%s quality') % (quality)
            menu_item = PaletteMenuItem(text, icon_name=quality + '-quality')
            menu_item.connect('activate', self._quality_selected_cb, quality)
            box.append_item(menu_item)
            menu_item.show()
Esempio n. 15
0
class DisplayPalette(Palette):

    def __init__(self):
        Palette.__init__(self, label=_('My Display'))

        self._screenshot = PaletteMenuItem(_('Take a screenshot'))
        icon = Icon(icon_name='camera-external',
                    pixel_size=style.SMALL_ICON_SIZE)
        self._screenshot.set_image(icon)
        icon.show()
        self._screenshot.connect('activate', self.__screenshot_cb)
        self._screenshot.show()

        self._box = PaletteMenuBox()

        self._brightness_manager = None
        # only add this widget if device available
        if brightness.get_instance().get_path():
            self._add_brightness_manager()

        self._box.append_item(self._screenshot, 0, 0)
        self._box.show()

        self.set_content(self._box)
        self.connect('popup', self.__popup_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 __popup_cb(self, palette):
        if self._brightness_manager is not None:
            self._brightness_manager.update()

    def __screenshot_cb(self, palette):
        frame_ = frame.get_view()
        frame_.hide()
        GObject.idle_add(self.__take_screenshot_cb, frame_)

    def __take_screenshot_cb(self, frame_):
        if frame_.is_visible():
            return True
        take_screenshot()
        frame_.show()
        return False
Esempio n. 16
0
    def _setup_timer_palette(self):
        self._timer_palette = self._timer_button.get_palette()
        box = PaletteMenuBox()
        self._timer_palette.set_content(box)
        box.show()

        for seconds in TIMER_VALUES:
            if seconds == 0:
                text = _('Immediate')
            else:
                text = ngettext('%s second', '%s seconds', seconds) % seconds
            menu_item = PaletteMenuItem(text, icon_name='timer-%d' % (seconds))
            menu_item.connect('activate', self._timer_selected_cb, seconds)
            box.append_item(menu_item)
            menu_item.show()
Esempio n. 17
0
    def _show_menu(self):
        logging.error('Show menu ')
        if self._palette_invoker is not None:
            self._palette = Palette(_('Select tag'))
            menu_box = PaletteMenuBox()
            self._palette.set_content(menu_box)
            menu_box.show()
            for tag in TAG_LIST:
                menu_item = PaletteMenuItem()
                menu_item.set_label(tag)
                menu_item.connect('activate', self._add_tag, tag)
                menu_box.append_item(menu_item)
                menu_item.show()

            self._palette_invoker.set_palette(self._palette)
            self._palette.popup(immediate=True)
Esempio n. 18
0
    def _setup_duration_palette(self):
        self._duration_palette = self._duration_button.get_palette()
        box = PaletteMenuBox()
        self._duration_palette.set_content(box)
        box.show()

        for minutes in DURATION_VALUES:
            if minutes == 0:
                text = Gtk.Label(_('Immediate'))
            else:
                text = ngettext('%s minute', '%s minutes', minutes) % minutes
            menu_item = PaletteMenuItem(text,
                                        icon_name='duration-%d' % (minutes))
            menu_item.connect('activate', self._duration_selected_cb, minutes)
            box.append_item(menu_item)
            menu_item.show()
Esempio n. 19
0
class InvitePalette(Palette):
    """Palette for frame or notification icon for invites."""

    __gsignals__ = {
        'remove-invite': (GObject.SignalFlags.RUN_FIRST, None, ([])),
    }

    def __init__(self, invite):
        Palette.__init__(self, '')

        self._invite = invite

        self.menu_box = PaletteMenuBox()
        self.set_content(self.menu_box)
        self.menu_box.show()

        menu_item = PaletteMenuItem(_('Join'), icon_name='dialog-ok')
        menu_item.connect('activate', self.__join_activate_cb)
        self.menu_box.append_item(menu_item)
        menu_item.show()

        menu_item = PaletteMenuItem(_('Decline'), icon_name='dialog-cancel')
        menu_item.connect('activate', self.__decline_activate_cb)
        self.menu_box.append_item(menu_item)
        menu_item.show()

        bundle_id = invite.get_bundle_id()

        registry = bundleregistry.get_registry()
        self._bundle = registry.get_bundle(bundle_id)
        if self._bundle:
            activity_name = self._bundle.get_name()
        else:
            activity_name = bundle_id
        self.set_primary_text(activity_name)

        title = self._invite.get_activity_title()
        if title is not None:
            self.set_secondary_text(title)

    def __join_activate_cb(self, menu_item):
        self._invite.join()
        self.emit('remove-invite')

    def __decline_activate_cb(self, menu_item):
        self.emit('remove-invite')
Esempio n. 20
0
class InvitePalette(Palette):
    """Palette for frame or notification icon for invites."""

    __gsignals__ = {
        'remove-invite': (GObject.SignalFlags.RUN_FIRST, None, ([])),
    }

    def __init__(self, invite):
        Palette.__init__(self, '')

        self._invite = invite

        self.menu_box = PaletteMenuBox()
        self.set_content(self.menu_box)
        self.menu_box.show()

        menu_item = PaletteMenuItem(_('Join'), icon_name='dialog-ok')
        menu_item.connect('activate', self.__join_activate_cb)
        self.menu_box.append_item(menu_item)
        menu_item.show()

        menu_item = PaletteMenuItem(_('Decline'), icon_name='dialog-cancel')
        menu_item.connect('activate', self.__decline_activate_cb)
        self.menu_box.append_item(menu_item)
        menu_item.show()

        bundle_id = invite.get_bundle_id()

        registry = bundleregistry.get_registry()
        self._bundle = registry.get_bundle(bundle_id)
        if self._bundle:
            activity_name = self._bundle.get_name()
        else:
            activity_name = bundle_id
        self.set_primary_text(activity_name)

        title = self._invite.get_activity_title()
        if title is not None:
            self.set_secondary_text(title)

    def __join_activate_cb(self, menu_item):
        self._invite.join()
        self.emit('remove-invite')

    def __decline_activate_cb(self, menu_item):
        self.emit('remove-invite')
Esempio n. 21
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(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)
Esempio n. 22
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)
Esempio n. 23
0
    def __init__(self, row, tree_view, collab):
        Palette.__init__(self, primary_text=_(row[MainList.COLUMN_TYPE]))
        self._collab = collab
        self._row = row
        self._tree_view = tree_view

        box = PaletteMenuBox()
        self.set_content(box)
        box.show()

        menu_item = PaletteMenuItem(_('Edit'), icon_name='toolbar-edit')
        menu_item.connect('activate', lambda *args: tree_view.edit(row))
        box.append_item(menu_item)
        menu_item.show()

        menu_item = PaletteMenuItem(_('Delete'), icon_name='edit-delete')
        menu_item.connect('activate', self.__delete_cb) 
        box.append_item(menu_item)
        menu_item.show()
Esempio n. 24
0
    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)
Esempio n. 25
0
    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)
Esempio n. 26
0
    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)
Esempio n. 27
0
    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)
Esempio n. 28
0
class VolumePalette(Palette):

    def __init__(self, mount):
        Palette.__init__(self, label=mount.get_name())
        self._mount = mount

        self.props.secondary_text = mount.get_root().get_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 __unmount_activate_cb(self, menu_item):
        flags = 0
        mount_operation = Gtk.MountOperation(
            parent=self.content_box.get_toplevel())
        cancellable = None
        user_data = None
        self._mount.unmount_with_operation(flags, mount_operation, cancellable,
                                           self.__unmount_cb, user_data)

    def __unmount_cb(self, mount, result, user_data):
        logging.debug('__unmount_cb %r %r', mount, result)
        mount.unmount_with_operation_finish(result)

    def __popup_cb(self, palette):
        mount_point = self._mount.get_root().get_path()
        stat = os.statvfs(mount_point)
        free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
        total_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BLOCKS]

        fraction = (total_space - free_space) / float(total_space)
        self._progress_bar.props.fraction = fraction
        self._free_space_label.props.label = _('%(free_space)d MiB Free') % \
            {'free_space': free_space / (1024 * 1024)}
Esempio n. 29
0
    def __init__(self, pc, toolbar_box):

        GObject.GObject.__init__(self)

        self._abiword_canvas = pc.abiword_canvas

        copy = CopyButton()
        copy.props.accelerator = '<Ctrl>C'
        copy.connect('clicked', lambda button: pc.abiword_canvas.copy())
        self.insert(copy, -1)
        copy.show()

        paste = PasteButton()
        paste.props.accelerator = '<Ctrl>V'
        paste.connect('clicked', self.__paste_button_cb)
        self.insert(paste, -1)
        paste.show()

        menu_box = PaletteMenuBox()
        paste.props.palette.set_content(menu_box)
        menu_box.show()
        menu_item = PaletteMenuItem()
        menu_item.set_label(_('Paste unformatted'))
        menu_item.connect('activate', self.__paste_special_button_cb)
        menu_box.append_item(menu_item)

        separator = Gtk.SeparatorToolItem()
        self.insert(separator, -1)
        separator.show()

        undo = UndoButton(sensitive=True)
        undo.connect('clicked', lambda button: pc.abiword_canvas.undo())
        pc.abiword_canvas.connect("can-undo", lambda abi, can_undo:
                                  undo.set_sensitive(can_undo))
        self.insert(undo, -1)
        undo.show()

        redo = RedoButton(sensitive=True)
        redo.connect('clicked', lambda button: pc.abiword_canvas.redo())
        pc.abiword_canvas.connect("can-redo", lambda abi, can_redo:
                                  redo.set_sensitive(can_redo))
        self.insert(redo, -1)
        redo.show()

        pc.abiword_canvas.connect('text-selected', lambda abi, b:
                                  copy.set_sensitive(True))
        pc.abiword_canvas.connect('image-selected', lambda abi, b:
                                  copy.set_sensitive(True))
        pc.abiword_canvas.connect('selection-cleared', lambda abi, b:
                                  copy.set_sensitive(False))

        separator = Gtk.SeparatorToolItem()
        self.insert(separator, -1)
        separator.show()

        search_label = Gtk.Label(label=_("Search") + ": ")
        search_label.show()
        search_item_page_label = Gtk.ToolItem()
        search_item_page_label.add(search_label)
        self.insert(search_item_page_label, -1)
        search_item_page_label.show()

        # setup the search options
        self._search_entry = iconentry.IconEntry()
        self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
                                              'system-search')
        self._search_entry.connect('activate', self._search_entry_activated_cb)
        self._search_entry.connect('changed', self._search_entry_changed_cb)
        self._search_entry.add_clear_button()
        self._add_widget(self._search_entry, expand=True)

        self._findprev = ToolButton('go-previous-paired')
        self._findprev.set_tooltip(_('Find previous'))
        self.insert(self._findprev, -1)
        self._findprev.show()
        self._findprev.connect('clicked', self._findprev_cb)

        self._findnext = ToolButton('go-next-paired')
        self._findnext.set_tooltip(_('Find next'))
        self.insert(self._findnext, -1)
        self._findnext.show()
        self._findnext.connect('clicked', self._findnext_cb)

        # set the initial state of the search controls
        # note: we won't simple call self._search_entry_changed_cb
        # here, as that will call into the abiword_canvas, which
        # is not mapped on screen here, causing the set_find_string
        # call to fail
        self._findprev.set_sensitive(False)
        self._findnext.set_sensitive(False)
Esempio n. 30
0
    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()
Esempio n. 31
0
class RecdButton(TrayButton):
    __gsignals__ = {
        'remove-requested': (GObject.SignalFlags.RUN_LAST, None, ()),
        'copy-clipboard-requested': (GObject.SignalFlags.RUN_LAST, None, ()),
    }

    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 _add_copy_menu_item(self):
        if self._recd.buddy and not self._recd.downloadedFromBuddy:
            return

        self._copy_menu_item = PaletteMenuItem(_('Copy to clipboard'),
                                               icon_name='edit-copy')
        self._copy_menu_item_handler = self._copy_menu_item.connect(
            'activate', self._copy_clipboard_clicked)
        self._box.append_item(self._copy_menu_item)
        self._copy_menu_item.show()

    def get_recd(self):
        return self._recd

    def get_image(self):
        ipb = self._recd.getThumbPixbuf()

        if ipb:
            w = ipb.get_width()
            h = ipb.get_height()
            a = float(w) / float(h)
        else:
            a = 16. / 9

        if a < 1.4:
            paths = {
                constants.TYPE_PHOTO: 'object-photo.svg',
                constants.TYPE_VIDEO: 'object-video.svg',
                constants.TYPE_AUDIO: 'object-audio.svg'
            }
            x = 8
            y = 8
        else:
            paths = {
                constants.TYPE_PHOTO: 'object-photo-16to9.svg',
                constants.TYPE_VIDEO: 'object-video-16to9.svg',
                constants.TYPE_AUDIO: 'object-audio-16to9.svg'
            }
            x = 9
            y = 18

        path = paths[self._recd.type]

        pixbuf = utils.load_colored_svg(path, self._recd.colorStroke,
                                        self._recd.colorFill)
        if ipb:
            ipb.composite(pixbuf, x, y, w, h, x, y, 1, 1,
                          GdkPixbuf.InterpType.BILINEAR, 255)
        img = Gtk.Image()
        img.set_from_pixbuf(pixbuf)
        img.show()
        return img

    def cleanup(self):
        self._rem_menu_item.disconnect(self._rem_menu_item_handler)
        if self._copy_menu_item_handler is not None:
            self._copy_menu_item.disconnect(self._copy_menu_item_handler)

    def _remove_clicked(self, widget):
        self.emit('remove-requested')

    def _copy_clipboard_clicked(self, widget):
        self.emit('copy-clipboard-requested')
    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title('Palettes')
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)

        vbox = Gtk.VBox()

        toolbarbox = ToolbarBox()
        vbox.add(toolbarbox)

        toolbar = toolbarbox.toolbar

        color_button = ColorToolButton()
        toolbar.insert(color_button, -1)

        button = ToolButton('list-add')
        button.set_tooltip('Palette with widgets')
        toolbar.insert(button, -1)

        palette = button.get_palette()
        palette_box = Gtk.VBox()
        palette.set_content(palette_box)

        checkbutton1 = Gtk.CheckButton('Option 1')
        palette_box.pack_start(checkbutton1, False, False, 0)

        checkbutton2 = Gtk.CheckButton('Option 2')
        palette_box.pack_start(checkbutton2, False, False, 0)

        checkbutton3 = Gtk.CheckButton('Option 3')
        palette_box.pack_start(checkbutton3, False, False, 0)

        separator = Gtk.VSeparator()
        palette_box.pack_start(separator, False, False, 0)

        radio_button1 = Gtk.RadioButton('Option 1')
        palette_box.pack_start(radio_button1, False, False, 0)

        radio_button2 = Gtk.RadioButton('Option 2', group=radio_button1)
        palette_box.pack_start(radio_button2, False, False, 0)

        radio_button3 = Gtk.RadioButton('Option 3', group=radio_button1)
        palette_box.pack_start(radio_button3, False, False, 0)

        palette_box.show_all()

        button = ToolButton(icon_name='format-justify-fill')
        button.props.tooltip = 'Select list'
        button.props.hide_tooltip_on_click = False
        button.palette_invoker.props.toggle_palette = True
        toolbar.insert(button, -1)

        menu_box = PaletteMenuBox()
        button.props.palette.set_content(menu_box)
        menu_box.show()

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-fill')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-center')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-left')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-right')
        menu_box.append_item(menu_item)

        self.add(vbox)
        self.show_all()

        self.connect('destroy', Gtk.main_quit)
Esempio n. 33
0
class RecdButton(TrayButton):
    __gsignals__ = {
        'remove-requested': (GObject.SignalFlags.RUN_LAST, None, ()),
        'copy-clipboard-requested': (GObject.SignalFlags.RUN_LAST, None, ()),
    }

    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 _add_copy_menu_item(self):
        if self._recd.buddy and not self._recd.downloadedFromBuddy:
            return

        self._copy_menu_item = PaletteMenuItem(
            _('Copy to clipboard'), icon_name='edit-copy')
        self._copy_menu_item_handler = self._copy_menu_item.connect(
            'activate', self._copy_clipboard_clicked)
        self._box.append_item(self._copy_menu_item)
        self._copy_menu_item.show()

    def get_recd(self):
        return self._recd

    def get_image(self):
        ipb = self._recd.getThumbPixbuf()

        if ipb:
            w = ipb.get_width()
            h = ipb.get_height()
            a = float(w) / float(h)
        else:
            a = 16. / 9

        if a < 1.4:
            paths = {constants.TYPE_PHOTO: 'object-photo.svg',
                     constants.TYPE_VIDEO: 'object-video.svg',
                     constants.TYPE_AUDIO: 'object-audio.svg'}
            x = 8
            y = 8
        else:
            paths = {constants.TYPE_PHOTO: 'object-photo-16to9.svg',
                     constants.TYPE_VIDEO: 'object-video-16to9.svg',
                     constants.TYPE_AUDIO: 'object-audio-16to9.svg'}
            x = 9
            y = 18

        path = paths[self._recd.type]

        pixbuf = utils.load_colored_svg(path, self._recd.colorStroke,
                                        self._recd.colorFill)
        if ipb:
            ipb.composite(pixbuf, x, y, w, h, x, y, 1, 1,
                          GdkPixbuf.InterpType.BILINEAR, 255)
        img = Gtk.Image()
        img.set_from_pixbuf(pixbuf)
        img.show()
        return img

    def cleanup(self):
        self._rem_menu_item.disconnect(self._rem_menu_item_handler)
        if self._copy_menu_item_handler is not None:
            self._copy_menu_item.disconnect(self._copy_menu_item_handler)

    def _remove_clicked(self, widget):
        self.emit('remove-requested')

    def _copy_clipboard_clicked(self, widget):
        self.emit('copy-clipboard-requested')
Esempio n. 34
0
    def __init__(self, pc, toolbar_box):

        GObject.GObject.__init__(self)

        self._abiword_canvas = pc.abiword_canvas

        copy = CopyButton()
        copy.props.accelerator = '<Ctrl>C'
        copy.connect('clicked', lambda button: pc.abiword_canvas.copy())
        self.insert(copy, -1)
        copy.show()

        paste = PasteButton()
        paste.props.accelerator = '<Ctrl>V'
        paste.connect('clicked', self.__paste_button_cb)
        self.insert(paste, -1)
        paste.show()

        menu_box = PaletteMenuBox()
        paste.props.palette.set_content(menu_box)
        menu_box.show()
        menu_item = PaletteMenuItem()
        menu_item.set_label(_('Paste unformatted'))
        menu_item.connect('activate', self.__paste_special_button_cb)
        menu_box.append_item(menu_item)

        separator = Gtk.SeparatorToolItem()
        self.insert(separator, -1)
        separator.show()

        undo = UndoButton(sensitive=True)
        undo.connect('clicked', lambda button: pc.abiword_canvas.undo())
        pc.abiword_canvas.connect(
            "can-undo", lambda abi, can_undo: undo.set_sensitive(can_undo))
        self.insert(undo, -1)
        undo.show()

        redo = RedoButton(sensitive=True)
        redo.connect('clicked', lambda button: pc.abiword_canvas.redo())
        pc.abiword_canvas.connect(
            "can-redo", lambda abi, can_redo: redo.set_sensitive(can_redo))
        self.insert(redo, -1)
        redo.show()

        pc.abiword_canvas.connect('text-selected',
                                  lambda abi, b: copy.set_sensitive(True))
        pc.abiword_canvas.connect('image-selected',
                                  lambda abi, b: copy.set_sensitive(True))
        pc.abiword_canvas.connect('selection-cleared',
                                  lambda abi, b: copy.set_sensitive(False))

        separator = Gtk.SeparatorToolItem()
        self.insert(separator, -1)
        separator.show()

        search_label = Gtk.Label(label=_("Search") + ": ")
        search_label.show()
        search_item_page_label = Gtk.ToolItem()
        search_item_page_label.add(search_label)
        self.insert(search_item_page_label, -1)
        search_item_page_label.show()

        # setup the search options
        self._search_entry = iconentry.IconEntry()
        self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
                                              'system-search')
        self._search_entry.connect('activate', self._search_entry_activated_cb)
        self._search_entry.connect('changed', self._search_entry_changed_cb)
        self._search_entry.add_clear_button()
        self._add_widget(self._search_entry, expand=True)

        self._findprev = ToolButton('go-previous-paired')
        self._findprev.set_tooltip(_('Find previous'))
        self.insert(self._findprev, -1)
        self._findprev.show()
        self._findprev.connect('clicked', self._findprev_cb)

        self._findnext = ToolButton('go-next-paired')
        self._findnext.set_tooltip(_('Find next'))
        self.insert(self._findnext, -1)
        self._findnext.show()
        self._findnext.connect('clicked', self._findnext_cb)

        # set the initial state of the search controls
        # note: we won't simple call self._search_entry_changed_cb
        # here, as that will call into the abiword_canvas, which
        # is not mapped on screen here, causing the set_find_string
        # call to fail
        self._findprev.set_sensitive(False)
        self._findnext.set_sensitive(False)
Esempio n. 35
0
class DetailToolbox(ToolbarBox):
    __gsignals__ = {
        'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
                         ([str, str])),
    }

    def __init__(self, journalactivity):
        ToolbarBox.__init__(self)
        self._journalactivity = journalactivity
        self._metadata = None
        self._temp_file_path = None
        self._refresh = None

        self._resume = ToolButton('activity-start')
        self._resume.connect('clicked', self._resume_clicked_cb)
        self.toolbar.insert(self._resume, -1)
        self._resume.show()
        self._resume_menu = None

        color = profile.get_color()
        self._copy = ToolButton()
        icon = Icon(icon_name='edit-copy', xo_color=color)
        self._copy.set_icon_widget(icon)
        icon.show()
        self._copy.set_tooltip(_('Copy to'))
        self._copy.connect('clicked', self._copy_clicked_cb)
        self.toolbar.insert(self._copy, -1)
        self._copy.show()

        self._duplicate = ToolButton()
        icon = Icon(icon_name='edit-duplicate', xo_color=color)
        self._duplicate.set_icon_widget(icon)
        self._duplicate.set_tooltip(_('Duplicate'))
        self._duplicate.connect('clicked', self._duplicate_clicked_cb)
        self.toolbar.insert(self._duplicate, -1)

        if accountsmanager.has_configured_accounts():
            self._refresh = ToolButton('entry-refresh')
            self._refresh.set_tooltip(_('Refresh'))
            self._refresh.connect('clicked', self._refresh_clicked_cb)
            self.toolbar.insert(self._refresh, -1)
            self._refresh.show()

        separator = Gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)
        separator.show()

        erase_button = ToolButton('list-remove')
        erase_button.set_tooltip(_('Erase'))
        erase_button.connect('clicked', self._erase_button_clicked_cb)
        self.toolbar.insert(erase_button, -1)
        erase_button.show()

    def set_metadata(self, metadata):
        self._metadata = metadata
        self._refresh_copy_palette()
        self._refresh_duplicate_palette()
        self._refresh_refresh_palette()
        self._refresh_resume_palette()

    def _resume_clicked_cb(self, button):
        if not misc.can_resume(self._metadata):
            palette = self._resume.get_palette()
            palette.popup(immediate=True)

        misc.resume(self._metadata,
                    alert_window=journalwindow.get_journal_window())

    def _copy_clicked_cb(self, button):
        button.palette.popup(immediate=True)

    def _refresh_clicked_cb(self, button):
        button.palette.popup(immediate=True)

    def _duplicate_clicked_cb(self, button):
        try:
            model.copy(self._metadata, '/')
        except IOError as e:
            logging.exception('Error while copying the entry.')
            self.emit('volume-error',
                      _('Error while copying the entry. %s') % (e.strerror, ),
                      _('Error'))

    def _erase_button_clicked_cb(self, button):
        alert = Alert()
        erase_string = _('Erase')
        alert.props.title = erase_string
        alert.props.msg = _('Do you want to permanently erase \"%s\"?') \
            % self._metadata['title']
        icon = Icon(icon_name='dialog-cancel')
        alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
        icon.show()
        ok_icon = Icon(icon_name='dialog-ok')
        alert.add_button(Gtk.ResponseType.OK, erase_string, ok_icon)
        ok_icon.show()
        alert.connect('response', self.__erase_alert_response_cb)
        journalwindow.get_journal_window().add_alert(alert)
        alert.show()

    def __erase_alert_response_cb(self, alert, response_id):
        journalwindow.get_journal_window().remove_alert(alert)
        if response_id is Gtk.ResponseType.OK:
            registry = bundleregistry.get_registry()
            bundle = misc.get_bundle(self._metadata)
            if bundle is not None and registry.is_installed(bundle):
                registry.uninstall(bundle)
            model.delete(self._metadata['uid'])

    def _resume_menu_item_activate_cb(self, menu_item, service_name):
        misc.resume(self._metadata, service_name,
                    alert_window=journalwindow.get_journal_window())

    def _refresh_copy_palette(self):
        palette = self._copy.get_palette()

        # Use the menu defined in CopyMenu
        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        CopyMenuBuilder(self._journalactivity, self.__get_uid_list_cb,
                        self.__volume_error_cb, palette.menu)

    def __get_uid_list_cb(self):
        return [self._metadata['uid']]

    def _refresh_duplicate_palette(self):
        color = misc.get_icon_color(self._metadata)
        self._copy.get_icon_widget().props.xo_color = color
        if self._metadata['mountpoint'] == '/':
            self._duplicate.show()
            icon = self._duplicate.get_icon_widget()
            icon.props.xo_color = color
            icon.show()
        else:
            self._duplicate.hide()

    def _refresh_refresh_palette(self):
        if self._refresh is None:
            return

        color = misc.get_icon_color(self._metadata)
        self._refresh.get_icon_widget().props.xo_color = color

        palette = self._refresh.get_palette()
        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)

        for account in accountsmanager.get_configured_accounts():
            if hasattr(account, 'get_shared_journal_entry'):
                entry = account.get_shared_journal_entry()
                if hasattr(entry, 'get_refresh_menu'):
                    menu = entry.get_refresh_menu()
                    palette.menu.append(menu)
                    menu.set_metadata(self._metadata)

    def __volume_error_cb(self, menu_item, message, severity):
        self.emit('volume-error', message, severity)

    def _refresh_resume_palette(self):
        if self._metadata.get('activity_id', ''):
            # TRANS: Action label for resuming an activity.
            self._resume.set_tooltip(_('Resume'))
        else:
            # TRANS: Action label for starting an entry.
            self._resume.set_tooltip(_('Start'))

        palette = self._resume.get_palette()

        if self._resume_menu is not None:
            self._resume_menu.destroy()

        self._resume_menu = PaletteMenuBox()
        palette.set_content(self._resume_menu)
        self._resume_menu.show()

        for activity_info in misc.get_activities(self._metadata):
            menu_item = PaletteMenuItem(file_name=activity_info.get_icon(),
                                        text_label=activity_info.get_name())
            menu_item.connect('activate', self._resume_menu_item_activate_cb,
                              activity_info.get_bundle_id())
            self._resume_menu.append_item(menu_item)
            menu_item.show()

        if not misc.can_resume(self._metadata):
            self._resume.set_tooltip(_('No activity to start entry'))
Esempio n. 36
0
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()
        self._palette_invoker = palette_invoker

    palette_invoker = GObject.property(
        type=object, setter=set_palette_invoker, getter=get_palette_invoker)

    def set_value(self, value):
        self._value = value
        if value.__class__ is str:
            self._label.set_text(value)
        else:
            self._label.set_text(value[0])
            self._set_icon(value[1])

    def get_value(self):
        return self._value
Esempio n. 37
0
class BatteryPalette(Palette):
    def __init__(self, primary_text):
        Palette.__init__(self, primary_text)
        self._level = 0
        self._time = 0
        self._status = _STATUS_NOT_PRESENT
        self._warning_capacity = _settings_get('warning-capacity')

        self._progress_widget = PaletteMenuBox()
        self.set_content(self._progress_widget)
        self._progress_widget.show()

        inner_box = Gtk.VBox()
        inner_box.set_spacing(style.DEFAULT_PADDING)
        self._progress_widget.append_item(inner_box, vertical_padding=0)
        inner_box.show()

        self._progress_bar = Gtk.ProgressBar()
        self._progress_bar.set_size_request(
            style.zoom(style.GRID_CELL_SIZE * 4), -1)
        inner_box.pack_start(self._progress_bar, True, True, 0)
        self._progress_bar.show()

        self._status_label = Gtk.Label()
        inner_box.pack_start(self._status_label, True, True, 0)
        self._status_label.show()

    def set_info(self, percentage, seconds, status):
        self._level = percentage
        self._time = seconds
        self._status = status
        self._progress_bar.set_fraction(percentage / 100.0)
        self._update_secondary()

    def _update_secondary(self):
        secondary_text = ''
        status_text = '%s%%' % (self._level, )

        progress_widget = self._progress_widget
        if self._status == _STATUS_NOT_PRESENT:
            secondary_text = _('Removed')
            progress_widget = None
        elif self._status == _STATUS_CHARGING:
            secondary_text = _('Charging')
        elif self._status == _STATUS_DISCHARGING:
            if self._level <= self._warning_capacity:
                secondary_text = _('Very little power remaining')
            else:
                minutes_remaining = self._time // 60
                remaining_hourpart = minutes_remaining // 60
                remaining_minpart = minutes_remaining % 60
                # TRANS: do not translate %(hour)d:%(min).2d  it is a variable,
                # only translate the word "remaining"
                secondary_text = _('%(hour)d:%(min).2d remaining') % \
                    {'hour': remaining_hourpart, 'min': remaining_minpart}
        else:
            secondary_text = _('Charged')

        self.set_content(progress_widget)

        self.props.secondary_text = secondary_text
        self._status_label.set_text(status_text)
Esempio n. 38
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        # abiword uses the current directory for all its file dialogs
        os.chdir(os.path.expanduser('~'))

        # create our main abiword canvas
        self.abiword_canvas = DocumentView()
        self._new_instance = True
        toolbar_box = ToolbarBox()

        self.activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(self.activity_button, -1)

        separator = Gtk.SeparatorToolItem()
        separator.show()
        self.activity_button.props.page.insert(separator, 2)
        ExportButtonFactory(self, self.abiword_canvas)
        self.activity_button.show()

        edit_toolbar = ToolbarButton()
        edit_toolbar.props.page = EditToolbar(self, toolbar_box)
        edit_toolbar.props.icon_name = 'toolbar-edit'
        edit_toolbar.props.label = _('Edit')
        toolbar_box.toolbar.insert(edit_toolbar, -1)

        view_toolbar = ToolbarButton()
        view_toolbar.props.page = ViewToolbar(self.abiword_canvas)
        view_toolbar.props.icon_name = 'toolbar-view'
        view_toolbar.props.label = _('View')
        toolbar_box.toolbar.insert(view_toolbar, -1)

        # due to http://bugzilla.abisource.com/show_bug.cgi?id=13585
        if self.abiword_canvas.get_version() != '3.0':
            self.speech_toolbar_button = ToolbarButton(icon_name='speak')
            toolbar_box.toolbar.insert(self.speech_toolbar_button, -1)
            self._init_speech()

        separator = Gtk.SeparatorToolItem()
        toolbar_box.toolbar.insert(separator, -1)

        text_toolbar = ToolbarButton()
        text_toolbar.props.page = TextToolbar(self.abiword_canvas)
        text_toolbar.props.icon_name = 'format-text'
        text_toolbar.props.label = _('Text')
        toolbar_box.toolbar.insert(text_toolbar, -1)

        para_toolbar = ToolbarButton()
        para_toolbar.props.page = ParagraphToolbar(self.abiword_canvas)
        para_toolbar.props.icon_name = 'paragraph-bar'
        para_toolbar.props.label = _('Paragraph')
        toolbar_box.toolbar.insert(para_toolbar, -1)

        insert_toolbar = ToolbarButton()
        insert_toolbar.props.page = InsertToolbar(self.abiword_canvas)
        insert_toolbar.props.icon_name = 'insert-table'
        insert_toolbar.props.label = _('Table')
        toolbar_box.toolbar.insert(insert_toolbar, -1)

        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()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_size_request(0, -1)
        separator.set_expand(True)
        separator.show()
        toolbar_box.toolbar.insert(separator, -1)

        stop = StopButton(self)
        toolbar_box.toolbar.insert(stop, -1)

        toolbar_box.show_all()
        self.set_toolbar_box(toolbar_box)

        # add a overlay to be able to show a icon while joining a shared doc
        overlay = Gtk.Overlay()
        overlay.add(self.abiword_canvas)
        overlay.show()

        self._connecting_box = ConnectingBox()
        overlay.add_overlay(self._connecting_box)

        self.set_canvas(overlay)

        # we want a nice border so we can select paragraphs easily
        self.abiword_canvas.set_show_margin(True)

        # Set default font face and size
        self._default_font_face = 'Sans'
        self._default_font_size = 12

        # activity sharing
        self.participants = {}
        self.joined = False

        self.connect('shared', self._shared_cb)

        if self.shared_activity:
            # we are joining the activity
            logger.debug('We are joining an activity')
            # display a icon while joining
            self._connecting_box.show()
            # disable the abi widget
            self.abiword_canvas.set_sensitive(False)
            self._new_instance = False
            self.connect('joined', self._joined_cb)
            self.shared_activity.connect('buddy-joined',
                                         self._buddy_joined_cb)
            self.shared_activity.connect('buddy-left', self._buddy_left_cb)
            if self.get_shared():
                self._joined_cb(self)
        else:
            # we are creating the activity
            logger.debug("We are creating an activity")

        self.abiword_canvas.zoom_width()
        self.abiword_canvas.show()
        self.connect_after('map-event', self.__map_activity_event_cb)

        self.abiword_canvas.connect('size-allocate', self.size_allocate_cb)
Esempio n. 39
0
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():
            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)
        return False

    def __font_selected_cb(self, menu, font_name):
        self._font_name = font_name
        self._font_label.set_font(font_name)
        self.emit('changed')

    def _add_menu(self, font_name, activate_cb):
        label = '<span font="%s">%s</span>' % (font_name, font_name)
        menu_item = PaletteMenuItem()
        menu_item.set_label(label)
        menu_item.connect('activate', activate_cb, font_name)
        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()
        self._palette_invoker = palette_invoker

    palette_invoker = GObject.property(
        type=object, setter=set_palette_invoker, getter=get_palette_invoker)

    def set_font_name(self, font_name):
        self._font_label.set_font(font_name)

    def get_font_name(self):
        return self._font_name
Esempio n. 40
0
    def __init__(self, abiword_canvas):
        GObject.GObject.__init__(self)

        self.font_name_combo = FontComboBox()
        self.font_name_combo.set_font_name('Sans')
        self._fonts_changed_id = self.font_name_combo.connect(
            'changed', self._font_changed_cb, abiword_canvas)
        self._abi_handler = abiword_canvas.connect('font-family',
                                                   self._font_family_cb)
        self.insert(ToolComboBox(self.font_name_combo), -1)

        self.font_size = FontSize()
        self._abi_handler = abiword_canvas.connect('font-size',
                                                   self._font_size_cb)
        self._changed_id = self.font_size.connect(
            'changed', self._font_size_changed_cb, abiword_canvas)
        self.insert(self.font_size, -1)

        bold = ToggleToolButton('format-text-bold')
        bold.set_tooltip(_('Bold'))
        bold.props.accelerator = '<Ctrl>B'
        bold_id = bold.connect('clicked', lambda sender:
                               abiword_canvas.toggle_bold())
        abiword_canvas.connect('bold', lambda abi, b:
                               self._setToggleButtonState(bold, b, bold_id))
        self.insert(bold, -1)

        italic = ToggleToolButton('format-text-italic')
        italic.set_tooltip(_('Italic'))
        italic.props.accelerator = '<Ctrl>I'
        italic_id = italic.connect('clicked', lambda sender:
                                   abiword_canvas.toggle_italic())
        abiword_canvas.connect('italic', lambda abi, b:
                               self._setToggleButtonState(italic, b,
                                                          italic_id))
        self.insert(italic, -1)

        underline = ToggleToolButton('format-text-underline')
        underline.set_tooltip(_('Underline'))
        underline.props.accelerator = '<Ctrl>U'
        underline_id = underline.connect('clicked', lambda sender:
                                         abiword_canvas.toggle_underline())
        abiword_canvas.connect('underline', lambda abi, b:
                               self._setToggleButtonState(underline, b,
                                                          underline_id))
        self.insert(underline, -1)

        # for super/subscript, we're using the same keyboard shorcuts as
        # abiword: <C-^> and <C-_>
        super_btn = ToggleToolButton('format-text-super')
        super_btn.set_tooltip(_('Superscript'))
        # found with gtk.accelerator_name
        super_btn.props.accelerator = '<Ctrl>asciicircum'
        super_id = super_btn.connect('clicked', lambda sender:
                               abiword_canvas.toggle_super())
        # no, this isn't a mistake. The method is called `toggle_super()', but
        # the *signal* is called `superscript'. Same goes for sub{script,}.
        abiword_canvas.connect('superscript', lambda abi, b:
                               self._setToggleButtonState(super_btn, b,
                                                          super_id))
        self.insert(super_btn, -1)

        sub = ToggleToolButton('format-text-sub')
        sub.set_tooltip(_('Subscript'))
        sub.props.accelerator = '<Ctrl>underscore'
        sub_id = sub.connect('clicked', lambda sender:
                               abiword_canvas.toggle_sub())
        abiword_canvas.connect('subscript', lambda abi, b:
                               self._setToggleButtonState(sub, b, sub_id))
        self.insert(sub, -1)

        color = ColorToolButton()
        color.connect('notify::color', self._text_color_cb,
                      abiword_canvas)
        tool_item = Gtk.ToolItem()
        tool_item.add(color)
        self.insert(tool_item, -1)
        abiword_canvas.connect(
            'color', lambda abi, r, g, b:
            color.set_color(Gdk.Color(r * 256, g * 256, b * 256)))

        # MAGIC NUMBER WARNING: Secondary toolbars are not a standard height?
        self.set_size_request(-1, style.GRID_CELL_SIZE)

        def append_align(icon_name, tooltip, do_abi_cb, style_name, button,
                         menu_box):
            menu_item = AbiMenuItem(abiword_canvas, style_name, do_abi_cb,
                                    icon_name, tooltip, button)
            menu_box.append_item(menu_item)
            menu_item.show()

        self._aligment_btn = ToolButton(icon_name='format-justify-left')
        self._aligment_btn.props.tooltip = _('Choose alignment')
        self._aligment_btn.props.hide_tooltip_on_click = False
        self._aligment_btn.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._aligment_btn.props.palette.set_content(menu_box)
        menu_box.show()

        append_align('format-justify-left', _('Left justify'),
                     abiword_canvas.align_left, 'left-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-center', _('Center justify'),
                     abiword_canvas.align_center, 'center-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-right', _('Right justify'),
                     abiword_canvas.align_right, 'right-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-fill', _('Fill justify'),
                     abiword_canvas.align_justify, 'justify-align',
                     self._aligment_btn, menu_box)

        self.insert(self._aligment_btn, -1)

        self.show_all()
Esempio n. 41
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        # abiword uses the current directory for all its file dialogs
        os.chdir(os.path.expanduser('~'))

        # create our main abiword canvas
        self.abiword_canvas = DocumentView()
        self._new_instance = True
        toolbar_box = ToolbarBox()

        self.activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(self.activity_button, -1)

        separator = Gtk.SeparatorToolItem()
        separator.show()
        self.activity_button.props.page.insert(separator, 2)
        ExportButtonFactory(self, self.abiword_canvas)
        self.activity_button.show()

        edit_toolbar = ToolbarButton()
        edit_toolbar.props.page = EditToolbar(self, toolbar_box)
        edit_toolbar.props.icon_name = 'toolbar-edit'
        edit_toolbar.props.label = _('Edit')
        toolbar_box.toolbar.insert(edit_toolbar, -1)

        view_toolbar = ToolbarButton()
        view_toolbar.props.page = ViewToolbar(self.abiword_canvas)
        view_toolbar.props.icon_name = 'toolbar-view'
        view_toolbar.props.label = _('View')
        toolbar_box.toolbar.insert(view_toolbar, -1)

        # due to http://bugzilla.abisource.com/show_bug.cgi?id=13585
        if self.abiword_canvas.get_version() != '3.0':
            self.speech_toolbar_button = ToolbarButton(icon_name='speak')
            toolbar_box.toolbar.insert(self.speech_toolbar_button, -1)
            self._init_speech()

        separator = Gtk.SeparatorToolItem()
        toolbar_box.toolbar.insert(separator, -1)

        text_toolbar = ToolbarButton()
        text_toolbar.props.page = TextToolbar(self.abiword_canvas)
        text_toolbar.props.icon_name = 'format-text'
        text_toolbar.props.label = _('Text')
        toolbar_box.toolbar.insert(text_toolbar, -1)

        para_toolbar = ToolbarButton()
        para_toolbar.props.page = ParagraphToolbar(self.abiword_canvas)
        para_toolbar.props.icon_name = 'paragraph-bar'
        para_toolbar.props.label = _('Paragraph')
        toolbar_box.toolbar.insert(para_toolbar, -1)

        insert_toolbar = ToolbarButton()
        insert_toolbar.props.page = InsertToolbar(self.abiword_canvas)
        insert_toolbar.props.icon_name = 'insert-table'
        insert_toolbar.props.label = _('Table')
        toolbar_box.toolbar.insert(insert_toolbar, -1)

        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()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_size_request(0, -1)
        separator.set_expand(True)
        separator.show()
        toolbar_box.toolbar.insert(separator, -1)

        stop = StopButton(self)
        toolbar_box.toolbar.insert(stop, -1)

        toolbar_box.show_all()
        self.set_toolbar_box(toolbar_box)

        # add a overlay to be able to show a icon while joining a shared doc
        overlay = Gtk.Overlay()
        overlay.add(self.abiword_canvas)
        overlay.show()

        self._connecting_box = ConnectingBox()
        overlay.add_overlay(self._connecting_box)

        self.set_canvas(overlay)

        # we want a nice border so we can select paragraphs easily
        self.abiword_canvas.set_show_margin(True)

        # Set default font face and size
        self._default_font_face = 'Sans'
        self._default_font_size = 12

        # activity sharing
        self.participants = {}
        self.joined = False

        self.connect('shared', self._shared_cb)

        if self.shared_activity:
            # we are joining the activity
            logger.debug('We are joining an activity')
            # display a icon while joining
            self._connecting_box.show()
            # disable the abi widget
            self.abiword_canvas.set_sensitive(False)
            self._new_instance = False
            self.connect('joined', self._joined_cb)
            self.shared_activity.connect('buddy-joined', self._buddy_joined_cb)
            self.shared_activity.connect('buddy-left', self._buddy_left_cb)
            if self.get_shared():
                self._joined_cb(self)
        else:
            # we are creating the activity
            logger.debug("We are creating an activity")

        self.abiword_canvas.zoom_width()
        self.abiword_canvas.show()
        self.connect_after('map-event', self.__map_activity_event_cb)

        self.abiword_canvas.connect('size-allocate', self.size_allocate_cb)
Esempio n. 42
0
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()
        self._palette_invoker = palette_invoker

    palette_invoker = GObject.property(type=object,
                                       setter=set_palette_invoker,
                                       getter=get_palette_invoker)

    def set_value(self, value):
        self._value = value
        if value.__class__ is str:
            self._label.set_text(value)
        else:
            self._label.set_text(value[0])
            self._set_icon(value[1])

    def get_value(self):
        return self._value
Esempio n. 43
0
    def __init__(self, toolbar, edit_toolbar, activity):

        self._page = activity.page
        self._activity = activity

        # agregar cuadro
        self.add_photo = ToolButton()
        self.add_photo.props.icon_name = 'insert-picture'
        self.add_photo.connect('clicked', self.__add_photo_clicked_cb)
        self.add_photo.set_tooltip(_('Add Photo'))
        toolbar.insert(self.add_photo, -1)

        self._globes = {
            'globe': _('Globe'), 'think': _('Think'),
            'whisper': _('Whisper'), 'exclamation': _('Exclamation'),
            'box': _('Box')}

        self._globes_menu = ToolButton(icon_name='globe')
        self._globes_menu.props.tooltip = _('Add a globe')
        self._globes_menu.props.hide_tooltip_on_click = False
        self._globes_menu.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._globes_menu.props.palette.set_content(menu_box)
        menu_box.show()

        for globe in self._globes.keys():
            menu_item = PaletteMenuItem(icon_name=globe,
                                        text_label=self._globes[globe])
            menu_item.connect('activate', self.__activate_add_globe_cb, globe)
            menu_box.append_item(menu_item)
            menu_item.show()
        toolbar.insert(self._globes_menu, -1)

        # lineas de movimiento
        # Agregar aqui el nombre de archivo de una linea de moviemiento
        self._lines = {
            'curves': _('Curves'), 'straight': _('Straight'),
            'highlight': _('Highlight'), 'idea': _('Idea')}

        self._lines_menu = ToolButton(icon_name='curves')
        self._lines_menu.props.tooltip = _('Choose a movement line')
        self._lines_menu.props.hide_tooltip_on_click = False
        self._lines_menu.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._lines_menu.props.palette.set_content(menu_box)
        menu_box.show()

        for line in self._lines.keys():
            menu_item = PaletteMenuItem(icon_name=line,
                                        text_label=self._lines[line])
            menu_item.connect('activate', self.__activate_add_line_cb, line)
            menu_box.append_item(menu_item)
            menu_item.show()
        toolbar.insert(self._lines_menu, -1)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        toolbar.insert(separator, -1)

        # girar
        self.b_girar = ToolButton('object-rotate-right')
        self.b_girar.connect('clicked', self.girar)
        self.b_girar.set_tooltip(_('Turn'))
        self.b_girar.show()
        edit_toolbar.insert(self.b_girar, -1)

        # borrar
        self.b_borrar = ToolButton('gtk-delete')
        self.b_borrar.connect('clicked', self.borrar)
        self.b_borrar.set_tooltip(_('Delete'))
        self.b_borrar.show()
        edit_toolbar.insert(self.b_borrar, -1)
Esempio n. 44
0
    def __init__(self, toolbar, edit_toolbar, activity):

        self._page = activity.page
        self._activity = activity

        # agregar cuadro
        self.add_photo = ToolButton()
        self.add_photo.props.icon_name = 'insert-picture'
        self.add_photo.connect('clicked', self.__add_photo_clicked_cb)
        self.add_photo.set_tooltip(_('Add Photo'))
        toolbar.insert(self.add_photo, -1)

        self._globes = {
            'globe': _('Globe'),
            'think': _('Think'),
            'whisper': _('Whisper'),
            'exclamation': _('Exclamation'),
            'box': _('Box')
        }

        self._globes_menu = ToolButton(icon_name='globe')
        self._globes_menu.props.tooltip = _('Add a globe')
        self._globes_menu.props.hide_tooltip_on_click = False
        self._globes_menu.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._globes_menu.props.palette.set_content(menu_box)
        menu_box.show()

        for globe in list(self._globes.keys()):
            menu_item = PaletteMenuItem(icon_name=globe,
                                        text_label=self._globes[globe])
            menu_item.connect('activate', self.__activate_add_globe_cb, globe)
            menu_box.append_item(menu_item)
            menu_item.show()
        toolbar.insert(self._globes_menu, -1)

        # lineas de movimiento
        # Agregar aqui el nombre de archivo de una linea de moviemiento
        self._lines = {
            'curves': _('Curves'),
            'straight': _('Straight'),
            'highlight': _('Highlight'),
            'idea': _('Idea')
        }

        self._lines_menu = ToolButton(icon_name='curves')
        self._lines_menu.props.tooltip = _('Choose a movement line')
        self._lines_menu.props.hide_tooltip_on_click = False
        self._lines_menu.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._lines_menu.props.palette.set_content(menu_box)
        menu_box.show()

        for line in list(self._lines.keys()):
            menu_item = PaletteMenuItem(icon_name=line,
                                        text_label=self._lines[line])
            menu_item.connect('activate', self.__activate_add_line_cb, line)
            menu_box.append_item(menu_item)
            menu_item.show()
        toolbar.insert(self._lines_menu, -1)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        toolbar.insert(separator, -1)

        # girar
        self.b_girar = ToolButton('object-rotate-right')
        self.b_girar.connect('clicked', self.girar)
        self.b_girar.set_tooltip(_('Turn'))
        self.b_girar.show()
        edit_toolbar.insert(self.b_girar, -1)

        # borrar
        self.b_borrar = ToolButton('gtk-delete')
        self.b_borrar.connect('clicked', self.borrar)
        self.b_borrar.set_tooltip(_('Delete'))
        self.b_borrar.show()
        edit_toolbar.insert(self.b_borrar, -1)
Esempio n. 45
0
class BatteryPalette(Palette):

    def __init__(self, primary_text):
        Palette.__init__(self, primary_text)
        self._level = 0
        self._time = 0
        self._status = _STATUS_NOT_PRESENT
        self._warning_capacity = _settings_get('warning-capacity')

        self._progress_widget = PaletteMenuBox()
        self.set_content(self._progress_widget)
        self._progress_widget.show()

        inner_box = Gtk.VBox()
        inner_box.set_spacing(style.DEFAULT_PADDING)
        self._progress_widget.append_item(inner_box, vertical_padding=0)
        inner_box.show()

        self._progress_bar = Gtk.ProgressBar()
        self._progress_bar.set_size_request(
            style.zoom(style.GRID_CELL_SIZE * 4), -1)
        inner_box.pack_start(self._progress_bar, True, True, 0)
        self._progress_bar.show()

        self._status_label = Gtk.Label()
        inner_box.pack_start(self._status_label, True, True, 0)
        self._status_label.show()

    def set_info(self, percentage, seconds, status):
        self._level = percentage
        self._time = seconds
        self._status = status
        self._progress_bar.set_fraction(percentage / 100.0)
        self._update_secondary()

    def _update_secondary(self):
        secondary_text = ''
        status_text = '%s%%' % (self._level, )

        progress_widget = self._progress_widget
        if self._status == _STATUS_NOT_PRESENT:
            secondary_text = _('Removed')
            progress_widget = None
        elif self._status == _STATUS_CHARGING:
            secondary_text = _('Charging')
        elif self._status == _STATUS_DISCHARGING:
            if self._level <= self._warning_capacity:
                secondary_text = _('Very little power remaining')
            else:
                minutes_remaining = self._time // 60
                remaining_hourpart = minutes_remaining // 60
                remaining_minpart = minutes_remaining % 60
                # TRANS: do not translate %(hour)d:%(min).2d  it is a variable,
                # only translate the word "remaining"
                secondary_text = _('%(hour)d:%(min).2d remaining') % \
                    {'hour': remaining_hourpart, 'min': remaining_minpart}
        else:
            secondary_text = _('Charged')

        self.set_content(progress_widget)

        self.props.secondary_text = secondary_text
        self._status_label.set_text(status_text)
Esempio n. 46
0
    def __init__(self, abiword_canvas):
        GObject.GObject.__init__(self)

        self.font_name_combo = FontComboBox()
        self.font_name_combo.set_font_name('Sans')
        self._fonts_changed_id = self.font_name_combo.connect(
            'changed', self._font_changed_cb, abiword_canvas)
        self._abi_handler = abiword_canvas.connect('font-family',
                                                   self._font_family_cb)
        self.insert(ToolComboBox(self.font_name_combo), -1)

        self.font_size = FontSize()
        self._abi_handler = abiword_canvas.connect('font-size',
                                                   self._font_size_cb)
        self._changed_id = self.font_size.connect(
            'changed', self._font_size_changed_cb, abiword_canvas)
        self.insert(self.font_size, -1)

        bold = ToggleToolButton('format-text-bold')
        bold.set_tooltip(_('Bold'))
        bold.props.accelerator = '<Ctrl>B'
        bold_id = bold.connect('clicked', lambda sender:
                               abiword_canvas.toggle_bold())
        abiword_canvas.connect('bold', lambda abi, b:
                               self._setToggleButtonState(bold, b, bold_id))
        self.insert(bold, -1)

        italic = ToggleToolButton('format-text-italic')
        italic.set_tooltip(_('Italic'))
        italic.props.accelerator = '<Ctrl>I'
        italic_id = italic.connect('clicked', lambda sender:
                                   abiword_canvas.toggle_italic())
        abiword_canvas.connect('italic', lambda abi, b:
                               self._setToggleButtonState(italic, b,
                                                          italic_id))
        self.insert(italic, -1)

        underline = ToggleToolButton('format-text-underline')
        underline.set_tooltip(_('Underline'))
        underline.props.accelerator = '<Ctrl>U'
        underline_id = underline.connect('clicked', lambda sender:
                                         abiword_canvas.toggle_underline())
        abiword_canvas.connect('underline', lambda abi, b:
                               self._setToggleButtonState(underline, b,
                                                          underline_id))
        self.insert(underline, -1)

        color = ColorToolButton()
        color.connect('notify::color', self._text_color_cb,
                      abiword_canvas)
        tool_item = Gtk.ToolItem()
        tool_item.add(color)
        self.insert(tool_item, -1)
        abiword_canvas.connect(
            'color', lambda abi, r, g, b:
            color.set_color(Gdk.Color(r * 256, g * 256, b * 256)))

        # MAGIC NUMBER WARNING: Secondary toolbars are not a standard height?
        self.set_size_request(-1, style.GRID_CELL_SIZE)

        def append_align(icon_name, tooltip, do_abi_cb, style_name, button,
                         menu_box):
            menu_item = AbiMenuItem(abiword_canvas, style_name, do_abi_cb,
                                    icon_name, tooltip, button)
            menu_box.append_item(menu_item)
            menu_item.show()

        self._aligment_btn = ToolButton(icon_name='format-justify-left')
        self._aligment_btn.props.tooltip = _('Choose alignment')
        self._aligment_btn.props.hide_tooltip_on_click = False
        self._aligment_btn.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        self._aligment_btn.props.palette.set_content(menu_box)
        menu_box.show()

        append_align('format-justify-left', _('Left justify'),
                     abiword_canvas.align_left, 'left-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-center', _('Center justify'),
                     abiword_canvas.align_center, 'center-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-right', _('Right justify'),
                     abiword_canvas.align_right, 'right-align',
                     self._aligment_btn, menu_box)

        append_align('format-justify-fill', _('Fill justify'),
                     abiword_canvas.align_justify, 'justify-align',
                     self._aligment_btn, menu_box)

        self.insert(self._aligment_btn, -1)

        self.show_all()
Esempio n. 47
0
    def __init__(self, abi):
        GObject.GObject.__init__(self)

        def append_style(icon_name, tooltip, do_abi_cb, on_abi_cb):
            button = AbiButton(abi, 'style-name', do_abi_cb, on_abi_cb)
            button.props.icon_name = icon_name
            button.props.group = group
            button.props.tooltip = tooltip
            self.insert(button, -1)
            return button

        group = None

        group = append_style(
            'list-none', _('Normal'),
            lambda: abi.set_style('Normal'),
            lambda abi, style: style not in [
                'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4',
                'Block Text', 'Plain Text'])

        append_style('paragraph-h1', _('Heading 1'),
                     lambda: abi.set_style('Heading 1'),
                     lambda abi, style: style == 'Heading 1')

        append_style('paragraph-h2', _('Heading 2'),
                     lambda: abi.set_style('Heading 2'),
                     lambda abi, style: style == 'Heading 2')

        append_style('paragraph-h3', _('Heading 3'),
                     lambda: abi.set_style('Heading 3'),
                     lambda abi, style: style == 'Heading 3')

        append_style('paragraph-h4', _('Heading 4'),
                     lambda: abi.set_style('Heading 4'),
                     lambda abi, style: style == 'Heading 4')

        append_style('paragraph-blocktext', _('Block Text'),
                     lambda: abi.set_style('Block Text'),
                     lambda abi, style: style == 'Block Text')

        append_style('paragraph-plaintext', _('Plain Text'),
                     lambda: abi.set_style('Plain Text'),
                     lambda abi, style: style == 'Plain Text')

        self.insert(Gtk.SeparatorToolItem(), -1)

        def append_list(icon_name, tooltip, do_abi_cb, on_abi_cb, button,
                        menu_box, button_icon=None):
            menu_item = AbiMenuItem(
                abi, 'style-name', do_abi_cb,
                icon_name, tooltip, button, on_abi_cb, button_icon)
            menu_box.append_item(menu_item)
            menu_item.show()

        list_btn = ToolButton(icon_name='toolbar-bulletlist')
        list_btn.props.tooltip = _('Select list')
        list_btn.props.hide_tooltip_on_click = False
        list_btn.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        list_btn.props.palette.set_content(menu_box)
        menu_box.show()

        append_list('list-none', _('Normal'),
                    lambda: abi.set_style('Normal'),
                    lambda abi, style:
                    style not in ['Bullet List',
                                  'Dashed List',
                                  'Numbered List',
                                  'Lower Case List',
                                  'Upper Case List'],
                    list_btn, menu_box, 'toolbar-bulletlist')

        append_list('list-bullet', _('Bullet List'),
                    lambda: abi.set_style('Bullet List'),
                    lambda abi, style: style == 'Bullet List', list_btn,
                    menu_box)

        append_list('list-dashed', _('Dashed List'),
                    lambda: abi.set_style('Dashed List'),
                    lambda abi, style: style == 'Dashed List', list_btn,
                    menu_box)

        append_list('list-numbered', _('Numbered List'),
                    lambda: abi.set_style('Numbered List'),
                    lambda abi, style: style == 'Numbered List', list_btn,
                    menu_box)

        append_list('list-lower-case', _('Lower Case List'),
                    lambda: abi.set_style('Lower Case List'),
                    lambda abi, style: style == 'Lower Case List', list_btn,
                    menu_box)

        append_list('list-upper-case', _('Upper Case List'),
                    lambda: abi.set_style('Upper Case List'),
                    lambda abi, style: style == 'Upper Case List', list_btn,
                    menu_box)

        self.insert(list_btn, -1)

        self.show_all()
Esempio n. 48
0
    def __init__(self, abi):
        GObject.GObject.__init__(self)

        def append_style(icon_name, tooltip, do_abi_cb, on_abi_cb):
            button = AbiButton(abi, 'style-name', do_abi_cb, on_abi_cb)
            button.props.icon_name = icon_name
            button.props.group = group
            button.props.tooltip = tooltip
            self.insert(button, -1)
            return button

        group = None

        group = append_style(
            'list-none', _('Normal'),
            lambda: abi.set_style('Normal'),
            lambda abi, style: style not in [
                'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4',
                'Block Text', 'Plain Text'])

        append_style('paragraph-h1', _('Heading 1'),
                     lambda: abi.set_style('Heading 1'),
                     lambda abi, style: style == 'Heading 1')

        append_style('paragraph-h2', _('Heading 2'),
                     lambda: abi.set_style('Heading 2'),
                     lambda abi, style: style == 'Heading 2')

        append_style('paragraph-h3', _('Heading 3'),
                     lambda: abi.set_style('Heading 3'),
                     lambda abi, style: style == 'Heading 3')

        append_style('paragraph-h4', _('Heading 4'),
                     lambda: abi.set_style('Heading 4'),
                     lambda abi, style: style == 'Heading 4')

        append_style('paragraph-blocktext', _('Block Text'),
                     lambda: abi.set_style('Block Text'),
                     lambda abi, style: style == 'Block Text')

        append_style('paragraph-plaintext', _('Plain Text'),
                     lambda: abi.set_style('Plain Text'),
                     lambda abi, style: style == 'Plain Text')

        self.insert(Gtk.SeparatorToolItem(), -1)

        def append_list(icon_name, tooltip, do_abi_cb, on_abi_cb, button,
                        menu_box, button_icon=None):
            menu_item = AbiMenuItem(
                abi, 'style-name', do_abi_cb,
                icon_name, tooltip, button, on_abi_cb, button_icon)
            menu_box.append_item(menu_item)
            menu_item.show()

        list_btn = ToolButton(icon_name='toolbar-bulletlist')
        list_btn.props.tooltip = _('Select list')
        list_btn.props.hide_tooltip_on_click = False
        list_btn.palette_invoker.props.toggle_palette = True

        menu_box = PaletteMenuBox()
        list_btn.props.palette.set_content(menu_box)
        menu_box.show()

        append_list('list-none', _('Normal'),
                    lambda: abi.set_style('Normal'),
                    lambda abi, style:
                    style not in ['Bullet List',
                                  'Dashed List',
                                  'Numbered List',
                                  'Lower Case List',
                                  'Upper Case List'],
                    list_btn, menu_box, 'toolbar-bulletlist')

        append_list('list-bullet', _('Bullet List'),
                    lambda: abi.set_style('Bullet List'),
                    lambda abi, style: style == 'Bullet List', list_btn,
                    menu_box)

        append_list('list-dashed', _('Dashed List'),
                    lambda: abi.set_style('Dashed List'),
                    lambda abi, style: style == 'Dashed List', list_btn,
                    menu_box)

        append_list('list-numbered', _('Numbered List'),
                    lambda: abi.set_style('Numbered List'),
                    lambda abi, style: style == 'Numbered List', list_btn,
                    menu_box)

        append_list('list-lower-case', _('Lower Case List'),
                    lambda: abi.set_style('Lower Case List'),
                    lambda abi, style: style == 'Lower Case List', list_btn,
                    menu_box)

        append_list('list-upper-case', _('Upper Case List'),
                    lambda: abi.set_style('Upper Case List'),
                    lambda abi, style: style == 'Upper Case List', list_btn,
                    menu_box)

        self.insert(list_btn, -1)

        self.show_all()
Esempio n. 49
0
    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()
Esempio n. 50
0
    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title('Palettes')
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)

        vbox = Gtk.VBox()

        toolbarbox = ToolbarBox()
        vbox.add(toolbarbox)

        toolbar = toolbarbox.toolbar

        color_button = ColorToolButton()
        toolbar.insert(color_button, -1)

        button = ToolButton('list-add')
        button.set_tooltip('Palette with widgets')
        toolbar.insert(button, -1)

        palette = button.get_palette()
        palette_box = Gtk.VBox()
        palette.set_content(palette_box)

        checkbutton1 = Gtk.CheckButton(label='Option 1')
        palette_box.pack_start(checkbutton1, False, False, 0)

        checkbutton2 = Gtk.CheckButton(label='Option 2')
        palette_box.pack_start(checkbutton2, False, False, 0)

        checkbutton3 = Gtk.CheckButton(label='Option 3')
        palette_box.pack_start(checkbutton3, False, False, 0)

        separator = Gtk.VSeparator()
        palette_box.pack_start(separator, False, False, 0)

        radio_button1 = Gtk.RadioButton(label='Option 1')
        palette_box.pack_start(radio_button1, False, False, 0)

        radio_button2 = Gtk.RadioButton(label='Option 2', group=radio_button1)
        palette_box.pack_start(radio_button2, False, False, 0)

        radio_button3 = Gtk.RadioButton(label='Option 3', group=radio_button1)
        palette_box.pack_start(radio_button3, False, False, 0)

        palette_box.show_all()

        button = ToolButton(icon_name='format-justify-fill')
        button.props.tooltip = 'Select list'
        button.props.hide_tooltip_on_click = False
        button.palette_invoker.props.toggle_palette = True
        toolbar.insert(button, -1)

        menu_box = PaletteMenuBox()
        button.props.palette.set_content(menu_box)
        menu_box.show()

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-fill')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1',
                                    icon_name='format-justify-center')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-left')
        menu_box.append_item(menu_item)

        menu_item = PaletteMenuItem('Item 1', icon_name='format-justify-right')
        menu_box.append_item(menu_item)

        self.add(vbox)
        self.show_all()

        self.connect('destroy', Gtk.main_quit)
Esempio n. 51
0
class FontComboBox(Gtk.ToolItem):

    __gsignals__ = {
        "changed": (GObject.SignalFlags.RUN_LAST, None, [str]),
    }

    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 _init_font_list(self):
        self._font_white_list = []
        self._font_white_list.extend(G.DEFAULT_FONTS)

        if not os.path.exists(G.USER_FONTS_FILE_PATH):
            if os.path.exists(G.GLOBAL_FONTS_FILE_PATH):
                shutil.copy(G.GLOBAL_FONTS_FILE_PATH, G.USER_FONTS_FILE_PATH)

        if os.path.exists(G.USER_FONTS_FILE_PATH):
            fonts_file = open(G.USER_FONTS_FILE_PATH)
            for line in fonts_file:
                self._font_white_list.append(line.strip())

            gio_fonts_file = Gio.File.new_for_path(G.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(G.DEFAULT_FONTS)
        fonts_file = open(G.USER_FONTS_FILE_PATH)

        for line in fonts_file:
            self._font_white_list.append(line.strip())

        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():
            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)

        return False

    def __font_selected_cb(self, menu, font_name):
        self._font_name = font_name
        self._font_label.set_font(font_name)
        self.emit("changed", self._font_name)

    def _add_menu(self, font_name, activate_cb):
        label = '<span font="%s">%s</span>' % (font_name, font_name)
        menu_item = PaletteMenuItem()
        menu_item.set_label(label)
        menu_item.connect("activate", activate_cb, font_name)
        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()
        self._palette_invoker = palette_invoker

    palette_invoker = GObject.property(type=object,
                                       setter=set_palette_invoker,
                                       getter=get_palette_invoker)

    def set_font_name(self, font_name):
        self._font_label.set_font(font_name)

    def get_font_name(self):
        return self._font_name
Esempio n. 52
0
class CurrentActivityPalette(BasePalette):

    __gsignals__ = {"done": (GObject.SignalFlags.RUN_FIRST, None, ([]))}

    def __init__(self, home_activity):
        self._home_activity = home_activity
        BasePalette.__init__(self, home_activity)

    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)
        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 __resume_activate_cb(self, menu_item):
        self._home_activity.get_window().activate(Gtk.get_current_event_time())
        self.emit("done")

    def __view_source__cb(self, menu_item):
        setup_view_source(self._home_activity)
        shell_model = shell.get_model()
        if self._home_activity is not shell_model.get_active_activity():
            self._home_activity.get_window().activate(Gtk.get_current_event_time())
        self.emit("done")

    def __view_help__cb(self, menu_item):
        setup_view_help(self._home_activity)
        self.emit("done")

    def __stop_activate_cb(self, menu_item):
        self._home_activity.stop()
        self.emit("done")
Esempio n. 53
0
class CurrentActivityPalette(BasePalette):

    __gsignals__ = {
        'done': (GObject.SignalFlags.RUN_FIRST,
                 None,
                 ([])),
    }

    def __init__(self, home_activity):
        self._home_activity = home_activity
        BasePalette.__init__(self, home_activity)

    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()

        if should_show_view_help(self._home_activity):
            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 __resume_activate_cb(self, menu_item):
        self._home_activity.get_window().activate(Gtk.get_current_event_time())
        self.emit('done')

    def __view_source__cb(self, menu_item):
        setup_view_source(self._home_activity)
        shell_model = shell.get_model()
        if self._home_activity is not shell_model.get_active_activity():
            self._home_activity.get_window().activate(
                Gtk.get_current_event_time())
        self.emit('done')

    def __view_help__cb(self, menu_item):
        setup_view_help(self._home_activity)
        self.emit('done')

    def __stop_activate_cb(self, menu_item):
        self._home_activity.stop()
        pid = self._home_activity.get_pid()
        GObject.timeout_add(3000, self.__kill_cb, pid, signal.SIGTERM)
        GObject.timeout_add(4500, self.__kill_cb, pid, signal.SIGKILL)
        self.emit('done')

    def __kill_cb(self, pid, sig):
        try:
            os.kill(pid, sig)
        finally:
            return False
Esempio n. 54
0
class DetailToolbox(ToolbarBox):
    __gsignals__ = {
        'volume-error': (GObject.SignalFlags.RUN_FIRST, None, ([str, str])),
    }

    def __init__(self, journalactivity):
        ToolbarBox.__init__(self)
        self._journalactivity = journalactivity
        self._metadata = None
        self._temp_file_path = None
        self._refresh = None

        self._resume = ToolButton('activity-start')
        self._resume.connect('clicked', self._resume_clicked_cb)
        self.toolbar.insert(self._resume, -1)
        self._resume.show()
        self._resume_menu = None

        color = profile.get_color()
        self._copy = ToolButton()
        icon = Icon(icon_name='edit-copy', xo_color=color)
        self._copy.set_icon_widget(icon)
        icon.show()
        self._copy.set_tooltip(_('Copy to'))
        self._copy.connect('clicked', self._copy_clicked_cb)
        self.toolbar.insert(self._copy, -1)
        self._copy.show()

        self._duplicate = ToolButton()
        icon = Icon(icon_name='edit-duplicate', xo_color=color)
        self._duplicate.set_icon_widget(icon)
        self._duplicate.set_tooltip(_('Duplicate'))
        self._duplicate.connect('clicked', self._duplicate_clicked_cb)
        self.toolbar.insert(self._duplicate, -1)

        if accountsmanager.has_configured_accounts():
            self._refresh = ToolButton('entry-refresh')
            self._refresh.set_tooltip(_('Refresh'))
            self._refresh.connect('clicked', self._refresh_clicked_cb)
            self.toolbar.insert(self._refresh, -1)
            self._refresh.show()

        separator = Gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)
        separator.show()

        erase_button = ToolButton('list-remove')
        erase_button.set_tooltip(_('Erase'))
        erase_button.connect('clicked', self._erase_button_clicked_cb)
        self.toolbar.insert(erase_button, -1)
        erase_button.show()

    def set_metadata(self, metadata):
        self._metadata = metadata
        self._refresh_copy_palette()
        self._refresh_duplicate_palette()
        self._refresh_refresh_palette()
        self._refresh_resume_palette()

    def _resume_clicked_cb(self, button):
        if not misc.can_resume(self._metadata):
            palette = self._resume.get_palette()
            palette.popup(immediate=True)

        misc.resume(self._metadata,
                    alert_window=journalwindow.get_journal_window())

    def _copy_clicked_cb(self, button):
        button.palette.popup(immediate=True)

    def _refresh_clicked_cb(self, button):
        button.palette.popup(immediate=True)

    def _duplicate_clicked_cb(self, button):
        try:
            model.copy(self._metadata, '/')
        except IOError as e:
            logging.exception('Error while copying the entry.')
            self.emit('volume-error',
                      _('Error while copying the entry. %s') % (e.strerror, ),
                      _('Error'))

    def _erase_button_clicked_cb(self, button):
        alert = Alert()
        erase_string = _('Erase')
        alert.props.title = erase_string
        alert.props.msg = _('Do you want to permanently erase \"%s\"?') \
            % self._metadata['title']
        icon = Icon(icon_name='dialog-cancel')
        alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
        icon.show()
        ok_icon = Icon(icon_name='dialog-ok')
        alert.add_button(Gtk.ResponseType.OK, erase_string, ok_icon)
        ok_icon.show()
        alert.connect('response', self.__erase_alert_response_cb)
        journalwindow.get_journal_window().add_alert(alert)
        alert.show()

    def __erase_alert_response_cb(self, alert, response_id):
        journalwindow.get_journal_window().remove_alert(alert)
        if response_id is Gtk.ResponseType.OK:
            registry = bundleregistry.get_registry()
            bundle = misc.get_bundle(self._metadata)
            if bundle is not None and registry.is_installed(bundle):
                registry.uninstall(bundle)
            model.delete(self._metadata['uid'])

    def _resume_menu_item_activate_cb(self, menu_item, service_name):
        misc.resume(self._metadata,
                    service_name,
                    alert_window=journalwindow.get_journal_window())

    def _refresh_copy_palette(self):
        palette = self._copy.get_palette()

        # Use the menu defined in CopyMenu
        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        CopyMenuBuilder(self._journalactivity, self.__get_uid_list_cb,
                        self.__volume_error_cb, palette.menu)

    def __get_uid_list_cb(self):
        return [self._metadata['uid']]

    def _refresh_duplicate_palette(self):
        color = misc.get_icon_color(self._metadata)
        self._copy.get_icon_widget().props.xo_color = color
        if self._metadata['mountpoint'] == '/':
            self._duplicate.show()
            icon = self._duplicate.get_icon_widget()
            icon.props.xo_color = color
            icon.show()
        else:
            self._duplicate.hide()

    def _refresh_refresh_palette(self):
        if self._refresh is None:
            return

        color = misc.get_icon_color(self._metadata)
        self._refresh.get_icon_widget().props.xo_color = color

        palette = self._refresh.get_palette()
        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)

        for account in accountsmanager.get_configured_accounts():
            if hasattr(account, 'get_shared_journal_entry'):
                entry = account.get_shared_journal_entry()
                if hasattr(entry, 'get_refresh_menu'):
                    menu = entry.get_refresh_menu()
                    palette.menu.append(menu)
                    menu.set_metadata(self._metadata)

    def __volume_error_cb(self, menu_item, message, severity):
        self.emit('volume-error', message, severity)

    def _refresh_resume_palette(self):
        if self._metadata.get('activity_id', ''):
            # TRANS: Action label for resuming an activity.
            self._resume.set_tooltip(_('Resume'))
        else:
            # TRANS: Action label for starting an entry.
            self._resume.set_tooltip(_('Start'))

        palette = self._resume.get_palette()

        if self._resume_menu is not None:
            self._resume_menu.destroy()

        self._resume_menu = PaletteMenuBox()
        palette.set_content(self._resume_menu)
        self._resume_menu.show()

        for activity_info in misc.get_activities(self._metadata):
            menu_item = PaletteMenuItem(file_name=activity_info.get_icon(),
                                        text_label=activity_info.get_name())
            menu_item.connect('activate', self._resume_menu_item_activate_cb,
                              activity_info.get_bundle_id())
            self._resume_menu.append_item(menu_item)
            menu_item.show()

        if not misc.can_resume(self._metadata):
            self._resume.set_tooltip(_('No activity to start entry'))