예제 #1
0
파일: qml_helper.py 프로젝트: fbob/dice-dev
    def view(self):
        with self.__view_creation_lock:
            if self._view is None:
                component = QQmlComponent(self.dice.qml_engine, self.qml_file,
                                          self)
                if component.status() == QQmlComponent.Error:
                    qDebug("errors loading component: " +
                           str(component.errors()))
                    qDebug(self.qml_file)
                    for error in component.errors():
                        qDebug(error.description())
                    return QQuickItem(self)

                # don't create the view immediately so the properties are available as soon as the view is created
                view = component.beginCreate(self.dice.qml_context)

                if view:
                    view.setParentItem(self.dice.main_window)
                    view.setProperty("appWindow", self.dice.app_window)
                    view.setProperty("app", self)
                    view.setProperty("mainWindow", self.dice.main_window)
                    self._view = view
                    component.completeCreate()
                    self.view_changed.emit()
                else:
                    component.completeCreate()
                    qDebug("no view")
                    view = QQuickItem(self)
                    view.setParentItem(self.dice.main_window)
                    # TODO: send an alert
                    return view
            return self._view
예제 #2
0
 def createControlInterface(self):
     if self._control_view is None:
         path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
         component = QQmlComponent(Application.getInstance()._engine, path)
         self._control_context = QQmlContext(Application.getInstance()._engine.rootContext())
         self._control_context.setContextProperty("manager", self)
         self._control_view = component.create(self._control_context)
예제 #3
0
    def _createAdditionalComponentsView(self):
        Logger.log(
            "d",
            "Creating additional ui components for OctoPrint-connected printers."
        )

        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(
                    "SculptoPrintPlugin"), "SculptoPrintPlugin.qml"))
        self._additional_component = QQmlComponent(
            Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self._additional_components_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._additional_components_context.setContextProperty("manager", self)

        self._additional_components_view = self._additional_component.create(
            self._additional_components_context)
        if not self._additional_components_view:
            Logger.log(
                "w",
                "Could not create additional components for OctoPrint-connected printers."
            )
            return
예제 #4
0
def main():
    app = QGuiApplication([])

    try:
        path = QUrl(sys.argv[1])
    except IndexError:
        print("Usage: pyqmlscene <filename>")
        sys.exit(1)

    engine = QQmlApplicationEngine()

    # Procedure similar to
    # https://github.com/qt/qtdeclarative/blob/0e9ab20b6a41bfd40aff63c9d3e686606e51e798/tools/qmlscene/main.cpp
    component = QQmlComponent(engine)
    component.loadUrl(path)
    root_object = component.create()

    if isinstance(root_object, QQuickWindow):
        # Display window object
        root_object.show()
    elif isinstance(root_object, QQuickItem):
        # Display arbitrary QQuickItems by reloading the source since
        # reparenting the existing root object to the view did not have any
        # effect. Neither does the QQuickView class have a setContent() method
        view = QQuickView(path)
        view.show()
    else:
        raise SystemExit("Error displaying {}".format(root_object))

    sys.exit(app.exec_())
예제 #5
0
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
예제 #6
0
    def _createAdditionalComponentsView(self):
        Logger.log(
            "d",
            "Creating additional ui components for Repetier-Server - connected printers."
        )

        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(
                    "RepetierServerPlugin"), "RepetierServerComponents.qml"))
        self._additional_component = QQmlComponent(
            Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self._additional_components_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._additional_components_context.setContextProperty("manager", self)

        self._additional_components_view = self._additional_component.create(
            self._additional_components_context)
        if not self._additional_components_view:
            Logger.log(
                "w",
                "Could not create additional components for Repetier-Server - connected printers."
            )
            return

        Application.getInstance().addAdditionalComponent(
            "monitorButtons",
            self._additional_components_view.findChild(
                QObject, "openRepetierServerButton"))
    def requestWrite(self, node, fileName=None, *args, **kwargs):
        if self._stage != OutputStage.ready:
            raise OutputDeviceError.DeviceBusyError()

        if fileName:
            fileName = os.path.splitext(fileName)[0] + '.gcode'
        else:
            fileName = "%s.gcode" % Application.getInstance(
            ).getPrintInformation().jobName
        self._fileName = fileName

        path = QUrl.fromLocalFile(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'UploadFilename.qml'))
        self._component = QQmlComponent(Application.getInstance()._engine,
                                        path)
        Logger.log("d", "Errors:", self._component.errors())
        self._context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._context.setContextProperty("manager", self)
        self._dialog = self._component.create(self._context)
        self._dialog.textChanged.connect(self.onFilenameChanged)
        self._dialog.accepted.connect(self.onFilenameAccepted)
        self._dialog.open()
        self._dialog.findChild(QObject, "nameField").setProperty(
            'text', self._fileName)
        self._dialog.findChild(QObject,
                               "nameField").select(0,
                                                   len(self._fileName) - 6)
        self._dialog.findChild(QObject, "nameField").setProperty('focus', True)
