[PATCH] fix #931

Gonzalo Odiard godiard at gmail.com
Thu May 20 01:51:30 EDT 2010


Make "keep aspect ratio" selection visible in the UI.

Tested-by: James Cameron <quozl at laptop.org>
Signed-off-by: James Cameron <quozl at laptop.org>
---
 Area.py    |    5 +++--
 toolbox.py |   19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Area.py b/Area.py
index 613e66e..611f944 100644
--- a/Area.py
+++ b/Area.py
@@ -155,6 +155,7 @@ class Area(gtk.DrawingArea):
         self.line_shape = 'circle'
         self.last = []
         self.rainbow_counter = 0
+        self.keep_aspect_ratio = False
                 
         self.font = pango.FontDescription('Sans 9')
         self._set_selection_bounds(0,0,0,0)
@@ -378,7 +379,7 @@ class Area(gtk.DrawingArea):
                     self.d.square(widget,event,coords,True,self.tool['fill'])
                     
                 elif self.tool['name'] == 'marquee-rectangular' and not self.selmove:
-                    if state & gtk.gdk.CONTROL_MASK:
+                    if (state & gtk.gdk.CONTROL_MASK) or self.keep_aspect_ratio:
                         coords = self._keep_selection_ratio(coords)
                     self.d.selection(widget,coords)
                 # selected
@@ -462,7 +463,7 @@ class Area(gtk.DrawingArea):
 
             elif self.tool['name'] == 'marquee-rectangular':
                 if self.selmove == False:
-                    if event.state & gtk.gdk.CONTROL_MASK:
+                    if (event.state & gtk.gdk.CONTROL_MASK) or self.keep_aspect_ratio:
                         coords = self._keep_selection_ratio(coords)
                     self.d.selection(widget,coords,False)
                     self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
diff --git a/toolbox.py b/toolbox.py
index 448847e..23fc4b7 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -357,6 +357,11 @@ class ToolsToolbar(gtk.Toolbar):
         self._tool_marquee_rectangular = ToolButton('tool-marquee-rectangular')
         self.insert(self._tool_marquee_rectangular, -1)
         self._tool_marquee_rectangular.set_tooltip(_('Rectangular Marquee'))
+        try:
+            self._configure_palette(self._tool_marquee_rectangular, self._TOOL_MARQUEE_RECTANGULAR)
+        except:
+            logging.debug('Could not create palette for tool Rectangular Marquee')
+
 
         # New connect method
         # Using dictionnaries to control tool's properties
@@ -483,7 +488,7 @@ class ToolsToolbar(gtk.Toolbar):
             label.show()
             
             colorbutton = ButtonFillColor(self._activity)
-            colorbutton.show()
+            colorbutton.show_all()
             
             hbox.pack_start(label)
             hbox.pack_start(colorbutton)
@@ -493,8 +498,20 @@ class ToolsToolbar(gtk.Toolbar):
             content_box.pack_start(hbox)
             
             colorbutton.connect_after('color-set', self._on_color_set, self._TOOL_POLYGON)
+        if tool['name'] is self._TOOL_MARQUEE_RECTANGULAR['name']:
+            # Creating a CheckButton named "Fill".
+            keep_aspect_checkbutton = gtk.CheckButton(_('Keep aspect'))
+            keep_aspect_checkbutton.show()
+            keep_aspect_checkbutton.set_active(self._activity.area.keep_aspect_ratio)
+
+            keep_aspect_checkbutton.connect('toggled', self._keep_aspect_checkbutton_toggled, widget)
+            palette.action_bar.pack_start(keep_aspect_checkbutton)
     
 
+    def _keep_aspect_checkbutton_toggled(self, checkbutton, button=None):
+        logging.debug('Keep aspect is Active: %s', checkbutton.get_active())
+        self._activity.area.keep_aspect_ratio = checkbutton.get_active()
+
     def set_shape(self, widget=None, tool=None, shape=None):
         """
         Set a tool shape according to user choice at Tool Palette
-- 
1.7.1

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list