Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/sketch/ChangeLog,v
retrieving revision 1.275
diff -c -r1.275 ChangeLog
*** ChangeLog	10 Dec 2005 23:58:06 -0000	1.275
--- ChangeLog	11 Dec 2005 00:51:42 -0000
***************
*** 1,5 ****
--- 1,44 ----
  2005-12-11  Bernhard Herzog  <bh@intevation.de>
  
+ 	Change which objects manage which tool is active.  Previously it
+ 	was the main context object, no it's the document editor.
+ 
+ 	* Sketch/Editor/doceditor.py (EditorWithSelection.SetTool): Issue
+ 	a TOOL message when the tool changes.
+ 
+ 	* Sketch/Editor/context.py: Change the meaning of the context's
+ 	TOOL message a little.  Previously it indicated that the user
+ 	selected a new tool and all editors had to be updated accordingly.
+ 	Now it means that the current editor has switched to a different
+ 	tool (or that a different editor has been made current).
+ 	(Context.editor_channels): Add TOOL so that the editor's new TOOL
+ 	messages are forwarded by the context.
+ 	(Context.__getattr__): New.  Recognize "tool" attributes and
+ 	return something sensible, usually the current editor's toolname.
+ 	(Context.__init__): "tool" is no longer an instance variable.
+ 	(Context.set_editor): Issue a TOOL message when the editor
+ 	changes.  The new editor may currently have a different tool than
+ 	the previous one.
+ 	(Context.SetTool): Simply call the current editor's SetTool
+ 	method.  Do not issue messages anymore.
+ 
+ 	* Sketch/UI/mainwindow.py (tool_changed): Removed.
+ 	(SketchMainWindow.__init__, SketchMainWindow.close): removed the
+ 	code that handled the TOOL messages or set the current tool.
+ 
+ 	* Sketch/UI/canvas.py (SketchCanvas.subscribe_editor)
+ 	(SketchCanvas.unsubscribe_editor): (Un)subscribe to/from the
+ 	editor's TOOL messages too.
+ 	(SketchCanvas.SetTool): Simply pass the tool through to the
+ 	editor.
+ 	(SketchCanvas.tool_changed): New.  Has the cursor update logic
+ 	formerly in SetTool.  This method is subscribed to the TOOL
+ 	message.
+ 	(SketchCanvas.realize_method): New. Extend
+ 	inherited method so that the cursors are set properly
+ 
+ 2005-12-11  Bernhard Herzog  <bh@intevation.de>
+ 
  	* Sketch/Editor/edittool.py: Remove unused imports
  
  2005-11-06  Bernhard Herzog  <bh@intevation.de>
Index: Sketch/Editor/context.py
===================================================================
RCS file: /cvs/gnome/sketch/Sketch/Editor/context.py,v
retrieving revision 1.9
diff -c -r1.9 context.py
*** Sketch/Editor/context.py	24 Sep 2005 22:06:43 -0000	1.9
--- Sketch/Editor/context.py	11 Dec 2005 00:51:42 -0000
***************
*** 1,5 ****
  # Sketch - A Python-based interactive drawing program
! # Copyright (C) 1996, 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
--- 1,5 ----
  # Sketch - A Python-based interactive drawing program
! # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2005 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
***************
*** 27,33 ****
  
  class Context(Sketch.Base.Publisher):
  
!     editor_channels = (SELECTION, STATE, HANDLES)
      document_channels = (UNDO, STYLE, LAYER, LAYER_ORDER, LAYER_ACTIVE,
                           OBJECT_CHANGED, TRANSACTION_START, TRANSACTION_END)
  
--- 27,33 ----
  
  class Context(Sketch.Base.Publisher):
  
!     editor_channels = (SELECTION, STATE, HANDLES, TOOL)
      document_channels = (UNDO, STYLE, LAYER, LAYER_ORDER, LAYER_ACTIVE,
                           OBJECT_CHANGED, TRANSACTION_START, TRANSACTION_END)
  
***************
*** 35,59 ****
          self.application = application
          self.document = None
          self.editor = None
-         self.tool = None
          self.main_tool = 'SelectionTool'
          Sketch.Base.preferences.Subscribe(CHANGED, self.forward, CONFIG)
          Sketch.Graphics.preferences.Subscribe(CHANGED, self.forward, CONFIG)
          Sketch.Editor.preferences.Subscribe(CHANGED, self.forward, CONFIG)
  
      def set_editor(self, editor):
          if editor is not self.editor:
              self._unsubscribe()
              if editor is None:
                  self.editor = None
                  self.document = None
-                 #self.tool = None
              else:
                  self.editor = editor
                  self.document = editor.Document()
-                 #self.tool = editor.Tool()
              self._subscribe()
              self.issue(CHANGED)
  
      def _subscribe(self):
          forward = self.forward
--- 35,66 ----
          self.application = application
          self.document = None
          self.editor = None
          self.main_tool = 'SelectionTool'
          Sketch.Base.preferences.Subscribe(CHANGED, self.forward, CONFIG)
          Sketch.Graphics.preferences.Subscribe(CHANGED, self.forward, CONFIG)
          Sketch.Editor.preferences.Subscribe(CHANGED, self.forward, CONFIG)
  
+     def __getattr__(self, attr):
+         """Pretend that context objects still have a tool attribute"""
+         if attr == "tool":
+             if self.editor is not None:
+                 return self.editor.toolname
+             return "SelectionTool"
+         else:
+             raise AttributeError(attr)
+ 
      def set_editor(self, editor):
          if editor is not self.editor:
              self._unsubscribe()
              if editor is None:
                  self.editor = None
                  self.document = None
              else:
                  self.editor = editor
                  self.document = editor.Document()
              self._subscribe()
              self.issue(CHANGED)
