@@ -54,8 +54,8 @@ async def stop(self):
54
54
55
55
56
56
class AppletDock (dockarea .Dock ):
57
- def __init__ (self , name , command ):
58
- dockarea .Dock .__init__ (self , "applet" + str (id ( self )), # TODO
57
+ def __init__ (self , uid , name , command ):
58
+ dockarea .Dock .__init__ (self , "applet" + str (uid ),
59
59
label = "Applet: " + name ,
60
60
closable = True )
61
61
self .setMinimumSize (QtCore .QSize (500 , 400 ))
@@ -125,6 +125,7 @@ class AppletsDock(dockarea.Dock):
125
125
def __init__ (self , dock_area ):
126
126
self .dock_area = dock_area
127
127
self .dock_to_checkbox = dict ()
128
+ self .applet_uids = set ()
128
129
self .workaround_pyqtgraph_bug = False
129
130
130
131
dockarea .Dock .__init__ (self , "Applets" )
@@ -168,8 +169,8 @@ def __init__(self, dock_area):
168
169
169
170
self .table .cellChanged .connect (self .cell_changed )
170
171
171
- def create (self , name , command ):
172
- dock = AppletDock (name , command )
172
+ def create (self , uid , name , command ):
173
+ dock = AppletDock (uid , name , command )
173
174
# If a dock is floated and then dock state is restored, pyqtgraph
174
175
# leaves a "phantom" window open.
175
176
if self .workaround_pyqtgraph_bug :
@@ -192,17 +193,17 @@ def cell_changed(self, row, column):
192
193
name = ""
193
194
else :
194
195
name = name .text ()
195
- dock = self .create (name , command )
196
+ dock = self .create (item . applet_uid , name , command )
196
197
item .applet_dock = dock
197
198
self .dock_to_checkbox [dock ] = item
198
199
else :
199
- dock = getattr ( item , " applet_dock" , None )
200
+ dock = item . applet_dock
200
201
if dock is not None :
201
202
# This calls self.on_dock_closed
202
203
dock .close ()
203
204
elif column == 1 or column == 2 :
204
205
new_value = self .table .item (row , column ).text ()
205
- dock = getattr ( self .table .item (row , 0 ), " applet_dock" , None )
206
+ dock = self .table .item (row , 0 ). applet_dock
206
207
if dock is not None :
207
208
if column == 1 :
208
209
dock .rename (new_value )
@@ -217,13 +218,19 @@ def on_dock_closed(self, dock):
217
218
checkbox_item .setCheckState (QtCore .Qt .Unchecked )
218
219
219
220
def new (self ):
221
+ uid = next (iter (set (range (len (self .applet_uids ) + 1 ))
222
+ - self .applet_uids ))
223
+ self .applet_uids .add (uid )
224
+
220
225
row = self .table .rowCount ()
221
226
self .table .insertRow (row )
222
227
checkbox = QtWidgets .QTableWidgetItem ()
223
228
checkbox .setFlags (QtCore .Qt .ItemIsSelectable |
224
229
QtCore .Qt .ItemIsUserCheckable |
225
230
QtCore .Qt .ItemIsEnabled )
226
231
checkbox .setCheckState (QtCore .Qt .Unchecked )
232
+ checkbox .applet_uid = uid
233
+ checkbox .applet_dock = None
227
234
self .table .setItem (row , 0 , checkbox )
228
235
self .table .setItem (row , 1 , QtWidgets .QTableWidgetItem ())
229
236
self .table .setItem (row , 2 , QtWidgets .QTableWidgetItem ())
@@ -237,23 +244,26 @@ def restart(self):
237
244
selection = self .table .selectedRanges ()
238
245
if selection :
239
246
row = selection [0 ].topRow ()
240
- dock = getattr ( self .table .item (row , 0 ), " applet_dock" , None )
247
+ dock = self .table .item (row , 0 ). applet_dock
241
248
if dock is not None :
242
249
asyncio .ensure_future (dock .restart ())
243
250
244
251
def delete (self ):
245
252
selection = self .table .selectedRanges ()
246
253
if selection :
247
254
row = selection [0 ].topRow ()
248
- dock = getattr (self .table .item (row , 0 ), "applet_dock" , None )
255
+ item = self .table .item (row , 0 )
256
+ dock = item .applet_dock
249
257
if dock is not None :
250
258
# This calls self.on_dock_closed
251
259
dock .close ()
260
+ self .applet_uids .remove (item .applet_uid )
252
261
self .table .removeRow (row )
253
262
263
+
254
264
async def stop (self ):
255
265
for row in range (self .table .rowCount ()):
256
- dock = getattr ( self .table .item (row , 0 ), " applet_dock" , None )
266
+ dock = self .table .item (row , 0 ). applet_dock
257
267
if dock is not None :
258
268
await dock .terminate ()
259
269
0 commit comments