예제 #1
0
    def __init__(self, *args, **kwargs):
        super(_StuckStrip, self).__init__(*args, **kwargs)

        self.orientation = Gtk.Orientation.HORIZONTAL

        spacer1 = Gtk.Label(label='')
        self.pack_start(spacer1, True, True, 0)

        spacer2 = Gtk.Label(label='')
        self.pack_end(spacer2, expand=True, fill=False, padding=0)

        self.set_spacing(10)

        self.set_border_width(10)

        label = Gtk.Label(label=_("Stuck?  You can still solve the puzzle."))
        self.pack_start(label, False, True, 0)

        icon = Icon()
        icon.set_from_icon_name('edit-undo', Gtk.IconSize.LARGE_TOOLBAR)
        self.button = Gtk.Button(stock=Gtk.STOCK_UNDO)
        self.button.set_image(icon)
        self.button.set_label(_("Undo some moves"))
        self.pack_end(self.button, expand=False, fill=False, padding=0)

        def callback(source):
            self.emit('undo-clicked')
        self.button.connect('clicked', callback)
예제 #2
0
    def _object_chooser(self, mime_type, type_name):
        chooser = ObjectChooser()
        matches_mime_type = False

        response = chooser.run()
        if response == Gtk.ResponseType.ACCEPT:
            jobject = chooser.get_selected_object()
            metadata = jobject.metadata
            file_path = jobject.file_path

            if metadata['mime_type'] == mime_type:
                matches_mime_type = True

            else:
                alert = Alert()

                alert.props.title = _('Invalid object')
                alert.props.msg = \
                       _('The selected object must be a %s file' % (type_name))

                ok_icon = Icon(icon_name='dialog-ok')
                alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
                ok_icon.show()

                alert.connect('response', lambda a, r: self.remove_alert(a))

                self.add_alert(alert)

                alert.show()

        return matches_mime_type, file_path, metadata['title']
예제 #3
0
 def can_close(self):
     if self._force_close:
         return True
     elif downloadmanager.can_quit():
         return True
     else:
         alert = Alert()
         alert.props.title = ngettext('Download in progress',
                                      'Downloads in progress',
                                      downloadmanager.num_downloads())
         message = ngettext('Stopping now will erase your download',
                            'Stopping now will erase your downloads',
                            downloadmanager.num_downloads())
         alert.props.msg = message
         cancel_icon = Icon(icon_name='dialog-cancel')
         cancel_label = ngettext('Continue download', 'Continue downloads',
                                 downloadmanager.num_downloads())
         alert.add_button(Gtk.ResponseType.CANCEL, cancel_label,
                          cancel_icon)
         stop_icon = Icon(icon_name='dialog-ok')
         alert.add_button(Gtk.ResponseType.OK, _('Stop'), stop_icon)
         stop_icon.show()
         self.add_alert(alert)
         alert.connect('response', self.__inprogress_response_cb)
         alert.show()
         self.present()
         return False
예제 #4
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()
예제 #5
0
 def add_icon(self, icon_name, stroke=style.COLOR_BUTTON_GREY.get_svg(),
              fill=style.COLOR_TRANSPARENT.get_svg(),
              icon_size=style.XLARGE_ICON_SIZE):
     icon = Icon(pixel_size=icon_size, icon_name=icon_name,
                 stroke_color=stroke, fill_color=fill)
     self._attach(icon)
     icon.show()
예제 #6
0
    def _update_invite_menu(self, activity):
        buddy_activity = self._buddy.props.current_activity
        if buddy_activity is not None:
            buddy_activity_id = buddy_activity.activity_id
        else:
            buddy_activity_id = None

        self._invite_menu.hide()
        if activity is None or \
           activity.is_journal() or \
           activity.get_activity_id() == buddy_activity_id:
            return

        bundle_activity = ActivityBundle(activity.get_bundle_path())
        if bundle_activity.get_max_participants() > 1:
            title = activity.get_title()
            self._invite_menu.set_label(_('Invite to %s') % title)

            icon = Icon(file=activity.get_icon_path(),
                        pixel_size=style.SMALL_ICON_SIZE)
            icon.props.xo_color = activity.get_icon_color()
            self._invite_menu.set_image(icon)
            icon.show()

            self._invite_menu.show()
예제 #7
0
    def _value_changed(self, cell, path, new_text, model, activity):
        _logger.info("Change '%s' to '%s'" % (model[path][1], new_text))
        is_number = True
        number = new_text.replace(",", ".")
        try:
            float(number)
        except ValueError:
            is_number = False

        if is_number:
            decimals = utils.get_decimals(str(float(number)))
            new_text = locale.format('%.' + decimals + 'f', float(number))
            model[path][1] = str(new_text)

            self.emit("value-changed", str(path), number)

        elif not is_number:
            alert = Alert()

            alert.props.title = _('Invalid Value')
            alert.props.msg = \
                           _('The value must be a number (integer or decimal)')

            ok_icon = Icon(icon_name='dialog-ok')
            alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
            ok_icon.show()

            alert.connect('response', lambda a, r: activity.remove_alert(a))

            activity.add_alert(alert)

            alert.show()
예제 #8
0
    def __init__(self, child, label=""):
        GObject.GObject.__init__(self)

        self._child = child
        self._label = Gtk.Label(label=label)
        self._label.set_alignment(0, 0.5)
        self.pack_start(self._label, True, True, 0)
        self._label.show()

        #self.modify_base(Gtk.StateType.NORMAL, Gdk.Color(0, 0, 0, 1))

        close_tab_icon = Icon(icon_name='close-tab')
        button = Gtk.Button()
        button.props.relief = Gtk.ReliefStyle.NONE
        button.props.focus_on_click = False
        icon_box = Gtk.HBox()
        icon_box.pack_start(close_tab_icon, True, False, 0)
        button.add(icon_box)
        button.connect('clicked', self.__button_clicked_cb)
        button.set_name('browse-tab-close')
        self.pack_start(button, False, True, 0)
        close_tab_icon.show()
        icon_box.show()
        button.show()
        self._close_button = button
예제 #9
0
class _IconWidget(Gtk.EventBox):

    __gtype_name__ = 'SugarTrayIconWidget'

    def __init__(self, icon_name=None, xo_color=None):
        GObject.GObject.__init__(self)

        self.set_app_paintable(True)
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.TOUCH_MASK |
                        Gdk.EventMask.BUTTON_RELEASE_MASK)

        self._icon = Icon(icon_name=icon_name, xo_color=xo_color,
                          icon_size=Gtk.IconSize.LARGE_TOOLBAR)
        self.add(self._icon)
        self._icon.show()

    def do_draw(self, cr):
        palette = self.get_parent().palette
        if palette and palette.is_up():
            invoker = palette.props.invoker
            invoker.draw_rectangle(cr, palette)

        Gtk.EventBox.do_draw(self, cr)

    def get_icon(self):
        return self._icon
예제 #10
0
    def add_text_icon_and_button(self, text, icon_name,
                                 button_icon=None,
                                 button_label=None,
                                 size='large', bold=False,
                                 color=style.COLOR_BLACK.get_html(),
                                 justify=Gtk.Justification.LEFT,
                                 stroke=style.COLOR_BUTTON_GREY.get_svg(),
                                 fill=style.COLOR_TRANSPARENT.get_svg(),
                                 icon_size=style.XLARGE_ICON_SIZE):
        label = Gtk.Label()
        label.set_use_markup(True)
        label.set_justify(justify)
        if bold:
            text = '<b>' + text + '</b>'
        span = '<span foreground="%s" size="%s">' % (color, size)
        label.set_markup(span + text + '</span>')

        icon = Icon(pixel_size=icon_size, icon_name=icon_name,
                    stroke_color=stroke, fill_color=fill)

        if button_icon is not None:
            button = ToolButton(button_icon)
        else:
            button = Gtk.Button()
            button.set_label(button_label)
        self._attach_three(label, icon, button)
        label.show()
        icon.show()
        button.show()
        return button
예제 #11
0
    def __init__(self, activity):
        Gtk.EventBox.__init__(self)

        self._area = Gtk.DrawingArea()
        self._area.connect('draw', self._area_draw_cb)

        self._boxes = []
        self._current_box = None

        prev_btn = Gtk.EventBox()
        prev_btn.connect('button-press-event', self._prev_slide)
        self._prev_icon = Icon(pixel_size=100)
        self._prev_icon.props.icon_name = 'go-previous'
        prev_btn.add(self._prev_icon)

        next_btn = Gtk.EventBox()
        next_btn.connect('button-press-event', self._next_slide)
        self._next_icon = Icon(pixel_size=100)
        self._next_icon.props.icon_name = 'go-next'
        next_btn.add(self._next_icon)

        hbox = Gtk.Box()
        hbox.set_border_width(10)
        hbox.pack_start(prev_btn, True, False, 0)
        hbox.pack_start(self._area, False, False, 0)
        hbox.pack_end(next_btn, True, False, 0)

        self.add(hbox)

        self.show_all()
예제 #12
0
    def add_radio_buttons(self, button_icons, colors=None):
        # Psuedo-radio buttons
        alignment = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        grid = Gtk.Grid()
        grid.set_row_spacing(style.DEFAULT_SPACING)
        grid.set_column_spacing(style.DEFAULT_SPACING)
        grid.set_border_width(style.DEFAULT_SPACING * 2)
        buttons = []
        for i, button_icon in enumerate(button_icons):
            if colors is not None:
                icon = Icon(pixel_size=style.STANDARD_ICON_SIZE,
                            icon_name=button_icon,
                            stroke_color=colors.get_stroke_color(),
                            fill_color=colors.get_fill_color())
            else:
                icon = Icon(pixel_size=style.STANDARD_ICON_SIZE,
                            icon_name=button_icon)

            buttons.append(Gtk.Button())
            buttons[i].set_image(icon)
            icon.show()
            grid.attach(buttons[i], i, 0, 1, 1)
            buttons[i].show()

        alignment.add(grid)
        grid.show()
        self._attach(alignment)
        alignment.show()

        return buttons
