Beispiel #1
0
 def _delete_cb(self, widget):
     """Properties dialog delete callback"""
     self._dialog.hide()
     name = brushmanager.translate_group_name(self._group)
     msg = C_(
         "brush group delete",
         u"Really delete group \u201C{group_name}\u201D?",
     ).format(group_name=name, )
     bm = self._app.brushmanager
     if not dialogs.confirm(self, msg):
         return
     bm.delete_group(self._group)
     if self._group not in bm.groups:
         GLib.idle_add(
             self._remove_panel_idle_cb,
             self.__gtype_name__,
             (self._group, ),
         )
         return
     # Special groups like "Deleted" cannot be deleted,
     # but the error message is very confusing in that case...
     msg = C_(
         "brush group delete",
         u"Could not delete group \u201C{group_name}\u201D.\n"
         u"Some special groups cannot be deleted.",
     ).format(group_name=name, )
     dialogs.error(self, msg)
 def _delete_cb(self, widget):
     """Properties dialog delete callback"""
     self._dialog.hide()
     name = brushmanager.translate_group_name(self._group)
     msg = C_(
         "brush group delete",
         u"Really delete group \u201C{group_name}\u201D?",
     ).format(
         group_name = name,
     )
     bm = self._app.brushmanager
     if not dialogs.confirm(self, msg):
         return
     bm.delete_group(self._group)
     if self._group not in bm.groups:
         GLib.idle_add(
             self._remove_panel_idle_cb,
             self.__gtype_name__, (self._group,),
         )
         return
     # Special groups like "Deleted" cannot be deleted,
     # but the error message is very confusing in that case...
     msg = C_(
         "brush group delete",
         u"Could not delete group \u201C{group_name}\u201D.\n"
         u"Some special groups cannot be deleted.",
     ).format(
         group_name = name,
     )
     dialogs.error(self, msg)
Beispiel #3
0
 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
Beispiel #4
0
 def _make_groups_sb_model(self):
     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
Beispiel #5
0
 def _make_groups_sb_model(self):
     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
Beispiel #6
0
 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 delete_group_cb(self, w, group):
     msg = _('Really delete group %s?') \
             % brushmanager.translate_group_name(group)
     if dialogs.confirm(self, msg):
         self.bm.delete_group(group)
         if group in self.bm.groups:
             msg = _('This group can not be deleted '
                     '(try to empty it first).')
             dialogs.error(self, msg)
Beispiel #8
0
 def _delete_cb(self, widget):
     """Properties dialog delete callback"""
     self._dialog.hide()
     name = brushmanager.translate_group_name(self._group)
     msg = _('Really delete group "%s"?') % (name, )
     bm = self._app.brushmanager
     if not dialogs.confirm(self, msg):
         return
     bm.delete_group(self._group)
     if self._group not in bm.groups:
         self._app.workspace.hide_tool_widget(self.__gtype_name__,
                                              (self._group, ))
         return
     msg = _('Group "%s" cannot be deleted. Try emptying it first.')
     dialogs.error(self, msg % (name, ))
Beispiel #9
0
 def _delete_cb(self, widget):
     """Properties dialog delete callback"""
     self._dialog.hide()
     name = brushmanager.translate_group_name(self._group)
     msg = _('Really delete group "%s"?') % (name,)
     bm = self._app.brushmanager
     if not dialogs.confirm(self, msg):
         return
     bm.delete_group(self._group)
     if self._group not in bm.groups:
         self._app.workspace.hide_tool_widget(self.__gtype_name__,
                                              (self._group,))
         return
     msg = _('Group "%s" cannot be deleted. Try emptying it first.')
     dialogs.error(self, msg % (name,))
 def _update(self, bm):
     """Update dynamic items in response to the groups list changing"""
     for item in self._items.itervalues():
         if item not in self:
             continue
         self.remove(item)
     activate_cb = self._brush_group_item_activate_cb
     for name in reversed(sorted(bm.groups)):
         if name in self._items:
             item = self._items[name]
         else:
             item = gtk.ImageMenuItem()
             label = brushmanager.translate_group_name(name)
             item.set_label(label)
             item.connect("activate", activate_cb, name)
             self._items[name] = item
         self.prepend(item)
     for name, item in list(self._items.iteritems()):
         if item in self:
             continue
         self._items.pop(name)
     self.show_all()
