def initialise(self): virtual_input_providers = CONFIG.get("virtual_input_providers", {}) for input_type, provider in virtual_input_providers.items(): obj = _initialize_object_from_dict(provider) input_type = input_type.replace('.', ':') self.input_providers[input_type] = obj app = QApplication.instance() app.focusChanged.connect(self.onFocusChanged) for vkb in self.input_providers.values(): vkb.hide()
def launch_designer(opts=DotDict()): if not opts.vcp and not opts.ui_file: fname, _ = QFileDialog.getOpenFileName( parent=None, caption="Choose VCP to Edit in QtDesigner", filter= "VCP Config Files (*.yml *.yaml);;VCP UI Files (*.ui);;All Files (*)", options=QFileDialog.Options() | QFileDialog.DontUseNativeDialog) if not fname: sys.exit(1) else: fname = opts.vcp or opts.ui_file if not '.' in fname or not '/' in fname: entry_points = {} for entry_point in iter_entry_points(group='qtpyvcp.example_vcp'): entry_points[entry_point.name] = entry_point for entry_point in iter_entry_points(group='qtpyvcp.vcp'): entry_points[entry_point.name] = entry_point try: vcp = entry_points[fname.lower()].load() fname = vcp.VCP_CONFIG_FILE except KeyError: pass if 'lib/python2.7/site-packages' in fname: print INSTALLED_ERROR_MSG sys.exit(1) cmd = ['designer'] ext = os.path.splitext(fname)[1] if ext in ['.yml', '.yaml']: print "Loading YAML config file:", fname from qtpyvcp import CONFIG, DEFAULT_CONFIG_FILE from qtpyvcp.utilities.config_loader import load_config_files try: CONFIG.update(load_config_files(fname, DEFAULT_CONFIG_FILE)) data = CONFIG.get('qtdesigner') except: print "Error loading YAML config file:" raise from qtpyvcp.utilities.settings import addSetting for k, v in CONFIG['settings'].items(): addSetting(k, **v) # add to path so that QtDesginer can load it when it starts os.environ['VCP_CONFIG_FILES'] = fname + ':' + os.getenv( 'VCP_CONFIG_FILES', '') if data is not None: yml_dir = os.path.realpath(os.path.dirname(fname)) # prefer command line ui file ui_file = opts.ui_file or data.get('ui_file') if ui_file is not None: ui_file = os.path.join(yml_dir, ui_file) cmd.append(ui_file) print "Loading UI file:", ui_file else: print "No UI file specified." # prefer command line qss file qss_file = opts.qss_file or data.get('qss_file') if qss_file is not None: qss_file = os.path.join(yml_dir, qss_file) os.environ['QSS_STYLESHEET'] = qss_file print "Loading QSS file:", qss_file else: print "No QSS file specified." elif ext == '.ui': cmd.append(fname) print "Loading UI file:", fname else: print "No valid file type selected.\n " \ "File must be a .yaml config file or a .ui file." sys.exit() base = os.path.dirname(__file__) sys.path.insert(0, base) os.environ['QTPYVCP_LOG_FILE'] = opts.log_file os.environ['QTPYVCP_LOG_LEVEL'] = opts.log_level os.environ['QT_SELECT'] = 'qt5' os.environ['PYQTDESIGNERPATH'] = os.path.join(base, '../widgets') print "\nStarting QtDesigner ..." sys.exit(subprocess.call(cmd))
os.environ['DESIGNER'] = 'true' from qtpyvcp.utilities.logger import initBaseLogger LOG = initBaseLogger("qtpyvcp-designer", log_level=os.getenv('QTPYVCP_LOG_LEVEL', 'ERROR'), log_file=os.getenv( 'QTPYVCP_LOG_FILE', os.path.expanduser('~/qtpyvcp-designer.log'))) from qtpyvcp import CONFIG, DEFAULT_CONFIG_FILE os.environ['VCP_CONFIG_FILES'] = os.getenv('VCP_CONFIG_FILES', '') + \ ':' + DEFAULT_CONFIG_FILE from qtpyvcp.utilities.config_loader import load_config_files_from_env CONFIG.update(load_config_files_from_env()) from qtpyvcp.app.launcher import loadPlugins loadPlugins(CONFIG['data_plugins']) from qtpyvcp.widgets.form_widgets.designer_plugins import * from qtpyvcp.widgets.button_widgets.designer_plugins import * from qtpyvcp.widgets.display_widgets.designer_plugins import * from qtpyvcp.widgets.input_widgets.designer_plugins import * from qtpyvcp.widgets.hal_widgets.designer_plugins import * from qtpyvcp.widgets.containers.designer_plugins import * from qtpyvcp.widgets.external_widgets import *
def launch_designer(opts=DotDict()) -> None: if not opts.vcp and not opts.ui_file: fname, _ = QFileDialog.getOpenFileName( parent=None, caption="Choose VCP to Edit in QtDesigner", filter= "VCP Config Files (*.yml *.yaml);;VCP UI Files (*.ui);;All Files (*)", options=QFileDialog.Options() | QFileDialog.DontUseNativeDialog) if not fname: sys.exit(1) else: fname = opts.vcp or opts.ui_file if '.' not in fname or '/' not in fname: entry_points = {} for entry_point in iter_entry_points(group='qtpyvcp.example_vcp'): entry_points[entry_point.name] = entry_point for entry_point in iter_entry_points(group='qtpyvcp.vcp'): entry_points[entry_point.name] = entry_point try: vcp = entry_points[fname.lower()].load() fname = vcp.VCP_CONFIG_FILE except KeyError: pass if 'lib/python2.7/site-packages' in fname: LOG.error(INSTALLED_ERROR_MSG) sys.exit(1) cmd = ['designer'] ext = os.path.splitext(fname)[1] if ext in ['.yml', '.yaml']: LOG.info(f"Loading YAML config file: {fname}") from qtpyvcp import CONFIG, DEFAULT_CONFIG_FILE from qtpyvcp.utilities.config_loader import load_config_files try: CONFIG.update(load_config_files(fname, DEFAULT_CONFIG_FILE)) data = CONFIG.get('qtdesigner') except Exception as e: LOG.error("Error loading YAML config file:") LOG.error(e) raise from qtpyvcp.utilities.settings import addSetting for k, v in list(CONFIG['settings'].items()): addSetting(k, **v) # add to path so that QtDesginer can load it when it starts config_file = f"{fname}:{os.getenv('VCP_CONFIG_FILES', '')}" os.environ['VCP_CONFIG_FILES'] = config_file if data is not None: yml_dir = os.path.realpath(os.path.dirname(fname)) # prefer command line ui file ui_file = opts.ui_file or data.get('ui_file') if ui_file is not None: ui_file = os.path.join(yml_dir, ui_file) cmd.append(ui_file) LOG.info(f"Loading UI file: {ui_file}") else: LOG.info("No UI file specified.") # prefer command line qss file qss_file = opts.qss_file or data.get('qss_file') if qss_file is not None: qss_file = os.path.join(yml_dir, qss_file) os.environ['QSS_STYLESHEET'] = qss_file LOG.info(f"Loading QSS file: {qss_file}") else: LOG.info("No QSS file specified.") elif ext == '.ui': cmd.append(fname) LOG.info(f"Loading UI file: {fname}") else: LOG.error("""No valid file type selected.\n File must be a .yaml config file or a .ui file.""") sys.exit() base = os.path.dirname(__file__) sys.path.insert(0, base) os.environ['QTPYVCP_LOG_FILE'] = opts.log_file os.environ['QTPYVCP_LOG_LEVEL'] = opts.log_level os.environ['QT_SELECT'] = 'qt5' os.environ['PYQTDESIGNERPATH'] = os.path.join(base, '../widgets') LOG.info("Starting QtDesigner ...") try: process = Popen(cmd, stdout=PIPE, stderr=STDOUT) with process.stdout: log_subprocess_output(process.stdout) exitcode = process.wait() # 0 means success except OSError as exception: LOG.error("""Designer not found, Install with\n sudo apt install qttools5-dev qttools5-dev-tools""") LOG.error(f'Exception occured: {exception}') LOG.error('Subprocess failed') return False else: # no exception was raised LOG.info('EditVCP finished')