+             self.issue(TOOL, self.editor.toolname)
  
      def _subscribe(self):
          forward = self.forward
***************
*** 85,95 ****
          return self.editor is not None
  
      def SetTool(self, tool):
!         if tool != self.tool:
!             if tool in main_tools:
!                 self.main_tool = tool
!             self.tool = tool
!             self.issue(TOOL, tool)
  
      def MainTool(self):
          return self.main_tool
--- 92,101 ----
          return self.editor is not None
  
      def SetTool(self, tool):
!         if tool in main_tools:
!             self.main_tool = tool
!         if self.editor is not None:
!             self.editor.SetTool(tool)
  
      def MainTool(self):
          return self.main_tool
Index: Sketch/Editor/doceditor.py
===================================================================
RCS file: /cvs/gnome/sketch/Sketch/Editor/doceditor.py,v
retrieving revision 1.28
diff -c -r1.28 doceditor.py
*** Sketch/Editor/doceditor.py	5 Nov 2005 23:46:18 -0000	1.28
--- Sketch/Editor/doceditor.py	11 Dec 2005 00:51:42 -0000
***************
*** 23,29 ****
  from Sketch import _, Point
  from Sketch.Base.const import SELECTION, UNDO, EDITED, HANDLES, STATE, \
       CURRENTINFO, TRANSACTION_END, TRANSACTION_START, INSERTED, \
!      OBJECT_CHANGED, CHILDREN,  REARRANGED, \
       SelectSet, SelectAdd, SelectSubtract, SelectSubobjects
  from Sketch.Graphics import Group
  from Sketch.Editor import AddEditorBuiltin
--- 23,29 ----
  from Sketch import _, Point
  from Sketch.Base.const import SELECTION, UNDO, EDITED, HANDLES, STATE, \
       CURRENTINFO, TRANSACTION_END, TRANSACTION_START, INSERTED, \
!      OBJECT_CHANGED, CHILDREN,  REARRANGED, TOOL, \
       SelectSet, SelectAdd, SelectSubtract, SelectSubobjects
  from Sketch.Graphics import Group
  from Sketch.Editor import AddEditorBuiltin
***************
*** 445,450 ****
--- 445,451 ----
          Finally, update the handles.
          """
          tool = Sketch.Editor.toolmap.get(toolname)
+         old_toolname = self.toolname
          if tool is not None:
              if self.toolname != toolname:
                  if self.tool is not None:
***************
*** 454,459 ****
--- 455,462 ----
          else:
              self.tool = None
              self.toolname = ''
+         if self.toolname != old_toolname:
+             self.issue(TOOL, self.toolname)
          self.update_handles()
  
      def Tool(self):
Index: Sketch/UI/canvas.py
===================================================================
RCS file: /cvs/gnome/sketch/Sketch/UI/canvas.py,v
retrieving revision 1.18
diff -c -r1.18 canvas.py
*** Sketch/UI/canvas.py	24 Sep 2005 22:06:42 -0000	1.18
--- Sketch/UI/canvas.py	11 Dec 2005 00:51:42 -0000
***************
*** 144,149 ****
--- 144,154 ----
          self.gc = self.invgc = self.hitgc = None
          SketchView.Destroy(self)
  
+     def realize_method(self, *args):
+         """Extend inherited method so that the cursors are set properly"""
+         SketchView.realize_method(self, *args)
+         self.tool_changed(self.editor.toolname)
+ 
      def init_gcs(self):
          self.invgc = InvertingDevice()
          self.invgc.init_gc(self.window)
***************
*** 175,187 ****
--- 180,198 ----
      def subscribe_editor(self):
          self.editor.Subscribe(Sketch.Base.const.HANDLES,
                                self.update_handles_idle)
+         self.editor.Subscribe(Sketch.Base.const.TOOL,
+                               self.tool_changed)
  
      def unsubscribe_editor(self):
+         self.editor.Unsubscribe(Sketch.Base.const.TOOL,
+                                 self.tool_changed)
          self.editor.Unsubscribe(Sketch.Base.const.HANDLES,
                                  self.update_handles_idle)
  
      def SetTool(self, toolname):
          self.editor.SetTool(toolname)
+ 
+     def tool_changed(self, toolname):
          info = Sketch.Editor.toolmap[toolname]
          cursor = getattr(cursors, info.cursor)
          self.cursor_shape = cursor
Index: Sketch/UI/mainwindow.py
===================================================================
RCS file: /cvs/gnome/sketch/Sketch/UI/mainwindow.py,v
retrieving revision 1.13
diff -c -r1.13 mainwindow.py
*** Sketch/UI/mainwindow.py	20 Aug 2005 18:36:15 -0000	1.13
--- Sketch/UI/mainwindow.py	11 Dec 2005 00:51:42 -0000
***************
*** 94,101 ****
          self.window = None
          self.build_window()
          self.set_window_title()
-         self.application.context.Subscribe(TOOL, self.tool_changed)
-         self.tool_changed(self.application.context.tool)
  
      def __del__(self):
          #pass
--- 94,99 ----
***************
*** 103,109 ****
  
      def close(self, *args):
          print 'SketchMainWindow.close', self
-         self.application.context.Unsubscribe(TOOL, self.tool_changed)
          self.editor.Unsubscribe(CURRENTINFO, self.infolabel.Update)
          self.document.Unsubscribe(UNDO, self.modified.Update)
          self.window.destroy()
--- 101,106 ----
***************
*** 349,362 ****
          self.set_window_title()
  
  
- 
- 
-     #
-     #
-     #
- 
-     def tool_changed(self, toolname):
-         self.canvas.SetTool(toolname)
  
  add = Sketch.Editor.Add
  cmd = command.WindowCommand
--- 346,351 ----
