Exemplo n.º 1
0
    def __init__(self, app, prefs_id=_DEFAULT_PREFS_ID):
        """Initialize"""
        Gtk.VBox.__init__(self)
        self.app = app
        self.bm = app.brushmanager

        self._prefs_key = self._PREFS_KEY_TEMPLATE % (prefs_id,)
        active_group_name = app.preferences.get(self._prefs_key, None)

        model = self._make_groups_sb_model()
        self.groups_sb = spinbox.ItemSpinBox(model, self._groups_sb_changed_cb,
                                             active_group_name)
        active_group_name = self.groups_sb.get_value()

        brushes = self.bm.groups[active_group_name][:]

        self.brushlist = PixbufList(brushes, self.ICON_SIZE, self.ICON_SIZE,
                                    namefunc=lambda x: x.name,
                                    pixbuffunc=lambda x: x.preview)
        self.brushlist.dragging_allowed = False
        self.bm.groups_changed += self._update_groups_sb
        self.brushlist.item_selected += self._item_selected_cb

        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
        scrolledwin.add_with_viewport(self.brushlist)
        w = int(self.ICON_SIZE * 4.5)
        h = int(self.ICON_SIZE * 5.0)
        scrolledwin.set_min_content_width(w)
        scrolledwin.set_min_content_height(h)
        scrolledwin.get_child().set_size_request(w, h)

        self.pack_start(self.groups_sb, False, False, 0)
        self.pack_start(scrolledwin, True, True, 0)
        self.set_spacing(widgets.SPACING_TIGHT)
Exemplo n.º 2
0
 def __init__(self, chooser, brushes):
     s = QuickBrushChooser.ICON_SIZE
     PixbufList.__init__(
         self, brushes, s, s,
         namefunc=lambda x: x.name,
         pixbuffunc=lambda x: x.preview
     )
     self.chooser = chooser
Exemplo n.º 3
0
 def __init__(self, chooser, brushes):
     s = QuickBrushChooser.ICON_SIZE
     PixbufList.__init__(self,
                         brushes,
                         s,
                         s,
                         namefunc=lambda x: x.name,
                         pixbuffunc=lambda x: x.preview)
     self.chooser = chooser