예제 #13
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)
예제 #14
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()
예제 #15
0
파일: Widgets.py 프로젝트: i5o/record-gtk3
    def __init__(self, icon_name):
        
        Gtk.Button.__init__(self)
        
        self.modify_bg(
            Gtk.StateType.NORMAL,
            style.COLOR_TOOLBAR_GREY.get_gdk_color())
            
        self.modify_bg(
            Gtk.StateType.ACTIVE,
            style.COLOR_BUTTON_GREY.get_gdk_color())
            
        self.set_relief(Gtk.ReliefStyle.NONE)
        
        self.set_size_request(
            style.GRID_CELL_SIZE,
            style.GRID_CELL_SIZE)

        icon = Icon(
            icon_name = icon_name,
            icon_size = Gtk.IconSize.SMALL_TOOLBAR)
            
        self.set_image(icon)
        
        icon.show()
        
        self.show_all()
        
        #self.connect('clicked', self._clicked_cb)
        
예제 #16
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)
예제 #17
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()
예제 #18
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()
    def __init__(self, browser):
        GObject.GObject.__init__(self)

        browser.connect('notify::title', self.__title_changed_cb)
        browser.connect('notify::load-status', self.__load_status_changed_cb)

        self._title = _('Untitled')
        self._label = Gtk.Label(label=self._title)
        self._label.set_ellipsize(Pango.EllipsizeMode.END)
        self._label.set_alignment(0, 0.5)
        self.pack_start(self._label, True, True, 0)
        self._label.show()

        close_tab_icon = Icon(icon_name='browse-close-tab')
        button = Gtk.Button()
        button.props.relief = Gtk.ReliefStyle.NONE
        button.props.focus_on_click = False
        icon_box = Gtk.HBox()
        icon_box.pack_start(close_tab_icon, True, False, 0)
        button.add(icon_box)
        button.connect('clicked', self.__button_clicked_cb)
        button.set_name('browse-tab-close')
        self.pack_start(button, False, True, 0)
        close_tab_icon.show()
        icon_box.show()
        button.show()
        self._close_button = button
예제 #20
0
class InlineAlert(Gtk.HBox):
    """UI interface for Inline alerts

    Inline alerts are different from the other alerts beause they are
    no dialogs, they only inform about a current event.

    Properties:
        'msg': the message of the alert,
        'icon': the icon that appears at the far left
    See __gproperties__
    """

    __gtype_name__ = 'SugarInlineAlert'

    __gproperties__ = {
        'msg': (str, None, None, None, GObject.ParamFlags.READWRITE),
        'icon': (object, None, None, GObject.ParamFlags.WRITABLE),
    }

    def __init__(self, **kwargs):

        self._msg = None
        self._msg_color = None
        self._icon = Icon(icon_name='emblem-warning',
                          fill_color=style.COLOR_SELECTION_GREY.get_svg(),
                          stroke_color=style.COLOR_WHITE.get_svg())

        self._msg_label = Gtk.Label()
        self._msg_label.set_max_width_chars(150)
        self._msg_label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT)
        self._msg_label.set_alignment(0, 0.5)
        self._msg_label.modify_fg(Gtk.StateType.NORMAL,
                                  style.COLOR_SELECTION_GREY.get_gdk_color())

        Gtk.HBox.__init__(self, **kwargs)

        self.set_spacing(style.DEFAULT_SPACING)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.pack_start(self._icon, False, False, 0)
        self.pack_start(self._msg_label, False, False, 0)
        self._msg_label.show()
        self._icon.show()

    def do_set_property(self, pspec, value):
        if pspec.name == 'msg':
            if self._msg != value:
                self._msg = value
                self._msg_label.set_markup(self._msg)
        elif pspec.name == 'icon':
            if self._icon != value:
                self._icon = value

    def do_get_property(self, pspec):
        if pspec.name == 'msg':
            return self._msg
예제 #21
0
class _BackupButton(Gtk.EventBox):

    __gproperties__ = {
        'icon-name': (str, None, None, None, GObject.PARAM_READWRITE),
        'pixel-size': (object, None, None, GObject.PARAM_READWRITE),
        'title': (str, None, None, None, GObject.PARAM_READWRITE),
    }

    def __init__(self, **kwargs):
        self._icon_name = None
        self._pixel_size = style.GRID_CELL_SIZE
        self._xo_color = None
        self._title = 'No Title'

        Gtk.EventBox.__init__(self, **kwargs)

        self._vbox = Gtk.VBox()
        self._icon = Icon(icon_name=self._icon_name,
                          pixel_size=self._pixel_size,
                          xo_color=XoColor('#000000,#000000'))
        self._vbox.pack_start(self._icon, expand=False, fill=False, padding=0)

        self._label = Gtk.Label(label=self._title)
        self._vbox.pack_start(self._label, expand=False, fill=False, padding=0)

        self._vbox.set_spacing(style.DEFAULT_SPACING)
        self.set_visible_window(False)
        self.set_app_paintable(True)
        self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)

        self.add(self._vbox)
        self._vbox.show()
        self._label.show()
        self._icon.show()

    def get_icon(self):
        return self._icon

    def do_set_property(self, pspec, value):
        if pspec.name == 'icon-name':
            if self._icon_name != value:
                self._icon_name = value
        elif pspec.name == 'pixel-size':
            if self._pixel_size != value:
                self._pixel_size = value
        elif pspec.name == 'title':
            if self._title != value:
                self._title = value

    def do_get_property(self, pspec):
        if pspec.name == 'icon-name':
            return self._icon_name
        elif pspec.name == 'pixel-size':
            return self._pixel_size
        elif pspec.name == 'title':
            return self._title
예제 #22
0
    def set_icon_name(self, icon_name):
        '''
        Set name of icon.

        Args:
            icon_name (string): name of icon
        '''
        icon = Icon(icon_name=icon_name)
        self.set_icon_widget(icon)
        icon.show()
예제 #23
0
    def __init__(self):
        GObject.GObject.__init__(self)

        add_tab_icon = Icon(icon_name='add')
        self.props.relief = Gtk.ReliefStyle.NONE
        self.props.focus_on_click = False
        self.add(add_tab_icon)
        self.connect('clicked', self.__button_clicked_cb)
        add_tab_icon.show()
        self.show()
예제 #24
0
    def add_action(self, label, icon_name=None):
        button = Gtk.Button(label)

        if icon_name:
            icon = Icon(icon_name)
            button.set_image(icon)
            icon.show()

        self.pack_start(button, True, True, 0)
        button.show()
예제 #25
0
파일: gui.py 프로젝트: richaseh/sugar
    def __accept_clicked_cb(self, widget):
        if hasattr(self._section_view, "apply"):
            self._section_view.apply()

        if self._section_view.needs_restart:
            self._section_toolbar.accept_button.set_sensitive(False)
            self._section_toolbar.cancel_button.set_sensitive(False)
            alert = Alert()
            alert.props.title = _("Warning")
            alert.props.msg = _("Changes require restart")

            if self._section_view.props.is_cancellable:
                icon = Icon(icon_name="dialog-cancel")
                alert.add_button(Gtk.ResponseType.CANCEL, _("Cancel changes"), icon)
                icon.show()

            if self._current_option not in ("aboutme", "backup"):
                icon = Icon(icon_name="dialog-ok")
                alert.add_button(Gtk.ResponseType.ACCEPT, _("Later"), icon)
                icon.show()

            icon = Icon(icon_name="system-restart")
            alert.add_button(Gtk.ResponseType.APPLY, _("Restart now"), icon)
            icon.show()

            self._vbox.pack_start(alert, False, False, 0)
            self._vbox.reorder_child(alert, 2)
            alert.connect("response", self.__response_cb)
            alert.show()
        else:
            self._show_main_view()
예제 #26
0
파일: gui.py 프로젝트: ChristoferR/sugar
    def __accept_clicked_cb(self, widget):
        if self._section_view.needs_restart:
            self._section_toolbar.accept_button.set_sensitive(False)
            self._section_toolbar.cancel_button.set_sensitive(False)
            alert = Alert()
            alert.props.title = _('Warning')
            alert.props.msg = _('Changes require restart')

            icon = Icon(icon_name='dialog-cancel')
            alert.add_button(Gtk.ResponseType.CANCEL,
                             _('Cancel changes'), icon)
            icon.show()

            if self._current_option != 'aboutme':
                icon = Icon(icon_name='dialog-ok')
                alert.add_button(Gtk.ResponseType.ACCEPT, _('Later'), icon)
                icon.show()

            icon = Icon(icon_name='system-restart')
            alert.add_button(Gtk.ResponseType.APPLY, _('Restart now'), icon)
            icon.show()

            self._vbox.pack_start(alert, False, False, 0)
            self._vbox.reorder_child(alert, 2)
            alert.connect('response', self.__response_cb)
            alert.show()
        else:
            self._show_main_view()
예제 #27
0
    def __accept_clicked_cb(self, widget):
        if hasattr(self._section_view, "apply"):
            self._section_view.apply()

        if self._section_view.needs_restart:
            self._section_toolbar.accept_button.set_sensitive(False)
            self._section_toolbar.cancel_button.set_sensitive(False)
            alert = Alert()
            alert.props.title = _('Warning')
            alert.props.msg = _('Changes require restart')

            if self._section_view.props.is_cancellable:
                icon = Icon(icon_name='dialog-cancel')
                alert.add_button(Gtk.ResponseType.CANCEL,
                                 _('Cancel changes'), icon)
                icon.show()

            if self._section_view.props.is_deferrable:
                icon = Icon(icon_name='dialog-ok')
                alert.add_button(Gtk.ResponseType.ACCEPT, _('Later'), icon)
                icon.show()

            icon = Icon(icon_name='system-restart')
            alert.add_button(Gtk.ResponseType.APPLY, _('Restart now'), icon)
            icon.show()

            self.add_alert(alert)
            alert.connect('response', self.__response_cb)
            alert.show()
        else:
            self._show_main_view()
예제 #28
0
    def __init__(self, interval=_INTERVAL, **kwargs):
        self._pulser = Pulser(self, interval)
        self._base_color = None
        self._pulse_color = None
        self._paused = False
        self._pulsing = False

        Icon.__init__(self, **kwargs)

        self._palette = None
        self.connect('destroy', self.__destroy_cb)
예제 #29
0
 def __init__(self):
     Gtk.VBox.__init__(self)
     self.props.halign = Gtk.Align.CENTER
     self.props.valign = Gtk.Align.CENTER
     waiting_icon = Icon(icon_name='zoom-neighborhood',
                         pixel_size=style.STANDARD_ICON_SIZE)
     waiting_icon.set_xo_color(XoColor('white'))
     self.add(waiting_icon)
     self.add(Gtk.Label(_('Connecting...')))
     self.show_all()
     self.hide()
