Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'widgets.py')
-rw-r--r--widgets.py61
1 files changed, 49 insertions, 12 deletions
diff --git a/widgets.py b/widgets.py
index 32734fa..f434ec7 100644
--- a/widgets.py
+++ b/widgets.py
@@ -28,6 +28,7 @@ class BrushButton(_ColorButton):
self._palette = None
self._accept_drag = True
self._brush_size = 2
+ self._stamp_size = 20
self._brush_shape = 'circle'
self._stamping = False
self._pixbuf_stamp = None
@@ -85,11 +86,24 @@ class BrushButton(_ColorButton):
self._color = color
self._preview.queue_draw()
+ def get_stamp_size(self):
+ return self._stamp_size
+
+ def set_stamp_size(self, stamp_size):
+ self._stamp_size = stamp_size
+ self._preview.queue_draw()
+
+ stamp_size = gobject.property(type=int, getter=get_stamp_size,
+ setter=set_stamp_size)
+
def set_stamping(self, stamping):
# receive True or False
self._stamping = stamping
self._preview.queue_draw()
+ def is_stamping(self):
+ return self._stamping
+
def expose(self, widget, event):
if self._gc is None:
self._setup()
@@ -101,10 +115,9 @@ class BrushButton(_ColorButton):
self._gc.set_foreground(self._color)
if self._stamping:
- size = self._brush_size
w = self._pixbuf_stamp.get_width()
h = self._pixbuf_stamp.get_height()
- wr, hr = size, int(size * h * 1.0 / w)
+ wr, hr = self._stamp_size, int(self._stamp_size * h * 1.0 / w)
resized_stamp = self._pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER)
width = resized_stamp.get_width()
@@ -165,6 +178,12 @@ class ButtonStrokeColor(gtk.ToolItem):
def __init__(self, activity, **kwargs):
self._activity = activity
self.properties = self._activity.area.tool
+
+ # This determines if the stamping tool is in use, if True the
+ # size changes the stamping size, else it changes the brush
+ # size:
+ self._stamping = False
+
self._accelerator = None
self._tooltip = None
self._palette_invoker = ToolInvoker()
@@ -178,6 +197,7 @@ class ButtonStrokeColor(gtk.ToolItem):
self.add(self.color_button)
self.color_button.set_brush_size(2)
self.color_button.set_brush_shape('circle')
+ self.color_button.set_stamp_size(20)
# The following is so that the behaviour on the toolbar is correct.
self.color_button.set_relief(gtk.RELIEF_NONE)
@@ -191,7 +211,9 @@ class ButtonStrokeColor(gtk.ToolItem):
self.color_button.connect('notify::title', self.__notify_change)
self.color_button.connect('can-activate-accel',
self.__button_can_activate_accel_cb)
-
+
+ self.create_palette()
+
def __button_can_activate_accel_cb(self, button, signal_id):
# Accept activation via accelerators regardless of this widget's state
return True
@@ -214,20 +236,20 @@ class ButtonStrokeColor(gtk.ToolItem):
color_palette_hbox = self._palette._picker_hbox
content_box = gtk.VBox()
- size_spinbutton = gtk.SpinButton()
+ self.size_spinbutton = gtk.SpinButton()
# This is where we set restrictions for size:
# Initial value, minimum value, maximum value, step
adj = gtk.Adjustment(self.properties['line size'], 1.0, 100.0, 1.0)
- size_spinbutton.set_adjustment(adj)
- size_spinbutton.set_numeric(True)
+ self.size_spinbutton.set_adjustment(adj)
+ self.size_spinbutton.set_numeric(True)
label = gtk.Label(_('Size: '))
hbox = gtk.HBox()
content_box.pack_start(hbox)
hbox.pack_start(label)
- hbox.pack_start(size_spinbutton)
- size_spinbutton.connect('value-changed', self._on_value_changed)
+ hbox.pack_start(self.size_spinbutton)
+ self.size_spinbutton.connect('value-changed', self._on_value_changed)
# User is able to choose Shapes for 'Brush' and 'Eraser'
item1 = gtk.RadioButton(None, _('Circle'))
@@ -273,18 +295,33 @@ class ButtonStrokeColor(gtk.ToolItem):
def _keep_aspect_checkbutton_toggled(self, checkbutton):
self._activity.area.keep_aspect_ratio = checkbutton.get_active()
-
+
+ def set_stamping(self, stamping):
+ self._stamping = stamping
+ self.color_button.set_stamping(stamping)
+ if stamping:
+ self.size_spinbutton.set_value(self.color_button.stamp_size)
+ else:
+ self.size_spinbutton.set_value(self.color_button.brush_size)
+
+ def is_stamping(self):
+ return self._stamping
+
def _on_value_changed(self, spinbutton):
size = spinbutton.get_value_as_int()
- self.properties['line size'] = size
+ if self.is_stamping():
+ self.properties['stamp size'] = size
+ self.color_button.set_stamp_size(self.properties['stamp size'])
+ else:
+ self.properties['line size'] = size
+ self.color_button.set_brush_size(self.properties['line size'])
self._activity.area.set_tool(self.properties)
- self.color_button.set_brush_size(self.properties['line size'])
def _on_toggled(self, radiobutton, tool, shape):
if radiobutton.get_active():
self.properties['line shape'] = shape
self.color_button.set_brush_shape(shape)
- self.color_button.set_brush_size(self.properties['line size'])
+ self.color_button.set_brush_size(self.properties['line size'])
def get_palette_invoker(self):
return self._palette_invoker