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
-
7
1
import logging
8
2
9
3
import matplotlib .cbook as cbook
15
9
16
10
17
11
class ToolEvent (object ):
18
- """Event for tool manipulation (add/remove)"""
12
+ """Event for tool manipulation (add/remove). """
19
13
def __init__ (self , name , sender , tool , data = None ):
20
14
self .name = name
21
15
self .sender = sender
@@ -24,17 +18,17 @@ def __init__(self, name, sender, tool, data=None):
24
18
25
19
26
20
class ToolTriggerEvent (ToolEvent ):
27
- """Event to inform that a tool has been triggered"""
21
+ """Event to inform that a tool has been triggered. """
28
22
def __init__ (self , name , sender , tool , canvasevent = None , data = None ):
29
23
ToolEvent .__init__ (self , name , sender , tool , data )
30
24
self .canvasevent = canvasevent
31
25
32
26
33
27
class ToolManagerMessageEvent (object ):
34
28
"""
35
- Event carrying messages from toolmanager
29
+ Event carrying messages from toolmanager.
36
30
37
- Messages usually get displayed to the user by the toolbar
31
+ Messages usually get displayed to the user by the toolbar.
38
32
"""
39
33
def __init__ (self , name , sender , message ):
40
34
self .name = name
@@ -44,7 +38,8 @@ def __init__(self, name, sender, message):
44
38
45
39
class ToolManager (object ):
46
40
"""
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.
48
43
49
44
Attributes
50
45
----------
@@ -76,14 +71,14 @@ def __init__(self, figure=None):
76
71
77
72
@property
78
73
def canvas (self ):
79
- """Canvas managed by FigureManager"""
74
+ """Canvas managed by FigureManager. """
80
75
if not self ._figure :
81
76
return None
82
77
return self ._figure .canvas
83
78
84
79
@property
85
80
def figure (self ):
86
- """Figure that holds the canvas"""
81
+ """Figure that holds the canvas. """
87
82
return self ._figure
88
83
89
84
@figure .setter
@@ -138,19 +133,18 @@ def func(event)
138
133
139
134
def toolmanager_disconnect (self , cid ):
140
135
"""
141
- Disconnect callback id *cid*
136
+ Disconnect callback id *cid*.
142
137
143
138
Example usage::
144
139
145
- cid = toolmanager.toolmanager_connect('tool_trigger_zoom',
146
- on_press)
140
+ cid = toolmanager.toolmanager_connect('tool_trigger_zoom', onpress)
147
141
#...later
148
142
toolmanager.toolmanager_disconnect(cid)
149
143
"""
150
144
return self ._callbacks .disconnect (cid )
151
145
152
146
def message_event (self , message , sender = None ):
153
- """ Emit a `ToolManagerMessageEvent`"""
147
+ """Emit a `ToolManagerMessageEvent`. """
154
148
if sender is None :
155
149
sender = self
156
150
@@ -160,13 +154,12 @@ def message_event(self, message, sender=None):
160
154
161
155
@property
162
156
def active_toggle (self ):
163
- """Currently toggled tools"""
164
-
157
+ """Currently toggled tools."""
165
158
return self ._toggled
166
159
167
160
def get_tool_keymap (self , name ):
168
161
"""
169
- Get the keymap associated with the specified tool
162
+ Get the keymap associated with the specified tool.
170
163
171
164
Parameters
172
165
----------
@@ -187,7 +180,7 @@ def _remove_keys(self, name):
187
180
188
181
def update_keymap (self , name , * keys ):
189
182
"""
190
- Set the keymap to associate with the specified tool
183
+ Set the keymap to associate with the specified tool.
191
184
192
185
Parameters
193
186
----------
@@ -210,7 +203,7 @@ def update_keymap(self, name, *keys):
210
203
211
204
def remove_tool (self , name ):
212
205
"""
213
- Remove tool from `ToolManager`
206
+ Remove tool named *name*.
214
207
215
208
Parameters
216
209
----------
@@ -235,16 +228,16 @@ def remove_tool(self, name):
235
228
236
229
def add_tool (self , name , tool , * args , ** kwargs ):
237
230
"""
238
- Add *tool* to `ToolManager`
231
+ Add *tool* to `ToolManager`.
239
232
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.
243
236
244
237
Parameters
245
238
----------
246
239
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.
248
241
tool : class_like, i.e. str or type
249
242
Reference to find the class of the Tool to added.
250
243
@@ -296,8 +289,8 @@ def _tool_added_event(self, tool):
296
289
297
290
def _handle_toggle (self , tool , sender , canvasevent , data ):
298
291
"""
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.
301
294
302
295
Parameters
303
296
----------
@@ -356,10 +349,9 @@ def _get_cls_to_instantiate(self, callback_class):
356
349
else :
357
350
return None
358
351
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 ):
361
353
"""
362
- Trigger a tool and emit the tool_trigger_[ name] event
354
+ Trigger a tool and emit the `` tool_trigger_{ name}`` event.
363
355
364
356
Parameters
365
357
----------
@@ -386,11 +378,7 @@ def trigger_tool(self, name, sender=None, canvasevent=None,
386
378
self ._callbacks .process (s , event )
387
379
388
380
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."""
394
382
tool = self .get_tool (name )
395
383
396
384
if isinstance (tool , tools .ToolToggleBase ):
@@ -411,13 +399,12 @@ def _key_press(self, event):
411
399
412
400
@property
413
401
def tools (self ):
414
- """Return the tools controlled by `ToolManager`"""
415
-
402
+ """A dict mapping tool name -> controlled tool."""
416
403
return self ._tools
417
404
418
405
def get_tool (self , name , warn = True ):
419
406
"""
420
- Return the tool object, also accepts the actual tool for convenience
407
+ Return the tool object, also accepts the actual tool for convenience.
421
408
422
409
Parameters
423
410
----------
0 commit comments