def setupEngine(self): ipfsCtx = self.app.ipfsCtx filesModel = ipfsCtx.currentProfile.filesModel # stores = services.getByDotName('ld.rdf.graphs') self.engine = QQmlEngine(self) ctx = self.engine.rootContext() # XML graph exports paths # ctx.setContextProperty('graphGXmlPath', # stores.graphG.xmlExportUrl) ctx.setContextProperty('g', self.gInterface) ctx.setContextProperty('ld', self.ldInterface) ctx.setContextProperty('sparql', self.sparqlInterface) ctx.setContextProperty('iContainer', self.iInterface) ctx.setContextProperty('ipid', self.ipidInterface) # Pass the web profile ctx.setContextProperty('ipfsWebProfile', self.webProfile) ctx.setContextProperty('modelArticles', self.models['Articles']) ctx.setContextProperty('modelMultiChannels', self.models['Channels']) ctx.setContextProperty('modelShouts', self.models['Shouts']) ctx.setContextProperty('modelMfs', filesModel)
def reloadProject(self, filename): engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl(filename)) self.site = component.create() if self.site is not None: self.site.setFilename(filename) self.site.setWindow(self) else: for error in component.errors(): print(error.toString()) return False self.site.loadMenus() self.site.loadPages() self.site.loadPosts() self.theme_settings_button.setVisible(False) Plugins.setActualThemeEditorPlugin("") for key in Plugins.themePluginNames(): tei = Plugins.getThemePlugin(key) if tei: if tei.theme_name == self.site.theme: Plugins.setActualThemeEditorPlugin(tei.class_name) self.theme_settings_button.setVisible(True) break #if not self.site.publisher: # if len(Plugins.publishPluginNames()) > 0: # self.site.publisher = Plugins.publishPluginNames[0] Plugins.setActualPublishPlugin(self.site.publisher) self.siteLoaded.emit(self.site) return True
def __init__(self, title, frame_rate, run_time): """ Create a new Animation. Arguments: title: str, the window title frame_rate: float, the number of frames to display per second run_time: float, the number of seconds to run the animation """ self.title = title assert 0 < frame_rate < 1000 self.frame_rate = frame_rate assert run_time > 0 self.run_time = run_time self.frame = 0 self.prev_update_time = None # import OpenGL so Qt can use it for rendering from OpenGL import GL # create the 3D window self.view = Qt3DWindow() self.view.setX(100) self.view.setY(100) self.view.setTitle(self.title) self.qml_engine = QQmlEngine(self.view)
def init_country_names_from_code(locale): '''Init the country description as found in GCompris geography/resource/board/board*.qml''' '''in the global descriptions hash''' po = None try: po = polib.pofile(gcompris_qt + '/po/gcompris_' + locale + '.po') except: print("**ERROR: Failed to load po file %s**" % ('/po/gcompris_' + locale + '.po')) print('') app = QCoreApplication(sys.argv) engine = QQmlEngine() component = QQmlComponent(engine) for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'): component.loadUrl(QUrl(qml)) board = component.create() levels = board.property('levels') for level in levels.toVariant(): if 'soundFile' in level and 'toolTipText' in level: sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg') tooltip = level['toolTipText'] if po: tooltip = po.find(tooltip).msgstr if po.find( tooltip) else tooltip descriptions[sound] = tooltip
def loadBook(self, filename): self.last_book = filename self.filename = "" engine = QQmlEngine() self.component = QQmlComponent(engine) self.component.statusChanged.connect(self.loadStatusChanged) self.component.loadUrl(QUrl.fromLocalFile(filename))
def loadMenus(self): engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl(os.path.join(self.source_path, "Menus.qml"))) self.menus = component.create() if self.menus is not None: self.win.statusBar().showMessage("Menus have been loaded") else: for error in component.errors(): print(error.toString()) del engine
def loadProject(self, filename): self.last_project = filename self.filename = "" engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl(filename)) self.project = component.create() if self.project is not None: self.project.setFilename(filename) self.project.setWindow(self) else: for error in component.errors(): print(error.toString()) return
def _initialise_qml_engine(self): self._qml_engine = QQmlEngine(self) qml_path = str(ConfigInstall.Path.qml_path) self._qml_engine.addImportPath(qml_path) context = self.qml_context self._application_style = ApplicationStyle() context.setContextProperty('application_style', self._application_style) self._icon_provider = IconProvider() self._qml_engine.addImageProvider('icon_provider', self._icon_provider)
def __init__(self) : QObject.__init__( self ) self.app = QApplication( sys.argv ) self.app.setApplicationName( 'Waterfall' ) engine = QQmlEngine() appDirPath = os.path.dirname( os.path.abspath( __file__ ) ) rootContext = engine.rootContext() rootContext.setContextProperty( 'controller', self ) rootContext.setContextProperty( 'appPath', appDirPath.replace( "\\", "/" ) + "/" ) windowComp = QQmlComponent( engine, QUrl( 'qml/Main.qml' ) ) self.window = windowComp.create() self.window.show() self.app.exec()
def main(argv, app): engine = QQmlEngine(app) engine.quit.connect(app.quit) component = QQmlComponent(engine) component.loadUrl(QUrl('Wizard/Wizard.qml')) if component.isReady(): mainWindow = component.create() file = FileInfo() context = engine.rootContext() context.setContextProperty('FileInfo', file) else: print(component.errorString()) sys.exit(app.exec_())
def loadContent(self, source, type): if type == ContentType.PAGE: sub = "pages" else: sub = "posts" engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl(os.path.join(self.source_path, sub, source))) content = component.create() if content is not None: content.source = source content.content_type = type else: for error in component.errors(): print(error.toString()) return content
def get_geography_on_letter_from_code(): '''Return all the countries in geography/resource/board/board-x.json''' words = set() app = QCoreApplication(sys.argv) engine = QQmlEngine() component = QQmlComponent(engine) for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'): component.loadUrl(QUrl(qml)) board = component.create() levels = board.property('levels') for level in levels.toVariant(): if 'soundFile' in level and (not 'type' in level or level['type'] != "SHAPE_BACKGROUND"): sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg') words.add(sound) return words
def loadMenus(self): engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl.fromLocalFile(os.path.join(self.source_path, "Menus.qml"))) self.menus = component.create() if self.menus is not None: self.win.statusBar().showMessage(QCoreApplication.translate("Site", "Menus have been loaded")) else: for error in component.errors(): print(error.toString()) del engine # we have to loop through the menu items to set the parent for subitems for i in range(0, len(self.menus._menus)): menu = self.menus._menus[i] for j in range(0, len(menu._items)): item = menu._items[j] for k in range(len(item._items)): subItem = item._items[k] subItem.setParentItem(item)
def main(arguments): 'Main logic' app = QCoreApplication([__file__] + arguments) # Register the Python type. Its URI is 'People', it's v1.0, and the type # will be called 'Person' in QML. qmlRegisterType(Person, 'People', 1, 0, 'Person') # Now we can load Person.qml, since it uses our registered python class engine = QQmlEngine() component = QQmlComponent(engine) component.loadUrl(QUrl('Person.qml')) person = component.create() if person is not None: print("The person's name is {0}.".format(person.name)) print('They wear a size {0} shoe.'.format(person.shoe_size)) else: for error in component.errors(): print(error.toString())
app = QCoreApplication(sys.argv) qmlRegisterType(BirthdayPartyAttached) qmlRegisterType(BirthdayParty, "People", 1, 0, "BirthdayParty", attachedProperties=BirthdayPartyAttached) qmlRegisterType(ShoeDescription) qmlRegisterType(Person) qmlRegisterType(Boy, "People", 1, 0, "Boy") qmlRegisterType(Girl, "People", 1, 0, "Girl") engine = QQmlEngine() component = QQmlComponent(engine) component.setData(QML, QUrl()) party = component.create() if party is not None and party.host is not None: print("\"%s\" is having a birthday!" % party.host.name) if isinstance(party.host, Boy): print("He is inviting:") else: print("She is inviting:") for guest in party.guests:
def __init__(self): self.engine = QQmlEngine()
def ros_qml_main(): try: rospy.init_node('ros_qml', sys.argv) my_argv = rospy.myargv(sys.argv) signal.signal(signal.SIGINT, sigint_handler) app = QApplication(my_argv) engine = QQmlEngine() engine.quit.connect(app.quit) plugins_dir = QLibraryInfo.location(QLibraryInfo.PluginsPath) # ## Add QML extension modules and plugins to the path, including ourselves plugins_paths = rospack.get_manifest(THIS_PACKAGE).get_export( THIS_PACKAGE, 'plugins') for idx, p in enumerate(plugins_paths): # If a relative path provided, treat it as relative to Qt plugins dir if not os.path.isabs(p): plugins_paths[idx] = plugins_dir + '/' + p qml_paths = rospack.get_manifest(THIS_PACKAGE).get_export( THIS_PACKAGE, 'imports') deps = rospack.get_depends_on(THIS_PACKAGE) for d in deps: pp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'plugins') for idx, p in enumerate(pp): # If a relative path provided, treat it as relative to Qt plugins dir if not os.path.isabs(p): pp[idx] = plugins_dir + '/' + p plugins_paths += pp qp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'imports') qml_paths += qp for p in plugins_paths: engine.addPluginPath(p) for p in qml_paths: engine.addImportPath(p) qml_sys_path = QLibraryInfo.location(QLibraryInfo.ImportsPath) engine.addImportPath(qml_sys_path) # Somehow we need to set the path both with QQmlEngine and with environment, # commenting any of the two will lead to 'module not installed' error os.environ['QML2_IMPORT_PATH'] = ':'.join( qml_paths) + ':' + qml_sys_path comp = QQmlComponent(engine) if len(my_argv) > 1 and my_argv[1]: qml_url = my_argv[1] comp.loadUrl(QUrl(qml_url)) elif rospy.has_param('qml_url'): qml_url = rospy.get_param('qml_url') comp.loadUrl(QUrl(qml_url)) elif rospy.has_param('qml_description'): # experimental qml_description = rospy.get_param('qml_description') # FIXME that hangs for unknown reason comp.setData(QByteArray(qml_description), QUrl()) else: rospy.logfatal( 'Neither /qml_url nor /qml_description (experimental) parameter is present' ) sys.exit(1) if not comp.isReady(): sys.stderr.write(comp.errorString()) sys.exit(1) win = comp.create() if not win: rospy.logfatal('Your root item has to be a Window') sys.exit(1) engine.setIncubationController(win.incubationController()) if win: win.show() # Poll Python interpreter every 500ms timer = QTimer() timer.start(500) timer.timeout.connect(lambda: None) sys.exit(app.exec_()) except KeyboardInterrupt: pass except rospy.ROSInterruptException: pass