def init(create_app=True): global APP if QApplication.instance() is None and create_app: APP = QApplication([]) QtWebEngine.initialize()
def galacteekGui(args): progName = args.binaryname if args.binaryname else sys.argv[0] gc.enable() if inPyInstaller(): folder = pyInstallerBundleFolder() binPath = folder.joinpath('bin') os.environ['PATH'] = str(binPath) + os.pathsep + os.environ['PATH'] os.chdir(str(folder)) if args.mallocdebug: tracemalloc.start() if args.debug: faulthandler.enable() # QtWebEngine init QtWebEngine.initialize() # Initialize webengine schemes before creating the application initializeSchemes() gApp = application.GalacteekApplication( profile=args.profile, debug=args.debug, enableOrbital=args.enableorbital, sslverify=False if args.nosslverify else True, progName=progName, cmdArgs=args) level = 'DEBUG' if args.debug else 'INFO' if args.logstderr: glogger.basicConfig(level=level, colorized=args.logcolorized, loop=gApp.loop) else: glogger.basicConfig(outputFile=gApp.mainLogFileLocation, level=level, colorized=args.logcolorized, loop=gApp.loop) if not gApp.acquireLock(): gApp.onExit() return gApp.configure() # Monitor event loop if aiomonitor is available # Use the context manager so loop cleanup/close is automatic loop = gApp.loop if args.monitor is True and haveAiomonitor: with aiomonitor.start_monitor(loop=loop): with loop: loop.run_forever() else: with loop: loop.run_forever()
def __init__(self, path, title): QDialog.__init__(self) #self.setModal(False) offset = 100#px windowsSize = [GetSystemMetrics(0)-offset, GetSystemMetrics(1)-offset] self.setWindowTitle(title) self.setWindowFlags(Qt.Window)# | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHint) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setMargin(0) self.webView = QtWebEngine.QWebEngineView(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.webView.sizePolicy().hasHeightForWidth()) self.webView.setSizePolicy(sizePolicy) self.horizontalLayout.addWidget(self.webView) self.webView.settings().setAttribute(QtWebEngine.QWebEngineSettings.PluginsEnabled, True) self.webView.show() self.webView.load(QUrl(path)) # Change path to actual file. QApplication.restoreOverrideCursor() self.exec_()
def setText(self, text): QApplication.clipboard().setText(text) class NetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory): def create(self, parent): nam = QNetworkAccessManager(parent) cache = QNetworkDiskCache(parent) cache_dir = QStandardPaths.writableLocation(QStandardPaths.CacheLocation) cache_subdir = os.path.join(cache_dir, "network") print("Cache dir:", cache_subdir) cache.setCacheDirectory(cache_subdir) nam.setCache(cache) return nam if __name__ == "__main__": app = QApplication(sys.argv) qmlRegisterType(EventSource, "ExpipeBrowser", 1, 0, "EventSource") qmlRegisterType(Clipboard, "ExpipeBrowser", 1, 0, "Clipboard") QApplication.setOrganizationName("Cinpla") QApplication.setApplicationName("Expipe Browser") QtWebEngine.initialize() engine = QQmlApplicationEngine() engine.setNetworkAccessManagerFactory(NetworkAccessManagerFactory()) engine.load(QUrl("main.qml")) app.exec_() for stream in streams: print(stream) stream.close()