Beispiel #11
0
 def _update(self, bm):
     """Update dynamic items in response to the groups list changing"""
     for item in self._items.itervalues():
         if item not in self:
             continue
         self.remove(item)
     activate_cb = self._brush_group_item_activate_cb
     for name in reversed(sorted(bm.groups)):
         if name in self._items:
             item = self._items[name]
         else:
             item = Gtk.ImageMenuItem()
             label = brushmanager.translate_group_name(name)
             item.set_label(label)
             item.connect("activate", activate_cb, name)
             self._items[name] = item
         self.prepend(item)
     for name, item in list(self._items.iteritems()):
         if item in self:
             continue
         self._items.pop(name)
     self.show_all()
 def tool_widget_title(self):
     return brushmanager.translate_group_name(self._group)
Beispiel #13
0
 def tool_widget_title(self):
     return brushmanager.translate_group_name(self._group)
Beispiel #14
0
    def lay_out_group_names(self, width):
        "Typeset the group names into a new Pango layout at a given width"
        self.ensure_style()
        style = self.get_style()
        layout = pango.Layout(self.get_pango_context())
        layout.set_width(width*pango.SCALE)
        #layout.set_font_description(style.font_desc) # Needed?

        all_groups = list(sorted(self.bm.groups.keys()))
        idx = 0
        attr = pango.AttrList()
        self.idx2group = {}

        # Pick separator chars. Platform-dependent, but assume Unicode
        # for modern OSes first.
        pad_s = u"\u202f"  # NARROW NO-BREAK SPACE
        sp_s = pad_s + u"\u200b"  # ZERO WIDTH SPACE

        import platform
        if platform.system() == 'Windows' or platform.system() == 'Darwin':
            # workaround for https://gna.org/bugs/?15192
            pad_s = ''
            sp_s = ' '

        def _gdk_color_to_hex(col):
            rgb = (col.red, col.green, col.blue)
            rgb = [max(min(c>>8, 255), 0) for c in rgb]
            return "#%02x%02x%02x" % tuple(rgb)

        markup = ''
        for group in all_groups:
            group_label = brushmanager.translate_group_name(group)
            u = pad_s + group_label + pad_s
            idx_start = idx
            for c in u.encode('utf-8'):
                self.idx2group[idx] = group
                idx += 1

            # Note the difference in terminology here
            bg_state = fg_state = gtk.STATE_NORMAL
            if group == self.gtkstate_active_group: # activated the menu
                bg_state = fg_state = gtk.STATE_ACTIVE
            elif group in self.bm.active_groups: # those groups visible
                bg_state = fg_state = gtk.STATE_SELECTED
            elif group == self.gtkstate_prelight_group:
                bg_state = fg_state = gtk.STATE_PRELIGHT

            style_fg, style_bg = style.fg, style.bg
            if group == self.drag_target_group:
                # Invert colours
                style_fg, style_bg = style.bg, style.fg

            # always use the STATE_SELECTED fg if the group is visible
            if group in self.bm.active_groups:
                fg_state = gtk.STATE_SELECTED

            c_bg = _gdk_color_to_hex(style_bg[bg_state])
            c_fg = _gdk_color_to_hex(style_fg[fg_state])
            m = escape(u)
            m = "<span fgcolor='%s' bgcolor='%s'>%s</span>" % (c_fg, c_bg, m)
            markup += m + sp_s
            idx += len(sp_s.encode("utf-8"))

        layout.set_markup(markup)
        leading = style.font_desc.get_size() / 6
        layout.set_spacing(leading)
        return layout
    def lay_out_group_names(self, width):
        "Typeset the group names into a new Pango layout at a given width"
        self.ensure_style()
        style = self.get_style()
        layout = pango.Layout(self.get_pango_context())
        layout.set_width(width*pango.SCALE)
        #layout.set_font_description(style.font_desc) # Needed?

        all_groups = list(sorted(self.bm.groups.keys()))
        idx = 0
        text = ''
        attr = pango.AttrList()
        self.idx2group = {}

        # Pick separator chars. Platform-dependent, but assume Unicode
        # for modern OSes first.
        pad_s = u"\u202f"  # NARROW NO-BREAK SPACE
        sp_s = pad_s + u"\u200b"  # ZERO WIDTH SPACE

        import platform
        if platform.system() == 'Windows':
            # workaround for https://gna.org/bugs/?15192
            pad_s = ''
            sp_s = ' '

        for group in all_groups:
            group_label = brushmanager.translate_group_name(group)
            u = pad_s + group_label + pad_s
            s = u.encode('utf-8')
            idx_start = idx
            for c in s:
                self.idx2group[idx] = group
                idx += 1
            
            # Note the difference in terminology here
            bg_state = fg_state = gtk.STATE_NORMAL
            if group == self.gtkstate_active_group: # activated the menu
                bg_state = fg_state = gtk.STATE_ACTIVE
            elif group in self.bm.active_groups: # those groups visible
                bg_state = fg_state = gtk.STATE_SELECTED
            elif group == self.gtkstate_prelight_group:
                bg_state = fg_state = gtk.STATE_PRELIGHT

            style_fg, style_bg = style.fg, style.bg
            if group == self.drag_target_group:
                # Invert colurs
                style_fg, style_bg = style.bg, style.fg
                # attr.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE, idx_start, idx))

            # always use the STATE_SELECTED fg if the group is visible
            if group in self.bm.active_groups:
                fg_state = gtk.STATE_SELECTED 

            c = style_bg[bg_state]
            attr.insert(pango.AttrBackground(c.red, c.green, c.blue, idx_start, idx))
            c = style_fg[fg_state]
            attr.insert(pango.AttrForeground(c.red, c.green, c.blue, idx_start, idx))

            text += u + sp_s
            idx += len(sp_s.encode("utf-8"))

        layout.set_text(text)
        layout.set_attributes(attr)

        leading = style.font_desc.get_size() / 6
        layout.set_spacing(leading)
        return layout
    def lay_out_group_names(self, width):
        """Typeset the group names into a new Pango layout at a given width.
        """
        layout = pango.Layout(self.get_pango_context())
        layout.set_width(width*pango.SCALE)

        all_groups = list(sorted(self.bm.groups.keys()))
        idx = 0
        attr = pango.AttrList()
        self.idx2group = {}

        # Pick separator chars. Platform-dependent, but assume Unicode
        # for modern OSes first.
        pad_s = u"\u202f"  # NARROW NO-BREAK SPACE
        sp_s = pad_s + u"\u200b"  # ZERO WIDTH SPACE

        if platform.system() == 'Windows' or platform.system() == 'Darwin':
            # workaround for https://gna.org/bugs/?15192
            pad_s = ''
            sp_s = ' '

        markup = ''
        for group in all_groups:
            group_label = brushmanager.translate_group_name(group)
            u = pad_s + group_label + pad_s
            idx_start = idx
            for c in u.encode('utf-8'):
                self.idx2group[idx] = group
                idx += 1

            # Note the difference in terminology here
            colors_name = "normal"
            set_bgcolor = False
            if group == self.gtkstate_active_group: # activated the menu
                colors_name = "active"
                set_bgcolor = True
            elif group in self.bm.active_groups: # those groups visible
                colors_name = "selected"
                set_bgcolor = True
            if group == self.gtkstate_prelight_group:
                colors_name += "_pre"
                set_bgcolor = True
            fg, bg = self._text_colors[colors_name]

            if group == self.drag_target_group:
                # Invert colours
                fg, bg = bg, fg

            c_fg = fg.to_hex_str()
            m = escape(u)
            if set_bgcolor:
                c_bg = bg.to_hex_str()
                bgcolor = " bgcolor='%s'" % (c_bg,)
            else:
                bgcolor = ""
            m = "<span fgcolor='%s'%s>%s</span>" % (c_fg, bgcolor, m)
            markup += m + sp_s
            idx += len(sp_s.encode("utf-8"))

        layout.set_markup(markup)
        layout.set_spacing(self._leading)
        return layout