From 601e46ff9c2ecc14d262defdcdd33eb2bf63b159 Mon Sep 17 00:00:00 2001 From: Emil Dudev Date: Tue, 17 Dec 2013 05:59:35 +0000 Subject: Paint tools enhancement Fixes #3603 --- diff --git a/toolbox.py b/toolbox.py index b4e624e..0df527c 100644 --- a/toolbox.py +++ b/toolbox.py @@ -150,6 +150,10 @@ class DrawToolbarBox(ToolbarBox): self.tools_builder = ToolsToolbarBuilder(self.toolbar, self._activity, self._fill_color_button) + separator = Gtk.SeparatorToolItem() + separator.set_draw(True) + self.toolbar.insert(separator, -1) + self.shapes_button = DrawToolButton('shapes', self._activity.tool_group, _('Shapes')) @@ -161,6 +165,10 @@ class DrawToolbarBox(ToolbarBox): self.toolbar.insert(item_fill_color, -1) + separator = Gtk.SeparatorToolItem() + separator.set_draw(True) + self.toolbar.insert(separator, -1) + fonts_button = ToolbarButton() fonts_button.props.page = TextToolbar(self._activity) fonts_button.props.icon_name = 'format-text-size' @@ -347,15 +355,6 @@ class ToolsToolbarBuilder(): self.properties = self._activity.area.tool self._fill_color_button = fill_color_button - self._stroke_color = ButtonStrokeColor(activity) - self._stroke_color.set_title(_('Brush properties')) - self._stroke_color.connect('notify::color', self._color_button_cb) - toolbar.insert(self._stroke_color, -1) - - separator = Gtk.SeparatorToolItem() - separator.set_draw(True) - toolbar.insert(separator, -1) - self._tool_brush = DrawToolButton('tool-brush', activity.tool_group, _('Brush')) activity.tool_group = self._tool_brush @@ -394,6 +393,11 @@ class ToolsToolbarBuilder(): self._tool_brush.connect('clicked', self.set_tool, self._TOOL_BRUSH_NAME) + self._stroke_color = ButtonStrokeColor(activity) + self.set_tool(self._tool_brush, 'brush') + self._stroke_color.connect('notify::color', self._color_button_cb) + toolbar.insert(self._stroke_color, -1) + def set_tool(self, widget, tool_name): """ Set tool to the Area object. Configures tool's color and size. @@ -405,6 +409,7 @@ class ToolsToolbarBuilder(): """ if widget != self._tool_brush: self._tool_brush.set_icon_name(widget.icon_name) + self._stroke_color.set_selected_tool(tool_name) if tool_name == 'stamp': resized_stamp = self._activity.area.setup_stamp() @@ -449,15 +454,27 @@ class ButtonFillColor(ColorToolButton): ColorToolButton.__init__(self) self._activity = activity self.properties = self._activity.area.tool - self.connect('notify::color', self._color_button_cb) + self._button_cb = self.connect('notify::color', self._color_button_cb) + self._inactive_color = style.COLOR_INACTIVE_FILL.get_gdk_color() + # self._old_color = self.get_color() def _color_button_cb(self, widget, pspec): - color = self.get_color() - self.set_fill_color(color) + self._old_color = self.get_color() + self.set_fill_color(self._old_color) def set_fill_color(self, color): self._activity.area.set_fill_color(color) + def set_sensitive(self, value): + self.handler_block(self._button_cb) + if value: + self.set_color(self._old_color) + else: + self.set_color(self._inactive_color) + self.handler_unblock(self._button_cb) + + ColorToolButton.set_sensitive(self, value) + def create_palette(self): self._palette = self.get_child().create_palette() color_palette_hbox = self._palette._picker_hbox diff --git a/widgets.py b/widgets.py index 74add83..4053dc8 100644 --- a/widgets.py +++ b/widgets.py @@ -181,6 +181,7 @@ class ButtonStrokeColor(Gtk.ToolItem): self._tooltip = None self._palette_invoker = ToolInvoker() self._palette = None + self._selected_tool = None GObject.GObject.__init__(self, **kwargs) @@ -259,7 +260,7 @@ class ButtonStrokeColor(Gtk.ToolItem): self.alpha_scale.connect('value-changed', self._on_alpha_changed) # User is able to choose Shapes for 'Brush' and 'Eraser' - shape_box = Gtk.HBox() + self.shape_box = Gtk.HBox() self.custom_box.pack_start(self.vbox_brush_options, True, True, 0) item1 = RadioToolButton() item1.set_icon_name('tool-shape-ellipse') @@ -276,11 +277,11 @@ class ButtonStrokeColor(Gtk.ToolItem): item1.connect('toggled', self._on_toggled, self.properties, 'circle') item2.connect('toggled', self._on_toggled, self.properties, 'square') - shape_box.pack_start(Gtk.Label(_('Shape')), True, True, 0) - shape_box.pack_start(item1, True, True, 0) - shape_box.pack_start(item2, True, True, 0) + self.shape_box.pack_start(Gtk.Label(_('Shape')), True, True, 0) + self.shape_box.pack_start(item1, True, True, 0) + self.shape_box.pack_start(item2, True, True, 0) - self.vbox_brush_options.pack_start(shape_box, True, True, 0) + self.vbox_brush_options.pack_start(self.shape_box, True, True, 0) keep_aspect_checkbutton = Gtk.CheckButton(_('Keep aspect')) ratio = self._activity.area.keep_aspect_ratio @@ -290,7 +291,8 @@ class ButtonStrokeColor(Gtk.ToolItem): self.vbox_brush_options.pack_start(keep_aspect_checkbutton, True, True, 0) - color_palette_hbox.pack_start(Gtk.VSeparator(), True, True, + self.custom_separator = Gtk.VSeparator() + color_palette_hbox.pack_start(self.custom_separator, True, True, padding=style.DEFAULT_SPACING) color_palette_hbox.pack_start(self.custom_box, True, True, padding=style.DEFAULT_SPACING) @@ -302,23 +304,48 @@ class ButtonStrokeColor(Gtk.ToolItem): self._activity.area.keep_aspect_ratio = checkbutton.get_active() def _update_palette(self): - palette_children = self._palette._picker_hbox.get_children() - if self.color_button.is_stamping(): - # Hide palette color widgets except size: - for ch in palette_children: - if ch != self.custom_box: - ch.hide() + tool_name = self._selected_tool + save_all = False + save_controls = () + save_colors = False + title = _('Brush properties') + + if tool_name == 'stamp': + save_controls = (self.size_label, self.size_scale) + title = _('Stamp properties') + elif tool_name == 'eraser': + save_controls = (self.size_label, self.size_scale, + self.shape_box) + title = _('Eraser properties') + elif tool_name == 'bucket': + save_colors = True + title = _('Bucket properties') + elif tool_name == 'picker': + save_colors = True + title = _('Picker properties') + elif tool_name == 'marquee-rectangular': + title = _('Select Area') + else: + save_all = True + + self._palette._picker_hbox.show_all() + # Hide palette color widgets except size: + if not save_all: + if not save_colors: + palette_children = self._palette._picker_hbox.get_children() + for ch in palette_children: + if ch != self.custom_box: + ch.hide() + elif not save_controls: + self.custom_separator.hide() + controls = self.vbox_brush_options.get_children() for control in controls: - if control not in (self.size_label, self.size_scale): + if control not in save_controls: control.hide() - # Change title: - self.set_title(_('Stamp properties')) - else: - # Show palette color widgets: - self._palette._picker_hbox.show_all() - # Change title: - self.set_title(_('Brush properties')) + + # Change title: + self.set_title(title) self._palette._picker_hbox.resize_children() self._palette._picker_hbox.queue_draw() @@ -404,6 +431,12 @@ class ButtonStrokeColor(Gtk.ToolItem): title = GObject.property(type=str, getter=get_title, setter=set_title) + def get_selected_tool(self): + return self._selected_tool + + def set_selected_tool(self, tool_name): + self._selected_tool = tool_name + def do_draw(self, cr): if self._palette and self._palette.is_up(): allocation = self.get_allocation() -- cgit v0.9.1