Browse Source

better loop logic

add-license-1
T-bone 7 years ago
parent
commit
1b9f832214
1 changed files with 56 additions and 9 deletions
  1. 56
    9
      akvo/gui/akvoGUI.py

+ 56
- 9
akvo/gui/akvoGUI.py View File

@@ -186,7 +186,11 @@ class ApplicationWindow(QtWidgets.QMainWindow):
186 186
                 pCell.setBackground( QtGui.QColor("lightgrey").lighter(110) )
187 187
                 self.ui.loopTableWidget.setItem(ir, ic, pCell)
188 188
 
189
-        self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged) 
189
+        self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged)
190
+        #self.ui.loopTableWidget.cellPressed.connect(self.loopCellChanged) 
191
+        self.ui.loopTableWidget.itemClicked.connect(self.loopCellClicked) 
192
+        #self.ui.loopTableWidget.cellPressed.connect(self.loopCellClicked) 
193
+
190 194
         self.ui.loopTableWidget.setDragDropOverwriteMode(False)
191 195
         self.ui.loopTableWidget.setDragEnabled(True)
192 196
         self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
@@ -216,6 +220,7 @@ class ApplicationWindow(QtWidgets.QMainWindow):
216 220
                 self.ui.layerTableWidget.setItem(ir, ic, pCell)
217 221
         self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged) 
218 222
 
223
+
219 224
     def sigmaCellChanged(self):
220 225
         self.ui.layerTableWidget.cellChanged.disconnect(self.sigmaCellChanged) 
221 226
         # TODO consider building the model whenever this is called. Would be nice to be able to 
@@ -284,36 +289,78 @@ class ApplicationWindow(QtWidgets.QMainWindow):
284 289
 
285 290
         self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged) 
286 291
 
292
+    def loopCellClicked(self, item):
293
+        print("checkstate", item.checkState(),item.row())
294
+
295
+        #self.ui.loopTableWidget.itemClicked.disconnect(self.loopCellClicked)
296
+        jj = item.column() 
297
+        ii = item.row()
298
+        tp = type(self.ui.loopTableWidget.item(ii, 0))
299
+        print("tp", tp, ii, jj)
300
+        if str(tp) == "<class 'NoneType'>": 
301
+            return 
302
+        #print("Clicked", ii, jj)
303
+        if jj == 5 and self.ui.loopTableWidget.item(ii, 0).text() in self.loops.keys():
304
+            #print("jj=5")
305
+            self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"] = self.ui.loopTableWidget.item(ii, 5).checkState()
306
+            # update surrogates  
307
+            print("updating surrogates")
308
+            for point in self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["points"][1:]:
309
+                pCell = self.ui.loopTableWidget.item(point, 5)
310
+                if self.ui.loopTableWidget.item(ii, 5).checkState():
311
+                    pCell.setCheckState(QtCore.Qt.Checked);
312
+                else:
313
+                    pCell.setCheckState(QtCore.Qt.Unchecked);
314
+ 
315
+            #print( "loops",  self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"]) 
316
+         
317
+        #self.ui.loopTableWidget.itemClicked.connect(self.loopCellClicked) 
287 318
 
288 319
     def loopCellChanged(self):
289
-       
290 320
         self.ui.loopTableWidget.cellChanged.disconnect(self.loopCellChanged) 
291 321
         
292 322
         jj = self.ui.loopTableWidget.currentColumn()
293 323
         ii = self.ui.loopTableWidget.currentRow()
294 324
 
295
-        if jj == 0: # ch. tag modified
296
-
325
+        if jj == 0 and len( self.ui.loopTableWidget.item(ii, jj).text().strip()) == 0:
326
+            for jjj in range(jj+1,jj+6): 
327
+                pCell = self.ui.loopTableWidget.item(ii, jjj)
328
+                pCell.setBackground( QtGui.QColor("white") )
329
+                pCell.setFlags( QtCore.Qt.NoItemFlags | QtCore.Qt.ItemIsUserCheckable   ) # not selectable 
330
+        elif jj == 0 and len( self.ui.loopTableWidget.item(ii, jj).text().strip() ): # ch. tag modified
297 331
             for jjj in range(jj+1,jj+5): 
298 332
                 pCell = self.ui.loopTableWidget.item(ii, jjj)
299 333
                 pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled )
300 334
                 pCell.setBackground( QtGui.QColor("lightblue") )
301 335
             if self.ui.loopTableWidget.item(ii, jj).text() not in self.loops.keys():
336
+                # This is a new loop ID 
302 337
                 self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ] = {}
303
-                print (self.loops.keys())
338
+                self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["Tx"] = self.ui.loopTableWidget.item(ii, 5).checkState()
339
+                self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["points"] = [ii] 
304 340
                 # Transmitter cell 
305 341
                 pCell = self.ui.loopTableWidget.item(ii, jj+5)
306
-                pCell.setCheckState(QtCore.Qt.Unchecked);
307
-                pCell.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled )
342
+                pCell.setCheckState(QtCore.Qt.Unchecked)
343
+                pCell.setFlags( QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled  )
308 344
                 pCell.setBackground( QtGui.QColor("lightblue") ) 
309 345
             else:
346
+                # This is an existing loop ID 
347
+                self.loops[ self.ui.loopTableWidget.item(ii, jj).text() ]["points"].append( ii ) 
310 348
                 pCell = self.ui.loopTableWidget.item(ii, jj+5)
311
-                pCell.setCheckState(QtCore.Qt.Unchecked);
349
+                pCell.setFlags(QtCore.Qt.NoItemFlags) # not selectable 
350
+                if self.loops[ self.ui.loopTableWidget.item(ii, 0).text() ]["Tx"]:
351
+                    pCell.setCheckState(QtCore.Qt.Checked);
352
+                else:
353
+                    pCell.setCheckState(QtCore.Qt.Unchecked);
312 354
                 #pCell.setFlags( )
313
-                pCell.setBackground( QtGui.QColor("lightblue") ) 
355
+                pCell.setBackground( QtGui.QColor("lightblue") )
356
+
357
+
358
+            
359
+ 
314 360
         self.plotLoops()
315 361
         self.ui.loopTableWidget.cellChanged.connect(self.loopCellChanged) 
316 362
 
363
+
317 364
     def plotLoops(self):
318 365
                
319 366
         #self.ui.mplwidget_3.fig.clear() 

Loading…
Cancel
Save