예제 #8
0
    def _createAdditionalComponentsView(self):
        Logger.log("d", "Creating additional ui components for UM3.")
        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(
                    "UM3NetworkPrinting"), "UM3InfoComponents.qml"))
        self.__additional_component = QQmlComponent(
            Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self.__additional_components_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self.__additional_components_context.setContextProperty(
            "manager", self)

        self.__additional_components_view = self.__additional_component.create(
            self.__additional_components_context)
        if not self.__additional_components_view:
            Logger.log("w", "Could not create ui components for UM3.")
            return

        Application.getInstance().addAdditionalComponent(
            "monitorButtons",
            self.__additional_components_view.findChild(
                QObject, "networkPrinterConnectButton"))
        Application.getInstance().addAdditionalComponent(
            "machinesDetailPane",
            self.__additional_components_view.findChild(
                QObject, "networkPrinterConnectionInfo"))
예제 #9
0
    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
예제 #10
0
    def _createCostView(self):
        path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("ElectricPrintCostCalculator"), "ElectricPrintCostCalculator.qml"))
        self._component = QQmlComponent(Application.getInstance()._engine, path)

        self._context = QQmlContext(Application.getInstance()._engine.rootContext())
        self._context.setContextProperty("manager", self)
        self._cost_view = self._component.create(self._context)
예제 #11
0
 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))
예제 #12
0
 def _createViewFromQML(self):
     path = QUrl.fromLocalFile(
         os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url))
     self._component = QQmlComponent(Application.getInstance()._engine, path)
     self._context = QQmlContext(Application.getInstance()._engine.rootContext())
     self._context.setContextProperty("manager", self)
     self._view = self._component.create(self._context)
    def _createAdditionalComponentsView(self):
        Logger.log(
            "d",
            "Creating additional ui components for OctoPrint-connected printers."
        )

        path = QUrl.fromLocalFile(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "OctoPrintComponents.qml"))
        self._additional_component = QQmlComponent(
            Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self._additional_components_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._additional_components_context.setContextProperty("manager", self)

        self._additional_components_view = self._additional_component.create(
            self._additional_components_context)
        if not self._additional_components_view:
            Logger.log(
                "w",
                "Could not create additional components for OctoPrint-connected printers."
            )
            return

        Application.getInstance().addAdditionalComponent(
            "monitorButtons",
            self._additional_components_view.findChild(QObject,
                                                       "openOctoPrintButton"))
    def _createAdditionalComponentsView(self):
        Logger.log(
            "d", "Creating additional ui components for Pause Backend plugin.")

        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(
                    "PauseBackendPlugin"), "PauseBackend.qml"))
        self._additional_component = QQmlComponent(
            Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self._additional_components_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._additional_components_context.setContextProperty("manager", self)

        self._additional_components_view = self._additional_component.create(
            self._additional_components_context)
        if not self._additional_components_view:
            Logger.log(
                "w",
                "Could not create additional components for Pause Backend plugin."
            )
            return

        Application.getInstance().addAdditionalComponent(
            "saveButton",
            self._additional_components_view.findChild(QObject,
                                                       "pauseResumeButton"))
    def _createView(self):
        Logger.log("d", "Creating post processing plugin view.")

        ## Load all scripts in the scripts folder
        try:
            self.loadAllScripts(
                os.path.join(
                    PluginRegistry.getInstance().getPluginPath(
                        "PostProcessingPlugin"), "scripts"))
        except Exception as e:
            print(
                "Exception occured", e
            )  # TODO: Debug code (far to general catch. Remove this once done testing)

        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(
                    "PostProcessingPlugin"), "PostProcessingPlugin.qml"))
        self._component = QQmlComponent(Application.getInstance()._engine,
                                        path)

        # We need access to engine (although technically we can't)
        self._context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._context.setContextProperty("manager", self)
        self._view = self._component.create(self._context)
        Logger.log("d", "Post processing view created.")

        Application.getInstance().addAdditionalComponent(
            "saveButton",
            self._view.findChild(QObject, "postProcessingSaveAreaButton"))
