def showDocInAssistant(self, name): url = self.resolveDocUrl(name) Colors.debug("Sending URL to Assistant:", url) # Start assistant if it's not already running. if self.assistantProcess.state() != QProcess.Running: app = QLibraryInfo.location( QLibraryInfo.BinariesPath) + QDir.separator() if sys.platform == 'darwin': app += 'Assistant.app/Contents/MacOS/Assistant' else: app += 'assistant' args = ['-enableRemoteControl'] self.assistantProcess.start(app, args) if not self.assistantProcess.waitForStarted(): QMessageBox.critical(None, "PyQt Demo", "Could not start %s." % app) return # Send command through remote control even if the process was just # started to activate assistant and bring it to the front. cmd_str = QTextStream(self.assistantProcess) cmd_str << 'SetSource ' << url << '\n'
def getResource(self, name): ba = self.helpEngine.fileData(QtCore.QUrl(name)) if ba.isEmpty(): Colors.debug(" - WARNING: Could not get", name) return ba
def loadDescription(self, startPara, nrPara): readme = QFile(self.readmePath) if not readme.open(QFile.ReadOnly): Colors.debug("- MenuContentItem.loadDescription: Could not load:", self.readmePath) return "" in_str = QTextStream(readme) # Skip a certain number of paragraphs. while startPara: if not in_str.readLine(): startPara -= 1 # Read in the number of wanted paragraphs. result = '' line = in_str.readLine() while True: result += line + " " line = in_str.readLine() if not line: nrPara -= 1 line = "<br><br>" + in_str.readLine() if nrPara == 0 or in_str.atEnd(): break return Colors.contentColor + result
def loadDescription(self, startPara, nrPara): readme = QFile(self.readmePath) if not readme.open(QFile.ReadOnly): Colors.debug("- MenuContentItem.loadDescription: Could not load:", self.readmePath) return "" in_str = QTextStream(readme) # Skip a certain number of paragraphs. while startPara: if not in_str.readLine(): startPara -= 1 # Read in the number of wanted paragraphs. result = "" line = in_str.readLine() while True: result += line + " " line = in_str.readLine() if not line: nrPara -= 1 line = "<br><br>" + in_str.readLine() if nrPara == 0 or in_str.atEnd(): break return Colors.contentColor + result
def __init__(self, editor, workdir, params, inputs, mode): #print "create MyQProcess........\n" #self.myprocess=MyQProcess(workdir, params) Colors.debug("WorkDir:", workdir) print "\ncreate MyThread......... \n" self.mode=mode self.thread=MyThread(workdir, params, editor, inputs, mode) print "\ncreate MyThread end ....\n"
def __init__(self, workdir, params): QtCore.QProcess.__init__(self) Colors.debug("WorkDir:", workdir) #print "1:"+ #self.startDetached(QtCore.QDir(workdir)) self.setWorkingDirectory(QtCore.QDir(workdir)) #.absolutePath() for param in params: self.addArgument(param)
def init(self, window): self.window = window # Create div. self.createTicker() self.createUpnDownButtons() self.createBackButton() # Create first level menu. rootElement = self.contentsDoc.documentElement() self.createRootMenu(rootElement) # Create second level menus. level2MenuNode = rootElement.firstChild() while not level2MenuNode.isNull(): level2MenuElement = level2MenuNode.toElement() self.createSubMenu(level2MenuElement) # Create leaf menu and example info. exampleNode = level2MenuElement.firstChild() while not exampleNode.isNull(): exampleElement = exampleNode.toElement() self.readInfoAboutExample(exampleElement) self.createLeafMenu(exampleElement) exampleNode = exampleNode.nextSibling() level2MenuNode = level2MenuNode.nextSibling() # Support QML if possible. try: from PyQt4 import QtDeclarative except ImportError: return self.declarativeEngine = QtDeclarative.QDeclarativeEngine(self) component = QtDeclarative.QDeclarativeComponent( self.declarativeEngine, QtCore.QUrl('qrc:/qml/qmlShell.qml'), self) if component.isReady(): self.qmlRoot = component.create() if self.qmlRoot is not None: self.qmlRoot.setHeight(window.scene.sceneRect().height()) self.qmlRoot.setWidth(window.scene.sceneRect().width()) self.qmlRoot.setZValue(101) self.qmlRoot.setCursor(QtCore.Qt.ArrowCursor) window.scene.addItem(self.qmlRoot) window.viewport().setFocusPolicy(QtCore.Qt.NoFocus) window.setFocusPolicy(QtCore.Qt.StrongFocus) window.scene.setStickyFocus(True) window.setFocus() else: Colors.debug( "Error initializing QML subsystem, Declarative examples will not work" )
def queueMovie(self, indexName, runMode=FROM_START, lockMode=SKIP_LOCK): try: movie = self.index[indexName] except KeyError: Colors.debug("Queuing movie:", indexName, "(does not exist)") return self.prepare(movie, runMode, lockMode) self.playList.append(PlayListMember(movie, runMode)) Colors.debug("Queuing movie:", indexName)
def init(self, window): self.window = window # Create div. self.createTicker() self.createUpnDownButtons() self.createBackButton() # Create first level menu. rootElement = self.contentsDoc.documentElement() self.createRootMenu(rootElement) # Create second level menus. level2MenuNode = rootElement.firstChild() while not level2MenuNode.isNull(): level2MenuElement = level2MenuNode.toElement() self.createSubMenu(level2MenuElement) # Create leaf menu and example info. exampleNode = level2MenuElement.firstChild() while not exampleNode.isNull(): exampleElement = exampleNode.toElement() self.readInfoAboutExample(exampleElement) self.createLeafMenu(exampleElement) exampleNode = exampleNode.nextSibling() level2MenuNode = level2MenuNode.nextSibling() # Support QML if possible. try: from PyQt4 import QtDeclarative except ImportError: return self.declarativeEngine = QtDeclarative.QDeclarativeEngine(self) self.declarativeEngine.quit.connect(self.quitQML) component = QtDeclarative.QDeclarativeComponent(self.declarativeEngine, QtCore.QUrl('qrc:/qml/qmlShell.qml'), self) if component.isReady(): self.qmlRoot = component.create() if self.qmlRoot is not None: self.qmlRoot.setHeight(window.scene.sceneRect().height()) self.qmlRoot.setWidth(window.scene.sceneRect().width()) self.qmlRoot.setZValue(101) self.qmlRoot.setCursor(QtCore.Qt.ArrowCursor) window.scene.addItem(self.qmlRoot) window.viewport().setFocusPolicy(QtCore.Qt.NoFocus) window.setFocusPolicy(QtCore.Qt.StrongFocus) window.scene.setStickyFocus(True) window.setFocus() else: Colors.debug("Error initializing QML subsystem, Declarative examples will not work")
def resolveQmlFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]['filename'].split('/')[-1] qmlFile = QFile(dir.path() + '/' + fileName + '.qml') if qmlFile.exists(): return qmlFile.fileName() Colors.debug("- WARNING: Could not resolve QML file:", dir.path(), fileName) return '__QML not found__'
def readInfoAboutExample(self, example): name = example.getAttribute('name') if name in self.info: Colors.debug("__WARNING: MenuManager.readInfoAboutExample: " "Demo/example with name", name, "appears twice in " "the xml-file!__") self.info.setdefault(name, {})['filename'] = example.getAttribute('filename') self.info[name]['dirname'] = example.parentNode.getAttribute('dirname') self.info[name]['changedirectory'] = example.getAttribute('changedirectory') self.info[name]['image'] = example.getAttribute('image') self.info[name]['qml'] = example.getAttribute('qml')
def readInfoAboutExample(self, example): name = str(example.attribute('name')) if name in self.info: Colors.debug("__WARNING: MenuManager.readInfoAboutExample: " "Demo/example with name", name, "appears twice in " "the xml-file!__") self.info.setdefault(name, {})['filename'] = str(example.attribute('filename')) self.info[name]['category'] = str(example.parentNode().toElement().tagName()) self.info[name]['dirname'] = str(example.parentNode().toElement().attribute('dirname')) self.info[name]['changedirectory'] = str(example.attribute('changedirectory')) self.info[name]['image'] = str(example.attribute('image'))
def resolveQmlFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]["filename"].split("/")[-1] qmlFile = QFile(dir.path() + "/" + fileName + ".qml") if qmlFile.exists(): return qmlFile.fileName() Colors.debug("- WARNING: Could not resolve QML file:", dir.path(), fileName) return "__QML not found__"
def launchQml(self, name): import_path = self.resolveDataDir(name) qml = self.resolveQmlFile(name) process = QProcess(self) process.error.connect(self.launchError) env = QProcessEnvironment.systemEnvironment() env.insert('QML2_IMPORT_PATH', import_path) process.setProcessEnvironment(env) executable = QLibraryInfo.location(QLibraryInfo.BinariesPath) + '/qmlscene' Colors.debug("Launching:", executable) process.start(executable, [qml])
def resolveExeFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]["filename"].split("/")[-1] pyFile = QFile(dir.path() + "/" + fileName + ".py") if pyFile.exists(): return pyFile.fileName() pywFile = QFile(dir.path() + "/" + fileName + ".pyw") if pywFile.exists(): return pywFile.fileName() Colors.debug("- WARNING: Could not resolve executable:", dir.path(), fileName) return "__executable not found__"
def resolveExeFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]['filename'].split('/')[-1] pyFile = QtCore.QFile(dir.path() + '/' + fileName + '.py') if pyFile.exists(): return pyFile.fileName() pywFile = QtCore.QFile(dir.path() + '/' + fileName + '.pyw') if pywFile.exists(): return pywFile.fileName() Colors.debug("- WARNING: Could not resolve executable:", dir.path(), fileName) return '__executable not found__'
def resolveExeFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]['filename'].split('/')[-1] pyFile = QFile(dir.path() + '/' + fileName + '.py') if pyFile.exists(): return pyFile.fileName() pywFile = QFile(dir.path() + '/' + fileName + '.pyw') if pywFile.exists(): return pywFile.fileName() Colors.debug("- WARNING: Could not resolve executable:", dir.path(), fileName) return '__executable not found__'
def loadDescription(self): ba = self._menu_manager.getHtml(self.name) exampleDoc = QtXml.QDomDocument() exampleDoc.setContent(ba, False) paragraphs = exampleDoc.elementsByTagName('p') if paragraphs.length() < 1: Colors.debug("- ExampleContent.loadDescription(): Could not load description:", self._menu_manager.info[self.name].get('docfile')) description = Colors.contentColor + "Could not load description. Ensure that the documentation for Qt is built." for p in range(paragraphs.length()): description = self.extractTextFromParagraph(paragraphs.item(p)) if self.isSummary(description): break return Colors.contentColor + description
def readInfoAboutExample(self, example): name = example.getAttribute("name") if name in self.info: Colors.debug( "__WARNING: MenuManager.readInfoAboutExample: " "Demo/example with name", name, "appears twice in " "the xml-file!__", ) self.info.setdefault(name, {})["filename"] = example.getAttribute("filename") self.info[name]["dirname"] = example.parentNode.getAttribute("dirname") self.info[name]["changedirectory"] = example.getAttribute( "changedirectory") self.info[name]["image"] = example.getAttribute("image") self.info[name]["qml"] = example.getAttribute("qml")
def setRenderingSystem(self): if Colors.openGlRendering: from PyQt4 import QtOpenGL viewport = QtOpenGL.QGLWidget(QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) if Colors.noScreenSync: viewport.format().setSwapInterval(0) viewport.setAutoFillBackground(False) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using OpenGL") else: viewport = QtGui.QWidget() self.setCacheMode(QtGui.QGraphicsView.CacheBackground) Colors.debug("- using software rendering") self.setViewport(viewport)
def loadDescription(self): contents = self._menu_manager.getHtml(self.name).data().decode('utf8') if contents == '': paragraphs = [] else: exampleDoc = parseString(contents) paragraphs = exampleDoc.getElementsByTagName('p') if len(paragraphs) < 1: Colors.debug("- ExampleContent.loadDescription(): Could not load description:", self._menu_manager.info[self.name].get('docfile')) description = Colors.contentColor + "Could not load description. Ensure that the documentation for Qt is built." for p in paragraphs: description = self.extractTextFromParagraph(p) if self.isSummary(description): break return Colors.contentColor + description
def setRenderingSystem(self): if Colors.openGlRendering: from PyQt4 import QtOpenGL viewport = QtOpenGL.QGLWidget( QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) if Colors.noScreenSync: viewport.format().setSwapInterval(0) viewport.setAutoFillBackground(False) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using OpenGL") else: viewport = QtGui.QWidget() self.setCacheMode(QtGui.QGraphicsView.CacheBackground) Colors.debug("- using software rendering") self.setViewport(viewport)
def loadDescription(self): contents = self._menu_manager.getHtml(self.name).data().decode('utf8') if contents == '': paragraphs = [] else: exampleDoc = parseString(contents) paragraphs = exampleDoc.getElementsByTagName('p') if len(paragraphs) < 1: Colors.debug( "- ExampleContent.loadDescription(): Could not load description:", self._menu_manager.info[self.name].get('docfile')) description = Colors.contentColor + "Could not load description. Ensure that the documentation for Qt is built." for p in paragraphs: description = self.extractTextFromParagraph(p) if self.isSummary(description): break return Colors.contentColor + description
def launchExample(self, name): executable = self.resolveExeFile(name) process = QtCore.QProcess(self) process.finished.connect(self.exampleFinished) process.error.connect(self.exampleError) if sys.platform == 'win32': # Make sure it finds the DLLs on Windows. curpath = os.getenv('PATH') newpath = 'PATH=%s;%s' % (QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.BinariesPath), curpath) process.setEnvironment([newpath]) if self.info[name]['changedirectory'] != 'false': workingDirectory = self.resolveDataDir(name) process.setWorkingDirectory(workingDirectory) Colors.debug("Setting working directory:", workingDirectory) Colors.debug("Launching:", executable) process.start(sys.executable, [executable])
def launchExample(self, name): executable = self.resolveExeFile(name) process = QProcess(self) process.error.connect(self.launchError) if sys.platform == 'win32': # Make sure it finds the DLLs on Windows. env = QProcessEnvironment.systemEnvironment() env.insert('PATH', QLibraryInfo.location(QLibraryInfo.BinariesPath) + ';' + env.value('PATH')) process.setProcessEnvironment(env) if self.info[name]['changedirectory'] != 'false': workingDirectory = self.resolveDataDir(name) process.setWorkingDirectory(workingDirectory) Colors.debug("Setting working directory:", workingDirectory) Colors.debug("Launching:", executable) process.start(sys.executable, [executable])
def checkAdapt(self): if self.doneAdapt or Colors.noTimerUpdate or self.demoStartTime.elapsed() < 2000: return self.doneAdapt = True self.forceFpsMedianCalculation() Colors.benchmarkFps = self.fpsMedian Colors.debug("- benchmark: %d FPS" % int(Colors.benchmarkFps)) if Colors.noAdapt: return if self.fpsMedian < 30: ticker = MenuManager.instance().ticker if ticker and ticker.scene(): self.scene.removeItem(ticker) Colors.noTimerUpdate = True self.switchTimerOnOff(False) if self.fpsLabel: self.fpsLabel.setText("FPS: (%d)" % int(self.fpsMedian)) Colors.debug("- benchmark adaption: removed ticker (fps < 30)") if self.fpsMedian < 20: Colors.noAnimations = True Colors.debug("- benchmark adaption: animations switched off (fps < 20)") Colors.adapted = True
def checkAdapt(self): if self.doneAdapt or Colors.noTimerUpdate or self.demoStartTime.elapsed( ) < 2000: return self.doneAdapt = True self.forceFpsMedianCalculation() Colors.benchmarkFps = self.fpsMedian Colors.debug("- benchmark: %d FPS" % int(Colors.benchmarkFps)) if Colors.noAdapt: return if self.fpsMedian < 30: ticker = MenuManager.instance().ticker if ticker and ticker.scene(): self.scene.removeItem(ticker) Colors.noTimerUpdate = True self.switchTimerOnOff(False) if self.fpsLabel: self.fpsLabel.setText("FPS: (%d)" % int(self.fpsMedian)) Colors.debug("- benchmark adaption: removed ticker (fps < 30)") if self.fpsMedian < 20: Colors.noAnimations = True Colors.debug( "- benchmark adaption: animations switched off (fps < 20)") Colors.adapted = True
def showDocInAssistant(self, name): url = self.resolveDocUrl(name) Colors.debug("Sending URL to Assistant:", url) # Start assistant if it's not already running. if self.assistantProcess.state() != QtCore.QProcess.Running: app = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.BinariesPath) + QtCore.QDir.separator() if sys.platform == 'darwin': app += 'Assistant.app/Contents/MacOS/Assistant' else: app += 'assistant' args = ['-enableRemoteControl'] self.assistantProcess.start(app, args) if not self.assistantProcess.waitForStarted(): QtGui.QMessageBox.critical(None, "PyQt Demo", "Could not start %s." % app) return # Send command through remote control even if the process was just # started to activate assistant and bring it to the front. cmd_str = QtCore.QTextStream(self.assistantProcess) cmd_str << 'SetSource ' << url << '\n'
def setRenderingSystem(self): if Colors.direct3dRendering: viewport.setAttribute(QtCore.Qt.WA_MSWindowsUseDirect3D) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using Direct3D") elif Colors.openGlRendering: from PySide2 import QtOpenGL viewport = QtOpenGL.QGLWidget(QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) if Colors.noScreenSync: viewport.format().setSwapInterval(0) viewport.setAutoFillBackground(False) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using OpenGL") else: viewport = QtGui.QWidget() self.setCacheMode(QtGui.QGraphicsView.CacheBackground) Colors.debug("- using software rendering") self.setViewport(viewport)
def setRenderingSystem(self): if Colors.direct3dRendering: viewport.setAttribute(QtCore.Qt.WA_MSWindowsUseDirect3D) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using Direct3D") elif Colors.openGlRendering: from PySide2 import QtOpenGL viewport = QtOpenGL.QGLWidget( QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) if Colors.noScreenSync: viewport.format().setSwapInterval(0) viewport.setAutoFillBackground(False) self.setCacheMode(QtGui.QGraphicsView.CacheNone) Colors.debug("- using OpenGL") else: viewport = QtGui.QWidget() self.setCacheMode(QtGui.QGraphicsView.CacheBackground) Colors.debug("- using software rendering") self.setViewport(viewport)
def playQue(self): for movie, runMode in self._playlist: self._play(movie, runMode) self._playlist = [] Colors.debug("********* Playing que *********")
def start(self): self.switchTimerOnOff(True) self.demoStartTime.restart() MenuManager.instance().itemSelected(MenuManager.ROOT, Colors.rootMenuName) Colors.debug("- starting demo")
def playQue(self): for member in self.playList: self.play(member.movie, member.runMode) self.playList = [] Colors.debug("********* Playing que *********")