def apply(self, idx): d = self.getObj(idx) pvd = self.pvdict[idx] for s in param.params.pobj.setflds: for f in s: if param.params.pobj.fldmap[f]['writezero']: try: v = d[f] # PV value except: continue v2 = self.getCfg(idx, f) # Configured value # # Write a value if: # 1. It's not derived (the value isn't None), and either # 2a. It's a change, or # 2b. It's a "must write" value. # if v2 != None and ( not param.equal(v, v2) or param.params.pobj.fldmap[f]['mustwrite']): try: z = param.params.pobj.fldmap[f]['enum'][0] except: z = 0 try: pv = pvd[f] if param.params.debug: print "Put %s to %s" % (str(z), pv.name) else: pv.put(z, timeout=-1.0) except: pass pyca.flush_io() for f in s: try: v = d[f] # PV value except: continue v2 = self.getCfg(idx, f) # Configured value if v2 != None and (not param.equal(v, v2) or param.params.pobj.fldmap[f]['mustwrite']): try: pv = pvd[f] if param.params.debug: print "Put %s to %s" % (str(v2), pv.name) else: pv.put(v2, timeout=-1.0) except: pass pyca.flush_io()
def fixChildren(self, idx, f, column, v, chcolor, setidx=None, cm=None): for c in self.tree[idx]['children']: cd = self.getCfg(c) if not cd['_color'][f] in [ param.params.blue, param.params.purple, param.params.almond ]: continue if v == None: cd[f] = None if not param.equal(v, cd[f]): cd[f] = v if idx < 0 and c >= 0: # If we inherit from a *new* config, we are purple! cd['_color'][f] = param.params.purple elif idx < 0 and chcolor == param.params.purple: # On the other hand, if we *are* a new config, we can't be purple! cd['_color'][f] = param.params.blue else: cd['_color'][f] = chcolor self.cfgChanged.emit(c, f) if c in self.path: r = self.path.index(c) index = self.index(r, column) self.dataChanged.emit(index, index) if setidx != None: cd['curmutex'] = cd['curmutex'][:setidx] + cm + cd['curmutex'][ setidx + 1:] self.fixChildren(c, f, column, v, cd['_color'][f], setidx, cm)
def setValue(self, idx, f, v): try: d = self.edits[idx] except: d = {} hadedit = (d != {}) # OK, the config/cfgname thing is slightly weird. The field name for our index is # 'cfgname', but we are passing an int that should go to 'config'. So we need to # change *both*! if f == 'cfgname': vlink = v v = param.params.db.getCfgName(vlink) try: del d[f] if f == 'cfgname': del d['config'] except: pass if f == 'category': v = param.params.catenum[param.params.catenum2.index(v)] v2 = self.getCfg(idx, f) if not param.equal(v, v2): d[f] = v if f == 'cfgname': d['config'] = vlink if not hadedit and idx >= 0: self.status[idx] = "".join(sorted("M" + self.status[idx])) self.statchange(idx) else: if hadedit and d == {} and idx >= 0: self.status[idx] = self.status[idx].replace("M", "") self.statchange(idx) if d != {}: if idx < 0: self.objs[idx].update(d) self.objs[idx]['_val'].update(d) else: self.edits[idx] = d else: try: del self.edits[idx] self.status[idx] = self.status[idx].replace("M", "") self.statchange(idx) except: pass mutex = self.getCfg(idx, 'mutex') try: cm = chr(param.params.pobj.fldmap[f]['colorder'] + 0x40) if cm in mutex: i = mutex.find(cm) self.promote(idx, f, i, mutex) except: pass
def setCfg(self, idx, cfg): self.setValue(idx, 'cfgname', cfg) acts = self.getObj(idx) flist = [d['fld'] for d in param.params.pobj.objflds] for f in flist: v = acts[f] v2 = self.getCfg(idx, f) # Configured value if v == None or v2 == None or param.equal(v, v2): try: self.istatus[idx].remove(f) except: pass else: self.istatus[idx].add(f) r = self.rowmap.index(idx) self.dataChanged.emit(self.index(r, 0), self.index(r, self.colcnt - 1))
def haveObjPVDiff(self, index): db = param.params.pobj try: (idx, f) = self.index2db(index) flist = [f] except: idx = self.rowmap[index] flist = [ d['fld'] for d in param.params.pobj.objflds if d['obj'] == True ] for f in flist: if idx < 0: try: vc = self.objs[idx]['_val'][f] except: pass try: va = self.objs[idx][f] except: pass else: try: vc = self.edits[idx][f] except: try: vc = db.objs[idx]['_val'][f] except: return False try: va = db.objs[idx][f] except: return False try: if db.fldmap[f]['obj'] and not param.equal(va, vc) and vc != None: return True except: pass return False
def checkSetMutex(self, d, e): for s in param.params.pobj.setflds: f = param.params.pobj.fldmap[s[0]] if not f['setmutex'] or not f['obj']: continue try: z = f['enum'][0] except: z = 0 vlist = [] for f in s: try: v = e[f] except: v = d[f] if v != None and not param.equal(v, z): if v in vlist: return [ param.params.pobj.fldmap[f]['alias'] for f in s ] else: vlist.append(v) return []
def data(self, index, role=QtCore.Qt.DisplayRole): if (role != QtCore.Qt.DisplayRole and role != QtCore.Qt.EditRole and role != QtCore.Qt.ForegroundRole and role != QtCore.Qt.BackgroundRole and role != QtCore.Qt.ToolTipRole): return QtGui.QStandardItemModel.data(self, index, role) if not index.isValid(): return QtCore.QVariant() (idx, f) = self.index2db(index) if role == QtCore.Qt.ToolTipRole: if f == 'status': return QtGui.QStandardItemModel.data(self, index, role) try: ve = self.edits[idx][f] # Edited value if ve == None: ve = "None" except: ve = None try: va = self.getObj(idx)[f] # Actual value except: va = None vc = self.getCfg(idx, f, False) # Configured value if ve == None and (vc == None or param.equal(va, vc)): return QtGui.QStandardItemModel.data(self, index, role) v = "Configured Value: %s" % str(vc) v += "\nActual Value: %s" % str(va) if ve != None: v += "\nEdited Value: %s" % str(ve) return QtCore.QVariant(v) if f == "status": if role == QtCore.Qt.ForegroundRole: return QtCore.QVariant(param.params.black) elif role == QtCore.Qt.BackgroundRole: return QtCore.QVariant(param.params.white) else: return QtCore.QVariant(self.getStatus(idx)) try: v = self.getObj(idx)[f] # Actual value except: v = None v2 = self.getCfg(idx, f) # Configured value if f[:4] == 'FLD_' or f[:3] == 'PV_': if v == None or v2 == None or param.equal(v, v2): try: self.istatus[idx].remove( f) # If we don't have a value (either # the PV isn't connected, or is is a # derived value in the configuration), # or the PV is equal to the configuration, # we're not inconsistent. except: pass else: self.istatus[idx].add(f) # Otherwise, we are! if role == QtCore.Qt.BackgroundRole: # If the actual value is None, the PV is not connected. # If the configuration value is None, the PV is derived. if f in self.cfld or param.params.pobj.fldmap[f]['obj']: # An object value! Let "derived" win! if v2 == None: return QtCore.QVariant( param.params.almond) # A derived value. elif v == None: return QtCore.QVariant(param.params.gray) # Not connected. elif v == "" and v2 != "": return QtCore.QVariant( param.params.ltblue ) # Actually empty, but there is a configured value. else: return QtCore.QVariant( param.params.white) # An ordinary cell. else: # A configuration value! Let "not connected" win! if v == None: return QtCore.QVariant(param.params.gray) # Not connected. elif v == "" and v2 != "": return QtCore.QVariant( param.params.ltblue ) # Actually empty, but there is a configured value. elif v2 == None: return QtCore.QVariant( param.params.almond) # A derived value. else: return QtCore.QVariant( param.params.ltgray) # An ordinary cell. elif role == QtCore.Qt.ForegroundRole: try: v = self.edits[idx][f] return QtCore.QVariant(param.params.red) except: pass if v2 == None or param.equal(v, v2): return QtCore.QVariant(param.params.black) else: return QtCore.QVariant(param.params.blue) return QtCore.QVariant() elif role == QtCore.Qt.DisplayRole: try: v = self.edits[idx][f] except: pass else: # QtCore.Qt.EditRole try: v = self.edits[idx][f] except: if v2 != None: v = v2 # DisplayRole or EditRole fall through... v has our value! if f == 'category': v = param.params.catenum2[param.params.catenum.index(v)] return QtCore.QVariant(v)
def setData(self, index, value, role=QtCore.Qt.EditRole): if role != QtCore.Qt.DisplayRole and role != QtCore.Qt.EditRole: return QtGui.QStandardItemModel.setData(self, index, value, role) t = value.type() if t == QtCore.QMetaType.QString: v = str(value.toString()) elif t == QtCore.QMetaType.Int: (v, ok) = value.toInt() elif t == QtCore.QMetaType.Double: (v, ok) = value.toDouble() elif t == QtCore.QMetaType.Void: v = None else: print "Unexpected QVariant type %d" % value.type() return False (idx, f) = self.index2db(index) # Get all the edits for this config. try: e = self.edits[idx] except: e = {} # OK, the config/cfgname thing is slightly weird. The field name for our index is # 'cfgname', but we are passing an int that should go to 'config'. So we need to # change *both*! if f == 'cfgname': vlink = v v = param.params.db.getCfgName(vlink) # Remove the old edit of this field, if any. try: del e[f] if f == 'cfgname': del e['config'] except: pass # Get the configured values. d = self.getCfg(idx) if not param.equal(v, d[f]): # If we have a change, set it as an edit. chg = True e[f] = v if f == 'cfgname': e['config'] = vlink self.createallval(None, index) else: chg = False # No change? # Save the edits for this id! if e != {}: if idx < 0: self.cfgs[idx].update(e) for k in e.keys(): self.cfgs[idx]['_val'][k] = True else: self.edits[idx] = e else: try: del self.edits[idx] except: pass self.setModifiedStatus(index, idx, d) # Set our color. if chg and idx >= 0: # Only mark changes to *existing* configurations in red! d['_color'][f] = param.params.red chcolor = param.params.purple elif self.geteditval(idx, f) != None: d['_color'][f] = param.params.red chcolor = param.params.purple else: if d['_val'][f]: d['_color'][f] = param.params.black chcolor = param.params.blue else: p = self.getCfg(d['config']) col = p['_color'][f] if col == param.params.black or col == param.params.blue: d['_color'][f] = param.params.blue chcolor = param.params.blue else: d['_color'][f] = param.params.purple chcolor = param.params.purple c = index.column() try: cm = chr(param.params.pobj.fldmap[f]['colorder'] + 0x40) if (d['_color'][f] != param.params.blue and d['_color'][f] != param.params.purple and cm in d['curmutex']): # This is a calculated value! i = d['curmutex'].find(cm) d['curmutex'] = self.promote(idx, f, i, d['curmutex']) except: pass self.dataChanged.emit(index, index) if c == self.namecol: param.params.db.setCfgName(idx, v) self.newname.emit(idx, v) else: self.cfgChanged.emit(idx, f) # Now, fix up the children that inherit from us! self.fixChildren(idx, f, c, v, chcolor) return True