[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch for ruler-guides
From: |
Ralf Engels |
Subject: |
Patch for ruler-guides |
Date: |
Mon, 6 Jan 2003 19:03:31 +0100 |
Hi,
the following patch makes it possible to draw guides from the rulers (again)
Known Problems:
New guides are not created in the guides layer
New guides can not be moved
After making a new guide the current tool is the new guide tool, but in the
toolbox the old tool stays selected
By the way, is there a sketch contrib directory where we can put the patches
into?
diff -Nur Sketch.old/Editor/__init__.py Sketch/Editor/__init__.py
--- Sketch.old/Editor/__init__.py Wed Dec 25 21:50:35 2002
+++ Sketch/Editor/__init__.py Mon Jan 6 18:30:03 2003
@@ -53,6 +53,7 @@
from drawer import Creator, RectangularCreator, Editor
+from drawguide import GuideCreator
from drawrectangle import RectangleCreator
from drawellipse import EllipseCreator
from drawbezier import PolyBezierCreator, PolyLineCreator, FreehandCreator
@@ -255,6 +258,8 @@
'EditTool': edittool.EditTool,
'TextTool': texttool.TextTool,
'ZoomTool': tools.ZoomTool,
+ 'CreateHGuide': tools.HGuideTool,
+ 'CreateVGuide': tools.VGuideTool,
'CreateRect': tools.RectangleTool,
'CreateCurve': tools.PolyBezierTool,
'CreateEllipse': tools.EllipseTool,
diff -Nur Sketch.old/Editor/doceditor.py Sketch/Editor/doceditor.py
--- Sketch.old/Editor/doceditor.py Wed Dec 25 21:50:35 2002
+++ Sketch/Editor/doceditor.py Mon Jan 6 18:23:59 2003
3, SelectAdd, SelectSubtract, SelectSubobjects
from Sketch.Graphics import Group
from Sketch.Editor import AddEditorBuiltin
from selection import Selection
@@ -267,6 +267,7 @@
def Hide(self, device, partially = 0):
self.tool.Hide(device, partially)
+ ## todo: no special handling for guides (Ralf)
def Cursor(self, context, p):
device = context.canvas.test_device()
object = self.PickActiveObject(device, p)
14
cursor = 'CurHGuide'
else:
cursor = 'CurVGuide'
+ elif self.tool is None:
+ cursor = 'CurDraw'
else:
cursor = self.tool.Cursor(context, p, object)
return cursor
diff -Nur Sketch.old/Editor/drawguide.py Sketch/Editor/drawguide.py
--- Sketch.old/Editor/drawguide.py Thu Jan 1 01:00:00 1970
+++ Sketch/Editor/drawguide.py Mon Jan 6 18:40:50 2003
@@ -0,0 +1,56 @@
+# Sketch - A Python-based interactive drawing program
+# Copyright (C) 1997, 1998, 1999, 2000 by Bernhard Herzog
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import Sketch
+from Sketch import _, Trafo
+from Sketch.Graphics import GuideLine
+from Sketch.Editor import RectangularCreator
+
+## Creates a Guide line.
+## Using the generic rectangular creator as starting point
+class GuideCreator(RectangularCreator):
+
+ creation_text = _("Create Guide")
+
+ state = 0
+
+ def __init__(self, horizontal = 0):
+ self.horizontal = horizontal
+
+ def MouseMove(self, p, state):
+ self.state = state
+ RectangularCreator.MouseMove(self, p, state)
+
+ def ButtonUp(self, p, button, state):
+ self.point = self.apply_constraint(p, state)
+
+ ## ToDo duplicate of editguide. (Ralf)
+ def DrawDragged(self, device, partially):
+ device.DrawGuideLine(self.drag_cur, self.horizontal)
+
+ ## ToDo duplicate of editguide. (Ralf)
+ def CurrentInfoText(self):
+ if self.horizontal:
+ text = _("Horizontal Guide Line at %(coord)[length]")
+ dict = {'coord': self.drag_cur.y}
+ else:
+ text = _("Vertical Guide Line at %(coord)[length]")
+ dict = {'coord': self.drag_cur.x}
+ return text, dict
+
+ def CreatedObject(self):
+ return GuideLine( self.point, self.horizontal )
diff -Nur Sketch.old/Editor/tools.py Sketch/Editor/tools.py
--- Sketch.old/Editor/tools.py Wed Dec 25 21:50:35 2002
+++ Sketch/Editor/tools.py Mon Jan 6 18:45:49 2003
@@ -188,6 +188,8 @@
class DrawToolInstance(ToolInstance):
+ ## todo: giving object_class as parameter seems to be bad.
+ ## need function CreateObject to overlay
def __init__(self, editor, object_class):
ToolInstance.__init__(self, editor)
self.object_class = object_class
@@ -205,6 +207,38 @@
def ButtonClick(self, context, p, snapped, button, state, handle = None):
pass
+## --- guide tools
+
+class HGuideToolInstance(DrawToolInstance):
+
+ title = ''"Horizontal Guide"
+
+ def __init__(self, editor):
+ DrawToolInstance.__init__(self, editor, Sketch.Editor.GuideCreator)
+
+ def ButtonPress(self, context, p, snapped, button, state, handle = None):
+ self.begin_edit_object(context, Sketch.Editor.GuideCreator(1),
+ snapped, button, state)
+
+
+HGuideTool = ToolInfo("HGuideTool", HGuideToolInstance,
+ cursor = 'CurHGuide', icon = None )
+
+class VGuideToolInstance(DrawToolInstance):
+
+ title = ''"Vertical Guide"
+
+ def __init__(self, editor):
+ DrawToolInstance.__init__(self, editor, Sketch.Editor.GuideCreator)
+
+ def ButtonPress(self, context, p, snapped, button, state, handle = None):
+ self.begin_edit_object(context, Sketch.Editor.GuideCreator(0),
+ snapped, button, state)
+
+VGuideTool = ToolInfo("VGuideTool", VGuideToolInstance,
+ cursor = 'CurVGuide', icon = None )
+
+## --- rectangular tools
class RectangleToolInstance(DrawToolInstance):
diff -Nur Sketch.old/UI/mainwindow.py Sketch/UI/mainwindow.py
--- Sketch.old/UI/mainwindow.py Wed Dec 25 21:50:35 2002
+++ Sketch/UI/mainwindow.py Mon Jan 6 18:47:15 2003
@@ -69,7 +74,7 @@
else:
self.ContextChanged()
-
+# for corresponding code see gimp source code display/gimpdisplayshell.c
class SketchMainWindow(Publisher):
def __init__(self, application, document = None, editor = None):
@@ -135,9 +140,17 @@
table.attach(menubutton, 0, 1, 0, 1, FILL, FILL)
self.hruler = gtk.GtkHRuler()
+ self.hruler.set_events( gtk.GDK.BUTTON_PRESS_MASK |
gtk.GDK.BUTTON_RELEASE_MASK );
+ self.hruler.connect('button_press_event', self.hruler_button_press)
+ self.hruler.connect('button_release_event',
self.hruler_button_release)
+ self.hruler.connect('motion_notify_event', self.hruler_motion_notify)
table.attach(self.hruler, 1, 2, 0, 1, EXPAND|FILL, 0)
self.vruler = gtk.GtkVRuler()
+ self.vruler.set_events( gtk.GDK.BUTTON_PRESS_MASK |
gtk.GDK.BUTTON_RELEASE_MASK );
+ self.vruler.connect('button_press_event', self.vruler_button_press)
+ self.vruler.connect('button_release_event',
self.vruler_button_release)
+ self.vruler.connect('motion_notify_event', self.vruler_motion_notify)
table.attach(self.vruler, 0, 1, 1, 2, 0, EXPAND|FILL)
hadjust = gtk.GtkAdjustment()
5ler['position'] = pos.x
self.vruler['position'] = pos.y
+
+ def hruler_button_press(self, widget, event):
+ self.canvas.SetTool( 'CreateHGuide' )
+ self.canvas.button_press( widget, event )
+
+ def hruler_button_release(self, widget, event):
+ self.canvas.button_release( widget, event )
+
+ def hruler_motion_notify(self, widget, event):
+ self.canvas.motion_notify( widget, event )
+
+ def vruler_button_press(self, widget, event):
+ self.canvas.SetTool( 'CreateVGuide' )
+ self.canvas.button_press( widget, event )
+
+ def vruler_button_release(self, widget, event):
+ self.canvas.button_release( widget, event )
+
+ def vruler_motion_notify(self, widget, event):
+ self.canvas.motion_notify( widget, event )
+
+
def show_menu(self, widget, event):
# this was inspired by gimp...
menu = self.application.Menu(self)
Ralf
--
________________________
Ralf Engels
Software design engineer
www.rengels.de
- Patch for ruler-guides,
Ralf Engels <=