Exemplo n.º 4
0
class QuickBrushChooser(Gtk.VBox):
    """A quick chooser widget for brushes"""

    ## Class constants

    _PREFS_KEY_TEMPLATE = u"brush_chooser.%s.selected_group"
    ICON_SIZE = 48

    ## Method defs

    def __init__(self, app, prefs_id=_DEFAULT_PREFS_ID):
        """Initialize"""
        Gtk.VBox.__init__(self)
        self.app = app
        self.bm = app.brushmanager

        self._prefs_key = self._PREFS_KEY_TEMPLATE % (prefs_id,)
        active_group_name = app.preferences.get(self._prefs_key, None)

        model = self._make_groups_sb_model()
        self.groups_sb = spinbox.ItemSpinBox(model, self._groups_sb_changed_cb, active_group_name)
        active_group_name = self.groups_sb.get_value()

        brushes = self.bm.get_group_brushes(active_group_name)

        self.brushlist = PixbufList(
            brushes,
            self.ICON_SIZE,
            self.ICON_SIZE,
            namefunc=brushselectionwindow.managedbrush_namefunc,
            pixbuffunc=brushselectionwindow.managedbrush_pixbuffunc,
            idfunc=brushselectionwindow.managedbrush_idfunc,
        )
        self.brushlist.dragging_allowed = False
        self.bm.groups_changed += self._groups_changed_cb
        self.bm.brushes_changed += self._brushes_changed_cb
        self.brushlist.item_selected += self._item_selected_cb

        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
        scrolledwin.add_with_viewport(self.brushlist)
        w = int(self.ICON_SIZE * 4.5)
        h = int(self.ICON_SIZE * 5.0)
        scrolledwin.set_min_content_width(w)
        scrolledwin.set_min_content_height(h)
        scrolledwin.get_child().set_size_request(w, h)

        self.pack_start(self.groups_sb, False, False, 0)
        self.pack_start(scrolledwin, True, True, 0)
        self.set_spacing(widgets.SPACING_TIGHT)

    def _item_selected_cb(self, pixbuf_list, brush):
        """Internal: call brush_selected event when an item is chosen"""
        self.brush_selected(brush)

    @event
    def brush_selected(self, brush):
        """Event: a brush was selected

        :param brush: The newly chosen brush
        """

    def _make_groups_sb_model(self):
        """Internal: create the model for the group choice spinbox"""
        group_names = sorted(self.bm.groups.keys())
        model = []
        for name in group_names:
            label_text = brushmanager.translate_group_name(name)
            model.append((name, label_text))
        return model

    def _groups_changed_cb(self, bm):
        """Internal: update the spinbox model at the top of the widget"""
        model = self._make_groups_sb_model()
        self.groups_sb.set_model(model)
        # In case the group has been deleted and recreated, we do this:
        group_name = self.groups_sb.get_value()
        group_brushes = self.bm.groups.get(group_name, [])
        self.brushlist.itemlist = group_brushes
        self.brushlist.update()
        # See https://github.com/mypaint/mypaint/issues/654

    def _brushes_changed_cb(self, bm, brushes):
        """Internal: update the PixbufList if its group was changed."""
        # CARE: this might be called in response to the group being deleted.
        # Don't recreate it by accident.
        group_name = self.groups_sb.get_value()
        group_brushes = self.bm.groups.get(group_name)
        if brushes is group_brushes:
            self.brushlist.update()

    def _groups_sb_changed_cb(self, group_name):
        """Internal: update the list of brush icons when the group changes"""
        self.app.preferences[self._prefs_key] = group_name
        group_brushes = self.bm.groups.get(group_name, [])
        self.brushlist.itemlist = group_brushes
        self.brushlist.update()

    def advance(self):
        """Advances to the next page of brushes."""
        self.groups_sb.next()
Exemplo n.º 5
0
class QuickBrushChooser(Gtk.VBox):
    """A quick chooser widget for brushes"""

    ## Class constants

    _PREFS_KEY_TEMPLATE = u"brush_chooser.%s.selected_group"
    ICON_SIZE = 48

    ## Method defs

    def __init__(self, app, prefs_id=_DEFAULT_PREFS_ID):
        """Initialize"""
        Gtk.VBox.__init__(self)
        self.app = app
        self.bm = app.brushmanager

        self._prefs_key = self._PREFS_KEY_TEMPLATE % (prefs_id, )
        active_group_name = app.preferences.get(self._prefs_key, None)

        model = self._make_groups_sb_model()
        self.groups_sb = spinbox.ItemSpinBox(model, self._groups_sb_changed_cb,
                                             active_group_name)
        active_group_name = self.groups_sb.get_value()

        brushes = self.bm.groups[active_group_name][:]

        self.brushlist = PixbufList(brushes,
                                    self.ICON_SIZE,
                                    self.ICON_SIZE,
                                    namefunc=lambda x: x.name,
                                    pixbuffunc=lambda x: x.preview)
        self.brushlist.dragging_allowed = False
        self.bm.groups_changed += self._update_groups_sb
        self.brushlist.item_selected += self._item_selected_cb

        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
        scrolledwin.add_with_viewport(self.brushlist)
        w = int(self.ICON_SIZE * 4.5)
        h = int(self.ICON_SIZE * 5.0)
        scrolledwin.set_min_content_width(w)
        scrolledwin.set_min_content_height(h)
        scrolledwin.get_child().set_size_request(w, h)

        self.pack_start(self.groups_sb, False, False)
        self.pack_start(scrolledwin, True, True)
        self.set_spacing(widgets.SPACING_TIGHT)

    def _item_selected_cb(self, pixbuf_list, brush):
        """Internal: call brush_selected event when an item is chosen"""
        self.brush_selected(brush)

    @event
    def brush_selected(self, brush):
        """Event: a brush was selected

        :param brush: The newly chosen brush
        """

    def _make_groups_sb_model(self):
        """Internal: create the model for the group choice spinbox"""
        group_names = self.bm.groups.keys()
        group_names.sort()
        model = []
        for name in group_names:
            label_text = brushmanager.translate_group_name(name)
            model.append((name, label_text))
        return model

    def _update_groups_sb(self, bm):
        """Internal: update the spinbox model at the top of the widget"""
        model = self._make_groups_sb_model()
        self.groups_sb.set_model(model)

    def _groups_sb_changed_cb(self, group_name):
        """Internal: update the list of brush icons when the group changes"""
        self.app.preferences[self._prefs_key] = group_name
        self.brushlist.itemlist[:] = self.bm.groups[group_name][:]
        self.brushlist.update()

    def advance(self):
        """Advances to the next page of brushes."""
        self.groups_sb.next()
