44
44
import numpy as np
45
45
46
46
47
- def qwtEnableLegendItems (plot , on ):
48
- if on :
49
- plot .legendDataChanged .connect (plot .updateLegendItems )
50
- else :
51
- plot .legendDataChanged .disconnect (plot .updateLegendItems )
52
-
53
-
54
47
def qwtSetTabOrder (first , second , with_children ):
55
48
tab_chain = [first , second ]
56
49
if with_children :
@@ -88,111 +81,10 @@ def removeItem(self, obj):
88
81
self .sortItems ()
89
82
90
83
91
- class QwtPlotDict_PrivateData (object ):
92
- def __init__ (self ):
93
- self .itemList = ItemList ()
94
- self .autoDelete = True
95
-
96
-
97
- class QwtPlotDict (object ):
98
- """
99
- A dictionary for plot items
100
-
101
- `QwtPlotDict` organizes plot items in increasing z-order.
102
- If `autoDelete()` is enabled, all attached items will be deleted
103
- in the destructor of the dictionary.
104
- `QwtPlotDict` can be used to get access to all `QwtPlotItem` items - or
105
- all items of a specific type - that are currently on the plot.
106
-
107
- .. seealso::
108
-
109
- :py:meth:`QwtPlotItem.attach()`, :py:meth:`QwtPlotItem.detach()`,
110
- :py:meth:`QwtPlotItem.z()`
111
- """
112
-
113
- def __init__ (self ):
114
- self .__data = QwtPlotDict_PrivateData ()
115
-
116
- def setAutoDelete (self , autoDelete ):
117
- """
118
- En/Disable Auto deletion
119
-
120
- If Auto deletion is on all attached plot items will be deleted
121
- in the destructor of `QwtPlotDict`. The default value is on.
122
-
123
- :param bool autoDelete: enable/disable
124
-
125
- .. seealso::
126
-
127
- :py:meth:`autoDelete()`, :py:meth:`insertItem()`
128
- """
129
- self .__data .autoDelete = autoDelete
130
-
131
- def autoDelete (self ):
132
- """
133
- :return: true if auto deletion is enabled
134
-
135
- .. seealso::
136
-
137
- :py:meth:`setAutoDelete()`, :py:meth:`insertItem()`
138
- """
139
- return self .__data .autoDelete
140
-
141
- def insertItem (self , item ):
142
- """
143
- Insert a plot item
144
-
145
- :param qwt.plot.QwtPlotItem item: PlotItem
146
-
147
- .. seealso::
148
-
149
- :py:meth:`removeItem()`
150
- """
151
- self .__data .itemList .insertItem (item )
152
-
153
- def removeItem (self , item ):
154
- """
155
- Remove a plot item
156
-
157
- :param qwt.plot.QwtPlotItem item: PlotItem
158
-
159
- .. seealso::
160
-
161
- :py:meth:`insertItem()`
162
- """
163
- self .__data .itemList .removeItem (item )
164
-
165
- def detachItems (self , rtti = None ):
166
- """
167
- Detach items from the dictionary
168
-
169
- :param rtti: In case of `QwtPlotItem.Rtti_PlotItem` or None (default) detach all items otherwise only those items of the type rtti.
170
- :type rtti: int or None
171
- """
172
- for item in self .__data .itemList [:]:
173
- if rtti in (None , QwtPlotItem .Rtti_PlotItem ) or item .rtti () == rtti :
174
- item .attach (None )
175
-
176
- def itemList (self , rtti = None ):
177
- """
178
- A list of attached plot items.
179
-
180
- Use caution when iterating these lists, as removing/detaching an
181
- item will invalidate the iterator. Instead you can place pointers
182
- to objects to be removed in a removal list, and traverse that list
183
- later.
184
-
185
- :param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
186
- :return: List of all attached plot items of a specific type. If rtti is None, return a list of all attached plot items.
187
- """
188
- if rtti is None or rtti == QwtPlotItem .Rtti_PlotItem :
189
- return self .__data .itemList
190
- return [item for item in self .__data .itemList if item .rtti () == rtti ]
191
-
192
-
193
- class QwtPlot_PrivateData (QwtPlotDict_PrivateData ):
84
+ class QwtPlot_PrivateData (object ):
194
85
def __init__ (self ):
195
86
super (QwtPlot_PrivateData , self ).__init__ ()
87
+ self .itemList = ItemList ()
196
88
self .titleLabel = None
197
89
self .footerLabel = None
198
90
self .canvas = None
@@ -217,7 +109,7 @@ def __init__(self):
217
109
self .scaleWidget = None # QwtScaleWidget
218
110
219
111
220
- class QwtPlot (QwtPlotDict , QFrame ):
112
+ class QwtPlot (QFrame ):
221
113
"""
222
114
A 2-D plotting widget
223
115
@@ -300,7 +192,6 @@ def __init__(self, *args):
300
192
"%s() takes 0, 1 or 2 argument(s) (%s given)"
301
193
% (self .__class__ .__name__ , len (args ))
302
194
)
303
- QwtPlotDict .__init__ (self )
304
195
QFrame .__init__ (self , parent )
305
196
306
197
self .__layout_state = None
@@ -359,7 +250,74 @@ def __init__(self, *args):
359
250
for idx in range (len (focusChain ) - 1 ):
360
251
qwtSetTabOrder (focusChain [idx ], focusChain [idx + 1 ], False )
361
252
362
- qwtEnableLegendItems (self , True )
253
+ self .legendDataChanged .connect (self .updateLegendItems )
254
+
255
+ def insertItem (self , item ):
256
+ """
257
+ Insert a plot item
258
+
259
+ :param qwt.plot.QwtPlotItem item: PlotItem
260
+
261
+ .. seealso::
262
+
263
+ :py:meth:`removeItem()`
264
+
265
+ .. note::
266
+
267
+ This was a member of QwtPlotDict in older versions.
268
+ """
269
+ self .__data .itemList .insertItem (item )
270
+
271
+ def removeItem (self , item ):
272
+ """
273
+ Remove a plot item
274
+
275
+ :param qwt.plot.QwtPlotItem item: PlotItem
276
+
277
+ .. seealso::
278
+
279
+ :py:meth:`insertItem()`
280
+
281
+ .. note::
282
+
283
+ This was a member of QwtPlotDict in older versions.
284
+ """
285
+ self .__data .itemList .removeItem (item )
286
+
287
+ def detachItems (self , rtti = None ):
288
+ """
289
+ Detach items from the dictionary
290
+
291
+ :param rtti: In case of `QwtPlotItem.Rtti_PlotItem` or None (default) detach all items otherwise only those items of the type rtti.
292
+ :type rtti: int or None
293
+
294
+ .. note::
295
+
296
+ This was a member of QwtPlotDict in older versions.
297
+ """
298
+ for item in self .__data .itemList [:]:
299
+ if rtti in (None , QwtPlotItem .Rtti_PlotItem ) or item .rtti () == rtti :
300
+ item .attach (None )
301
+
302
+ def itemList (self , rtti = None ):
303
+ """
304
+ A list of attached plot items.
305
+
306
+ Use caution when iterating these lists, as removing/detaching an
307
+ item will invalidate the iterator. Instead you can place pointers
308
+ to objects to be removed in a removal list, and traverse that list
309
+ later.
310
+
311
+ :param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
312
+ :return: List of all attached plot items of a specific type. If rtti is None, return a list of all attached plot items.
313
+
314
+ .. note::
315
+
316
+ This was a member of QwtPlotDict in older versions.
317
+ """
318
+ if rtti is None or rtti == QwtPlotItem .Rtti_PlotItem :
319
+ return self .__data .itemList
320
+ return [item for item in self .__data .itemList if item .rtti () == rtti ]
363
321
364
322
def setFlatStyle (self , state ):
365
323
"""
@@ -1573,9 +1531,9 @@ def insertLegend(self, legend, pos=None, ratio=-1):
1573
1531
if self .__data .legend .parent () is not self :
1574
1532
self .__data .legend .setParent (self )
1575
1533
1576
- qwtEnableLegendItems ( self , False )
1534
+ self . blockSignals ( True )
1577
1535
self .updateLegend ()
1578
- qwtEnableLegendItems ( self , True )
1536
+ self . blockSignals ( False )
1579
1537
1580
1538
lpos = self .__data .layout .legendPosition ()
1581
1539
0 commit comments