def receive(self, message): self.message = message visHas5000 = boolean(conf.value('Validator/VisHas5000')) cloudHeightHas450 = boolean(conf.value('Validator/CloudHeightHas450')) try: self.parser = Parser(self.message['rpt'], visHas5000=visHas5000, cloudHeightHas450=cloudHeightHas450) self.parser.validate() html = '<p>{}<br/>{}</p>'.format(self.message['sign'], self.parser.renderer(style='html')) if self.parser.tips: html += '<p style="color: grey"># {}</p>'.format('<br/># '.join(self.parser.tips)) self.rpt.setHtml(html) self.message['rpt'] = self.parser.renderer() except Exception as e: logger.error(e)
def setup(self): self.setWindowIcon(QIcon(':/logo.png')) # 初始化剪贴板 self.clip = QApplication.clipboard() # 闹钟提示框 self.remindBox = RemindMessageBox(self) # 初始化窗口 self.settingDialog = SettingDialog(self) self.tafSender = TafSender(self) self.trendSender = TrendSender(self) self.sigmetSender = SigmetSender(self) self.reSender = ReSender(self) self.tafEditor = TafEditor(self, self.tafSender) self.trendEditor = TrendEditor(self, self.trendSender) self.sigmetEditor = SigmetEditor(self, self.sigmetSender) if boolean(conf.value('General/Serious')): self.taskBrowser = TaskBrowser(self) self.taskTafSender = TaskTafSender(self) self.taskTafEditor = TaskTafEditor(self, self.taskTafSender) self.setRecent() self.setTable() self.setContractMenu() # 设置切换联系人菜单 self.setSysTray() self.setStatus() self.setThread() self.setSound()
def closeEvent(self, event): if event.spontaneous(): event.ignore() self.hide() else: self.tafSender.setAttribute(Qt.WA_DeleteOnClose) self.trendSender.setAttribute(Qt.WA_DeleteOnClose) self.sigmetSender.setAttribute(Qt.WA_DeleteOnClose) self.reSender.setAttribute(Qt.WA_DeleteOnClose) self.tafEditor.setAttribute(Qt.WA_DeleteOnClose) self.trendEditor.setAttribute(Qt.WA_DeleteOnClose) self.sigmetEditor.setAttribute(Qt.WA_DeleteOnClose) self.settingDialog.setAttribute(Qt.WA_DeleteOnClose) self.tafSender.close() self.trendSender.close() self.sigmetSender.close() self.reSender.close() self.tafEditor.close() self.trendEditor.close() self.sigmetEditor.close() self.settingDialog.close() if boolean(conf.value('General/Serious')): self.taskTafSender.setAttribute(Qt.WA_DeleteOnClose) self.taskTafEditor.setAttribute(Qt.WA_DeleteOnClose) self.taskBrowser.setAttribute(Qt.WA_DeleteOnClose) self.taskTafSender.close() self.taskTafEditor.close() self.taskBrowser.close() self.tray.hide() event.accept()
def keyPressEvent(self, event): if boolean(conf.value('General/Serious')): if event.modifiers() == (Qt.ShiftModifier | Qt.ControlModifier): if event.key() == Qt.Key_P: self.taskTafEditor.show() if event.key() == Qt.Key_T: self.taskBrowser.show()
def loadValue(self, path, option, category='text'): val = conf.value(path) option = getattr(self, option) if val is None: return 0 if category in ['text', 'plaintext']: option.setText(val) if category == 'bool': val = boolean(val) option.setChecked(val) if category == 'combox': index = option.findText(val, Qt.MatchFixedString) option.setCurrentIndex(index) if category == 'slider': option.setValue(int(val)) if category == 'list': try: items = json.loads(val) option.addItems(items) except (ValueError, TypeError): pass if category == 'mobile': person = db.query(User).filter_by(mobile=val).first() if person: index = option.findText(person.name, Qt.MatchFixedString) option.setCurrentIndex(index)
def main(): import sys app = QApplication(sys.argv) translator = QTranslator() locale = QLocale.system().name() translateFile = os.path.join(BASEDIR, 'i18n\\translations', '{}.qm'.format(locale)) if translator.load(translateFile): app.installTranslator(translator) # QApplication.setStyle(QStyleFactory.create('Fusion')) if boolean(conf.value('General/LargeFont')): font = QFont('Courier New', 14) app.setFont(font) serverName = 'Tafor' socket = QLocalSocket() socket.connectToServer(serverName) # 如果连接成功,表明server已经存在,当前已有实例在运行 if socket.waitForConnected(500): return(app.quit()) # 没有实例运行,创建服务器 localServer = QLocalServer() localServer.listen(serverName) try: window = MainWindow() window.show() sys.exit(app.exec_()) except Exception as e: logger.error(e, exc_info=True) finally: localServer.close()
def setFont(self): font = QFont('Segoe UI') if boolean(conf.value('General/LargeFont')): font.setPointSize(15) else: font.setPixelSize(14) self.rpt.setFont(font)
def actionController(self): alwaysShow = boolean(conf.value('General/AlwaysShowEditor')) if not alwaysShow: self.previewSignal.connect(self.hide) self.previewSignal.connect(self.sender.receive) self.previewSignal.connect(self.sender.show) self.sender.sendSignal.connect(self.parent.updateGui) self.sender.backSignal.connect(self.show) self.sender.closeSignal.connect(self.close)
def remindSigmet(self): remindSwitch = boolean(conf.value('Monitor/RemindSIGMET')) if not remindSwitch: return None text = QCoreApplication.translate('MainWindow', 'Time to post {}').format('SIGMET') self.sigmetSound.play() self.remindBox.setText(text) ret = self.remindBox.exec_() if not ret: QTimer.singleShot(1000 * 60 * 5, self.remindSigmet) self.sigmetSound.stop()
def singer(self): warnSwitch = self.warnTafAction.isChecked() trendSwitch = boolean(conf.value('Monitor/RemindTrend')) # 管理趋势声音 utc = datetime.datetime.utcnow() if trendSwitch and utc.minute in (58, 59): self.trendSound.play() else: self.trendSound.stop() # 管理报文告警声音 if warnSwitch and context.taf.isWarning(): self.alarmSound.play() else: self.alarmSound.stop()
def remindTaf(self, tt): remindSwitch = boolean(conf.value('Monitor/RemindTAF')) if not remindSwitch: return None state = context.taf.state() clock = state[tt]['clock'] period = state[tt]['period'] sent = state[tt]['sent'] warnning = state[tt]['warnning'] if clock and not warnning and not sent: current = tt + period[2:] text = QCoreApplication.translate('MainWindow', 'Time to post {}').format(current) self.ringSound.play() self.remindBox.setText(text) ret = self.remindBox.exec_() if not ret: QTimer.singleShot(1000 * 60 * 5, lambda: self.remindTaf(tt)) self.ringSound.stop()