def __init__(self, source, root=None): super(Launcher, self).__init__() engine = QtQml.QQmlApplicationEngine() engine.objectCreated.connect(self.on_object_created) # engine.warnings.connect(self.on_warnings) engine.addImportPath(QML_IMPORT_DIR) try: io.install() except IOError: raise # Server refused to connect # Install actions from . import install install() terminal.init() app_root = os.path.dirname(__file__).replace('\\', '/') res_path = "file:///{}/res/".format(app_root) controller = control.Controller(root, self) engine.rootContext().setContextProperty("controller", controller) engine.rootContext().setContextProperty("terminal", terminal.model) engine.rootContext().setContextProperty("res_path", res_path) self._icon = QtGui.QIcon(ICON_PATH) self._tray = None self.window = None self.engine = engine self.controller = controller # self.window = object self.controller.init() engine.load(QtCore.QUrl.fromLocalFile(source))
def __init__(self, root, source): super(Application, self).__init__(sys.argv) self.setWindowIcon(QtGui.QIcon(ICON_PATH)) engine = QtQml.QQmlApplicationEngine() engine.objectCreated.connect(self.on_object_created) engine.warnings.connect(self.on_warnings) engine.addImportPath(QML_IMPORT_DIR) try: io.install() except IOError: raise # Server refused to connect # Install actions from . import install install() terminal.init() controller = control.Controller(root, self) engine.rootContext().setContextProperty("controller", controller) engine.rootContext().setContextProperty("terminal", terminal.model) self._tray = None self.window = None self.engine = engine self.controller = controller engine.load(QtCore.QUrl.fromLocalFile(source)) self.setQuitOnLastWindowClosed(False)
def __init__(self, qmlSrc: Union[str, Path], qmlFile: Optional[Union[str, Path, QtCore.QUrl]] = None, parent: QtCore.QObject = None): """Parameters ---------- qmlSrc Either QML source code or :py:class:`Path` pointing to source file. qmlFile If `qmlSrc` is source code, behave as if it had been loaded from a file named `qmlFile`. parent Parent QObject """ super().__init__(parent) self._status = self.Status.Error if qmlFile is None: qmlFile = QtCore.QUrl() elif isinstance(qmlFile, (str, Path)): qmlFile = QtCore.QUrl.fromLocalFile(str(qmlFile)) self._engine = QtQml.QQmlApplicationEngine() self._engine.addImportPath(qmlPath) useBundledIconTheme() self._engine.objectCreated.connect(self._instanceCreated) # TODO: A user can only connect to status_Changed after __init__ # finishes and will therefore miss this signal and also the one # emitted by _instanceCreated. Maybe add callback parameter to # __init__? self._status = self.Status.Loading self.status_Changed.emit(self._status) if isinstance(qmlSrc, Path): self._engine.load(str(qmlSrc)) else: self._engine.loadData(qmlSrc.encode(), qmlFile)
def __init__(self, argv): super(Application, self).__init__(argv) self._console_ctrl = console.Controller() self._tray = None self._popen = None self._window = None # Virtual host properties self._vhost_ctrl = virtual_host.Controller() with open(self.THEMEPATH) as f: self._theme = json.load(f) self.engine = QtQml.QQmlApplicationEngine() self.engine.addImportPath(self.QMLPATH) self.engine.objectCreated.connect(self.on_object_created) self.focusWindowChanged.connect(self.on_focus_changed) self._console_ctrl.autohideChanged.connect(self.on_autohide_changed) context = self.engine.rootContext() context.setContextProperty("applicationTheme", self._theme) context.setContextProperty("consoleCtrl", self._console_ctrl) context.setContextProperty("hostCtrl", self._vhost_ctrl) # Toggles self.toggles = {"autoHide": True} # Timers keep_visible = QtCore.QTimer(self) keep_visible.setInterval(1000) keep_visible.setSingleShot(True) self.timers = {"keepVisible": keep_visible}
def __init__(self, gates=None, allow_mouse_wheel_updates: bool = True): """ Parameter viewer for gates Args: gates: Gate instrument to use. If None, use qcodes.Station.default.gates allow_mouse_wheel_updates: If True, then allow changing parameter values using mouse scrolling """ super().__init__() self.app = QtCore.QCoreApplication.instance() self.instance_ready = True if self.app is None: self.instance_ready = False self.app = QtWidgets.QApplication([]) self.engine = QtQml.QQmlApplicationEngine() if gates is None: if hasattr(qc.Station.default, 'gates'): gates = qc.Station.default.gates else: raise ValueError( 'No gates Instrument found in the station, pleasse add manually.' ) self.real_gate_model = gate_model( gates, list(gates.hardware.dac_gate_map.keys()), allow_mouse_wheel_updates=allow_mouse_wheel_updates) self.engine.rootContext().setContextProperty("real_gate_model", self.real_gate_model) v_gates = list() for i in gates.v_gates.values(): v_gates += i self.virtual_gate_model = gate_model( gates, v_gates, allow_mouse_wheel_updates=allow_mouse_wheel_updates) self.engine.rootContext().setContextProperty("virtual_gate_model", self.virtual_gate_model) self.engine.rootContext().setContextProperty("param_viewer", self) filename = os.path.join(qml_in.__file__[:-12], "param_viewer.qml") self.engine.load(QtCore.QUrl.fromLocalFile(filename)) self.win = self.engine.rootObjects()[0] self.timer_real = QtCore.QTimer() self.timer_real.timeout.connect(self.real_gate_model.update_model) self.timer_real.start(500) self.timer_virt = QtCore.QTimer() self.timer_virt.timeout.connect(self.virtual_gate_model.update_model) self.timer_virt.start(500) if self.instance_ready == False: self.app.exec_() print('exec')
def __init__(self): super().__init__() self.app = QtCore.QCoreApplication.instance() self.instance_ready = True if self.app is None: self.instance_ready = False self.app = QtWidgets.QApplication([]) self.engine = QtQml.QQmlApplicationEngine() self.date_model = date_model([]) self.data_overview_model = data_overview_model([]) self.project_model = combobox_model(['any', sample_info.project]) self.set_up_model = combobox_model(['any', sample_info.set_up]) self.sample_model = combobox_model(['any', sample_info.sample]) self.signal_handler = signale_handler(self.project_model, self.set_up_model, self.sample_model, self.date_model, self.data_overview_model) self.engine.rootContext().setContextProperty("combobox_project_model", self.project_model) self.engine.rootContext().setContextProperty("combobox_set_up_model", self.set_up_model) self.engine.rootContext().setContextProperty("combobox_sample_model", self.sample_model) self.engine.rootContext().setContextProperty("date_list_model", self.date_model) self.engine.rootContext().setContextProperty("data_content_view_model", self.data_overview_model) self.engine.rootContext().setContextProperty("local_conn_status", True) self.engine.rootContext().setContextProperty("remote_conn_status", True) self.engine.rootContext().setContextProperty("signal_handler", self.signal_handler) # grab directory from the import! filename = os.path.join(qml_in.__file__[:-11], "data_browser.qml") self.engine.load(QtCore.QUrl.fromLocalFile(filename)) self.win = self.engine.rootObjects()[0] self.signal_handler.init_gui_variables(self.win) if self.instance_ready == False: self.app.exec_() print('exec')
def __init__(self, args, qml: str): """ Args: args: system level arguments qml : main qml file """ self._app = create_application(args) self._engine = QtQml.QQmlApplicationEngine() self._settings = ApplicationSettings() self._engine.rootContext().setContextProperty("qtVersion", QtCore.QT_VERSION_STR) self.register_qml_types() self._engine.load(QtCore.QUrl(qml)) assert(len(self._engine.rootObjects()) > 0)
def main(qml_file="millerLauncher.qml", path=""): # _root = os.path.abspath(path) # List._root = os.path.abspath(path) # Show QML Window full_directory = os.path.dirname(os.path.abspath(__file__)) app = pigui.pyqt5.widget.QApplication(sys.argv) # app = QtWidgets.QApplication(sys.argv) QtQml.qmlRegisterType(Controller, 'Controller', 1, 0, 'Controller') engine = QtQml.QQmlApplicationEngine() qml_file = os.path.join(full_directory, qml_file) engine.load(str(qml_file)) window = engine.rootObjects()[0] window.show() sys.exit(app.exec_())
def launch(self): global VhclSpeed myApp = QtGui.QGuiApplication(sys.argv) myEngine = QtQml.QQmlApplicationEngine() self.manager = SpeedMeterManager() myEngine.rootContext().setContextProperty("smManager", self.manager) directory = os.path.dirname(os.path.abspath(__file__)) myEngine.load(QtCore.QUrl.fromLocalFile(os.path.join(directory, 'speedMeter.qml'))) if not myEngine.rootObjects(): return -1 self.dashB = myEngine.rootObjects()[0] timer = QtCore.QTimer(interval=500) # timer.timeout.connect(partial(self.updateSpeed, VhclSpeed)) timer.timeout.connect(self.fetchBrake) timer.timeout.connect(self.fetchAccl) timer.start() return myApp.exec_()
def __init__(self, root, source): super(Application, self).__init__(sys.argv) self.setWindowIcon(QtGui.QIcon(ICON_PATH)) pixmap = QtGui.QPixmap(SPLASH_PATH) splash = QtWidgets.QSplashScreen(pixmap) splash.show() self._splash = splash engine = QtQml.QQmlApplicationEngine() engine.objectCreated.connect(self.on_object_created) engine.warnings.connect(self.on_warnings) engine.addImportPath(QML_IMPORT_DIR) self._splash.showMessage("Connecting database...", QtCore.Qt.AlignBottom, QtCore.Qt.black) try: io.install() except IOError: raise # Server refused to connect # Install actions from . import install install() self._splash.showMessage("Starting Studio Launcher...", QtCore.Qt.AlignBottom, QtCore.Qt.black) terminal.init() controller = control.Controller(root, self) engine.rootContext().setContextProperty("controller", controller) engine.rootContext().setContextProperty("terminal", terminal.model) self._tray = None self.window = None self.engine = engine self.controller = controller engine.load(QtCore.QUrl.fromLocalFile(source)) self.setQuitOnLastWindowClosed(False)
def __init__(self): super().__init__() # self.app = QtGui.QGuiApplication(sys.argv) self.app = QtCore.QCoreApplication.instance() self.instance_ready = True if self.app is None: self.instance_ready = False self.app = QtWidgets.QApplication([]) hw = hardware() self.engine = QtQml.QQmlApplicationEngine() self.attenuation_model = attenuation_model(hw.awg2dac_ratios) self.engine.rootContext().setContextProperty("attenuation_model", self.attenuation_model) if len(hw.virtual_gates) > 0: self.row_header_model = table_header_model( hw.virtual_gates[0].gates) self.column_header_model = table_header_model( hw.virtual_gates[0].v_gates) self.vg_matrix_model = vg_matrix_model(hw.virtual_gates[0]) self.engine.rootContext().setContextProperty( 'row_header_model', self.row_header_model) self.engine.rootContext().setContextProperty( 'column_header_model', self.column_header_model) self.engine.rootContext().setContextProperty( 'vg_matrix_model', self.vg_matrix_model) # grab directory from the import! filename = os.path.join(qml_in.__file__[:-12], "virt_gate_matrix_gui.qml") self.engine.load(QtCore.QUrl.fromLocalFile(filename)) self.win = self.engine.rootObjects()[0] timer = QtCore.QTimer() timer.timeout.connect(lambda: None) timer.start(100) if self.instance_ready == False: self.app.exec_() print('exec')
def main(): app = QtWidgets.QApplication(sys.argv) app.setFont(QtGui.QFont("Ubuntu Mono")) engine = QtQml.QQmlApplicationEngine() interfaces = Interfaces() engine.rootContext().setContextProperty('interfaces', interfaces) sniffer = Sniffer() engine.rootContext().setContextProperty('sniffer', sniffer) packetItemModel = sniffer.packetItemModel engine.rootContext().setContextProperty('packetItemModel', packetItemModel) engine.load(QUrl('main.qml')) topLevel = QtCore.QObject() topLevel = engine.rootObjects()[0] window = QtQuick.QQuickWindow() window = topLevel window.show() sys.exit(app.exec_())
def setup(self): if not os.path.exists(self.THUMB_DIR): os.makedirs(self.THUMB_DIR) user_database.setup() self.qml_engine = QtQml.QQmlApplicationEngine() self.qml_engine.addImportPath(self.QML_PATH) # self.qml_engine.addPluginPath(self.QML_PATH) self.setAttribute(QtCore.Qt.AA_UseOpenGLES, True) self.qml_engine.load(os.path.join(self.QML_PATH, "main.qml")) self.app_window = self.qml_engine.rootObjects()[0] self.app_window.updateGalleryRating.connect(self.update_gallery_rating) self.app_window.askForTags.connect(self.get_tags_from_search) self.app_window.saveSettings.connect(self.update_config) self.app_window.setSortMethod.connect(self.set_sorting) self.app_window.setSearchText.connect(self.update_search) self.app_window.pageChange.connect(self.switch_page) self.app_window.scanGalleries.connect(self.find_galleries) self.app_window.openGallery.connect(self.open_gallery) self.app_window.openGalleryFolder.connect(self.open_gallery_folder) self.app_window.metadataSearch.connect(self.get_metadata) self.app_window.removeGallery.connect(self.remove_gallery_by_uuid) self.app_window.openOnEx.connect(self.open_on_ex) self.app_window.saveGallery.connect(self.save_gallery_customization) self.app_window.searchForDuplicates.connect(self.remove_duplicates) self.app_window.closedUI.connect(self.close) self.app_window.getDetailedGallery.connect(self.get_detailed_gallery) self.app_window.getGalleryImageFolder.connect( self.get_gallery_image_folder) self.app_window.setGalleryImage.connect(self.set_gallery_image) self.app_window.setUISort.emit(Config.sort_type, 1 if Config.sort_mode_reversed else 0) self.completer_line = QtWidgets.QLineEdit() self.completer_line.hide() self.setup_completer() self.setWindowIcon( QtGui.QIcon(Utils.convert_from_relative_path("icon.ico"))) self.set_ui_config() self.app_window.show()
def __init__(self, data): super().__init__() # self.app = QtGui.QGuiApplication(sys.argv) self.app = QtCore.QCoreApplication.instance() self.instance_ready = True if self.app is None: self.instance_ready = False self.app = QtWidgets.QApplication([]) self.engine = QtQml.QQmlApplicationEngine() self.categories_model = categories_model(list(data.keys())) self.data = data if len(data) == 0: self.data_model = name_value_model({}) else: self.data_model = name_value_model(data[list(data.keys())[0]]) self.singal_hander = singal_hander_4_variable_exporer( self.categories_model, self.data_model, data) self.engine.rootContext().setContextProperty("cat_model", self.categories_model) self.engine.rootContext().setContextProperty( "variable_name_value_pair_list", self.data_model) self.engine.rootContext().setContextProperty("test_function", self.singal_hander) # grab directory from the import! filename = os.path.join(qml_in.__file__[:-11], "variable_mgr_window.qml") self.engine.load(QtCore.QUrl.fromLocalFile(filename)) self.win = self.engine.rootObjects()[0] timer = QtCore.QTimer() timer.timeout.connect(lambda: None) timer.start(100) if self.instance_ready == False: self.app.exec_() print('exec')
return True def lprint(self, message): # 日志打印 global GTime k = GTime[0:2] if not self.log.get(str(k)): self.log[str(k)] = [] self.log[str(k)].append(message) json.dump(self.log, open("log.json", "w"), ensure_ascii=False) if __name__ == '__main__': # 界面初始化 app = QtWidgets.QApplication(sys.argv) engine = QtQml.QQmlApplicationEngine() context = engine.rootContext() # 配置qml属性 system = System() context.setContextProperty("system", system) timer = Timer() context.setContextProperty("timer", timer) # 加载qml属性 engine.addImportPath(absPath + "qtquickcontrols2.conf") engine.load(QUrl(absPath + 'main.qml')) engine.load(QUrl(absPath + 'loginPage.qml')) # 信号与槽连接
def __init__(self, virtual_gate_name: Union[str, int] = 0): """ Args: virtual_gate_name: Name or index of virtual gate to display """ super().__init__() # self.app = QtGui.QGuiApplication(sys.argv) self.app = QtCore.QCoreApplication.instance() self.instance_ready = True if self.app is None: self.instance_ready = False self.app = QtWidgets.QApplication([]) hw = hardware() self.engine = QtQml.QQmlApplicationEngine() self.attenuation_model = attenuation_model(hw.awg2dac_ratios) self.engine.rootContext().setContextProperty("attenuation_model", self.attenuation_model) if isinstance(virtual_gate_name, int): self.virtual_gate_index = virtual_gate_name else: self.virtual_gate_index = ( hw.virtual_gates.virtual_gate_names).index(virtual_gate_name) if len(hw.virtual_gates) > self.virtual_gate_index: hw = hardware() vg = hw.virtual_gates[self.virtual_gate_index] logging.info( f'creating objects for index {self.virtual_gate_index}') self.vg_matrix_model = vg_matrix_model(vg) self.vg_matrix_model._manipulate_callback = self.set_table_headers self.gates_header_model = table_header_model(vg.gates) self.vgates_header_model = table_header_model(vg.v_gates) root_context = self.engine.rootContext() root_context.setContextProperty('virt_gate_matrix_GUI', self) root_context.setContextProperty('vg_matrix_model', self.vg_matrix_model) root_context.setContextProperty('row_header_model', self.gates_header_model) root_context.setContextProperty('column_header_model', self.vgates_header_model) else: print('virtual gate name {virtual_gate_name} could not be found') # grab directory from the import! filename = os.path.join(qml_in.__file__[:-12], "virt_gate_matrix_gui.qml") logging.info(f'loading qml from {filename}') self.engine.load(QtCore.QUrl.fromLocalFile(filename)) self.win = self.engine.rootObjects()[0] self._mat_inv_switch = self.engine.rootObjects()[0].findChild( QtCore.QObject, "mat_inv_switch") self.set_table_headers() timer = QtCore.QTimer() timer.timeout.connect(lambda: None) timer.start(100) if self.instance_ready == False: self.app.exec_() print('exec')
@QtCore.pyqtSlot() def GetServerNames(self): def go(): serverNames = ["one", "two", "three"] self.serverNames.emit(serverNames) threading.Thread(target=go).start() @QtCore.pyqtSlot() def GetLastLogin(self): def go(): login = "******" self.lastLogin.emit(login) threading.Thread(target=go).start() @QtCore.pyqtSlot() def GetLastServerName(self): def go(): serverName = "three" self.lastServer.emit(serverName) threading.Thread(target=go).start() app = QtGui.QGuiApplication(sys.argv) QtQml.qmlRegisterType(LoginManager, 'LoginManager', 1, 0, 'LoginManager') engine = QtQml.QQmlApplicationEngine("Main.qml") app.exec_()
def __init__(self, parent=None): super().__init__(parent) self.api_v = "5.101" self.app_id = "7285008" self.scope = "groups,wall,photos" self._current_page = "" self.vk_session = None self._engine = QtQml.QQmlApplicationEngine() self._authentication = AuthenticationManager() self._manager = ComponentCacheManager(self._engine) self._db_manager = DataBaseManager() self._reader = FileReader() self._authentication.login_signal.connect(self.on_login_signal) self._authentication.logout_signal.connect(self.on_logout_signal) self._authentication.close_signal.connect(self.on_close_signal) self._db_manager.choose_group_signal.connect(self.on_choose_group) self._db_manager.update_signal.connect(self.on_update) self._db_manager.load_posts_signal.connect(self.on_load_posts) self._db_manager.get_post_signal.connect(self.on_get_post) self._db_manager.get_posts_by_time_signal.connect(self.on_get_posts_by_time) self._db_manager.get_tags_signal.connect(self.on_get_tags) self._db_manager.get_templates_signal.connect(self.on_get_templates) self._db_manager.get_groups_signal.connect(self.on_get_groups) self._db_manager.add_tag_signal.connect(self.on_add_tag) self._db_manager.save_post_signal.connect(self.on_save_post) self._db_manager.publish_post_signal.connect(self.on_publish_post) self._db_manager.delete_post_signal.connect(self.on_delete_post) self._db_manager.get_template_signal.connect(self.on_get_template) self._db_manager.save_template_signal.connect(self.on_save_template) self._db_manager.delete_template_signal.connect(self.on_delete_template) self._authentication.get_wall_posts_signal.connect(self.on_get_wall_posts) self._authentication.get_wall_postponed_signal.connect(self.on_get_wall_postponed) self._engine.rootContext().setContextProperty( "authentication", self._authentication ) self._engine.rootContext().setContextProperty( "componentCache", self._manager ) self._engine.rootContext().setContextProperty( "db_manager", self._db_manager ) self._engine.rootContext().setContextProperty( "APIv", self.api_v ) self._engine.rootContext().setContextProperty( "app_id", self.app_id ) self._engine.rootContext().setContextProperty( "scope", self.scope ) self._engine.rootContext().setContextProperty( "fileReader", self._reader )
import os import sys from PyQt5 import QtQml, QtWidgets if __name__ == '__main__': if 'CONFIG' in os.environ: print(os.environ['CONFIG']) app = QtWidgets.QApplication(sys.argv + ["-nograb"]) engine = QtQml.QQmlApplicationEngine("Debug.qml") sys.exit(app.exec_())
if self.player.isRunning(): self.player.terminate() @QtCore.pyqtSlot(float) def scrub(self, where): if self.isPlaying: self.isPlaying = False self.progress = where self.isPlaying = True else: self.progress = where filename_changed, filename = autoProperty(str, 'filename') isPlaying_changed, isPlaying = autoProperty(bool, 'isPlaying') progress_changed, progress = autoProperty(float, 'progress') waveform_changed, waveform = autoProperty(QtCore.QVariant, 'waveform', readonly=True) length_changed, length = autoProperty(float, 'length', readonly=True) if __name__ == "__main__": if not QtGui.QGuiApplication.instance(): app = QtGui.QGuiApplication(sys.argv) QtQml.qmlRegisterType(Player, 'Player', 1, 0, 'Player') engine = QtQml.QQmlApplicationEngine('main.qml') if len(engine.rootObjects()) > 0: mainWindow = engine.rootObjects()[0] mainWindow.setVisible(True) app.exec()
import sys from PyQt5 import QtQml from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) engine = QtQml.QQmlApplicationEngine("example.qml") app.exec_()
def main(): app = QtGui.QGuiApplication(sys.argv) QtQml.qmlRegisterType(JSManager, 'JSManager', 1, 0, 'JSManager') engine = QtQml.QQmlApplicationEngine(os.path.join(THIS_DIR, "main.qml")) app.exec_()