Exemplo n.º 6
0
class QuickBrushChooser (Gtk.VBox):
    """A quick chooser widget for brushes"""

    ## Class constants

    _PREFS_KEY_TEMPLATE = u"brush_chooser.%s.selected_group"
    ICON_SIZE = 48

    ## Method defs

    def __init__(self, app, prefs_id=_DEFAULT_PREFS_ID):
        """Initialize"""
        Gtk.VBox.__init__(self)
        self.app = app
        self.bm = app.brushmanager

        self._prefs_key = self._PREFS_KEY_TEMPLATE % (prefs_id,)
        active_group_name = app.preferences.get(self._prefs_key, None)

        model = self._make_groups_sb_model()
        self.groups_sb = spinbox.ItemSpinBox(model, self._groups_sb_changed_cb,
                                             active_group_name)
        active_group_name = self.groups_sb.get_value()

        brushes = self.bm.groups[active_group_name][:]

        self.brushlist = PixbufList(brushes, self.ICON_SIZE, self.ICON_SIZE,
                                    namefunc=lambda x: x.name,
                                    pixbuffunc=lambda x: x.preview)
        self.brushlist.dragging_allowed = False
        self.bm.groups_changed += self._update_groups_sb
        self.brushlist.item_selected += self._item_selected_cb

        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
        scrolledwin.add_with_viewport(self.brushlist)
        w = int(self.ICON_SIZE * 4.5)
        h = int(self.ICON_SIZE * 5.0)
        scrolledwin.set_min_content_width(w)
        scrolledwin.set_min_content_height(h)
        scrolledwin.get_child().set_size_request(w, h)

        self.pack_start(self.groups_sb, False, False, 0)
        self.pack_start(scrolledwin, True, True, 0)
        self.set_spacing(widgets.SPACING_TIGHT)

    def _item_selected_cb(self, pixbuf_list, brush):
        """Internal: call brush_selected event when an item is chosen"""
        self.brush_selected(brush)

    @event
    def brush_selected(self, brush):
        """Event: a brush was selected

        :param brush: The newly chosen brush
        """

    def _make_groups_sb_model(self):
        """Internal: create the model for the group choice spinbox"""
        group_names = self.bm.groups.keys()
        group_names.sort()
        model = []
        for name in group_names:
            label_text = brushmanager.translate_group_name(name)
            model.append((name, label_text))
        return model

    def _update_groups_sb(self, bm):
        """Internal: update the spinbox model at the top of the widget"""
        model = self._make_groups_sb_model()
        self.groups_sb.set_model(model)

    def _groups_sb_changed_cb(self, group_name):
        """Internal: update the list of brush icons when the group changes"""
        self.app.preferences[self._prefs_key] = group_name
        self.brushlist.itemlist[:] = self.bm.groups[group_name][:]
        self.brushlist.update()

    def advance(self):
        """Advances to the next page of brushes."""
        self.groups_sb.next()