예제 #30
0
 def set_widget_icon(self, icon_name=None, file_name=None):
     if file_name is not None:
         icon = Icon(file=file_name,
                     pixel_size=style.SMALL_ICON_SIZE,
                     xo_color=XoColor('white'))
     else:
         icon = Icon(icon_name=icon_name,
                     pixel_size=style.SMALL_ICON_SIZE,
                     xo_color=XoColor('white'))
     self.set_icon_widget(icon)
     icon.show()
예제 #31
0
    def __init__(self, metadata, detail=False):

        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(metadata)
        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 == 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()
예제 #32
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()
예제 #33
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()
예제 #34
0
파일: gui.py 프로젝트: upman/sugar
class _SectionIcon(Gtk.EventBox):
    __gtype_name__ = 'SugarSectionIcon'

    __gproperties__ = {
        'icon-name': (str, None, None, None, GObject.PARAM_READWRITE),
        'pixel-size': (object, None, None, GObject.PARAM_READWRITE),
        'xo-color': (object, None, None, GObject.PARAM_READWRITE),
        'title': (str, None, None, None, GObject.PARAM_READWRITE),
    }

    def __init__(self, **kwargs):
        self._icon_name = None
        self._pixel_size = style.GRID_CELL_SIZE
        self._xo_color = None
        self._title = 'No Title'

        Gtk.EventBox.__init__(self, **kwargs)

        self._vbox = Gtk.VBox()
        self._icon = Icon(icon_name=self._icon_name,
                          pixel_size=self._pixel_size,
                          xo_color=self._xo_color)
        self._vbox.pack_start(self._icon, expand=False, fill=False, padding=0)

        self._label = Gtk.Label(label=self._title)
        self._label.modify_fg(Gtk.StateType.NORMAL,
                              style.COLOR_WHITE.get_gdk_color())
        self._vbox.pack_start(self._label, expand=False, fill=False, padding=0)

        self._vbox.set_spacing(style.DEFAULT_SPACING)
        self.set_visible_window(False)
        self.set_app_paintable(True)
        self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)

        self.add(self._vbox)
        self._vbox.show()
        self._label.show()
        self._icon.show()

    def get_icon(self):
        return self._icon

    def do_set_property(self, pspec, value):
        if pspec.name == 'icon-name':
            if self._icon_name != value:
                self._icon_name = value
        elif pspec.name == 'pixel-size':
            if self._pixel_size != value:
                self._pixel_size = value
        elif pspec.name == 'xo-color':
            if self._xo_color != value:
                self._xo_color = value
        elif pspec.name == 'title':
            if self._title != value:
                self._title = value

    def do_get_property(self, pspec):
        if pspec.name == 'icon-name':
            return self._icon_name
        elif pspec.name == 'pixel-size':
            return self._pixel_size
        elif pspec.name == 'xo-color':
            return self._xo_color
        elif pspec.name == 'title':
            return self._title
예제 #35
0
    def __init__(self, text, icon_name):
        Gtk.VBox.__init__(self)
        self._progress_bar = None
        self._adjustment = None

        icon = Icon(pixel_size=style.SMALL_ICON_SIZE)
        icon.props.icon_name = icon_name
        icon.props.xo_color = XoColor(
            '%s,%s' %
            (style.COLOR_WHITE.get_svg(), style.COLOR_BUTTON_GREY.get_svg()))
        icon.show()

        label = Gtk.Label(text)
        label.show()

        grid = Gtk.Grid()
        grid.set_column_spacing(style.DEFAULT_SPACING)
        grid.attach(icon, 0, 0, 1, 1)
        grid.attach(label, 1, 0, 1, 1)
        grid.show()

        alignment = Gtk.Alignment()
        alignment.set(0.5, 0, 0, 0)
        alignment.add(grid)
        alignment.show()
        self.add(alignment)

        alignment = Gtk.Alignment()
        alignment.set(0.5, 0, 0, 0)
        alignment.set_padding(0, 0, style.DEFAULT_SPACING,
                              style.DEFAULT_SPACING)

        self._model = brightness.get_instance()
        self._model_changed_hid = \
            self._model.changed_signal.connect(self.__brightness_changed_cb)

        # if sugar-backlight-helper finds the device
        if self._model.get_path():
            adjustment = Gtk.Adjustment(
                value=self._model.get_brightness(),
                lower=0,
                upper=self._model.get_max_brightness() + 1,
                step_incr=self._model.get_step_amount(),
                page_incr=self._model.get_step_amount(),
                page_size=self._model.get_step_amount())
            self._adjustment = adjustment

            self._adjustment_timeout_id = None
            self._adjustment_hid = \
                self._adjustment.connect('value-changed', self.__adjusted_cb)

            hscale = Gtk.HScale()
            hscale.props.draw_value = False
            hscale.set_adjustment(adjustment)
            hscale.set_digits(0)
            hscale.set_size_request(style.GRID_CELL_SIZE * 4, -1)
            alignment.add(hscale)
            hscale.show()
        else:
            self._progress_bar = Gtk.ProgressBar()
            self._progress_bar.set_size_request(
                style.zoom(style.GRID_CELL_SIZE * 4), -1)
            alignment.props.top_padding = style.DEFAULT_PADDING
            alignment.add(self._progress_bar)
            self._progress_bar.show()

        alignment.show()
        self.add(alignment)
예제 #36
0
    def __init__(self, handle):

        activity.Activity.__init__(self, handle, True)

        self.max_participants = 1

        # CHART_OPTIONS

        self.x_label = ''
        self.y_label = ''
        self.chart_color = utils.get_user_fill_color('str')
        self.chart_line_color = utils.get_user_stroke_color('str')
        self.current_chart = None
        self.charts_area = None
        self.chart_data = []
        self.chart_type_buttons = []

        # TOOLBARS
        toolbarbox = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        activity_btn_toolbar = activity_button.page

        activity_btn_toolbar.title.connect('changed', self._set_chart_title)

        save_as_image = ToolButton('save-as-image')
        save_as_image.connect('clicked', self._save_as_image)
        save_as_image.set_tooltip(_('Save as image'))
        activity_btn_toolbar.insert(save_as_image, -1)

        save_as_image.show()

        import_freespace = ToolButton("import-freespace")
        import_freespace.connect("clicked", self.__import_freespace_cb)
        import_freespace.set_tooltip(_("Read Freespace data"))
        toolbarbox.toolbar.insert(import_freespace, -1)

        import_freespace.show()

        import_journal = ToolButton('import-journal')
        import_journal.connect('clicked', self.__import_journal_cb)
        import_journal.set_tooltip(_('Read Journal data'))
        toolbarbox.toolbar.insert(import_journal, -1)

        import_journal.show()

        import_turtle = ToolButton('import-turtle')
        import_turtle.connect('clicked', self.__import_turtle_cb)
        import_turtle.set_tooltip(_('Read Turtle data'))
        toolbarbox.toolbar.insert(import_turtle, -1)

        import_turtle.show()

        toolbarbox.toolbar.insert(activity_button, 0)

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

        # We create two sets: one for the main toolbar and one for the
        # chart toolbar. We choose which set to use based on the
        # screen width.
        self._create_chart_buttons(toolbarbox.toolbar)

        self._chart_button = ToolbarButton(icon_name='vbar')
        chart_toolbar = Gtk.Toolbar()
        self._create_chart_buttons(chart_toolbar)
        self._chart_button.props.page = chart_toolbar
        chart_toolbar.show_all()
        toolbarbox.toolbar.insert(self._chart_button, -1)

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

        self._fullscreen_button = ToolButton('view-fullscreen')
        self._fullscreen_button.set_tooltip(_("Fullscreen"))
        self._fullscreen_button.props.accelerator = '<Alt>Return'
        self._fullscreen_button.connect('clicked', self.__fullscreen_cb)
        toolbarbox.toolbar.insert(self._fullscreen_button, -1)

        charthelp.create_help(toolbarbox.toolbar)

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

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        self.set_toolbar_box(toolbarbox)

        # Invisible widgets
        self.v_label = Entry(_('Vertical label...'))
        self.h_label = Entry(_('Horizontal label...'))
        self._remove_v = ToolButton('gtk-remove')
        self._options_button = ToolbarButton(icon_name='preferences-system')

        # CANVAS
        paned = Gtk.HPaned()
        box = Gtk.VBox()
        self.box = box

        # Set the info box width to 1/3 of the screen:
        def size_allocate_cb(widget, allocation):
            paned.disconnect(self._setup_handle)
            box_width = allocation.width / 3
            box.set_size_request(box_width, -1)

        self._setup_handle = paned.connect('size_allocate',
                    size_allocate_cb)

        scroll = Gtk.ScrolledWindow()
        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.labels_and_values = ChartData(self)
        scroll.add(self.labels_and_values)

        self.labels_and_values.connect('label-changed', self._label_changed)
        self.labels_and_values.connect('value-changed', self._value_changed)

        box.pack_start(scroll, True, True, 0)

        liststore_toolbar = Gtk.Toolbar()

        move_up = ToolButton('go-up')
        move_up.set_tooltip(_('Move up'))
        move_up.connect('clicked', self._move_up)

        move_down = ToolButton('go-down')
        move_down.set_tooltip(_('Move down'))
        move_down.connect('clicked', self._move_down)

        liststore_toolbar.insert(move_up, 0)
        liststore_toolbar.insert(move_down, 1)

        box.pack_end(liststore_toolbar, False, False, 0)

        paned.add1(box)

        # CHARTS AREA
        eventbox = Gtk.EventBox()
        self.charts_area = ChartArea(self)

        eventbox.modify_bg(Gtk.StateType.NORMAL, _WHITE)
        eventbox.add(self.charts_area)

        self._notebook = Gtk.Notebook()
        self._notebook.set_property('show-tabs', False)
        self._notebook.append_page(eventbox, Gtk.Label())

        # EMPTY WIDGETS
        empty_widgets = Gtk.EventBox()
        empty_widgets.modify_bg(Gtk.StateType.NORMAL,
                                style.COLOR_WHITE.get_gdk_color())

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        mvbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox.pack_start(mvbox, True, False, 0)

        image_icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
                          icon_name='chart',
                          stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                          fill_color=style.COLOR_TRANSPARENT.get_svg())
        mvbox.pack_start(image_icon, False, False, style.DEFAULT_PADDING)

        label = Gtk.Label('<span foreground="%s"><b>%s</b></span>' %
                          (style.COLOR_BUTTON_GREY.get_html(),
                          _('No data')))
        label.set_use_markup(True)
        mvbox.pack_start(label, False, False, style.DEFAULT_PADDING)

        hbox = Gtk.Box()
        open_image_btn = Gtk.Button()
        open_image_btn.connect('clicked', self._add_value)
        add_image = Gtk.Image.new_from_stock(Gtk.STOCK_ADD,
                                             Gtk.IconSize.BUTTON)
        buttonbox = Gtk.Box()
        buttonbox.pack_start(add_image, False, True, 0)
        buttonbox.pack_end(Gtk.Label(_('Add a value')), True, True, 5)
        open_image_btn.add(buttonbox)
        hbox.pack_start(open_image_btn, True, False, 0)
        mvbox.pack_start(hbox, False, False, style.DEFAULT_PADDING)

        empty_widgets.add(vbox)
        empty_widgets.show_all()
        self._notebook.append_page(empty_widgets, Gtk.Label())

        paned.add2(self._notebook)

        self.set_canvas(paned)
        self.charts_area.connect('size_allocate', self._chart_size_allocate)

        self.show_all()

        Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
        self._configure_cb()
