def on_but_edit(self): #logger.debug('on_but_edit') if self.w_edit is None: logger.debug("TBD Open configuration editor window") resp = self.select_config_type_and_dev() if resp is None: return cfgtype, dev = resp self.device = dev inst, confdb = self.inst_configdb('on_but_edit: ') try: self.config = confdb.get_configuration(cfgtype, dev, hutch=inst) except ValueError as err: logger.error('ValueError: %s' % err) return msg = 'get_configuration(%s, %s, %s):\n' % (cfgtype, dev, inst)\ + '%s\n type(config): %s'%(str_json(self.config), type(self.config)) logger.debug(msg) self.w_edit = CGWConfigEditor(dictj=self.config) self.w_edit.move(self.mapToGlobal(QPoint(self.width() + 10, 0))) self.w_edit.show() else: logger.debug("Close configuration editor window") self.w_edit.close() self.w_edit = None
def load_dict(self): ifname = self.ifname_json logger.info('CGWConfigEditor: load json from %s' % ifname) self.dictj = dj = load_json_from_file(ifname) sj = str_json(dj) logger.debug( 'CGWConfigEditor: dict of json as str:\n%s\nconfiguration object type: %s' % (sj, type(dj)))
def on_but_apply(self): logger.debug('on_but_apply') dj = self.get_content() sj = str_json(dj) logger.info('on_but_apply jason/dict:\n%s' % sj) if cp.cgwmainconfiguration is None: logger.warning("parent (ctrl) is None - changes can't be applied to DB") return else: cp.cgwmainconfiguration.save_dictj_in_db(dj, msg='CGWConfigEditor: ')
def on_but_edit_v0(self): #logger.debug('on_but_edit') if self.w_edit is None: inst, confdb = self.inst_configdb('on_but_edit: ') cfgtype = self.but_type_text() dev = self.but_dev_text() self.config = confdb.get_configuration(cfgtype, dev, hutch=inst) msg = 'get_configuration(%s, %s, %s):\n' % (cfgtype, dev, inst)\ + '%s\n type(config): %s'%(str_json(self.config), type(self.config)) logger.debug(msg) self.w_edit = CGWConfigEditor(dictj=self.config) self.w_edit.move(self.mapToGlobal(QPoint(self.width() + 10, 0))) self.w_edit.show() else: self.w_edit.close() self.w_edit = None
def select_configuration_dict_to_edit(self): logger.debug('select_configuration_dict_to_edit') resp = self.select_config_type_and_dev() if resp is None: return None cfgtype, dev = resp self.device_edit = dev self.cfgtype_edit = cfgtype inst, confdb = self.inst_configdb('on_but_edit: ') try: self.config = confdb.get_configuration(cfgtype, dev, hutch=inst) except ValueError as err: logger.error('ValueError: %s' % err) return None except Exception as err: logger.error('Exception: %s' % err) return None msg = 'get_configuration(%s, %s, %s):\n' % (cfgtype, dev, inst)\ + '%s\n type(config): %s'%(str_json(self.config), type(self.config)) logger.debug(msg) return self.config
def save_dict_in_file(self): logger.info('save_dict_in_file %s' % self.ofname_json) dj = self.get_content() sj = str_json(dj) save_textfile(sj, self.ofname_json, mode='w', verb=True)
def set_content(self, dictj): """Interface method """ self.dictj = dictj sj = str_json(dictj) self.edi_txt.setText(str(sj))