def __init__(self, _parent):
        SugarEditToolbar.__init__(self)

        self._parent = _parent

        self.undo.connect('clicked', self.__undo_cb)
        self.redo.connect('clicked', self.__redo_cb)
        self.copy.connect('clicked', self.__copy_cb)
        self.paste.connect('clicked', self.__paste_cb)

        menu_item = MenuItem(_('Cut'))
        menu_item.connect('activate', self.__cut_cb)
        menu_item.show()
        self.copy.get_palette().menu.append(menu_item)

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

        self.erase_button = ToolButton('edit-delete')
        self.erase_button.set_tooltip(_('Erase selected thought(s)'))
        self.erase_button.connect('clicked', self.__delete_cb)
        self.insert(self.erase_button, -1)

        self.show_all()
        self.clipboard = Gtk.Clipboard()

        self.copy.set_sensitive(False)
        self.paste.set_sensitive(False)
        self.erase_button.set_sensitive(False)
예제 #2
0
    def __init__(self, file_name, document_path, title, bundle=False):
        RadioToolButton.__init__(self)

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

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

        client = GConf.Client.get_default()
        self._color = client.get_string('/desktop/sugar/user/color')
        icon = Icon(file=file_name,
                    icon_size=Gtk.IconSize.LARGE_TOOLBAR,
                    xo_color=XoColor(self._color))
        self.set_icon_widget(icon)
        icon.show()

        if bundle:
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        icon_size=Gtk.IconSize.MENU,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__copy_to_home_cb)
        else:
            menu_item = MenuItem(_('Keep'))
            icon = Icon(icon_name='document-save',
                        icon_size=Gtk.IconSize.MENU,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        menu_item.set_image(icon)

        self.props.palette.menu.append(menu_item)
        menu_item.show()
예제 #3
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    def __init__(self):
        Gtk.Menu.__init__(self)

        if filetransfer.file_transfer_available():
            friends_model = friends.get_model()
            for friend in friends_model:
                if friend.is_present():
                    menu_item = MenuItem(text_label=friend.get_nick(),
                                         icon_name='computer-xo',
                                         xo_color=friend.get_color())
                    menu_item.connect('activate', self.__item_activate_cb,
                                      friend)
                    self.append(menu_item)
                    menu_item.show()

            if not self.get_children():
                menu_item = MenuItem(_('No friends present'))
                menu_item.set_sensitive(False)
                self.append(menu_item)
                menu_item.show()
        else:
            menu_item = MenuItem(_('No valid connection found'))
            menu_item.set_sensitive(False)
            self.append(menu_item)
            menu_item.show()
예제 #4
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

        if joined:
            item = MenuItem(_('Resume'), 'activity-start')
            item.connect('activate', self.__palette_item_clicked_cb)
            item.show()
            palette.menu.append(item)
        elif not private:
            item = MenuItem(_('Join'), 'activity-start')
            item.connect('activate', self.__palette_item_clicked_cb)
            item.show()
            palette.menu.append(item)

        self.connect_to_palette_pop_events(palette)
        return palette
예제 #5
0
    def __init__(self, calc):
        Gtk.Toolbar.__init__(self)

        copy_tool = ToolButton('edit-copy')
        copy_tool.set_tooltip(_('Copy'))
        copy_tool.set_accelerator(_('<ctrl>c'))
        copy_tool.connect('clicked', lambda x: calc.text_copy())
        self.insert(copy_tool, -1)

        menu_item = MenuItem(_('Cut'))

        try:
            menu_item.set_accelerator(_('<ctrl>x'))
        except AttributeError:
            pass

        menu_item.connect('activate', lambda x: calc.text_cut())
        menu_item.show()
        copy_tool.get_palette().menu.append(menu_item)

        self.insert(IconToolButton('edit-paste', _('Paste'),
                                   lambda x: calc.text_paste(),
                                   alt_html='Paste'), -1)

        self.show_all()
예제 #6
0
 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.props.palette.menu.get_children():
         self.props.palette.menu.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 font_name in sorted(tmp_list):
         menu_item = MenuItem(font_name)
         markup = '<span font="%s">%s</span>' % (font_name, font_name)
         menu_item.get_children()[0].set_markup(markup)
         menu_item.connect('activate', self.__menu_activated, font_name)
         self.props.palette.menu.append(menu_item)
         menu_item.show()
     return False
    def __init__(self, title, url, owner_document):
        Palette.__init__(self)

        self._title = title
        self._url = url
        self._owner_document = owner_document

        self.props.primary_text = title
        self.props.secondary_text = url

        menu_item = MenuItem(_('Keep image'))
        icon = Icon(icon_name='document-save', xo_color=profile.get_color(),
                    icon_size=Gtk.IconSize.MENU)
        menu_item.set_image(icon)
        menu_item.connect('activate', self.__download_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_('Copy image'))
        icon = Icon(icon_name='edit-copy', xo_color=profile.get_color(),
                    icon_size=Gtk.IconSize.MENU)
        menu_item.set_image(icon)
        menu_item.connect('activate', self.__copy_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()
예제 #8
0
    def __init__(self):
        Gtk.ComboBox.__init__(self)

        ToolButton.__init__(self, icon_name='font-text',
                            tooltip=_('Select font'))
        self.connect('clicked', self.__font_selection_cb)

        context = self.get_pango_context()

        self._init_font_list()

        self._font_name = 'Sans'
        font_names = []

        for family in context.list_families():
            name = family.get_name()
            if name in self._font_white_list:
                font_names.append(name)

        for font_name in sorted(font_names):
            menu_item = MenuItem(font_name)
            markup = '<span font="%s">%s</span>' % (font_name, font_name)
            menu_item.get_children()[0].set_markup(markup)
            menu_item.connect('activate', self.__menu_activated, font_name)
            self.props.palette.menu.append(menu_item)
            menu_item.show()

        self.show()
예제 #9
0
    def refresh_activity_list(self):
        self.menu = Gtk.Menu()

        def process_dir(activity_path):
            for dir_name in sorted(os.listdir(activity_path)):
                bundles_installed = []
                if dir_name.endswith('.activity'):
                    bundle_dir = os.path.join(activity_path, dir_name)
                    bundle = ActivityBundle(bundle_dir)
                    bundles_installed.append(bundle)

                    item = MenuItem(file_name=bundle.get_icon(),
                                    xo_color=xocolor.XoColor())
                    item.set_label(bundle.get_name())
                    item.set_reserve_indicator(True)
                    item.set_submenu(self.make_submenu(bundle))
                    self.menu.append(item)

        process_dir('/usr/share/sugar/activities/')
        process_dir(activities_path) # ~/Activities

        separator = Gtk.SeparatorMenuItem()
        self.menu.append(separator)

        about = MenuItem()
        about.set_label("About")
        about.connect("activate", self.show_about_dialog)
        self.menu.append(about)

        quit = MenuItem()
        quit.set_label("Quit")
        quit.connect("activate", Gtk.main_quit)
        self.menu.append(quit)

        self.menu.show_all()
예제 #10
0
 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.props.palette.menu.get_children():
         self.props.palette.menu.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 font_name in sorted(tmp_list):
         menu_item = MenuItem(font_name)
         markup = '<span font="%s">%s</span>' % (font_name, font_name)
         menu_item.get_children()[0].set_markup(markup)
         menu_item.connect('activate', self.__menu_activated, font_name)
         self.props.palette.menu.append(menu_item)
         menu_item.show()
     return False
예제 #11
0
    def __init__(self, file_name, document_path, title, bundle=False):
        RadioToolButton.__init__(self)

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

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

        client = GConf.Client.get_default()
        self._color = client.get_string('/desktop/sugar/user/color')
        icon = Icon(file=file_name,
                    icon_size=Gtk.IconSize.LARGE_TOOLBAR,
                    xo_color=XoColor(self._color))
        self.set_icon_widget(icon)
        icon.show()

        if bundle:
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        icon_size=Gtk.IconSize.MENU,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__copy_to_home_cb)
        else:
            menu_item = MenuItem(_('Keep'))
            icon = Icon(icon_name='document-save',
                        icon_size=Gtk.IconSize.MENU,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        menu_item.set_image(icon)

        self.props.palette.menu.append(menu_item)
        menu_item.show()
예제 #12
0
    def __init__(self, calc):
        Gtk.Toolbar.__init__(self)

        copy_tool = ToolButton('edit-copy')
        copy_tool.set_tooltip(_('Copy'))
        copy_tool.set_accelerator(_('<ctrl>c'))
        copy_tool.connect('clicked', lambda x: calc.text_copy())
        self.insert(copy_tool, -1)

        menu_item = MenuItem(_('Cut'))

        try:
            menu_item.set_accelerator(_('<ctrl>x'))
        except AttributeError:
            pass

        menu_item.connect('activate', lambda x: calc.text_cut())
        menu_item.show()
        copy_tool.get_palette().menu.append(menu_item)

        self.insert(
            IconToolButton('edit-paste',
                           _('Paste'),
                           lambda x: calc.text_paste(),
                           alt_html='Paste'), -1)

        self.show_all()
예제 #13
0
    def __init__(self, file_name, document_path, title, bundle=False):
        RadioToolButton.__init__(self)

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

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

        if bundle:
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        pixel_size=style.SMALL_ICON_SIZE,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__copy_to_home_cb)
        else:
            menu_item = MenuItem(_('Keep'))
            icon = Icon(icon_name='document-save',
                        pixel_size=style.SMALL_ICON_SIZE,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        menu_item.set_image(icon)

        self.props.palette.menu.append(menu_item)
        menu_item.show()
예제 #14
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

        if joined:
            item = MenuItem(_('Resume'), 'activity-start')
            item.connect('activate', self.__palette_item_clicked_cb)
            item.show()
            palette.menu.append(item)
        elif not private:
            item = MenuItem(_('Join'), 'activity-start')
            item.connect('activate', self.__palette_item_clicked_cb)
            item.show()
            palette.menu.append(item)

        self.connect_to_palette_pop_events(palette)
        return palette
예제 #15
0
    def __init__(self, invite):
        Palette.__init__(self, '')

        self._invite = invite

        menu_item = MenuItem(_('Join'), icon_name='dialog-ok')
        menu_item.connect('activate', self.__join_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_('Decline'), icon_name='dialog-cancel')
        menu_item.connect('activate', self.__decline_activate_cb)
        self.menu.append(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:
            name = self._bundle.get_name()
        else:
            name = bundle_id

        self.set_primary_text(name)
예제 #16
0
파일: viewsource.py 프로젝트: svineet/sugar
    def __init__(self, file_name, document_path, title, bundle=False):
        RadioToolButton.__init__(self)

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

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

        settings = Gio.Settings("org.sugarlabs.user")
        self._color = settings.get_string("color")
        icon = Icon(file=file_name, icon_size=Gtk.IconSize.LARGE_TOOLBAR, xo_color=XoColor(self._color))
        self.set_icon_widget(icon)
        icon.show()

        if bundle:
            menu_item = MenuItem(_("Duplicate"))
            icon = Icon(icon_name="edit-duplicate", icon_size=Gtk.IconSize.MENU, xo_color=XoColor(self._color))
            menu_item.connect("activate", self.__copy_to_home_cb)
        else:
            menu_item = MenuItem(_("Keep"))
            icon = Icon(icon_name="document-save", icon_size=Gtk.IconSize.MENU, xo_color=XoColor(self._color))
            menu_item.connect("activate", self.__keep_in_journal_cb)

        menu_item.set_image(icon)

        self.props.palette.menu.append(menu_item)
        menu_item.show()
예제 #17
0
    def __init__(self, file_name, document_path, title, bundle=False):
        RadioToolButton.__init__(self)

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

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

        if bundle:
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        pixel_size=style.SMALL_ICON_SIZE,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__copy_to_home_cb)
        else:
            menu_item = MenuItem(_('Keep'))
            icon = Icon(icon_name='document-save',
                        pixel_size=style.SMALL_ICON_SIZE,
                        xo_color=XoColor(self._color))
            menu_item.connect('activate', self.__keep_in_journal_cb)

        menu_item.set_image(icon)

        self.props.palette.menu.append(menu_item)
        menu_item.show()
예제 #18
0
    def __init__(self, invite):
        Palette.__init__(self, "")

        self._invite = invite

        menu_item = MenuItem(_("Join"), icon_name="dialog-ok")
        menu_item.connect("activate", self.__join_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_("Decline"), icon_name="dialog-cancel")
        menu_item.connect("activate", self.__decline_activate_cb)
        self.menu.append(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:
            name = self._bundle.get_name()
        else:
            name = bundle_id

        self.set_primary_text(GLib.markup_escape_text(name))
예제 #19
0
    def __init__(self, _parent):
        SugarEditToolbar.__init__(self)

        self._parent = _parent

        self.undo.connect('clicked', self.__undo_cb)
        self.redo.connect('clicked', self.__redo_cb)
        self.copy.connect('clicked', self.__copy_cb)
        self.paste.connect('clicked', self.__paste_cb)

        menu_item = MenuItem(_('Cut'))
        menu_item.connect('activate', self.__cut_cb)
        menu_item.show()
        self.copy.get_palette().menu.append(menu_item)

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

        self.erase_button = ToolButton('edit-delete')
        self.erase_button.set_tooltip(_('Erase selected thought(s)'))
        self.erase_button.connect('clicked', self.__delete_cb)
        self.insert(self.erase_button, -1)

        self.show_all()
        self.clipboard = Gtk.Clipboard()

        self.copy.set_sensitive(False)
        self.paste.set_sensitive(False)
        self.erase_button.set_sensitive(False)
예제 #20
0
    def __init__(self):
        Gtk.Menu.__init__(self)

        if filetransfer.file_transfer_available():
            friends_model = friends.get_model()
            for friend in friends_model:
                if friend.is_present():
                    menu_item = MenuItem(text_label=friend.get_nick(),
                                         icon_name='computer-xo',
                                         xo_color=friend.get_color())
                    menu_item.connect('activate', self.__item_activate_cb,
                                      friend)
                    self.append(menu_item)
                    menu_item.show()

            if not self.get_children():
                menu_item = MenuItem(_('No friends present'))
                menu_item.set_sensitive(False)
                self.append(menu_item)
                menu_item.show()
        else:
            menu_item = MenuItem(_('No valid connection found'))
            menu_item.set_sensitive(False)
            self.append(menu_item)
            menu_item.show()
예제 #21
0
    def __init__(self):
        ToolButton.__init__(self,
                            icon_name='font-text',
                            tooltip=_('Select font'))
        self.connect('clicked', self.__font_selection_cb)

        context = self.get_pango_context()

        self._init_font_list()

        self._font_name = 'Sans'
        font_names = []

        for family in context.list_families():
            name = family.get_name()
            if name in self._font_white_list:
                font_names.append(name)

        for font_name in sorted(font_names):
            menu_item = MenuItem(font_name)
            markup = '<span font="%s">%s</span>' % (font_name, font_name)
            menu_item.get_children()[0].set_markup(markup)
            menu_item.connect('activate', self.__menu_activated, font_name)
            self.props.palette.menu.append(menu_item)
            menu_item.show()

        self.show()
예제 #22
0
    def _setup_notes_palette(self):
        self._notes_palette = self._notes_button.get_palette()

        for note in NOTES:
            menu_item = MenuItem(icon_name='', text_label=note)
            menu_item.connect('activate', self._note_selected_cb, note)
            self._notes_palette.menu.append(menu_item)
            menu_item.show()
예제 #23
0
    def _setup_octaves_palette(self):
        self._octaves_palette = self._octaves_button.get_palette()

        for octave in range(9):
            menu_item = MenuItem(icon_name='', text_label=str(octave))
            menu_item.connect('activate', self._octave_selected_cb, octave)
            self._octaves_palette.menu.append(menu_item)
            menu_item.show()
예제 #24
0
    def _setup_notes_palette(self):
        self._notes_palette = self._notes_button.get_palette()

        for note in NOTES:
            menu_item = MenuItem(icon_name='',
                                 text_label=note)
            menu_item.connect('activate', self._note_selected_cb, note)
            self._notes_palette.menu.append(menu_item)
            menu_item.show()
예제 #25
0
    def _add_erase_option(self, registry, activity_info):
        menu_item = MenuItem(_('Erase'), 'list-remove')
        menu_item.connect('activate', self.__erase_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        if not os.access(activity_info.get_path(), os.W_OK) or \
           registry.is_activity_protected(self._bundle_id):
            menu_item.props.sensitive = False
예제 #26
0
    def _setup_octaves_palette(self):
        self._octaves_palette = self._octaves_button.get_palette()

        for octave in range(9):
            menu_item = MenuItem(icon_name='',
                                 text_label=str(octave))
            menu_item.connect('activate', self._octave_selected_cb, octave)
            self._octaves_palette.menu.append(menu_item)
            menu_item.show()
예제 #27
0
    def _add_erase_option(self, registry, activity_info):
        menu_item = MenuItem(_('Erase'), 'list-remove')
        menu_item.connect('activate', self.__erase_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        if not os.access(activity_info.get_path(), os.W_OK) or \
           registry.is_activity_protected(self._bundle_id):
            menu_item.props.sensitive = False
예제 #28
0
    def __init__(self, activity, abi):
        ToolButton.__init__(self, 'document-save')
        self.props.tooltip = _('Export')
        self.props.label = _('Export')

        for i in self._EXPORT_FORMATS:
            menu_item = MenuItem(i['title'])
            menu_item.connect('activate', self.__activate_cb, activity, abi, i)
            self.props.palette.menu.append(menu_item)
            menu_item.show()
예제 #29
0
    def _setup_robot_palette(self):
        self._robot_palette = self._robot_time_button.get_palette()

        for seconds in ROBOT_TIMER_VALUES:
            text = ROBOT_TIMER_LABELS[seconds]
            menu_item = MenuItem(icon_name='timer-%d' % (seconds),
                                 text_label=text)
            menu_item.connect('activate', self._robot_selected_cb, seconds)
            self._robot_palette.menu.append(menu_item)
            menu_item.show()
예제 #30
0
    def _setup_robot_palette(self):
        self._robot_palette = self._robot_time_button.get_palette()

        for seconds in ROBOT_TIMER_VALUES:
            text = ROBOT_TIMER_LABELS[seconds]
            menu_item = MenuItem(icon_name='timer-%d' % (seconds),
                                 text_label=text)
            menu_item.connect('activate', self._robot_selected_cb, seconds)
            self._robot_palette.menu.append(menu_item)
            menu_item.show()
예제 #31
0
    def _setup_log_palette(self):
        self._log_palette = self._log_button.get_palette()

        for tenth_seconds in LOG_TIMER_VALUES:
            text = self._log_to_string(tenth_seconds)
            menu_item = MenuItem(icon_name='timer-%d' % (tenth_seconds),
                                 text_label=text)
            menu_item.connect('activate', self._log_selected_cb, tenth_seconds)
            self._log_palette.menu.append(menu_item)
            menu_item.show()
예제 #32
0
    def create_palette(self, text, help_cb):
        p = Palette(text)

        if help_cb is not None:
            item = MenuItem(_('Help'), 'action-help')
            item.connect('activate', help_cb)
            item.show()
            p.menu.append(item)

        self.set_palette(p)
예제 #33
0
    def create_palette(self, text, help_cb):
        p = Palette(text)

        if help_cb is not None:
            item = MenuItem(_('Help'), 'action-help')
            item.connect('activate', help_cb)
            item.show()
            p.menu.append(item)

        self.set_palette(p)
예제 #34
0
    def __init__(self, activity, abi):
        ToolButton.__init__(self, 'document-save')
        self.props.tooltip = _('Export')
        self.props.label = _('Export')

        for i in self._EXPORT_FORMATS:
            menu_item = MenuItem(i['title'])
            menu_item.connect('activate', self.__activate_cb, activity, abi, i)
            self.props.palette.menu.append(menu_item)
            menu_item.show()
예제 #35
0
    def _setup_instrument_palette(self):
        self.instrument_palette = self._instrument_button.get_palette()

        self.instrument = []
        for k in INSTRUMENT_DICT.keys():
            self.instrument.append(k)
            menu_item = MenuItem(icon_name='', text_label=k)
            menu_item.connect('activate', self.instrument_selected_cb, k)
            self.instrument_palette.menu.append(menu_item)
            menu_item.show()
예제 #36
0
    def _setup_instrument_palette(self):
        self.instrument_palette = self._instrument_button.get_palette()

        self.instrument = []
        for k in INSTRUMENT_DICT.keys():
            self.instrument.append(k)
            menu_item = MenuItem(icon_name='',
                                 text_label=k)
            menu_item.connect('activate', self.instrument_selected_cb, k)
            self.instrument_palette.menu.append(menu_item)
            menu_item.show()
예제 #37
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'

        for property_, icon, label in self._SORT_OPTIONS:
            button = MenuItem(icon_name=icon, text_label=label)
            button.connect('activate', self.__sort_type_changed_cb, property_,
                           icon)
            button.show()
            self.props.palette.menu.insert(button, -1)
예제 #38
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'

        for property_, icon, label in self._SORT_OPTIONS:
            button = MenuItem(icon_name=icon, text_label=label)
            button.connect('activate',
                           self.__sort_type_changed_cb,
                           property_,
                           icon)
            button.show()
            self.props.palette.menu.insert(button, -1)
예제 #39
0
    def _create_back_button(self):
        back = ToolButton('go-previous-paired')
        back.set_tooltip(_('Back'))
        back.props.sensitive = False
        palette = back.get_palette()

        previous_page = MenuItem(text_label=_("Previous page"))
        previous_page.show()
        previous_bookmark = MenuItem(text_label=_("Previous bookmark"))
        previous_bookmark.show()
        palette.menu.append(previous_page)
        palette.menu.append(previous_bookmark)

        back.connect('clicked', self.__go_back_cb)
        previous_page.connect('activate', self.__go_back_page_cb)
        previous_bookmark.connect('activate', self.__prev_bookmark_activate_cb)
        return back
예제 #40
0
    def _create_forward_button(self):
        forward = ToolButton('go-next-paired')
        forward.set_tooltip(_('Forward'))
        forward.props.sensitive = False
        palette = forward.get_palette()

        next_page = MenuItem(text_label=_("Next page"))
        next_page.show()
        next_bookmark = MenuItem(text_label=_("Next bookmark"))
        next_bookmark.show()

        palette.menu.append(next_page)
        palette.menu.append(next_bookmark)

        forward.connect('clicked', self.__go_forward_cb)
        next_page.connect('activate', self.__go_forward_page_cb)
        next_bookmark.connect('activate', self.__next_bookmark_activate_cb)
        return forward
예제 #41
0
    def _setup_tuning_palette(self, instrument):
        self._tuning_palette = self._tuning_button.get_palette()

        self.tuning = []
        self.tuning.append(_('All notes'))
        menu_item = MenuItem(icon_name='', text_label=_('All notes'))
        menu_item.connect('activate', self._tuning_selected_cb, instrument, -1)
        self._tuning_palette.menu.append(menu_item)
        menu_item.show()

        for i, f in enumerate(INSTRUMENT_DICT[instrument]):
            self.tuning.append(freq_note(f))
            menu_item = MenuItem(icon_name='', text_label=freq_note(f))
            menu_item.connect('activate', self._tuning_selected_cb, instrument,
                              i)
            self._tuning_palette.menu.append(menu_item)
            menu_item.show()

        self.show_all()
예제 #42
0
    def new_note_cb(self, *args):
        ''' Add a new note to instrument tuning list '''
        name = self._name_entry.get_text()
        if name not in INSTRUMENT_DICT:
            INSTRUMENT_DICT[name] = []
            self.activity.tuning_toolbar.instrument.append(name)
            menu_item = MenuItem(icon_name='', text_label=name)
            menu_item.connect(
                'activate',
                self.activity.tuning_toolbar.instrument_selected_cb, name)
            self.activity.tuning_toolbar.instrument_palette.menu.append(
                menu_item)
            menu_item.show()
            self.new_instruments.append(name)

        freq = A0 * pow(TWELTHROOT2,
                        self._octave * 12 + NOTES.index(self._note))
        if freq not in INSTRUMENT_DICT[name]:
            INSTRUMENT_DICT[name].append(freq)
예제 #43
0
    def _setup_tuning_palette(self, instrument):
        self._tuning_palette = self._tuning_button.get_palette()

        self.tuning = []
        self.tuning.append(_('All notes'))
        menu_item = MenuItem(icon_name='', text_label=_('All notes'))
        menu_item.connect('activate', self._tuning_selected_cb,
                          instrument, -1)
        self._tuning_palette.menu.append(menu_item)
        menu_item.show()

        for i, f in enumerate(INSTRUMENT_DICT[instrument]):
            self.tuning.append(freq_note(f))
            menu_item = MenuItem(icon_name='',
                                 text_label=freq_note(f))
            menu_item.connect('activate', self._tuning_selected_cb,
                              instrument, i)
            self._tuning_palette.menu.append(menu_item)
            menu_item.show()

        self.show_all()
예제 #44
0
    def __init__(self, metadata):
        Gtk.Menu.__init__(self)

        self._metadata = metadata

        for activity_info in misc.get_activities(metadata):
            menu_item = MenuItem(activity_info.get_name())
            menu_item.set_image(Icon(file=activity_info.get_icon(), icon_size=Gtk.IconSize.MENU))
            menu_item.connect("activate", self.__item_activate_cb, activity_info.get_bundle_id())
            self.append(menu_item)
            menu_item.show()

        if not self.get_children():
            if metadata.get("activity_id", ""):
                resume_label = _("No activity to resume entry")
            else:
                resume_label = _("No activity to start entry")
            menu_item = MenuItem(resume_label)
            menu_item.set_sensitive(False)
            self.append(menu_item)
            menu_item.show()
예제 #45
0
    def new_note_cb(self, *args):
        ''' Add a new note to instrument tuning list '''
        name = self._name_entry.get_text()
        if name not in INSTRUMENT_DICT:
            INSTRUMENT_DICT[name] = []
            self.activity.tuning_toolbar.instrument.append(name)
            menu_item = MenuItem(icon_name='',
                                 text_label=name)
            menu_item.connect(
                'activate',
                self.activity.tuning_toolbar.instrument_selected_cb,
                name)
            self.activity.tuning_toolbar.instrument_palette.menu.append(
                menu_item)
            menu_item.show()
            self.new_instruments.append(name)

        freq = A0 * pow(TWELTHROOT2,
                        self._octave * 12 + NOTES.index(self._note))
        if freq not in INSTRUMENT_DICT[name]:
            INSTRUMENT_DICT[name].append(freq)
예제 #46
0
    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()

        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        for activity_info in misc.get_activities(self._metadata):
            menu_item = MenuItem(activity_info.get_name())
            menu_item.set_image(Icon(file=activity_info.get_icon(),
                                     icon_size=Gtk.IconSize.MENU))
            menu_item.connect('activate', self._resume_menu_item_activate_cb,
                              activity_info.get_bundle_id())
            palette.menu.append(menu_item)
            menu_item.show()
예제 #47
0
    def __init__(self, metadata):
        Gtk.Menu.__init__(self)

        self._metadata = metadata

        for activity_info in misc.get_activities(metadata):
            menu_item = MenuItem(activity_info.get_name())
            menu_item.set_image(Icon(file=activity_info.get_icon(),
                                     pixel_size=style.SMALL_ICON_SIZE))
            menu_item.connect('activate', self.__item_activate_cb,
                              activity_info.get_bundle_id())
            self.append(menu_item)
            menu_item.show()

        if not self.get_children():
            if metadata.get('activity_id', ''):
                resume_label = _('No activity to resume entry')
            else:
                resume_label = _('No activity to start entry')
            menu_item = MenuItem(resume_label)
            menu_item.set_sensitive(False)
            self.append(menu_item)
            menu_item.show()
예제 #48
0
    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()

        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        for activity_info in misc.get_activities(self._metadata):
            menu_item = MenuItem(activity_info.get_name())
            menu_item.set_image(
                Icon(file=activity_info.get_icon(),
                     icon_size=Gtk.IconSize.MENU))
            menu_item.connect('activate', self._resume_menu_item_activate_cb,
                              activity_info.get_bundle_id())
            palette.menu.append(menu_item)
            menu_item.show()
    def _setup_timer_palette(self):
        self.timer_values = [None, 30, 180, 600]
        self.timer_tooltips = [
            '', _('30 seconds'),
            _('3 minutes'),
            _('10 minutes')
        ]
        self.timer_labels = [
            _('Disabled'),
            # TRANS: Lightning chess 30 seconds between moves
            _('Lightning: %d seconds') % (30),
            # TRANS: Blitz chess 3 minutes between moves
            _('Blitz: %d minutes') % (3),
            # TRANS: Tournament chess 10 minutes between moves
            _('Tournament: %d minutes') % (10)
        ]
        self.timer_palette = self.timer_button.get_palette()

        for i, label in enumerate(self.timer_labels):
            menu_item = MenuItem(icon_name='timer-%d' % (i), text_label=label)
            menu_item.connect('activate', self._timer_selected_cb, i)
            self.timer_palette.menu.append(menu_item)
            menu_item.show()
예제 #50
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    def __init__(self, metadata):
        Gtk.Menu.__init__(self)

        self._metadata = metadata

        for activity_info in misc.get_activities(metadata):
            menu_item = MenuItem(activity_info.get_name())
            menu_item.set_image(Icon(file=activity_info.get_icon(),
                                     pixel_size=style.SMALL_ICON_SIZE))
            menu_item.connect('activate', self.__item_activate_cb,
                              activity_info.get_bundle_id())
            self.append(menu_item)
            menu_item.show()

        if not self.get_children():
            if metadata.get('activity_id', ''):
                resume_label = _('No activity to resume entry')
            else:
                resume_label = _('No activity to start entry')
            menu_item = MenuItem(resume_label)
            menu_item.set_sensitive(False)
            self.append(menu_item)
            menu_item.show()
    def __init__(self, browser, title, url, owner_document):
        Palette.__init__(self)

        self._browser = browser
        self._title = title
        self._url = url
        self._owner_document = owner_document

        if title is not None:
            self.props.primary_text = title
            self.props.secondary_text = url
        else:
            self.props.primary_text = url

        menu_item = MenuItem(_('Follow link'), 'browse-follow-link')
        menu_item.connect('activate', self.__follow_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_('Follow link in new tab'),
                             'browse-follow-link-new-tab')
        menu_item.connect('activate', self.__follow_activate_cb, True)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_('Keep link'))
        icon = Icon(icon_name='document-save', xo_color=profile.get_color(),
                    icon_size=Gtk.IconSize.MENU)
        menu_item.set_image(icon)
        menu_item.connect('activate', self.__download_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()

        menu_item = MenuItem(_('Copy link'))
        icon = Icon(icon_name='edit-copy', xo_color=profile.get_color(),
                    icon_size=Gtk.IconSize.MENU)
        menu_item.set_image(icon)
        menu_item.connect('activate', self.__copy_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()
예제 #52
0
    def make_submenu(self, bundle):
        submenu = Gtk.Menu()

        newitem = MenuItem(icon_name='activity-start')
        newitem.set_label("Start new")
        newitem.connect("activate", self.launch, bundle)
        submenu.append(newitem)

        results, n = _datastore.find(
                            {'limit':10, 
                             'activity':bundle.get_bundle_id()},
                            ['uid', 'title', 'mime_type'])

        if n>0:
            separator = Gtk.SeparatorMenuItem()
            submenu.append(separator)

        for i in results:
            title = ''.join([chr(byte) for byte in i['title']])
            uid = i['uid']

            item = MenuItem(file_name=bundle.get_icon(),
                            xo_color=xocolor.XoColor())
            item.set_label(title)
            item.connect("activate", self.launch_with_uid, bundle, uid)
            submenu.append(item)

        if n>0:
            separator = Gtk.SeparatorMenuItem()
            submenu.append(separator)

        view_source = MenuItem(icon_name='view-source')
        view_source.set_label("View Source")
        view_source.connect("activate", self.view_source, bundle)
        submenu.append(view_source)

        return submenu
예제 #53
0
    def __init__(self, journalactivity, metadata, detail=False):

        self._journalactivity = journalactivity
        self._metadata = metadata

        activity_icon = Icon(pixel_size=style.STANDARD_ICON_SIZE)
        activity_icon.props.file = misc.get_icon_name(metadata)
        color = misc.get_icon_color(metadata)
        activity_icon.props.xo_color = color

        if 'title' in metadata:
            title = metadata['title']
        else:
            title = _('Untitled')

        Palette.__init__(self, primary_text=title, icon=activity_icon)

        description = metadata.get('description', '')
        if description:
            self.set_secondary_text(description)

        if misc.can_resume(metadata):
            if metadata.get('activity_id', ''):
                resume_label = _('Resume')
                resume_with_label = _('Resume with')
            else:
                resume_label = _('Start')
                resume_with_label = _('Start with')
            menu_item = MenuItem(resume_label, 'activity-start')
            menu_item.connect('activate', self.__start_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            menu_item = MenuItem(resume_with_label, 'activity-start')
            self.menu.append(menu_item)
            menu_item.show()
            start_with_menu = StartWithMenu(self._metadata)
            menu_item.set_submenu(start_with_menu)

        elif metadata.get('activity', None) == PROJECT_BUNDLE_ID:
            open_label = _('Open')
            menu_item = MenuItem(open_label, 'project-box')
            menu_item.connect('activate', self.__open_project_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        else:
            menu_item = MenuItem(_('No activity to start entry'))
            menu_item.set_sensitive(False)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Copy to'))
        icon = Icon(icon_name='edit-copy',
                    xo_color=color,
                    pixel_size=style.SMALL_ICON_SIZE)
        menu_item.set_image(icon)
        self.menu.append(menu_item)
        menu_item.show()
        copy_menu = CopyMenu(self._journalactivity, self.__get_uid_list_cb)
        copy_menu.connect('volume-error', self.__volume_error_cb)
        menu_item.set_submenu(copy_menu)

        if not metadata.get('activity', None) == PROJECT_BUNDLE_ID:
            menu_item = MenuItem(_('Send to project...'), 'project-box')
            menu_item.connect('activate', self.__copy_to_project_activated_cb)
            self.menu.append(menu_item)
            menu_item.show()

        if self._metadata['mountpoint'] == '/':
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        xo_color=color,
                        pixel_size=style.SMALL_ICON_SIZE)
            menu_item.set_image(icon)
            menu_item.connect('activate', self.__duplicate_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Send to'), 'document-send')
        self.menu.append(menu_item)
        menu_item.show()

        friends_menu = FriendsMenu()
        friends_menu.connect('friend-selected', self.__friend_selected_cb)
        menu_item.set_submenu(friends_menu)

        if detail is True:
            menu_item = MenuItem(_('View Details'), 'go-right')
            menu_item.connect('activate', self.__detail_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Erase'), 'list-remove')
        menu_item.connect('activate', self.__erase_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()
예제 #54
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    def __init__(self, journalactivity, metadata, detail=False):

        self._journalactivity = journalactivity
        self._metadata = metadata

        activity_icon = Icon(pixel_size=style.STANDARD_ICON_SIZE)
        activity_icon.props.file = misc.get_icon_name(metadata)
        color = misc.get_icon_color(metadata)
        activity_icon.props.xo_color = color

        if 'title' in metadata:
            title = metadata['title']
        else:
            title = _('Untitled')

        Palette.__init__(self, primary_text=title,
                         icon=activity_icon)

        description = metadata.get('description', '')
        if description:
            self.set_secondary_text(description)

        if misc.can_resume(metadata):
            if metadata.get('activity_id', ''):
                resume_label = _('Resume')
                resume_with_label = _('Resume with')
            else:
                resume_label = _('Start')
                resume_with_label = _('Start with')
            menu_item = MenuItem(resume_label, 'activity-start')
            menu_item.connect('activate', self.__start_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            menu_item = MenuItem(resume_with_label, 'activity-start')
            self.menu.append(menu_item)
            menu_item.show()
            start_with_menu = StartWithMenu(self._metadata)
            menu_item.set_submenu(start_with_menu)

        elif metadata.get('activity', None) == PROJECT_BUNDLE_ID:
            open_label = _('Open')
            menu_item = MenuItem(open_label, 'project-box')
            menu_item.connect('activate', self.__open_project_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        else:
            menu_item = MenuItem(_('No activity to start entry'))
            menu_item.set_sensitive(False)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Copy to'))
        icon = Icon(icon_name='edit-copy', xo_color=color,
                    pixel_size=style.SMALL_ICON_SIZE)
        menu_item.set_image(icon)
        self.menu.append(menu_item)
        menu_item.show()
        copy_menu = CopyMenu(self._journalactivity, self.__get_uid_list_cb)
        copy_menu.connect('volume-error', self.__volume_error_cb)
        menu_item.set_submenu(copy_menu)

        if not metadata.get('activity', None) == PROJECT_BUNDLE_ID:
            menu_item = MenuItem(_('Send to project...'), 'project-box')
            menu_item.connect('activate', self.__copy_to_project_activated_cb)
            self.menu.append(menu_item)
            menu_item.show()

        if self._metadata['mountpoint'] == '/':
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate', xo_color=color,
                        pixel_size=style.SMALL_ICON_SIZE)
            menu_item.set_image(icon)
            menu_item.connect('activate', self.__duplicate_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Send to'), 'document-send')
        self.menu.append(menu_item)
        menu_item.show()

        friends_menu = FriendsMenu()
        friends_menu.connect('friend-selected', self.__friend_selected_cb)
        menu_item.set_submenu(friends_menu)

        if detail is True:
            menu_item = MenuItem(_('View Details'), 'go-right')
            menu_item.connect('activate', self.__detail_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Erase'), 'list-remove')
        menu_item.connect('activate', self.__erase_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()
예제 #55
0
    def _update(self):
        new_state = self.file_transfer.props.state
        logging.debug('_update state: %r', new_state)
        if new_state == filetransfer.FT_STATE_PENDING:

            menu_item = MenuItem(_('Cancel'), icon_name='dialog-cancel')
            menu_item.connect('activate', self.__cancel_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            vbox = Gtk.VBox()
            self.set_content(vbox)
            vbox.show()

            if self.file_transfer.description:
                label = Gtk.Label(label=self.file_transfer.description)
                vbox.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))
            vbox.add(label)
            label.show()

        elif new_state in [filetransfer.FT_STATE_ACCEPTED,
                           filetransfer.FT_STATE_OPEN]:

            for item in self.menu.get_children():
                self.menu.remove(item)

            menu_item = MenuItem(_('Cancel'), icon_name='dialog-cancel')
            menu_item.connect('activate', self.__cancel_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            vbox = Gtk.VBox()
            self.set_content(vbox)
            vbox.show()

            self.progress_bar = Gtk.ProgressBar()
            vbox.add(self.progress_bar)
            self.progress_bar.show()

            self.progress_label = Gtk.Label(label='')
            vbox.add(self.progress_label)
            self.progress_label.show()

            self.update_progress()

        elif new_state in [filetransfer.FT_STATE_COMPLETED,
                           filetransfer.FT_STATE_CANCELLED]:

            for item in self.menu.get_children():
                self.menu.remove(item)

            menu_item = MenuItem(_('Dismiss'), icon_name='dialog-cancel')
            menu_item.connect('activate', self.__dismiss_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            self.update_progress()
예제 #56
0
    def __init__(self, journalactivity, metadata, detail=False):

        self._journalactivity = journalactivity
        self._metadata = metadata

        activity_icon = Icon(icon_size=Gtk.IconSize.LARGE_TOOLBAR)
        activity_icon.props.file = misc.get_icon_name(metadata)
        color = misc.get_icon_color(metadata)
        activity_icon.props.xo_color = color

        if 'title' in metadata:
            title = GObject.markup_escape_text(metadata['title'])
        else:
            title = GLib.markup_escape_text(_('Untitled'))

        Palette.__init__(self, primary_text=title, icon=activity_icon)

        if misc.get_activities(metadata) or misc.is_bundle(metadata):
            if metadata.get('activity_id', ''):
                resume_label = _('Resume')
                resume_with_label = _('Resume with')
            else:
                resume_label = _('Start')
                resume_with_label = _('Start with')
            menu_item = MenuItem(resume_label, 'activity-start')
            menu_item.connect('activate', self.__start_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

            menu_item = MenuItem(resume_with_label, 'activity-start')
            self.menu.append(menu_item)
            menu_item.show()
            start_with_menu = StartWithMenu(self._metadata)
            menu_item.set_submenu(start_with_menu)

        else:
            menu_item = MenuItem(_('No activity to start entry'))
            menu_item.set_sensitive(False)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Copy to'))
        icon = Icon(icon_name='edit-copy',
                    xo_color=color,
                    icon_size=Gtk.IconSize.MENU)
        menu_item.set_image(icon)
        self.menu.append(menu_item)
        menu_item.show()
        copy_menu = CopyMenu(self._journalactivity, self.__get_uid_list_cb)
        copy_menu.connect('volume-error', self.__volume_error_cb)
        menu_item.set_submenu(copy_menu)

        if self._metadata['mountpoint'] == '/':
            menu_item = MenuItem(_('Duplicate'))
            icon = Icon(icon_name='edit-duplicate',
                        xo_color=color,
                        icon_size=Gtk.IconSize.MENU)
            menu_item.set_image(icon)
            menu_item.connect('activate', self.__duplicate_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Send to'), 'document-send')
        self.menu.append(menu_item)
        menu_item.show()

        friends_menu = FriendsMenu()
        friends_menu.connect('friend-selected', self.__friend_selected_cb)
        menu_item.set_submenu(friends_menu)

        if detail is True:
            menu_item = MenuItem(_('View Details'), 'go-right')
            menu_item.connect('activate', self.__detail_activate_cb)
            self.menu.append(menu_item)
            menu_item.show()

        menu_item = MenuItem(_('Erase'), 'list-remove')
        menu_item.connect('activate', self.__erase_activate_cb)
        self.menu.append(menu_item)
        menu_item.show()
예제 #57
0
class ReadToolbar(Gtk.Toolbar):
    __gtype_name__ = 'ReadToolbar'

    def __init__(self):
        Gtk.Toolbar.__init__(self)

        self.back = ToolButton('go-previous')
        self.back.set_tooltip(_('Back'))
        self.back.props.sensitive = False
        palette = self.back.get_palette()
        self.prev_page = MenuItem(text_label=_("Previous page"))
        palette.menu.append(self.prev_page)
        self.prev_page.show_all()
        self.prev_bookmark = MenuItem(text_label=_("Previous bookmark"))
        palette.menu.append(self.prev_bookmark)
        self.prev_bookmark.show_all()
        self.back.connect('clicked', self.go_back_cb)
        self.prev_page.connect('activate', self.go_back_cb)
        self.prev_bookmark.connect('activate', self.prev_bookmark_activate_cb)
        self.insert(self.back, -1)
        self.back.show()

        self.forward = ToolButton('go-next')
        self.forward.set_tooltip(_('Forward'))
        self.forward.props.sensitive = False
        palette = self.forward.get_palette()
        self.next_page = MenuItem(text_label=_("Next page"))
        palette.menu.append(self.next_page)
        self.next_page.show_all()
        self.next_bookmark = MenuItem(text_label=_("Next bookmark"))
        palette.menu.append(self.next_bookmark)
        self.next_bookmark.show_all()
        self.forward.connect('clicked', self.go_forward_cb)
        self.next_page.connect('activate', self.go_forward_cb)
        self.next_bookmark.connect('activate', self.next_bookmark_activate_cb)
        self.insert(self.forward, -1)
        self.forward.show()

        num_page_item = Gtk.ToolItem()

        self.num_page_entry = Gtk.Entry()
        self.num_page_entry.set_text('0')
        self.num_page_entry.set_alignment(1)
        self.num_page_entry.connect('insert-text',
                                    self.num_page_entry_insert_text_cb)
        self.num_page_entry.connect('activate',
                                    self.num_page_entry_activate_cb)

        self.num_page_entry.set_width_chars(4)

        num_page_item.add(self.num_page_entry)
        self.num_page_entry.show()

        self.insert(num_page_item, -1)
        num_page_item.show()

        total_page_item = Gtk.ToolItem()

        self.total_page_label = Gtk.Label()
        self.total_page_label.set_markup(
            "<span size='14000' foreground='black'>")

        self.total_page_label.set_text(' / 0')
        total_page_item.add(self.total_page_label)
        self.total_page_label.show()

        self.insert(total_page_item, -1)
        total_page_item.show()

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

        bookmarkitem = Gtk.ToolItem()
        self.bookmarker = ToggleToolButton('emblem-favorite')
        self.bookmarker.set_tooltip(_('Toggle Bookmark'))
        self.bookmarker_handler_id = self.bookmarker.connect(
            'clicked', self.bookmarker_clicked_cb)

        bookmarkitem.add(self.bookmarker)

        self.insert(bookmarkitem, -1)
        bookmarkitem.show_all()

        underline_item = Gtk.ToolItem()
        self.underline = ToggleToolButton('format-text-underline')
        self.underline.set_tooltip(_('Underline'))
        self.underline.props.sensitive = False
        self.underline_id = self.underline.connect('clicked',
                                                   self.underline_cb)
        underline_item.add(self.underline)
        self.insert(underline_item, -1)
        underline_item.show_all()

    def num_page_entry_insert_text_cb(self, entry, text, length, position):
        if not re.match('[0-9]', text):
            entry.emit_stop_by_name('insert-text')
            return True
        return False

    def num_page_entry_activate_cb(self, entry):
        if entry.props.text:
            page = int(entry.props.text) - 1
        else:
            page = 0

        if page >= self.total_pages:
            page = self.total_pages - 1
        elif page < 0:
            page = 0

        self.current_page = page
        self.activity.set_current_page(page)
        self.activity.show_page(page)
        entry.props.text = str(page + 1)
        self.update_nav_buttons()

    def go_back_cb(self, button):
        self.activity.page_previous()

    def go_forward_cb(self, button):
        self.activity.page_next()

    def update_nav_buttons(self):
        current_page = self.current_page
        self.back.props.sensitive = current_page > 0
        self.forward.props.sensitive = \
            current_page < self.total_pages - 1

        self.num_page_entry.props.text = str(current_page + 1)
        self.total_page_label.props.label = \
            ' / ' + str(self.total_pages)

    def set_total_pages(self, pages):
        self.total_pages = pages

    def set_current_page(self, page):
        self.current_page = page
        self.update_nav_buttons()

    def set_activity(self, activity):
        self.activity = activity

    def prev_bookmark_activate_cb(self, menuitem):
        self.activity.prev_bookmark()

    def next_bookmark_activate_cb(self, menuitem):
        self.activity.next_bookmark()

    def bookmarker_clicked_cb(self, button):
        self.activity.bookmarker_clicked(button)

    def underline_cb(self, button):
        self.activity.underline_clicked(button)

    def setToggleButtonState(self, button, b, id):
        button.handler_block(id)
        button.set_active(b)
        button.handler_unblock(id)

    def update_underline_button(self, state):
        self.setToggleButtonState(self.underline, state, self.underline_id)

    def update_bookmark_button(self, state):
        self.setToggleButtonState(self.bookmarker, state,
                                  self.bookmarker_handler_id)