예제 #37
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)

        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 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()
예제 #38
0
        ['battery-100', '#AC32FF,#FF2B34']]


def _button_activated_cb(button):
    import random

    global data
    random.shuffle(data)

    for i in range(0, len(test.get_children()) - 1):
        test.get_children()[i].props.icon_name = data[i][0]
        test.get_children()[i].props.xo_color = XoColor(data[i][1])


for d in data:
    icon = Icon(icon_name=d[0],
                pixel_size=style.STANDARD_ICON_SIZE,
                xo_color=XoColor(d[1]))
    test.pack_start(icon, True, True, 0)
    icon.show()

button = Gtk.Button('mec mac')
test.pack_start(button, True, True, 0)
button.connect('activate', _button_activated_cb)
button.show()

test.show()

if __name__ == '__main__':
    common.main(test)
예제 #39
0
class ClipboardIcon(RadioToolButton):
    __gtype_name__ = 'SugarClipboardIcon'

    def __init__(self, cb_object, group):
        RadioToolButton.__init__(self, group=group)

        self.props.palette_invoker = FrameWidgetInvoker(self)
        self.palette_invoker.props.toggle_palette = True

        self._cb_object = cb_object
        self.owns_clipboard = False
        self.props.sensitive = False
        self.props.active = False
        self._notif_icon = None
        self._current_percent = None

        self._icon = Icon()
        color = profile.get_color()
        self._icon.props.xo_color = color
        self.set_icon_widget(self._icon)
        self._icon.show()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)
        cb_service.connect('object-selected', self._object_selected_cb)

        child = self.get_child()
        child.connect('drag_data_get', self._drag_data_get_cb)
        self.connect('notify::active', self._notify_active_cb)

    def create_palette(self):
        palette = ClipboardMenu(self._cb_object)
        palette.set_group_id('frame')
        return palette

    def get_object_id(self):
        return self._cb_object.get_id()

    def _drag_data_get_cb(self, widget, context, selection, target_type,
                          event_time):
        target_atom = selection.get_target()
        target_name = target_atom.name()
        logging.debug('_drag_data_get_cb: requested target %s', target_name)
        data = self._cb_object.get_formats()[target_name].get_data()
        selection.set(target_atom, 8, data)

    def _put_in_clipboard(self):
        logging.debug('ClipboardIcon._put_in_clipboard')

        if self._cb_object.get_percent() < 100:
            raise ValueError('Object is not complete, cannot be put into the'
                             ' clipboard.')

        targets = self._get_targets()
        if targets:
            x_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

            # XXX SL#4307 - until set_with_data bindings are fixed upstream
            if hasattr(x_clipboard, 'set_with_data'):
                stored = x_clipboard.set_with_data(targets,
                                                   self._clipboard_data_get_cb,
                                                   self._clipboard_clear_cb,
                                                   targets)
            else:
                stored = SugarExt.clipboard_set_with_data(
                    x_clipboard, targets, self._clipboard_data_get_cb,
                    self._clipboard_clear_cb, targets)

            if not stored:
                logging.error('GtkClipboard.set_with_data failed!')
            else:
                self.owns_clipboard = True

    def _clipboard_data_get_cb(self, x_clipboard, selection, info, targets):
        selection_target = selection.get_target()
        entries_targets = [entry.target for entry in targets]
        if not str(selection_target) in entries_targets:
            logging.warning(
                'ClipboardIcon._clipboard_data_get_cb: asked %s'
                ' but only have %r.', selection_target, entries_targets)
            return
        data = self._cb_object.get_formats()[str(selection_target)].get_data()
        selection.set(selection_target, 8, data)

    def _clipboard_clear_cb(self, x_clipboard, targets):
        logging.debug('ClipboardIcon._clipboard_clear_cb')
        self.owns_clipboard = False

    def _object_state_changed_cb(self, cb_service, cb_object):
        if cb_object != self._cb_object:
            return

        if cb_object.get_icon():
            self._icon.props.icon_name = cb_object.get_icon()
            if self._notif_icon:
                self._notif_icon.props.icon_name = self._icon.props.icon_name
        else:
            self._icon.props.icon_name = 'application-octet-stream'

        child = self.get_child()
        child.connect('drag-begin', self._drag_begin_cb)
        child.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
                              self._get_targets(), Gdk.DragAction.COPY)

        if cb_object.get_percent() == 100:
            self.props.sensitive = True

        # Clipboard object became complete. Make it the active one.
        if self._current_percent < 100 and cb_object.get_percent() == 100:
            self.props.active = True
            self.show_notification()

        self._current_percent = cb_object.get_percent()

    def _object_selected_cb(self, cb_service, object_id):
        if object_id != self._cb_object.get_id():
            return
        self.props.active = True
        self.show_notification()
        logging.debug('ClipboardIcon: %r was selected', object_id)

    def show_notification(self):
        self._notif_icon = NotificationIcon()
        self._notif_icon.props.icon_name = self._icon.props.icon_name
        self._notif_icon.props.xo_color = \
            XoColor('%s,%s' % (self._icon.props.stroke_color,
                               self._icon.props.fill_color))
        frame = jarabe.frame.get_view()
        frame.add_notification(self._notif_icon, Gtk.CornerType.BOTTOM_LEFT)

    def _drag_begin_cb(self, widget, context):
        # TODO: We should get the pixbuf from the icon, with colors, etc.
        icon_theme = Gtk.IconTheme.get_default()
        pixbuf = icon_theme.load_icon(self._icon.props.icon_name,
                                      style.STANDARD_ICON_SIZE, 0)
        Gtk.drag_set_icon_pixbuf(context,
                                 pixbuf,
                                 hot_x=pixbuf.props.width / 2,
                                 hot_y=pixbuf.props.height / 2)

    def _notify_active_cb(self, widget, pspec):
        if self.props.active:
            self._put_in_clipboard()
        else:
            self.owns_clipboard = False

    def _get_targets(self):
        targets = []
        for format_type in self._cb_object.get_formats().keys():
            targets.append(
                Gtk.TargetEntry.new(format_type, Gtk.TargetFlags.SAME_APP, 0))
        return targets
예제 #40
0
class InviteButton(ToolButton):
    """Invite to shared activity"""

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

    def __init__(self, invite):
        ToolButton.__init__(self)

        self._invite = invite

        self.connect('clicked', self.__clicked_cb)
        self.connect('destroy', self.__destroy_cb)

        bundle_registry = bundleregistry.get_registry()
        bundle = bundle_registry.get_bundle(invite.get_bundle_id())

        self._icon = Icon()
        self._icon.props.xo_color = invite.get_color()
        if bundle is not None:
            self._icon.props.file = bundle.get_icon()
        else:
            self._icon.props.icon_name = 'image-missing'
        self.set_icon_widget(self._icon)
        self._icon.show()

        palette = InvitePalette(invite)
        palette.props.invoker = FrameWidgetInvoker(self)
        palette.set_group_id('frame')
        palette.connect('remove-invite', self.__remove_invite_cb)
        self.set_palette(palette)

        self._notif_icon = NotificationIcon()
        self._notif_icon.connect('button-release-event',
                                 self.__button_release_event_cb)

        self._notif_icon.props.xo_color = invite.get_color()
        if bundle is not None:
            self._notif_icon.props.icon_filename = bundle.get_icon()
        else:
            self._notif_icon.props.icon_name = 'image-missing'

        frame = jarabe.frame.get_view()
        frame.add_notification(self._notif_icon, Gtk.CornerType.TOP_LEFT)

    def __button_release_event_cb(self, icon, event):
        if self._notif_icon is not None:
            frame = jarabe.frame.get_view()
            frame.remove_notification(self._notif_icon)
            self._notif_icon = None
            self._invite.join()
            self.emit('remove-invite')

    def __clicked_cb(self, button):
        self.palette.popup(immediate=True, state=Palette.SECONDARY)

    def __remove_invite_cb(self, palette):
        self.emit('remove-invite')

    def __destroy_cb(self, button):
        if self._notif_icon is not None:
            frame = jarabe.frame.get_view()
            frame.remove_notification(self._notif_icon)
            self._notif_icon = None
    def __download_finished_cb(self, download):
        if hasattr(self._activity, 'busy'):
            self._activity.unbusy()

        if self._progress_sid is not None:
            GObject.source_remove(self._progress_sid)

        if self.dl_jobject is None:
            return  # the "failed" signal was observed

        self.dl_jobject.metadata['title'] = self._suggested_filename
        self.dl_jobject.metadata['description'] = _('From: %s') \
            % self._source
        self.dl_jobject.metadata['progress'] = '100'
        self.dl_jobject.file_path = self._dest_path

        mime_type = Gio.content_type_guess(self._dest_path)[0]
        if mime_type != 'application/vnd.olpc-sugar':
            mime_type = download.get_response().get_mime_type()

        self.dl_jobject.metadata['mime_type'] = mime_type

        if mime_type in ('image/bmp', 'image/gif', 'image/jpeg',
                         'image/png', 'image/tiff'):
            preview = self._get_preview()
            if preview is not None:
                self.dl_jobject.metadata['preview'] = \
                    dbus.ByteArray(preview)

        datastore.write(self.dl_jobject,
                        transfer_ownership=True,
                        reply_handler=self.__internal_save_cb,
                        error_handler=self.__internal_error_cb,
                        timeout=360)

        self._stop_alert = Alert()
        self._stop_alert.props.title = _('Download completed')
        self._stop_alert.props.msg = self._suggested_filename

        bundle = None
        if _HAS_BUNDLE_LAUNCHER:
            bundle = get_bundle(object_id=self._object_id)

        if bundle is not None:
            icon = Icon(file=bundle.get_icon())
            label = _('Open with %s') % bundle.get_name()
            response_id = Gtk.ResponseType.APPLY
        else:
            icon = Icon(icon_name='zoom-activity')
            label = _('Show in Journal')
            response_id = Gtk.ResponseType.ACCEPT

        self._stop_alert.add_button(response_id, label, icon)
        icon.show()

        ok_icon = Icon(icon_name='dialog-ok')
        self._stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
        ok_icon.show()

        self._activity.add_alert(self._stop_alert)
        self._stop_alert.connect('response', self.__stop_response_cb)
        self._stop_alert.show()
