SHARE
TWEET

Untitled

a guest Feb 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [ ]All1           [ ]All2        
  2.  
  3. [ ]checkbox1A     [ ]checkbox1B
  4.  
  5. [ ]checkbox2A     [ ]checkbox2B
  6.    
  7. cbPairKeys = cbPairs.keys()
  8.     for key in cbPairKeys:
  9.         cbOne = cbPairs[key][0][0]
  10.         cbTwo = cbPairs[key][1][0]
  11.         cbOne.stateChanged.connect(self.syncCB)
  12.         cbTwo.stateChanged.connect(self.syncCB)
  13.  
  14. def syncCB(self):              
  15.     pairKeys = cbPairs.keys()
  16.     for keys in pairKeys:
  17.         cbOne = cbPairs[keys][0][0]
  18.         cbOneAllCB = cbPairs[keys][0][4]
  19.         cbTwo = cbPairs[keys][1][0]
  20.         cbTwoAllCB = cbPairs[keys][1][4]
  21.  
  22.         if self.sender() == cbOne:
  23.             if cbOne.isChecked() or cbTwoAllCB.isChecked():
  24.                 cbTwo.setChecked(True)
  25.             else:
  26.                 cbTwo.setChecked(False)
  27.         else:
  28.             if cbTwo.isChecked() or cbOneAllCB.isChecked():
  29.                 cbOne.setChecked(True)
  30.             else:
  31.                 cbOne.setChecked(False)
  32.    
  33. #Connect checkbox pairs    
  34. cbPairKeys = cbPairs.keys()
  35.     for key in cbPairKeys:
  36.         cbOne = cbPairs[key][0][0]
  37.         cbTwo = cbPairs[key][1][0]
  38.         cbOne.toggled.connect(cbTwo.setChecked)
  39.         cbTwo.toggled.connect(cbOne.setChecked)
  40.  
  41. #Connect allCB and allRO signals    
  42. cbsKeys = allCBList.keys()
  43.     for keys in cbsKeys:
  44.         for checkbox in allCBList[keys]:
  45.             keys.toggled.connect(checkbox.setChecked)
  46.    
  47. { All1 : [checkbox1A, checkbox1B],
  48.   All2 : [checkbox2A, checkbox2B]}
  49.    
  50. for key, checkboxes in allCBList.iteritems():
  51.     for checkbox in checkboxes:
  52.         checkbox.toggled.connect(lambda checked, checkboxes=checkboxes, key=key: key.setChecked(checked and all(checkbox.isChecked() for checkbox in checkboxes))
  53.    
  54. lambda checked, checkboxes=checkboxes, key=key:
  55.    
  56. key.setChecked(...)
  57.    
  58. checked and all(checkbox.isChecked() for checkbox in checkboxes)
  59.    
  60. # Connect checkbox pairs
  61. # you just use the values
  62. # change 'itervalues' to 'values' if you are on Python 3.x
  63. for cbPair in cbPairs.itervalues():
  64.     cbOne = cbPair[0][0]
  65.     cbTwo = cbPair[1][0]
  66.     cbOne.toggled.connect(cbTwo.setChecked)
  67.     cbTwo.toggled.connect(cbOne.setChecked)
  68.  
  69. # Connect allCB and allRO signals
  70. # change 'iteritems' to 'items' if you are on Python 3.x
  71. for key, checkboxes in allCBList.iteritems():
  72.     for checkbox in checkboxes:
  73.         key.clicked.connect(checkbox.setChecked)
  74.         checkbox.toggled.connect(lambda checked, checkboxes=checkboxes, key=key: key.setChecked(checked and all(checkbox.isChecked() for checkbox in checkboxes))
  75.    
  76. self.cbPair = {}
  77.     self.cbPair['0'] = (QtGui.QCheckBox('all1', parent),
  78.         QtGui.QCheckBox('all2', parent))
  79.     self.cbPair['1'] = (QtGui.QCheckBox('1a', parent),
  80.         QtGui.QCheckBox('1b', parent))
  81.     self.cbPair['2'] = (QtGui.QCheckBox('2a', parent),
  82.         QtGui.QCheckBox('2b', parent))
  83.  
  84.     for v in self.cbPair.values():
  85.         for cb in v:
  86.             cb.clicked.connect(self.updateCB)
  87.  
  88. def updateCB(self):
  89.     cb = self.sender()
  90.     is_checked = cb.isChecked()
  91.     id = str(cb.text())
  92.     try:
  93.         # Update a whole column
  94.         column = int(id[-1]) - 1
  95.         rows = ('1', '2')
  96.     except ValueError:
  97.         # Update a row and the headers row
  98.         rows = (id[0], )
  99.         column = {'a': 1, 'b': 0}.get(id[-1])
  100.         if not is_checked:
  101.             for c in (0, 1):
  102.                 self.cbPair['0'][c].setChecked(is_checked)
  103.     for r in rows:
  104.         self.cbPair[r][column].setChecked(is_checked)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top