예제 #16
0
    def createQmlComponent(
        self,
        qml_file_path: str,
        context_properties: Dict[str,
                                 "QObject"] = None) -> Optional["QObject"]:
        if self._qml_engine is None:  # Protect in case the engine was not initialized yet
            return None
        path = QUrl.fromLocalFile(qml_file_path)
        component = QQmlComponent(self._qml_engine, path)
        result_context = QQmlContext(
            self._qml_engine.rootContext()
        )  #type: ignore #MyPy doens't realise that self._qml_engine can't be None here.
        if context_properties is not None:
            for name, value in context_properties.items():
                result_context.setContextProperty(name, value)
        result = component.create(result_context)
        for err in component.errors():
            Logger.log("e", str(err.toString()))
        if result is None:
            return None

        # We need to store the context with the qml object, else the context gets garbage collected and the qml objects
        # no longer function correctly/application crashes.
        result.attached_context = result_context
        return result
예제 #17
0
    def createQmlComponent(self, qml_file_path: str, context_properties: Dict[str, "QObject"] = None) -> Optional["QObject"]:
        """Create a QML component from a qml file.
        :param qml_file_path:: The absolute file path to the root qml file.
        :param context_properties:: Optional dictionary containing the properties that will be set on the context of the
        qml instance before creation.
        :return: None in case the creation failed (qml error), else it returns the qml instance.
        :note If the creation fails, this function will ensure any errors are logged to the logging service.
        """

        if self._qml_engine is None: # Protect in case the engine was not initialized yet
            return None
        path = QUrl.fromLocalFile(qml_file_path)
        component = QQmlComponent(self._qml_engine, path)
        result_context = QQmlContext(self._qml_engine.rootContext()) #type: ignore #MyPy doens't realise that self._qml_engine can't be None here.
        if context_properties is not None:
            for name, value in context_properties.items():
                result_context.setContextProperty(name, value)
        result = component.create(result_context)
        for err in component.errors():
            Logger.log("e", str(err.toString()))
        if result is None:
            return None

        # We need to store the context with the qml object, else the context gets garbage collected and the qml objects
        # no longer function correctly/application crashes.
        result.attached_context = result_context
        return result
예제 #18
0
def run():
    directory = os.path.dirname(os.path.abspath(__file__))

    appIcon = QIcon()
    appIcon.addFile(os.path.join(directory, "python.png"), QSize(64, 64))
    app.setWindowIcon(appIcon)

    from . import registerQmlTypes

    registerQmlTypes()

    engine = QQmlApplicationEngine()
    context = QQmlContext(engine)

    mainQml = QUrl.fromLocalFile(os.path.join(directory, "Main.qml"))

    component = QQmlComponent(engine)
    component.loadUrl(mainQml)

    if component.isError():
        for error in component.errors():
            print("Error: ", error.toString())

    dialog = component.create(context)

    return app.exec_()
예제 #19
0
    def _createConfigUI(self):
        if self._ui_view is None:
            path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("CuraSolidWorksPlugin"), "ExportSTLUI.qml"))
            component = QQmlComponent(Application.getInstance()._engine, path)
            self._ui_context = QQmlContext(Application.getInstance()._engine.rootContext())
            self._ui_context.setContextProperty("manager", self)
            self._ui_view = component.create(self._ui_context)

            self._ui_view.setFlags(self._ui_view.flags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowMinimizeButtonHint & ~Qt.WindowMaximizeButtonHint)
예제 #20
0
 def _createViewFromQML(self):
     path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("3MFReader"), self._qml_url))
     self._component = QQmlComponent(Application.getInstance()._engine, path)
     self._context = QQmlContext(Application.getInstance()._engine.rootContext())
     self._context.setContextProperty("manager", self)
     self._view = self._component.create(self._context)
     if self._view is None:
         Logger.log("c", "QQmlComponent status %s", self._component.status())
         Logger.log("c", "QQmlComponent error string %s", self._component.errorString())
예제 #21
0
 def createChangelogWindow(self):
     path = QUrl.fromLocalFile(
         os.path.join(
             PluginRegistry.getInstance().getPluginPath("ChangeLogPlugin"),
             "ChangeLog.qml"))
     component = QQmlComponent(Application.getInstance()._engine, path)
     self._changelog_context = QQmlContext(
         Application.getInstance()._engine.rootContext())
     self._changelog_context.setContextProperty("manager", self)
     self._changelog_window = component.create(self._changelog_context)
