Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def create_palette(self):
        primary_text = GLib.markup_escape_text(self._model.bundle.get_name())
        secondary_text = GLib.markup_escape_text(self._model.get_name())
        palette_icon = Icon(file=self._model.bundle.get_icon(),
                            xo_color=self._model.get_color())
        palette_icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
        palette = Palette(None,
                          primary_text=primary_text,
                          secondary_text=secondary_text,
                          icon=palette_icon)

        private = self._model.props.private
        joined = get_owner_instance() in self._model.props.buddies

        menu_box = PaletteMenuBox()

        if joined:
            item = PaletteMenuItem(_('Resume'))
            icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)
        elif not private:
            item = PaletteMenuItem(_('Join'))
            icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)

        palette.set_content(menu_box)
        menu_box.show_all()

        self.connect_to_palette_pop_events(palette)
        return palette
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
    def create_palette(self):
        primary_text = self._model.bundle.get_name()
        secondary_text = self._model.get_name()
        palette_icon = Icon(file=self._model.bundle.get_icon(),
                            pixel_size=style.STANDARD_ICON_SIZE,
                            xo_color=self._model.get_color())
        palette = Palette(None,
                          primary_text=primary_text,
                          secondary_text=secondary_text,
                          icon=palette_icon)

        private = self._model.props.private
        joined = get_owner_instance() in self._model.props.buddies
        is_joinable = self._is_joinable is None or self._is_joinable()

        menu_box = PaletteMenuBox()

        if joined:
            item = PaletteMenuItem(_('Resume'))
            icon = Icon(
                pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)
        elif not private and is_joinable:
            item = PaletteMenuItem(_('Join'))
            icon = Icon(
                pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)

        palette.set_content(menu_box)
        menu_box.show_all()

        self.connect_to_palette_pop_events(palette)
        return palette
Ejemplo n.º 7
0
    def create_palette(self):
        primary_text = GLib.markup_escape_text(self._model.bundle.get_name())
        secondary_text = GLib.markup_escape_text(self._model.get_name())
        palette_icon = Icon(file=self._model.bundle.get_icon(),
                            xo_color=self._model.get_color())
        palette_icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
        palette = Palette(None,
                          primary_text=primary_text,
                          secondary_text=secondary_text,
                          icon=palette_icon)

        private = self._model.props.private
        joined = get_owner_instance() in self._model.props.buddies

        menu_box = PaletteMenuBox()

        if joined:
            item = PaletteMenuItem(_('Resume'))
            icon = Icon(icon_size=Gtk.IconSize.MENU,
                        icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)
        elif not private:
            item = PaletteMenuItem(_('Join'))
            icon = Icon(icon_size=Gtk.IconSize.MENU,
                        icon_name='activity-start')
            item.set_image(icon)
            item.connect('activate', self.__palette_item_clicked_cb)
            menu_box.append_item(item)

        palette.set_content(menu_box)
        menu_box.show_all()

        self.connect_to_palette_pop_events(palette)
        return palette
Ejemplo n.º 8
0
 def create_palette(self):
     notification_box = NotificationBox(self._name)
     palette = Palette(self._name)
     palette.set_group_id('frame')
     palette.set_content(notification_box)
     self.set_palette(palette)
Ejemplo n.º 9
0
 def create_palette(self):
     notification_box = NotificationBox(self._name)
     palette = Palette(self._name)
     palette.set_group_id('frame')
     palette.set_content(notification_box)
     self.set_palette(palette)
Ejemplo n.º 10
0
test = common.TestPalette()

palette = Palette('Test radio and toggle')
test.set_palette(palette)

box = Gtk.HBox()

toggle = Gtk.ToggleButton()

icon = Icon(icon_name='go-previous', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
toggle.set_image(icon)

box.pack_start(toggle, False)
toggle.show()

radio = Gtk.RadioButton()

icon = Icon(icon_name='go-next', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
radio.set_image(icon)

radio.set_mode(False)
box.pack_start(radio, False)
radio.show()

palette.set_content(box)
box.show()

if __name__ == '__main__':
    common.main(test)
Ejemplo n.º 11
0
class TagEditor(Gtk.TextView):

    def __init__(self, text, tag_list):
        Gtk.TextView.__init__(self)
        text_buffer = Gtk.TextBuffer()
        self._test_hid = None
        text_buffer.set_text(text)
        self.set_buffer(text_buffer)

        self._palette_invoker = TextViewInvoker(self)
        self._palette_invoker.attach(self)
        self.connect('destroy', self.__destroy_cb)

        text_buffer.connect('changed', self.__buffer_changed_cb)
        self.connect('move-cursor', self.__move_cursor_cb)

    def __destroy_cb(self, icon):
        if self._palette_invoker is not None:
            self._palette_invoker.detach()

    def __buffer_changed_cb(self, text_buffer):
        self._delayed_word_test()

    def __move_cursor_cb(self, text_view, step, count, extended_selection):
        self._delayed_word_test()

    def _delayed_word_test(self):
        if self._test_hid is not None:
            GObject.source_remove(self._test_hid)
        self._test_hid = GObject.timeout_add(TIMEOUT, self._real_word_test)

    def _real_word_test(self):
        tbuffer = self.get_buffer()
        cursor_position = tbuffer.props.cursor_position
        text = tbuffer.get_text(
            tbuffer.get_start_iter(), tbuffer.get_end_iter(), False)
        if cursor_position == len(text):
            if text[cursor_position - 1] == '#':
                self._show_menu()
        else:
            previous_space = text.rfind(' ', 0, cursor_position)
            if text[previous_space + 1] == '#':
                self._show_menu()

    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)

    def _add_tag(self, menu, tag):
        # probably this is not the best way to replace the word
        tbuffer = self.get_buffer()
        cursor_position = tbuffer.props.cursor_position
        text = tbuffer.get_text(
            tbuffer.get_start_iter(), tbuffer.get_end_iter(), False)

        bold_tag = tbuffer.create_tag('b', weight=Pango.Weight.BOLD)
        if cursor_position == len(text):
            start_iter = tbuffer.get_iter_at_offset(len(text) - 2)
            end_iter = tbuffer.get_end_iter()
        else:
            previous_space = text.rfind(' ', 0, cursor_position)
            next_space = text.find(' ', cursor_position)
            start_iter = tbuffer.get_iter_at_offset(previous_space)
            end_iter = tbuffer.get_iter_at_offset(next_space)

        tbuffer.delete(start_iter, end_iter)
        tbuffer.insert_with_tags(start_iter, tag, bold_tag)