예제 #42
0
                    icon.alpha = 0.33

    def __register_activate_cb(self, icon):
        alert = Alert()
        try:
            schoolserver.register_laptop()
        except RegisterError, e:
            alert.props.title = _('Registration Failed')
            alert.props.msg = '%s' % e
        else:
            alert.props.title = _('Registration Successful')
            alert.props.msg = _('You are now registered '
                                'with your school server.')
            self._owner_icon.set_registered()

        ok_icon = Icon(icon_name='dialog-ok')
        alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)

        self._box.add_alert(alert)
        alert.connect('response', self.__register_alert_response_cb)

    def __register_alert_response_cb(self, alert, response_id):
        self._box.remove_alert()

    def set_resume_mode(self, resume_mode):
        self._resume_mode = resume_mode
        for icon in self.get_children():
            if hasattr(icon, 'set_resume_mode'):
                icon.set_resume_mode(self._resume_mode)

예제 #43
0
        ['battery-100', '#AC32FF,#FF2B34']]


def _button_activated_cb(button):
    import random

    global data
    random.shuffle(data)

    for i in range(0, len(test.get_children()) - 1):
        test.get_children()[i].props.icon_name = data[i][0]
        test.get_children()[i].props.xo_color = XoColor(data[i][1])


for d in data:
    icon = Icon(icon_name=d[0],
                icon_size=Gtk.IconSize.LARGE_TOOLBAR,
                xo_color=XoColor(d[1]))
    test.pack_start(icon, True, True, 0)
    icon.show()

button = Gtk.Button('mec mac')
test.pack_start(button, True, True, 0)
button.connect('activate', _button_activated_cb)
button.show()

test.show()

if __name__ == '__main__':
    common.main(test)
예제 #44
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)
예제 #45
0
    def __init__(self, text, icon_name, device):
        Gtk.VBox.__init__(self)
        self._device = device

        self._ok_icon = Icon(icon_name='dialog-ok')
        self._cancel_icon = Icon(icon_name='dialog-cancel')

        icon = Icon(pixel_size=style.SMALL_ICON_SIZE)
        icon.props.icon_name = icon_name
        icon.props.xo_color = XoColor(
            '%s,%s' %
            (style.COLOR_WHITE.get_svg(), style.COLOR_BUTTON_GREY.get_svg()))
        icon.show()

        label = Gtk.Label(text)
        label.show()

        grid = Gtk.Grid()
        grid.set_column_spacing(style.DEFAULT_SPACING)
        grid.attach(icon, 0, 0, 1, 1)
        grid.attach(label, 1, 0, 1, 1)
        grid.show()

        alignment = Gtk.Alignment()
        alignment.set(0.5, 0, 0, 0)
        alignment.add(grid)
        alignment.show()

        self.add(alignment)

        adjustment = Gtk.Adjustment(value=device.props.level,
                                    lower=0,
                                    upper=100 + sound.VOLUME_STEP,
                                    step_incr=sound.VOLUME_STEP,
                                    page_incr=sound.VOLUME_STEP,
                                    page_size=sound.VOLUME_STEP)
        self._adjustment = adjustment

        hscale = Gtk.HScale()
        hscale.props.draw_value = False
        hscale.set_adjustment(adjustment)
        hscale.set_digits(0)
        hscale.set_size_request(style.GRID_CELL_SIZE * 4, -1)
        hscale.show()

        button = Gtk.Button()
        button.props.relief = Gtk.ReliefStyle.NONE
        button.props.focus_on_click = False
        button.connect('clicked', self.__muted_clicked_cb)
        button.show()
        self._button = button

        grid = Gtk.Grid()
        grid.set_column_spacing(style.DEFAULT_SPACING)
        grid.attach(hscale, 0, 0, 1, 1)
        grid.attach(button, 1, 0, 1, 1)
        grid.show()

        alignment = Gtk.Alignment()
        alignment.set(0.5, 0, 0, 0)
        alignment.set_padding(0, 0, style.DEFAULT_SPACING,
                              style.DEFAULT_SPACING)
        alignment.add(grid)
        alignment.show()

        self.add(alignment)

        self._adjustment_hid = \
            self._adjustment.connect('value_changed',
                                     self.__level_adjusted_cb)
예제 #46
0
    def __init__(self,
                 text_label=None,
                 icon_name=None,
                 text_maxlen=60,
                 xo_color=None,
                 file_name=None):

        Gtk.EventBox.__init__(self)
        self.set_above_child(True)

        self.icon = None
        self._hbox = Gtk.HBox()

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

        hbox = Gtk.HBox()
        vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING)
        hbox.show()

        hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING)

        if icon_name is not None:
            self.icon = Icon(icon_name=icon_name,
                             icon_size=Gtk.IconSize.SMALL_TOOLBAR)
            if xo_color is not None:
                self.icon.props.xo_color = xo_color
            self._hbox.pack_start(self.icon,
                                  expand=False,
                                  fill=False,
                                  padding=style.DEFAULT_PADDING)
        elif file_name is not None:
            self.icon = Icon(file=file_name,
                             icon_size=Gtk.IconSize.SMALL_TOOLBAR)
            if xo_color is not None:
                self.icon.props.xo_color = xo_color
            self._hbox.pack_start(self.icon,
                                  expand=False,
                                  fill=False,
                                  padding=style.DEFAULT_PADDING)

        align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
        self.label = Gtk.Label(text_label)
        if text_maxlen > 0:
            self.label.set_max_width_chars(text_maxlen)
            self.label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
        align.add(self.label)
        self._hbox.pack_start(align,
                              expand=True,
                              fill=True,
                              padding=style.DEFAULT_PADDING)

        self.id_bt_release_cb = self.connect('button-release-event',
                                             self.__button_release_cb)
        self.id_enter_notify_cb = self.connect('enter-notify-event',
                                               self.__enter_notify_cb)
        self.id_leave_notify_cb = self.connect('leave-notify-event',
                                               self.__leave_notify_cb)

        self.show_all()
예제 #47
0
    def __init__(self, model, alerts):
        SectionView.__init__(self)

        self._model = model
        self.restart_alerts = alerts

        services = get_webaccount_services()

        grid = Gtk.Grid()

        if len(services) == 0:
            grid.set_row_spacing(style.DEFAULT_SPACING)

            icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
                        icon_name='module-webaccount',
                        stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                        fill_color=style.COLOR_TRANSPARENT.get_svg())

            grid.attach(icon, 0, 0, 1, 1)
            icon.show()

            label = Gtk.Label()
            label.set_justify(Gtk.Justification.CENTER)
            label.set_markup(
                '<span foreground="%s" size="large">%s</span>' %
                (style.COLOR_BUTTON_GREY.get_html(),
                 GLib.markup_escape_text(
                     _('No web services are installed.\n'
                       'Please visit %s for more details.' %
                       'http://wiki.sugarlabs.org/go/WebServices'))))
            label.show()
            grid.attach(label, 0, 1, 1, 1)

            alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
            alignment.add(grid)
            grid.show()

            self.add(alignment)
            alignment.show()
            return

        grid.set_row_spacing(style.DEFAULT_SPACING * 4)
        grid.set_column_spacing(style.DEFAULT_SPACING * 4)
        grid.set_border_width(style.DEFAULT_SPACING * 2)
        grid.set_column_homogeneous(True)

        width = Gdk.Screen.width() - 2 * style.GRID_CELL_SIZE
        nx = int(width / (style.GRID_CELL_SIZE + style.DEFAULT_SPACING * 4))

        self._service_config_box = Gtk.VBox()

        x = 0
        y = 0
        for service in services:
            service_grid = Gtk.Grid()
            icon = CanvasIcon(icon_name=service.get_icon_name())
            icon.show()
            service_grid.attach(icon, x, y, 1, 1)

            icon.connect('activate', service.config_service_cb, None,
                         self._service_config_box)

            label = Gtk.Label()
            label.set_justify(Gtk.Justification.CENTER)
            name = get_service_name(service)
            label.set_markup(name)
            service_grid.attach(label, x, y + 1, 1, 1)
            label.show()

            grid.attach(service_grid, x, y, 1, 1)
            service_grid.show()

            x += 1
            if x == nx:
                x = 0
                y += 1

        alignment = Gtk.Alignment.new(0.5, 0, 0, 0)
        alignment.add(grid)
        grid.show()

        vbox = Gtk.VBox()
        vbox.pack_start(alignment, False, False, 0)
        alignment.show()

        scrolled = Gtk.ScrolledWindow()
        vbox.pack_start(scrolled, True, True, 0)

        self.add(vbox)
        scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scrolled.show()

        workspace = Gtk.VBox()
        scrolled.add_with_viewport(workspace)
        workspace.show()

        workspace.add(self._service_config_box)
        workspace.show_all()
        vbox.show()