예제 #22
0
    def spawnFirmwareInterface(self, serial_port):
        if self._firmware_view is None:
            path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "FirmwareUpdateWindow.qml"))
            component = QQmlComponent(Application.getInstance()._engine, path)

            self._firmware_context = QQmlContext(Application.getInstance()._engine.rootContext())
            self._firmware_context.setContextProperty("manager", self)
            self._firmware_view = component.create(self._firmware_context)

        self._firmware_view.show()
예제 #23
0
    def _createView(self):
        ## Load all scripts in the scripts folder
        self.loadAllScripts(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "scripts"))
        
        path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "PostProcessingPlugin.qml"))
        self._component = QQmlComponent(Application.getInstance()._engine, path)

        self._context = QQmlContext(Application.getInstance()._engine.rootContext())
        self._context.setContextProperty("manager", self)
        self._view = self._component.create(self._context)
예제 #24
0
 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
예제 #25
0
    def _createDialogue(self):
        #Create a QML component from the Hello.qml file.
        qml_file = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(self.getPluginId()),
                "SelectionInfo.qml"))
        component = QQmlComponent(Application.getInstance()._engine, qml_file)
        qml_context = QQmlContext(
            Application.getInstance()._engine.rootContext(
            ))  #List the QML component as subcomponent of the main window.

        return component.create(qml_context)
예제 #26
0
    def createUserAgreementWindow(self):
        path = QUrl.fromLocalFile(
            os.path.join(
                PluginRegistry.getInstance().getPluginPath(self.getPluginId()),
                "UserAgreement.qml"))

        component = QQmlComponent(Application.getInstance()._engine, path)
        self._user_agreement_context = QQmlContext(
            Application.getInstance()._engine.rootContext())
        self._user_agreement_context.setContextProperty("manager", self)
        self._user_agreement_window = component.create(
            self._user_agreement_context)
예제 #27
0
    def _createConfigUI(self):
        if self._ui_view is None:
            Logger.log("d", "Creating ImageReader config UI")
            path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("ImageReader"), "ConfigUI.qml"))
            component = QQmlComponent(Application.getInstance()._engine, path)
            self._ui_context = QQmlContext(Application.getInstance()._engine.rootContext())
            self._ui_context.setContextProperty("manager", self)
            self._ui_view = component.create(self._ui_context)

            self._ui_view.setFlags(self._ui_view.flags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowMinimizeButtonHint & ~Qt.WindowMaximizeButtonHint);

            self._disable_size_callbacks = False
예제 #28
0
    def _createDialog(self):
        Logger.log("d", "PluginBrowser")

        path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "PluginBrowser.qml"))
        self._qml_component = QQmlComponent(Application.getInstance()._engine, path)

        # We need access to engine (although technically we can't)
        self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
        self._qml_context.setContextProperty("manager", self)
        self._dialog = self._qml_component.create(self._qml_context)
        if self._dialog is None:
            Logger.log("e", "QQmlComponent status %s", self._qml_component.status())
            Logger.log("e", "QQmlComponent errorString %s", self._qml_component.errorString())
예제 #29
0
 def connect(self):
     self.host = self.get_obj('host_input_text').property('text')
     self.port = self.get_obj('port_input_text').property('text')
     answer = requests.get(self.address() + '/')
     if answer.status_code == 200:
         args = answer.json()
         self.id = args['id']
         self.key = args['key']
         self.root.close()
         self.engine = QQmlApplicationEngine('form.qml')
         self.root = self.engine.rootObjects()[0]
         self.root.show()
         self.get_obj('return_button').clicked.connect(self.stop_find_chat)
         self.get_obj('find_chat_button').clicked.connect(self.find_chat)
         self.get_obj('disconnect_button').clicked.connect(self.disconnect)
         self.get_obj('text_input').message_ready.connect(self.send_message)
         self.get_obj('leave_chat_button').clicked.connect(self.leave_chat)
         self.message0_component = QQmlComponent(self.engine)
         self.message0_component.loadUrl(QUrl('message0.qml'))
         self.message1_component = QQmlComponent(self.engine)
         self.message1_component.loadUrl(QUrl('message1.qml'))
         self.draw_main()
예제 #30
0
 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