def setValue(self, path, option, category='text'): option = getattr(self, option) if category == 'text': val = option.text() if category == 'bool': val = option.isChecked() if category == 'combox': val = option.currentText() if category == 'slider': val = option.value() if category == 'plaintext': val = option.toPlainText() if category == 'list': items = [option.item(i).text() for i in range(option.count())] val = json.dumps(items) if category == 'mobile': name = option.currentText() person = db.query(User).filter_by(name=name).first() val = person.mobile if person else '' conf.setValue(path, val)
def generate(self): """生成 AFTN 电报格式的报文 :return: 报文列表 """ channel = conf.value('Communication/Channel') number = conf.value('Communication/ChannelSequenceNumber') number = int(number) if number else 0 level = 'FF' if self.reportType in ['SIGMET', 'AIRMET'] else 'GG' sendAddress = conf.value('Communication/{}Address'.format( self.reportType)) or '' originatorAddress = conf.value('Communication/OriginatorAddress') or '' groups = self.divideAddress(sendAddress) time = self.time.strftime('%d%H%M') origin = ' '.join([time, originatorAddress]) ending = 'NNNN' self.messages = [] for addr in groups: heading = ' '.join(['ZCZC', channel + str(number).zfill(4)]) address = ' '.join([level] + addr) items = [heading, address, origin] + self.text + [ending] items = self.formatLinefeed(items) self.messages.append(self.lineBreak.join(items)) number += 1 conf.setValue('Communication/ChannelSequenceNumber', str(number)) return self.messages
def changeContract(self): target = self.contractsActionGroup.checkedAction() if self.contractNo == target: conf.setValue('Monitor/SelectedMobile', '') logger.info('关闭电话提醒') else: name = target.text() person = db.query(User).filter_by(name=name).first() mobile = person.mobile if person else '' conf.setValue('Monitor/SelectedMobile', mobile) logger.info('切换联系人 %s %s' % (name, mobile))
def importConf(self, defaultPath=False): if defaultPath: filename = os.path.join(BASEDIR, 'default.json') path = self.importPath.text() if path and os.path.isfile(path): filename = self.exportPath.text() try: with open(filename) as file: data = json.load(file) for path, val in data.items(): conf.setValue(path, val) except Exception as e: pass else: self.load() self.parent.statusBar.showMessage(QCoreApplication.translate('Settings', 'Configuration has been imported'), 5000)
def cli(whysoserious): conf.setValue('General/Serious', whysoserious) main()
def resetChannelNumber(self): """重置流水号""" conf.setValue('Communication/ChannelSequenceNumber', '1') self.channelSequenceNumber.setText('1') logger.info('Reset channel sequence number to one')
def loadConf(filename): with open(filename) as file: data = json.load(file) for path, val in data.items(): conf.setValue(path, val)