Exemplo n.º 7
0
class QuickBrushChooser (Gtk.VBox):
    """A quick chooser widget for brushes"""

    ## Class constants

    _PREFS_KEY_TEMPLATE = u"brush_chooser.%s.selected_group"
    ICON_SIZE = 48

    ## Method defs

    def __init__(self, app, prefs_id=_DEFAULT_PREFS_ID):
        """Initialize"""
        Gtk.VBox.__init__(self)
        self.app = app
        self.bm = app.brushmanager

        self._prefs_key = self._PREFS_KEY_TEMPLATE % (prefs_id,)
        active_group_name = app.preferences.get(self._prefs_key, None)

        model = self._make_groups_sb_model()
        self.groups_sb = spinbox.ItemSpinBox(model, self._groups_sb_changed_cb,
                                             active_group_name)
        active_group_name = self.groups_sb.get_value()

        brushes = self.bm.get_group_brushes(active_group_name)

        self.brushlist = PixbufList(
            brushes, self.ICON_SIZE, self.ICON_SIZE,
            namefunc=brushselectionwindow.managedbrush_namefunc,
            pixbuffunc=brushselectionwindow.managedbrush_pixbuffunc,
            idfunc=brushselectionwindow.managedbrush_idfunc
        )
        self.brushlist.dragging_allowed = False
        self.bm.groups_changed += self._groups_changed_cb
        self.bm.brushes_changed += self._brushes_changed_cb
        self.brushlist.item_selected += self._item_selected_cb

        scrolledwin = Gtk.ScrolledWindow()
        scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
        scrolledwin.add_with_viewport(self.brushlist)
        w = int(self.ICON_SIZE * 4.5)
        h = int(self.ICON_SIZE * 5.0)
        scrolledwin.set_min_content_width(w)
        scrolledwin.set_min_content_height(h)
        scrolledwin.get_child().set_size_request(w, h)

        self.pack_start(self.groups_sb, False, False, 0)
        self.pack_start(scrolledwin, True, True, 0)
        self.set_spacing(widgets.SPACING_TIGHT)

    def _item_selected_cb(self, pixbuf_list, brush):
        """Internal: call brush_selected event when an item is chosen"""
        self.brush_selected(brush)

    @event
    def brush_selected(self, brush):
        """Event: a brush was selected

        :param brush: The newly chosen brush
        """

    def _make_groups_sb_model(self):
        """Internal: create the model for the group choice spinbox"""
        group_names = sorted(self.bm.groups.keys())
        model = []
        for name in group_names:
            label_text = brushmanager.translate_group_name(name)
            model.append((name, label_text))
        return model

    def _groups_changed_cb(self, bm):
        """Internal: update the spinbox model at the top of the widget"""
        model = self._make_groups_sb_model()
        self.groups_sb.set_model(model)
        # In case the group has been deleted and recreated, we do this:
        group_name = self.groups_sb.get_value()
        group_brushes = self.bm.groups.get(group_name, [])
        self.brushlist.itemlist = group_brushes
        self.brushlist.update()
        # See https://github.com/mypaint/mypaint/issues/654

    def _brushes_changed_cb(self, bm, brushes):
        """Internal: update the PixbufList if its group was changed."""
        # CARE: this might be called in response to the group being deleted.
        # Don't recreate it by accident.
        group_name = self.groups_sb.get_value()
        group_brushes = self.bm.groups.get(group_name)
        if brushes is group_brushes:
            self.brushlist.update()

    def _groups_sb_changed_cb(self, group_name):
        """Internal: update the list of brush icons when the group changes"""
        self.app.preferences[self._prefs_key] = group_name
        group_brushes = self.bm.groups.get(group_name, [])
        self.brushlist.itemlist = group_brushes
        self.brushlist.update()

    def advance(self):
        """Advances to the next page of brushes."""
        self.groups_sb.next()