예제 #48
0
파일: view.py 프로젝트: vish-321/sugar
    def __init__(self, operation, view):
        Gtk.Grid.__init__(self)
        self.set_orientation(Gtk.Orientation.VERTICAL)
        self.set_row_spacing(style.DEFAULT_SPACING)
        self.set_valign(Gtk.Align.CENTER)
        self.set_halign(Gtk.Align.CENTER)

        self._view = view
        self._operation = operation
        self._backend = None

        _icon = Icon(icon_name='backup-%s' % operation,
                     pixel_size=style.XLARGE_ICON_SIZE)
        self.add(_icon)
        _icon.show()

        self._message_label = Gtk.Label()
        self._message_label.set_line_wrap(True)
        self._message_label.set_width_chars(40)
        self._message_label.set_single_line_mode(False)
        align = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        align.set_padding(0, 0, style.GRID_CELL_SIZE * 2,
                          style.GRID_CELL_SIZE * 2)
        align.show()
        align.add(self._message_label)
        self.add(align)
        self._message_label.show()

        self._options_combo = Gtk.ComboBox()
        cell = Gtk.CellRendererText()
        self._options_combo.pack_start(cell, True)
        self._options_combo.add_attribute(cell, 'text', 0)
        self.add(self._options_combo)

        self._progress_bar = Gtk.ProgressBar()
        self.add(self._progress_bar)
        self._progress_bar.set_size_request(
            Gdk.Screen.width() - style.GRID_CELL_SIZE * 6, -1)

        self._confirm_restore_chkbtn = Gtk.CheckButton()
        align = Gtk.Alignment()
        align.set_padding(0, 0, style.GRID_CELL_SIZE * 2,
                          style.GRID_CELL_SIZE * 2)
        align.show()
        align.add(self._confirm_restore_chkbtn)
        self.add(align)

        btn_box = Gtk.ButtonBox()
        btn_box.show()
        self._continue_btn = Gtk.Button(_('Continue'))
        btn_box.add(self._continue_btn)
        self.add(btn_box)
        self._continue_btn_handler_id = 0

        self.show()

        # check if there are activities running
        # and request close them if any.
        if self._view.manager.need_stop_activities():
            self._message_label.set_text(
                _('Please close all the activities, and start again'))

        # check the backend availables, if there are more than one
        # show to the user to select one
        if len(self._view.manager.get_backends()) > 1:
            if operation == OPERATION_BACKUP:
                message = _('Select where you want create your backup')
            if operation == OPERATION_RESTORE:
                message = _('Select where you want retrieve your restore')
            combo_options = []
            for backend in self._view.manager.get_backends():
                option = {}
                option['description'] = backend.get_name()
                option['value'] = backend
                combo_options.append(option)

            self._ask_options(message, combo_options, self._select_backend)
        else:
            self._backend = self._view.manager.get_backends()[0]
            GLib.idle_add(self._start_operation)
예제 #49
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        self._book_model = BookModel()
        self._actual_page = 1

        # we do not have collaboration features
        # make the share option insensitive
        self.max_participants = 1

        # get the language configured by the user
        # will be used to translate the names of the media files
        locale = os.environ.get('LANG', '')
        language_location = locale.split('.', 1)[0].lower()
        self._language = language_location.split('_')[0]
        if self._language == 'en':
            # we don't need translate the file names if langauage is 'en'
            self._language = None
        self._translations = None
        if self._language is not None:
            # read the translations file if available
            dict_path = os.path.join(activity.get_bundle_path(), 'data',
                                     "%s_dict.csv" % self._language)
            logging.debug('Looking for media translation dictionary %s',
                          dict_path)
            if os.path.exists(dict_path):
                logging.debug('Loading translations')
                self._translations = {}
                with open(dict_path) as dict_file:
                    for line in dict_file:
                        words = line.split(',')
                        self._translations[words[0]] = words[1].strip()

        toolbar_box = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(activity_button, 0)

        self._edit_toolbar = EditToolbar()
        edit_toolbar_button = ToolbarButton(page=self._edit_toolbar,
                                            icon_name='toolbar-edit')
        toolbar_box.toolbar.insert(edit_toolbar_button, 1)

        set_background_button = ToolButton('set-background')
        set_background_button.set_tooltip(_('Set the background'))
        set_background_button.connect('clicked',
                                      self.__set_background_clicked_cb)
        toolbar_box.toolbar.insert(set_background_button, -1)

        insert_picture_button = ToolButton('insert-picture')
        insert_picture_button.set_tooltip(_('Add a picture'))
        insert_picture_button.connect('clicked', self.__add_image_clicked_cb)
        toolbar_box.toolbar.insert(insert_picture_button, -1)

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

        self._duplicate_page_button = ToolButton()
        icon = Icon(icon_name='edit-duplicate', xo_color=profile.get_color())
        self._duplicate_page_button.set_icon_widget(icon)

        self._duplicate_page_button.set_tooltip(_('Duplicate page'))
        self._duplicate_page_button.connect('clicked',
                                            self.__duplicate_page_clicked_cb)
        toolbar_box.toolbar.insert(self._duplicate_page_button, -1)

        self._add_page_button = ToolButton('list-add')
        self._add_page_button.set_tooltip(_('Add a page'))
        self._add_page_button.connect('clicked', self.__add_page_clicked_cb)
        toolbar_box.toolbar.insert(self._add_page_button, -1)

        self._remove_button = ToolButton('edit-delete')
        self._remove_button.set_tooltip(_('Remove an image or page'))
        self._remove_button.connect('clicked', self.__remove_clicked_cb)
        toolbar_box.toolbar.insert(self._remove_button, -1)

        self._prev_page_button = ToolButton('go-previous-paired')
        self._prev_page_button.set_tooltip(_('Previous page'))
        self._prev_page_button.connect('clicked', self.__prev_page_clicked_cb)
        toolbar_box.toolbar.insert(self._prev_page_button, -1)

        self._next_page_button = ToolButton('go-next-paired')
        self._next_page_button.set_tooltip(_('Next page'))
        self._next_page_button.connect('clicked', self.__next_page_clicked_cb)
        toolbar_box.toolbar.insert(self._next_page_button, -1)

        self._view_list_button = ToggleToolButton('view-list')
        self._view_list_button.set_tooltip(_('View pages'))
        self._view_list_button.connect('toggled', self.__view_list_toggled_cb)
        toolbar_box.toolbar.insert(self._view_list_button, -1)

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

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

        # add export buttons
        activity_toolbar = activity_button.props.page
        epub_button = ToolButton('save-as-epub')
        epub_button.set_tooltip(_('Save as EPUB book'))
        epub_button.connect('clicked', self.__save_ebook_clicked_cb)
        activity_toolbar.insert(epub_button, -1)
        epub_button.show()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show_all()

        edition_canvas = self.create_edition_canvas()

        hbox = Gtk.HBox()
        self._preview_panel = PreviewPanel(self._book_model.get_pages())
        self._preview_panel.connect('page-activated', self.__page_activated_cb)
        self._preview_panel.connect('page-moved', self.__page_moved_cb)
        hbox.pack_start(self._preview_panel, False, False, 0)
        hbox.pack_start(edition_canvas, True, True, 0)

        self.set_canvas(hbox)
        self.prepare_edit_toolbar()
        self._update_page_buttons()

        self.show_all()
        self._preview_panel.hide()
    def __state_change_cb(self, download, gparamspec):
        state = self._download.get_status()
        if state == WebKit.DownloadStatus.STARTED:
            # Check free space and cancel the download if there is not enough.
            total_size = self._download.get_total_size()
            logging.debug('Total size of the file: %s', total_size)
            enough_space = self.enough_space(total_size, path=self.temp_path)
            if not enough_space:
                logging.debug('Download canceled because of Disk Space')
                self.cancel()

                self._canceled_alert = Alert()
                self._canceled_alert.props.title = _('Not enough space '
                                                     'to download')

                total_size_mb = total_size / 1024.0**2
                free_space_mb = (self._free_available_space(
                    path=self.temp_path) - SPACE_THRESHOLD) \
                    / 1024.0 ** 2
                filename = self._download.get_suggested_filename()
                self._canceled_alert.props.msg = \
                    _('Download "%{filename}" requires %{total_size_in_mb}'
                      ' MB of free space, only %{free_space_in_mb} MB'
                      ' is available' %
                      {'filename': filename,
                       'total_size_in_mb': format_float(total_size_mb),
                       'free_space_in_mb': format_float(free_space_mb)})
                ok_icon = Icon(icon_name='dialog-ok')
                self._canceled_alert.add_button(Gtk.ResponseType.OK, _('Ok'),
                                                ok_icon)
                ok_icon.show()
                self._canceled_alert.connect('response',
                                             self.__stop_response_cb)
                self._activity.add_alert(self._canceled_alert)
            else:
                # FIXME: workaround for SL #4385
                # self._download.connect('notify::progress',
                #                        self.__progress_change_cb)
                self._download.connect('notify::current-size',
                                       self.__current_size_changed_cb)

                self._create_journal_object()
                self._object_id = self.dl_jobject.object_id

                alert = TimeoutAlert(9)
                alert.props.title = _('Download started')
                alert.props.msg = _('%s' %
                                    self._download.get_suggested_filename())
                self._activity.add_alert(alert)
                alert.connect('response', self.__start_response_cb)
                alert.show()
                global _active_downloads
                _active_downloads.append(self)

        elif state == WebKit.DownloadStatus.FINISHED:
            self._stop_alert = Alert()
            self._stop_alert.props.title = _('Download completed')
            self._stop_alert.props.msg = \
                _('%s' % self._download.get_suggested_filename())
            open_icon = Icon(icon_name='zoom-activity')
            self._stop_alert.add_button(Gtk.ResponseType.APPLY,
                                        _('Show in Journal'), open_icon)
            open_icon.show()
            ok_icon = Icon(icon_name='dialog-ok')
            self._stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
            ok_icon.show()
            self._activity.add_alert(self._stop_alert)
            self._stop_alert.connect('response', self.__stop_response_cb)
            self._stop_alert.show()

            if self._progress_sid is not None:
                GObject.source_remove(self._progress_sid)

            self.dl_jobject.metadata['title'] = \
                self._download.get_suggested_filename()
            self.dl_jobject.metadata['description'] = _('From: %s') \
                % self._source
            self.dl_jobject.metadata['progress'] = '100'
            self.dl_jobject.file_path = self._dest_path

            # sniff for a mime type, no way to get headers from WebKit
            sniffed_mime_type = mime.get_for_file(self._dest_path)
            self.dl_jobject.metadata['mime_type'] = sniffed_mime_type

            if sniffed_mime_type in ('image/bmp', 'image/gif', 'image/jpeg',
                                     'image/png', 'image/tiff'):
                preview = self._get_preview()
                if preview is not None:
                    self.dl_jobject.metadata['preview'] = \
                        dbus.ByteArray(preview)

            datastore.write(self.dl_jobject,
                            transfer_ownership=True,
                            reply_handler=self.__internal_save_cb,
                            error_handler=self.__internal_error_cb,
                            timeout=360)

        elif state == WebKit.DownloadStatus.CANCELLED:
            self.cleanup()
