def _getPixelRatio(): if PyQtImpl in ["PyQt5", "PySide2", "PySide6"]: # Source: https://stackoverflow.com/a/40053864/3388962 pos = QCursor.pos() for screen in QApplication.screens(): rect = screen.geometry() if rect.contains(pos): return screen.devicePixelRatio() # Should never happen, but try to find a good fallback. return QApplication.instance().devicePixelRatio() else: # Qt4 seems not to provide any cross-platform means to get the # pixel ratio. return 1.
def toggle(self): if self.tabs.currentWidget().objectName() == 'udp': self.udpFrame.toggle() elif self.tabs.currentWidget().objectName() == 'webSocket': self.webFrame.toggle() def eventFilter(self, obj, event): if event.type() == QtCore.QEvent.KeyPress: if event.key() == QtCore.Qt.Key_R: self.loop.create_task(self.messenger.connectSocket()) return super(MainWindow, self).eventFilter(obj, event) def exitHandler(self): self.webFrame.messenger.terminate() if __name__ == '__main__': import logging app = QApplication() app.setQuitOnLastWindowClosed(True) window = MainWindow() app.aboutToQuit.connect(window.exitHandler) if SECOND_DISPLAY: display = app.screens()[1] window.setScreen(display) window.move(display.geometry().x() + 200, display.geometry().y() + 200) window.show() sys.exit(app.exec_())
def run(): initialization_result = initialize() conf = config() window_config = conf['window'] WIDTH = window_config['width'] HEIGHT = window_config['height'] app = QApplication(sys.argv) app.setStyleSheet(style) geometry = app.screens()[0].size() clipboard = app.clipboard() widget = MainWidget(clipboard) widget.setWindowOpacity(window_config['opacity']) widget.resize(WIDTH, HEIGHT) widget.move(0, geometry.height() - HEIGHT - 280) widget.setWindowTitle('Albion Online Stats') widget.setWindowIcon(QtGui.QIcon(path('albion-stats-icon.png'))) if window_config['always_on_top']: widget.setWindowFlag(Qt.WindowStaysOnTopHint) if window_config['frameless']: widget.setWindowFlag(Qt.FramelessWindowHint) widget.show() current_version, latest_version = (get_current_version(), get_latest_version()) if latest_version and current_version != latest_version: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle("Update available!") msg.setText("Another version of app is avaliable.") msg.setInformativeText( "You are using app in version {}, latest version is {}".format( current_version, latest_version)) msg.setStandardButtons(QMessageBox.Ok) msg.show() if initialization_result == InitializationResult.NetworkInterfaceListMissing: msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setWindowTitle("Unable to track network traffic data!") msg.setText( "On windows make sure that WinPcap is installed in your system.") msg.setInformativeText( "WinPcap can be installed from <a href='{}'>here</a> <br>\ <b>Make sure to install with the \"Install Npcap in WinPcap API-compatible Mode\"<b> option<br><br>\ In case where npcap is installed try to fix npcap and restart the app" .format('https://nmap.org/npcap/dist/npcap-0.9990.exe')) msg.setStandardButtons(QMessageBox.Ok) button = QPushButton("Fix npcap") button.clicked.connect(fix_npcap) msg.addButton(button, QMessageBox.NoRole) msg.show() sys.exit(app.exec_())