1- """
2- `ToolManager`
3- Class that makes the bridge between user interaction (key press,
4- toolbar clicks, ..) and the actions in response to the user inputs.
5- """
6-
71import logging
82
93import matplotlib .cbook as cbook
159
1610
1711class ToolEvent (object ):
<
77F3
/code>18- """Event for tool manipulation (add/remove)"""
12+ """Event for tool manipulation (add/remove). """
1913 def __init__ (self , name , sender , tool , data = None ):
2014 self .name = name
2115 self .sender = sender
@@ -24,17 +18,17 @@ def __init__(self, name, sender, tool, data=None):
2418
2519
2620class ToolTriggerEvent (ToolEvent ):
27- """Event to inform that a tool has been triggered"""
21+ """Event to inform that a tool has been triggered. """
2822 def __init__ (self , name , sender , tool , canvasevent = None , data = None ):
2923 ToolEvent .__init__ (self , name , sender , tool , data )
3024 self .canvasevent = canvasevent
3125
3226
3327class ToolManagerMessageEvent (object ):
3428 """
35- Event carrying messages from toolmanager
29+ Event carrying messages from toolmanager.
3630
37- Messages usually get displayed to the user by the toolbar
31+ Messages usually get displayed to the user by the toolbar.
3832 """
3933 def __init__ (self , name , sender , message ):
4034 self .name = name
@@ -44,7 +38,8 @@ def __init__(self, name, sender, message):
4438
4539class ToolManager (object ):
4640 """
47- Helper class that groups all the user interactions for a Figure.
41+ Manager for actions triggered by user interactions (key press, toolbar
42+ clicks, ...) on a Figure.
4843
4944 Attributes
5045 ----------
@@ -76,14 +71,14 @@ def __init__(self, figure=None):
7671
7772 @property
7873 def canvas (self ):
79- """Canvas managed by FigureManager"""
74+ """Canvas managed by FigureManager. """
8075 if not self ._figure :
8176 return None
8277 return self ._figure .canvas
8378
8479 @property
8580 def figure (self ):
86- """Figure that holds the canvas"""
81+ """Figure that holds the canvas. """
8782 return self ._figure
8883
8984 @figure .setter
@@ -138,19 +133,18 @@ def func(event)
138133
139134 def toolmanager_disconnect (self , cid ):
140135 """
141- Disconnect callback id *cid*
136+ Disconnect callback id *cid*.
142137
143138 Example usage::
144139
145- cid = toolmanager.toolmanager_connect('tool_trigger_zoom',
146- on_press)
140+ cid = toolmanager.toolmanager_connect('tool_trigger_zoom', onpress)
147141 #...later
148142 toolmanager.toolmanager_disconnect(cid)
149143 """
150144 return self ._callbacks .disconnect (cid )
151145
152146 def message_event (self , message , sender = None ):
153- """ Emit a `ToolManagerMessageEvent`"""
147+ """Emit a `ToolManagerMessageEvent`. """
154148 if sender is None :
155149 sender = self
156150
@@ -160,13 +154,12 @@ def message_event(self, message, sender=None):
160154
161155 @property
162156 def active_toggle (self ):
163- """Currently toggled tools"""
164-
157+ """Currently toggled tools."""
165158 return self ._toggled
166159
167160 def get_tool_keymap (self , name ):
168161 """
169- Get the keymap associated with the specified tool
162+ Get the keymap associated with the specified tool.
170163
171164 Parameters
172165 ----------
@@ -187,7 +180,7 @@ def _remove_keys(self, name):
187180
188181 def update_keymap (self , name , * keys ):
189182 """
190- Set the keymap to associate with the specified tool
183+ Set the keymap to associate with the specified tool.
191184
192185 Parameters
193186 ----------
@@ -210,7 +203,7 @@ def update_keymap(self, name, *keys):
210203
211204 def remove_tool (self , name ):
212205 """
213- Remove tool from `ToolManager`
206+ Remove tool named *name*.
214207
215208 Parameters
216209 ----------
@@ -235,16 +228,16 @@ def remove_tool(self, name):
235228
236229 def add_tool (self , name , tool , * args , ** kwargs ):
237230 """
238- Add *tool* to `ToolManager`
231+ Add *tool* to `ToolManager`.
239232
240- If successful adds a new event `tool_trigger_name` where ** name** is
241- the ** name** of the tool, this event is fired everytime
242- the tool is triggered.
233+ If successful, adds a new event ``tool_trigger_{ name}`` where
234+ ``{name}`` is the *name* of the tool; the event is fired everytime the
235+ tool is triggered.
243236
244237 Parameters
245238 ----------
246239 name : str
247- Name of the tool, treated as the ID, has to be unique
240+ Name of the tool, treated as the ID, has to be unique.
248241 tool : class_like, i.e. str or type
249242 Reference to find the class of the Tool to added.
250243
@@ -296,8 +289,8 @@ def _tool_added_event(self, tool):
296289
297290 def _handle_toggle (self , tool , sender , canvasevent , data ):
298291 """
299- Toggle tools, need to untoggle prior to using other Toggle tool
300- Called from trigger_tool
292+ Toggle tools, need to untoggle prior to using other Toggle tool.
293+ Called from trigger_tool.
301294
302295 Parameters
303296 ----------
@@ -356,10 +349,9 @@ def _get_cls_to_instantiate(self, callback_class):
356349 else :
357350 return None
358351
359- def trigger_tool (self , name , sender = None , canvasevent = None ,
360- data = None ):
352+ def trigger_tool (self , name , sender = None , canvasevent = None , data = None ):
361353 """
362- Trigger a tool and emit the tool_trigger_[ name] event
354+ Trigger a tool and emit the `` tool_trigger_{ name}`` event.
363355
364356 Parameters
365357 ----------
@@ -386,11 +378,7 @@ def trigger_tool(self, name, sender=None, canvasevent=None,
386378 self ._callbacks .process (s , event )
387379
388380 def _trigger_tool (self , name , sender = None , canvasevent = None , data = None ):
389- """
390- Trigger on a tool
391-
392- Method to actually trigger the tool
393- """
381+ """Actually trigger a tool."""
394382 tool = self .get_tool (name )
395383
396384 if isinstance (tool , tools .ToolToggleBase ):
@@ -411,13 +399,12 @@ def _key_press(self, event):
411399
412400 @property
413401 def tools (self ):
414- """Return the tools controlled by `ToolManager`"""
415-
402+ """A dict mapping tool name -> controlled tool."""
416403 return self ._tools
417404
418405 def get_tool (self , name , warn = True ):
419406 """
420- Return the tool object, also accepts the actual tool for convenience
407+ Return the tool object, also accepts the actual tool for convenience.
421408
422409 Parameters
423410 ----------
0 commit comments