예제 #51
0
    def __init__(self, timeout=5, **kwargs):
        _TimeoutAlert.__init__(self, timeout, _('Continue'), **kwargs)

        icon = Icon(icon_name='dialog-cancel')
        self.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
        icon.show()
예제 #52
0
    def __init__(self, **kwargs):
        Alert.__init__(self, **kwargs)

        icon = Icon(icon_name='dialog-ok')
        self.add_button(Gtk.ResponseType.OK, _('Ok'), icon)
        icon.show()
예제 #53
0
        d = (self.end_size - self.start_size) * current
        self._icon.props.pixel_size = int(self.start_size + d)


def __animation_completed_cb(anim):
    print 'Animation completed'


def _destroy_cb(widget, data=None):
    Gtk.main_quit()


w = Gtk.Window()
w.connect("destroy", _destroy_cb)

box = Gtk.VBox()
w.add(box)

anim = animator.Animator(5)
anim.connect('completed', __animation_completed_cb)

my_icon = Icon(icon_name='go-next')
box.pack_start(my_icon, False, False, 0)

anim.add(_Animation(my_icon, style.STANDARD_ICON_SIZE, style.XLARGE_ICON_SIZE))
anim.start()

w.show_all()

Gtk.main()
예제 #54
0
class SpeakerPalette(Palette):
    def __init__(self, primary_text, model):
        Palette.__init__(self, label=primary_text)

        self._model = model

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

        self._mute_item = PaletteMenuItem('')
        self._mute_icon = Icon(icon_size=Gtk.IconSize.MENU)
        self._mute_item.set_image(self._mute_icon)
        box.append_item(self._mute_item)
        self._mute_item.show()
        self._mute_item.connect('activate', self.__mute_activate_cb)

        separator = PaletteMenuItemSeparator()
        box.append_item(separator)
        separator.show()

        vol_step = sound.VOLUME_STEP
        self._adjustment = Gtk.Adjustment(value=self._model.props.level,
                                          lower=0,
                                          upper=100 + vol_step,
                                          step_incr=vol_step,
                                          page_incr=vol_step,
                                          page_size=vol_step)

        hscale = Gtk.HScale()
        hscale.props.draw_value = False
        hscale.set_adjustment(self._adjustment)
        hscale.set_digits(0)
        box.append_item(hscale, vertical_padding=0)
        hscale.show()

        self._adjustment_handler_id = \
            self._adjustment.connect('value_changed',
                                     self.__adjustment_changed_cb)

        self._model_notify_level_handler_id = \
            self._model.connect('notify::level', self.__level_changed_cb)
        self._model.connect('notify::muted', self.__muted_changed_cb)

        self.connect('popup', self.__popup_cb)

    def _update_muted(self):
        if self._model.props.muted:
            mute_item_text = _('Unmute')
            mute_item_icon_name = 'dialog-ok'
        else:
            mute_item_text = _('Mute')
            mute_item_icon_name = 'dialog-cancel'
        self._mute_item.set_label(mute_item_text)
        self._mute_icon.props.icon_name = mute_item_icon_name
        self._mute_icon.show()

    def _update_level(self):
        if self._adjustment.props.value != self._model.props.level:
            self._adjustment.handler_block(self._adjustment_handler_id)
            try:
                self._adjustment.props.value = self._model.props.level
            finally:
                self._adjustment.handler_unblock(self._adjustment_handler_id)

    def __adjustment_changed_cb(self, adj_):
        self._model.handler_block(self._model_notify_level_handler_id)
        try:
            self._model.props.level = self._adjustment.props.value
        finally:
            self._model.handler_unblock(self._model_notify_level_handler_id)
        self._model.props.muted = self._adjustment.props.value == 0

    def __level_changed_cb(self, pspec_, param_):
        self._update_level()

    def __mute_activate_cb(self, menuitem_):
        self._model.props.muted = not self._model.props.muted

    def __muted_changed_cb(self, pspec_, param_):
        self._update_muted()

    def __popup_cb(self, palette_):
        self._update_level()
        self._update_muted()
예제 #55
0
    def _setup_page(self):
        for child in self.get_children():
            self.remove(child)

        def _setup_name_page(self):
            self._current_page = self._name_page

        def _setup_color_page(self):
            self._current_page = self._color_page

        def _setup_gender_page(self):
            if self._color_page.get_color() is not None:
                self._gender_page.update_color(self._color_page.get_color())
            self._current_page = self._gender_page

        def _setup_age_page(self):
            if self._gender_page.get_gender() is not None:
                self._age_page.update_gender(self._gender_page.get_gender())
            if self._color_page.get_color() is not None:
                self._age_page.update_color(self._color_page.get_color())
            self._current_page = self._age_page

        setup_methods = [
            _setup_name_page,
            _setup_color_page,
            _setup_gender_page,
            _setup_age_page
        ]

        setup_methods[self._page](self)
        self.pack_start(self._current_page, True, True, 0)
        self._current_page.show()

        button_box = Gtk.HButtonBox()
        if self._page == self.PAGE_FIRST:
            button_box.set_layout(Gtk.ButtonBoxStyle.END)
        else:
            button_box.set_layout(Gtk.ButtonBoxStyle.EDGE)
            back_button = Gtk.Button(_('Back'))
            image = Icon(icon_name='go-left')
            back_button.set_image(image)
            back_button.connect('clicked', self._back_activated_cb)
            button_box.pack_start(back_button, True, True, 0)
            back_button.show()

        self._next_button = Gtk.Button()
        image = Icon(icon_name='go-right')
        self._next_button.set_image(image)

        if self._page == self.PAGE_LAST:
            self._next_button.set_label(_('Done'))
            self._next_button.connect('clicked', self._done_activated_cb)
        else:
            self._next_button.set_label(_('Next'))
            self._next_button.connect('clicked', self._next_activated_cb)

        self._current_page.activate()

        self._update_next_button()
        button_box.pack_start(self._next_button, True, True, 0)
        self._next_button.show()

        self._current_page.connect('notify::valid',
                                   self._page_valid_changed_cb)

        self.pack_start(button_box, False, True, 0)
        button_box.show()

        if not self.PAGES[self._page]:
            self.next()
예제 #56
0
class FilterToolItem(Gtk.ToolItem):
    def __init__(self, primary_icon, secondary_icon, default_label,
                 widget):
        Gtk.ToolItem.__init__(self)

        self.set_size_request(style.GRID_CELL_SIZE * 3, -1)

        self._widget = widget
        self._visible = False

        grid = Gtk.Grid()
        grid.set_column_spacing(style.DEFAULT_SPACING)
        self.add(grid)
        grid.show()

        self._primary_icon = Icon(icon_name=primary_icon)
        self._secondary_icon = Icon(icon_name=secondary_icon)
        self._button = Gtk.Button()
        self._button.set_image(self._primary_icon)
        self._primary_icon.show()
        self._secondary_icon.show()
        grid.attach(self._button, 0, 0, 1, 1)
        self._button.show()
        self._button.connect('clicked', self.button_cb)

        event_box = Gtk.EventBox()
        self._label_widget = Gtk.Label()
        self._label_widget.set_alignment(0.0, 0.5)
        self._label_widget.set_use_markup(True)
        self.set_widget_label(default_label)
        event_box.add(self._label_widget)
        self._label_widget.show()
        grid.attach(event_box, 1, 0, 1, 1)
        event_box.show()
        # Allow clicking on the label in addition to the button
        event_box.set_events(Gdk.EventMask.TOUCH_MASK)
        event_box.connect('touch-event', self._touch_event_cb)

    def set_widget(self, widget):
        self._widget.destroy()
        self._widget = widget
        if self._visible:
            self._widget.show()
        else:
            self._widget.hide()

    def is_visible(self):
        return self._visible

    def _touch_event_cb(self, widget, event):
        if event.type in [Gdk.EventType.TOUCH_BEGIN]:
            self.button_cb(widget)

    def button_cb(self, widget=None):
        if self._visible:
            self._widget.hide()
            self._button.set_image(self._primary_icon)
        else:
            self._widget.show()
            self._button.set_image(self._secondary_icon)
        self._visible = not self._visible

    def set_widget_label(self, label):
        size = 'x-large'
        color = style.COLOR_BLACK.get_html()
        span = '<span foreground="%s" size="%s">' % (color, size)
        self._label_widget.set_markup(span + label + '</span>')
예제 #57
0
    def __init__(self):
        Gtk.Window.__init__(self)

        self.set_border_width(style.LINE_WIDTH)
        offset = style.GRID_CELL_SIZE
        width = Gdk.Screen.width() - offset * 2
        height = Gdk.Screen.height() - offset * 2
        self.set_size_request(width, height)
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_decorated(False)
        self.set_resizable(False)
        self.set_modal(True)

        self._main_view = Gtk.EventBox()
        self._vbox = Gtk.VBox()
        self._vbox.set_spacing(style.DEFAULT_SPACING)
        self._vbox.set_border_width(style.GRID_CELL_SIZE * 2)
        self._main_view.modify_bg(Gtk.StateType.NORMAL,
                                  style.COLOR_BLACK.get_gdk_color())
        self._main_view.add(self._vbox)
        self._vbox.show()

        color = profile.get_color()

        icon = Icon(icon_name='activity-journal',
                    pixel_size=style.XLARGE_ICON_SIZE,
                    xo_color=color)
        self._vbox.pack_start(icon, expand=False, fill=False, padding=0)
        icon.show()

        self._title = Gtk.Label()
        self._title.modify_fg(Gtk.StateType.NORMAL,
                              style.COLOR_WHITE.get_gdk_color())
        self._title.set_markup('<b>%s</b>' % _('Your Journal is full'))
        self._vbox.pack_start(self._title, expand=False, fill=False, padding=0)
        self._title.show()

        self._message = Gtk.Label(
            label=_('Please delete some old Journal'
                    ' entries to make space for new ones.'))
        self._message.modify_fg(Gtk.StateType.NORMAL,
                                style.COLOR_WHITE.get_gdk_color())
        self._vbox.pack_start(self._message,
                              expand=False,
                              fill=False,
                              padding=0)
        self._message.show()

        alignment = Gtk.Alignment.new(xalign=0.5,
                                      yalign=0.5,
                                      xscale=0.0,
                                      yscale=0.0)
        self._vbox.pack_start(alignment, expand=False, fill=True, padding=0)
        alignment.show()

        self._show_journal = Gtk.Button()
        self._show_journal.set_label(_('Show Journal'))
        alignment.add(self._show_journal)
        self._show_journal.show()
        self._show_journal.connect('clicked', self.__show_journal_cb)

        self.add(self._main_view)
        self._main_view.show()

        self.connect('realize', self.__realize_cb)
