class UFDebugTool(QWidget): def __init__(self): super(UFDebugTool, self).__init__() self.ui = UFDebugToolUI(self) self.log_window = LogWindow(self) icon = QIcon() icon.addPixmap(QPixmap(os.path.join(icon_path, 'main.png')), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.log_window.setWindowIcon(icon) self.tornado_thread = TornadoThread() self.tornado_thread.start() # self.log_window.show() # logger.debug('*****debug log style******') # logger.info('*****info log style******') # logger.warn('*****warn log style******') # logger.error('*****error log style******') # logger.critical('*****critical log style******') # sys.stdout.write('*****stdout style******') # sys.stderr.write('*****stderr style******') # print('*****print style******') def closeEvent(self, event): self.log_window.close() super(UFDebugTool, self).closeEvent(event) def show(self): super(UFDebugTool, self).show() if self.log_window.isHidden(): self.ui.logAction.setText('Open-Log') else: self.ui.logAction.setText('Close-Log')
def __init__(self): super(UFDebugTool, self).__init__() self.ui = UFDebugToolUI(self) self.log_window = LogWindow(self) icon = QIcon() icon.addPixmap(QPixmap(os.path.join(icon_path, 'main.png')), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.log_window.setWindowIcon(icon) self.tornado_thread = TornadoThread() self.tornado_thread.start()
def __init__(self, *args): self.logPanel = LogWindow() GuiWindow.__init__(self, lowerItem=self.logPanel) self.clearWebCache() self.postmen = None self.toolbar = self.makeToolbar([ ("images/toolbar-home.png", self.onHomeClicked, "mainwindow.toolbar.home"), ("images/toolbar-people.png", self.onContactsClicked, "mainwindow.toolbar.contacts"), ("images/toolbar-messages.png", self.onMessagesClicked, "mainwindow.toolbar.messages"), ("images/toolbar-messages-highlight.png", self.onMessagesClicked, "mainwindow.toolbar.messages"), ("images/toolbar-calendar.png", self.onCalendarClicked, "mainwindow.toolbar.calendar"), ("images/toolbar-settings.png", self.onSettingsClicked, "mainwindow.toolbar.settings") ]) self.addToolBar(self.toolbar) self.setContextMenuPolicy(QtCore.Qt.NoContextMenu) # status bar self.statusbar = QtWidgets.QStatusBar(self) self.statusbar.setObjectName("statusbar") self.setStatusBar(self.statusbar) self.setWindowTitle(I18nManager.getText("mainwindow.title")) self.setStatusTip("Murmeli") self.setPageServer(PageServer()) self.navigateTo("/") # we want to be notified of Config changes Config.registerSubscriber(self) self.postmen = [ postmen.IncomingPostman(self), postmen.OutgoingPostman(self) ] self.postmen[1].messageSentSignal.connect(self.logPanel.notifyLogEvent) MessageShuffler.getTannoy().updateSignal.connect( self.logPanel.notifyLogEvent) # Make sure Tor client is started if not TorClient.isStarted(): TorClient.startTor() # Create database instance if not already set if not DbI.hasDbSet(): DbI.setDb(MurmeliDb(Config.getSsDatabaseFile())) # Make sure the status of the contacts matches our keyring missingKeyNames = ContactMaker.checkAllContactsKeys() if missingKeyNames: warningTexts = [I18nManager.getText("warning.keysnotfoundfor") ] + missingKeyNames QtWidgets.QMessageBox.warning(self, "Murmeli", "\n ".join(warningTexts))
def __init__(self, view): self.ui = view self.client = None self._connected = False self.address_list = ["opc.tcp://10.42.0.2:4840/OPCUAproject"] self.security_mode = None self.security_policy = None self.certificate_path = None self.private_key_path = None self.ui.closeEvent = self.closeEvent for addr in self.address_list: self.ui.addressComboBox.addItem(addr) self.tree_ui = TreeWidget(self.ui.treeView) self.attrs_ui = AttrsWidget(self.ui.attrView) #self.refs_ui = RefsWidget(self.ui.refView) self.subscription_window = SubscriptionWindow() self.log_window = LogWindow() self.datachange_ui = DataChangeUI(self, self.subscription_window) #self.ui.treeView.selectionModel().selectionChanged.connect(lambda sel: self.show_refs(sel)) self.ui.treeView.selectionModel().selectionChanged.connect( lambda sel: self.show_attrs(sel)) # self.ui.endpointsButton.clicked.connect(lambda : self.get_endpoints()) # self.ui.connSettingsButton.clicked.connect(lambda : self.show_connection_dialog()) # self.ui.connectButton.clicked.connect(lambda : self.connect()) # self.ui.disconnectButton.clicked.connect(lambda: self.disconnect()) # self.ui.readButton.clicked.connect(lambda : self.read_value()) # self.ui.writeButton.clicked.connect(lambda : self.show_write_dialog()) # self.ui.showReferencesButton.clicked.connect(lambda : self.show_refs_dialog()) # self.ui.showSubscriptionsButton.clicked.connect(lambda : self.show_subs_dialog()) # self.ui.showLogsButton.clicked.connect(lambda : self.show_logs_dialog()) self.ui.actionQuery_endpoints.triggered.connect( lambda: self.get_endpoints()) self.ui.actionConnection_settings.triggered.connect( lambda: self.show_connection_dialog()) self.ui.actionConnect.triggered.connect(lambda: self.connect()) self.ui.actionDisconnect.triggered.connect(lambda: self.disconnect()) self.ui.actionRead.triggered.connect(lambda: self.read_value()) self.ui.actionWrite.triggered.connect(lambda: self.show_write_dialog()) self.ui.actionReferences.triggered.connect( lambda: self.show_refs_dialog()) self.ui.actionSubscriptions.triggered.connect( lambda: self.show_subs_dialog()) self.ui.actionLogs.triggered.connect(lambda: self.show_logs_dialog())
class ClientController: def __init__(self, view): self.ui = view self.client = None self._connected = False self.address_list = ["opc.tcp://10.42.0.2:4840/OPCUAproject"] self.security_mode = None self.security_policy = None self.certificate_path = None self.private_key_path = None self.ui.closeEvent = self.closeEvent for addr in self.address_list: self.ui.addressComboBox.addItem(addr) self.tree_ui = TreeWidget(self.ui.treeView) self.attrs_ui = AttrsWidget(self.ui.attrView) #self.refs_ui = RefsWidget(self.ui.refView) self.subscription_window = SubscriptionWindow() self.log_window = LogWindow() self.datachange_ui = DataChangeUI(self, self.subscription_window) #self.ui.treeView.selectionModel().selectionChanged.connect(lambda sel: self.show_refs(sel)) self.ui.treeView.selectionModel().selectionChanged.connect( lambda sel: self.show_attrs(sel)) # self.ui.endpointsButton.clicked.connect(lambda : self.get_endpoints()) # self.ui.connSettingsButton.clicked.connect(lambda : self.show_connection_dialog()) # self.ui.connectButton.clicked.connect(lambda : self.connect()) # self.ui.disconnectButton.clicked.connect(lambda: self.disconnect()) # self.ui.readButton.clicked.connect(lambda : self.read_value()) # self.ui.writeButton.clicked.connect(lambda : self.show_write_dialog()) # self.ui.showReferencesButton.clicked.connect(lambda : self.show_refs_dialog()) # self.ui.showSubscriptionsButton.clicked.connect(lambda : self.show_subs_dialog()) # self.ui.showLogsButton.clicked.connect(lambda : self.show_logs_dialog()) self.ui.actionQuery_endpoints.triggered.connect( lambda: self.get_endpoints()) self.ui.actionConnection_settings.triggered.connect( lambda: self.show_connection_dialog()) self.ui.actionConnect.triggered.connect(lambda: self.connect()) self.ui.actionDisconnect.triggered.connect(lambda: self.disconnect()) self.ui.actionRead.triggered.connect(lambda: self.read_value()) self.ui.actionWrite.triggered.connect(lambda: self.show_write_dialog()) self.ui.actionReferences.triggered.connect( lambda: self.show_refs_dialog()) self.ui.actionSubscriptions.triggered.connect( lambda: self.show_subs_dialog()) self.ui.actionLogs.triggered.connect(lambda: self.show_logs_dialog()) def closeEvent(self, event): self.disconnect() def get_endpoints(self): uri = self.ui.addressComboBox.currentText() client = Client(uri, timeout=2) try: edps = client.connect_and_get_server_endpoints() for i, ep in enumerate(edps, start=1): self.log_window.ui.logTextEdit.append('Endpoint %s:' % i) for (n, v) in endpoint_to_strings(ep): self.log_window.ui.logTextEdit.append(' %s: %s' % (n, v)) self.log_window.ui.logTextEdit.append('') except Exception as ex: self.log_window.ui.logTextEdit.append(str(ex)) raise return edps def show_connection_dialog(self): dia = ConnectionDialog(self, self.ui.addressComboBox.currentText()) #dia.security_mode = self.security_mode #dia.security_policy = self.security_policy #dia.certificate_path = self.certificate_path #dia.private_key_path = self.private_key_path ret = dia.exec_() if ret: #self.security_mode = dia.security_mode #self.security_policy = dia.security_policy self.certificate_path = dia.certificate_path self.private_key_path = dia.private_key_path def show_write_dialog(self): node = self.get_current_node() if node.get_node_class() == ua.NodeClass.Variable: dia = WriteDialog(node, self.log_window.ui.logTextEdit) ret = dia.exec_() else: self.log_window.ui.logTextEdit.append( "Only Variable can be written") def connect(self): self.disconnect() uri = self.ui.addressComboBox.currentText() self.log_window.ui.logTextEdit.append( "Connecting to %s with parameters %s, %s, %s, %s" % (uri, self.security_mode, self.security_policy, self.certificate_path, self.private_key_path)) try: self.client = Client(uri) self.client.application_uri = "urn:opcua:python:client" if self.security_mode is not None and self.security_policy is not None: self.client.set_security(getattr( crypto.security_policies, 'SecurityPolicy' + self.security_policy), self.certificate_path, self.private_key_path, mode=getattr(ua.MessageSecurityMode, self.security_mode)) self.client.connect() self._connected = True except Exception as ex: self.log_window.ui.logTextEdit.append(str(ex)) try: self.client.uaclient._uasocket._thread.isAlive() self.tree_ui.set_root_node(self.client.get_root_node()) self.ui.treeView.setFocus() except Exception as ex: print("Connection error") def _reset(self): self.client = None self._connected = False self.datachange_ui._datachange_sub = {} self.datachange_ui._subs_dc = {} def disconnect(self): try: if self._connected: self.log_window.ui.logTextEdit.append( "Disconnecting from server") self._connected = False if self.client: if self.datachange_ui._datachange_sub: sub_ids = list(self.datachange_ui._datachange_sub.keys()) for sub_id in sub_ids: self.datachange_ui.delete_subscription(sub_id) self.client.disconnect() self._reset() except Exception as ex: self.log_window.ui.logTextEdit.append(str(ex)) finally: self.tree_ui.clear() #self.refs_ui.clear() self.attrs_ui.clear() self.datachange_ui.clear() def show_attrs(self, selection): if isinstance(selection, QItemSelection): if not selection.indexes(): # no selection return node = self.get_current_node() if node: self.attrs_ui.show_attrs(node) '''def show_refs(self, selection): if isinstance(selection, QItemSelection): if not selection.indexes(): # no selection return node = self.get_current_node() if node: self.refs_ui.show_refs(node)''' def show_refs_dialog(self): self.references_window = ReferencesWindow(self) self.references_window.show() def show_subs_dialog(self): self.subscription_window.show() def show_logs_dialog(self): self.log_window.show() def get_current_node(self, idx=None): return self.tree_ui.get_current_node(idx) def read_value(self): node = self.get_current_node() try: self.attrs_ui.show_attrs(node) if node.get_node_class() == ua.NodeClass.Variable: value = node.get_value() data = "Node: %s, Value: %s" % (node.get_browse_name(), value) self.log_window.ui.logTextEdit.append(data) except Exception as ex: self.log_window.ui.logTextEdit.append(str(ex))
class MainWindow(GuiWindow): '''Class for main window''' def __init__(self, *args): self.logPanel = LogWindow() GuiWindow.__init__(self, lowerItem=self.logPanel) self.clearWebCache() self.postmen = None self.toolbar = self.makeToolbar([ ("images/toolbar-home.png", self.onHomeClicked, "mainwindow.toolbar.home"), ("images/toolbar-people.png", self.onContactsClicked, "mainwindow.toolbar.contacts"), ("images/toolbar-messages.png", self.onMessagesClicked, "mainwindow.toolbar.messages"), ("images/toolbar-messages-highlight.png", self.onMessagesClicked, "mainwindow.toolbar.messages"), ("images/toolbar-calendar.png", self.onCalendarClicked, "mainwindow.toolbar.calendar"), ("images/toolbar-settings.png", self.onSettingsClicked, "mainwindow.toolbar.settings") ]) self.addToolBar(self.toolbar) self.setContextMenuPolicy(QtCore.Qt.NoContextMenu) # status bar self.statusbar = QtWidgets.QStatusBar(self) self.statusbar.setObjectName("statusbar") self.setStatusBar(self.statusbar) self.setWindowTitle(I18nManager.getText("mainwindow.title")) self.setStatusTip("Murmeli") self.setPageServer(PageServer()) self.navigateTo("/") # we want to be notified of Config changes Config.registerSubscriber(self) self.postmen = [ postmen.IncomingPostman(self), postmen.OutgoingPostman(self) ] self.postmen[1].messageSentSignal.connect(self.logPanel.notifyLogEvent) MessageShuffler.getTannoy().updateSignal.connect( self.logPanel.notifyLogEvent) # Make sure Tor client is started if not TorClient.isStarted(): TorClient.startTor() # Create database instance if not already set if not DbI.hasDbSet(): DbI.setDb(MurmeliDb(Config.getSsDatabaseFile())) # Make sure the status of the contacts matches our keyring missingKeyNames = ContactMaker.checkAllContactsKeys() if missingKeyNames: warningTexts = [I18nManager.getText("warning.keysnotfoundfor") ] + missingKeyNames QtWidgets.QMessageBox.warning(self, "Murmeli", "\n ".join(warningTexts)) def makeToolbar(self, deflist): '''Given a list of (image, method, tooltip), make a QToolBar with those actions''' toolbar = QtWidgets.QToolBar(self) toolbar.setFloatable(False) toolbar.setMovable(False) toolbar.setIconSize(QtCore.QSize(48, 48)) self.toolbarActions = [] for actdef in deflist: action = toolbar.addAction(QtGui.QIcon(actdef[0]), "_", actdef[1]) action.tooltipkey = actdef[2] self.toolbarActions.append(action) self.configUpdated() # to set the tooltips return toolbar def modifyToolbar(self, highlightMessages): '''Either highlight (if flag True) or not-highlight the new messages toolbar icon''' self.toolbar.actions()[2].setVisible(not highlightMessages) self.toolbar.actions()[3].setVisible(highlightMessages) def onHomeClicked(self): self.navigateTo("/") def onContactsClicked(self): self.navigateTo("/contacts/") def onMessagesClicked(self): self.navigateTo("/messages/") def onCalendarClicked(self): self.navigateTo("/calendar/") def onSettingsClicked(self): self.navigateTo("/settings/") def configUpdated(self): '''React to a change in settings by changing tooltips and log panel visibility''' for a in self.toolbarActions: a.setToolTip(I18nManager.getText(a.tooltipkey)) # Show/hide log window if Config.getProperty(Config.KEY_SHOW_LOG_WINDOW): self.logPanel.show() else: self.logPanel.hide() def postmanKnock(self): # Maybe we don't care about the outgoing postman knocking actually... highlightInbox = self.postmen[0].isSomethingInInbox( ) if self.postmen else False print("Calling modify with value", ("yes" if highlightInbox else "no")) self.modifyToolbar(highlightInbox) def clearWebCache(self): '''Delete all the files in the web cache''' cacheDir = Config.getWebCacheDir() shutil.rmtree(cacheDir, ignore_errors=True) os.makedirs(cacheDir) def closeEvent(self, event): '''Clean up before closing by stopping all services''' print("Closing Murmeli") # Tell postmen to stop working for p in self.postmen: p.stop() DbI.releaseDb() TorClient.stopTor() self.clearWebCache() event.accept()
from printHat import PrintHat from pyqtpicam import PiVideoStream from sysTemp import SystemTemperatures from imageProcessor import ImageProcessor from batchProcessor import BatchProcessor from autoFocus import AutoFocus from checkWiFi import CheckWiFi if __name__ == "__main__": settings = QSettings("settings.ini", QSettings.IniFormat) # Create event loop and instantiate objects app = QApplication(sys.argv) mw = MainWindow() lw = LogWindow() vs = PiVideoStream() ph = PrintHat( ) # Connect to printhat virtual port (this links the klipper software as well) st = SystemTemperatures(interval=10, alarm_temperature=55) ip = ImageProcessor() bp = BatchProcessor() af = AutoFocus(display=True) cf = CheckWiFi() # Connect logging signals bp.setLogFileName.connect(lw.setLogFileName) vs.postMessage.connect(lw.append) ph.signals.message.connect(lw.append) ph.signals.error.connect(lambda s: "error;{}".format(lw.append(s[2]))) st.signals.message.connect(lw.append)