@@ -72,31 +72,14 @@ class ToolBase(object):
72
72
`name` is used as label in the toolbar button
73
73
"""
74
74
75
- toggle = False # Change the status (take control of the events)
76
- """Is toggleable tool
77
-
78
- **bool**:
79
-
80
- * **True**: The tool is a toogleable tool
81
- * **False**: The tool is not toggleable
82
-
83
- """
84
-
85
- persistent = False
86
- """Is persistent tool
87
-
88
- **bool**:
89
- * `True`: The tool is persistent
90
- * `False`: The tool is not persistent
91
- """
92
-
93
75
cursor = None
94
76
"""Cursor to use when the tool is active
95
77
"""
96
78
97
79
def __init__ (self , figure , event = None ):
98
- self .figure = figure
99
- self .navigation = figure .canvas .manager .navigation
80
+ self .figure = None
81
+ self .navigation = None
82
+ self .set_figure (figure )
100
83
self .trigger (event )
101
84
102
85
def trigger (self , event ):
@@ -109,6 +92,18 @@ def trigger(self, event):
109
92
"""
110
93
pass
111
94
95
+ def set_figure (self , figure ):
96
+ """Set the figure and navigation
97
+
98
+ Set the figure to be affected by this tool
99
+
100
+ Parameters
101
+ ----------
102
+ figure : `Figure`
103
+ """
104
+ self .figure = figure
105
+ self .navigation = figure .canvas .manager .navigation
106
+
112
107
113
108
class ToolPersistentBase (ToolBase ):
114
109
"""Persisten tool
@@ -121,12 +116,13 @@ class ToolPersistentBase(ToolBase):
121
116
The difference with `ToolBase` is that `trigger` method
122
117
is not called automatically at initialization
123
118
"""
124
- persistent = True
125
119
126
120
def __init__ (self , figure , event = None ):
127
- self .figure = figure
128
- self .navigation = figure .canvas .manager .navigation
121
+ self .figure = None
122
+ self .navigation = None
123
+ self .set_figure (figure )
129
124
#persistent tools don't call trigger a at instantiation
125
+ #it will be called by Navigation
130
126
131
127
def unregister (self , * args ):
132
128
"""Unregister the tool from the instances of Navigation
@@ -145,7 +141,6 @@ class ToolToggleBase(ToolPersistentBase):
145
141
Every time it is triggered, it switches between enable and disable
146
142
147
143
"""
148
- toggle = True
149
144
_toggled = False
150
145
151
146
def trigger (self , event ):
0 commit comments