예제 #58
0
파일: gui.py 프로젝트: upman/sugar
    def __accept_clicked_cb(self, widget):
        if self._section_view.needs_restart:
            self._section_toolbar.accept_button.set_sensitive(False)
            self._section_toolbar.cancel_button.set_sensitive(False)
            alert = Alert()
            alert.props.title = _('Warning')
            alert.props.msg = _('Changes require restart')

            icon = Icon(icon_name='dialog-cancel')
            alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel changes'),
                             icon)
            icon.show()

            if self._current_option != 'aboutme':
                icon = Icon(icon_name='dialog-ok')
                alert.add_button(Gtk.ResponseType.ACCEPT, _('Later'), icon)
                icon.show()

            icon = Icon(icon_name='system-restart')
            alert.add_button(Gtk.ResponseType.APPLY, _('Restart now'), icon)
            icon.show()

            self._vbox.pack_start(alert, False, False, 0)
            self._vbox.reorder_child(alert, 2)
            alert.connect('response', self.__response_cb)
            alert.show()
        else:
            self._show_main_view()
예제 #59
0
    def __init__(self, title, bundle_path, document_path, sugar_toolkit_path):
        Gtk.Toolbar.__init__(self)

        document_button = None
        self.bundle_path = bundle_path
        self.sugar_toolkit_path = sugar_toolkit_path

        self._add_separator()

        activity_bundle = get_bundle_instance(bundle_path)
        file_name = activity_bundle.get_icon()
        activity_name = activity_bundle.get_name()

        if document_path is not None and os.path.exists(document_path):
            document_button = DocumentButton(file_name, document_path,
                                             activity_name, title)
            document_button.connect('toggled', self.__button_toggled_cb,
                                    document_path)
            self.insert(document_button, -1)
            document_button.show()
            self._add_separator()

        if bundle_path is not None and os.path.exists(bundle_path):
            activity_button = DocumentButton(file_name, bundle_path,
                                             activity_name, title, bundle=True)
            icon = Icon(file=file_name,
                        pixel_size=style.STANDARD_ICON_SIZE,
                        fill_color=style.COLOR_TRANSPARENT.get_svg(),
                        stroke_color=style.COLOR_WHITE.get_svg())
            activity_button.set_icon_widget(icon)
            icon.show()
            if document_button is not None:
                activity_button.props.group = document_button
            activity_button.props.tooltip = _('Activity Bundle Source')
            activity_button.connect('toggled', self.__button_toggled_cb,
                                    bundle_path)
            self.insert(activity_button, -1)
            activity_button.show()
            self._add_separator()

        if sugar_toolkit_path is not None:
            sugar_button = RadioToolButton()
            icon = Icon(icon_name='computer-xo',
                        pixel_size=style.STANDARD_ICON_SIZE,
                        fill_color=style.COLOR_TRANSPARENT.get_svg(),
                        stroke_color=style.COLOR_WHITE.get_svg())
            sugar_button.set_icon_widget(icon)
            icon.show()
            if document_button is not None:
                sugar_button.props.group = document_button
            else:
                sugar_button.props.group = activity_button
            sugar_button.props.tooltip = _('Sugar Toolkit Source')
            sugar_button.connect('toggled', self.__button_toggled_cb,
                                 sugar_toolkit_path)
            self.insert(sugar_button, -1)
            sugar_button.show()
            self._add_separator()

        self.activity_title_text = _('View source: %s') % title
        self.sugar_toolkit_title_text = _('View source: %r') % 'Sugar Toolkit'
        self.label = Gtk.Label()
        self.label.set_markup('<b>%s</b>' % self.activity_title_text)
        self.label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT)
        self.label.set_alignment(0, 0.5)
        self._add_widget(self.label, expand=True)

        self._add_separator(False)

        stop = ToolButton(icon_name='dialog-cancel')
        stop.set_tooltip(_('Close'))
        stop.connect('clicked', self.__stop_clicked_cb)
        self.insert(stop, -1)
        stop.show()
예제 #60
0
class BookmarkView(Gtk.EventBox):

    __gsignals__ = {
        'bookmark-changed':
        (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ([])),
    }

    def __init__(self):
        Gtk.EventBox.__init__(self)
        self._box = Gtk.VButtonBox()
        self._box.set_layout(Gtk.ButtonBoxStyle.START)
        self._box.set_margin_top(style.GRID_CELL_SIZE / 2)
        self.add(self._box)
        self._box.show()

        self._bookmark_icon = None
        self._bookmark_manager = None
        self._is_showing_local_bookmark = False
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('draw', self.__draw_cb)
        self.connect('event', self.__event_cb)

    def __draw_cb(self, widget, ctx):
        width = style.GRID_CELL_SIZE
        height = style.GRID_CELL_SIZE * (len(self._bookmarks) + 1)

        ctx.rectangle(0, 0, width, height)
        ctx.set_source_rgba(*self._fill_color.get_rgba())
        ctx.paint()

        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.line_to(width, 0)
        ctx.line_to(width, height)
        ctx.line_to(width / 2, height - width / 2)
        ctx.line_to(0, height)
        ctx.close_path()
        ctx.set_source_rgba(*self._stroke_color.get_rgba())
        ctx.fill()

    def _add_bookmark_icon(self, bookmark):
        self._xo_color = XoColor(str(bookmark.color))
        self._fill_color = style.Color(self._xo_color.get_fill_color())
        self._stroke_color = style.Color(self._xo_color.get_stroke_color())
        self._bookmark_icon = Icon(icon_name='emblem-favorite',
                                   xo_color=self._xo_color,
                                   pixel_size=style.STANDARD_ICON_SIZE)
        self._bookmark_icon.set_valign(Gtk.Align.START)

        self._box.props.has_tooltip = True
        self.__box_query_tooltip_cb_id = self._box.connect(
            'query_tooltip', self.__bookmark_query_tooltip_cb)

        self._box.pack_start(self._bookmark_icon, False, False, 0)
        self._bookmark_icon.show_all()

        if bookmark.is_local():
            self._is_showing_local_bookmark = True

    def __bookmark_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip):
        vbox = Gtk.VBox()
        for bookmark in self._bookmarks:

            tooltip_header = bookmark.get_note_title()
            tooltip_body = bookmark.get_note_body()
            time = timestamp_to_elapsed_string(bookmark.timestamp)
            # TRANS: This goes like Bookmark added by User 5 days ago
            # TRANS: (the elapsed string gets translated automatically)
            tooltip_footer = (_('Bookmark added by %(user)s %(time)s') % {
                'user': bookmark.nick.decode('utf-8'),
                'time': time.decode('utf-8')
            })

            l = Gtk.Label('<big>%s</big>' % tooltip_header)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

            l = Gtk.Label('%s' % tooltip_body)
            l.set_use_markup(True)
            l.set_alignment(0, 0)
            l.set_padding(2, 6)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            l.set_justify(Gtk.Justification.FILL)
            vbox.pack_start(l, True, True, 0)
            l.show()

            l = Gtk.Label('<small><i>%s</i></small>' % tooltip_footer)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

        tip.set_custom(vbox)
        return True

    def __event_cb(self, widget, event):
        if event.type == Gdk.EventType.BUTTON_PRESS:
            # TODO: show the first bookmark
            dialog = BookmarkEditDialog(self.get_toplevel().get_window(),
                                        _("Add notes for bookmark: "),
                                        self._bookmarks, self._page, self)
            dialog.show_all()

        return False

    def _clear_bookmarks(self):
        for bookmark_icon in self._box.get_children():
            bookmark_icon.destroy()
            self._bookmark_icon = None
            self._is_showing_local_bookmark = False

    def set_bookmarkmanager(self, bookmark_manager):
        self._bookmark_manager = bookmark_manager

    def get_bookmarkmanager(self):
        return (self._bookmark_manager)

    def update_for_page(self, page):
        self._page = page
        self._clear_bookmarks()
        if self._bookmark_manager is None:
            return

        self._bookmarks = self._bookmark_manager.get_bookmarks_for_page(page)

        if self._bookmarks:
            self.show()
        else:
            self.hide()

        for bookmark in self._bookmarks:
            self._add_bookmark_icon(bookmark)

        self.set_size_request(
            style.GRID_CELL_SIZE,
            style.GRID_CELL_SIZE * (len(self._bookmarks) + 1))

        self.notify_bookmark_change()

    def notify_bookmark_change(self):
        self.queue_draw()
        self.emit('bookmark-changed')

    def add_bookmark(self, page):
        bookmark_title = (_("%s's bookmark") % profile.get_nick_name())
        bookmark_content = (_("Bookmark for page %d") % (int(page) + 1))
        dialog = BookmarkAddDialog(parent_xid=self.get_toplevel().get_window(),
                                   dialog_title=_("Add notes for bookmark: "),
                                   bookmark_title=bookmark_title,
                                   bookmark_content=bookmark_content,
                                   page=page,
                                   sidebarinstance=self)
        dialog.show_all()

    def _real_add_bookmark(self, page, content):
        self._bookmark_manager.add_bookmark(page, unicode(content))
        self.update_for_page(page)

    def del_bookmark(self, page):
        self._bookmark_manager.del_bookmark(page)
        self.update_for_page(page)

    def is_showing_local_bookmark(self):
        return self._is_showing_local_bookmark