コード例 #1
0
ファイル: vcp_launcher.py プロジェクト: gitter-badger/qtpyvcp
def _load_vcp_from_yaml_file(yaml_file, opts):
    LOG.info("Loading VCP from YAML file: yellow<{}>".format(yaml_file))
    from qtpyvcp.utilities.config_loader import load_config_files
    cfg_files = [opts.config_file or '']
    cfg_files.extend(os.getenv('VCP_CONFIG_FILES', '').split(':'))
    cfg_files.append(yaml_file)
    cfg_files.append(qtpyvcp.DEFAULT_CONFIG_FILE)
    config = load_config_files(*cfg_files)
    launch_application(opts, config)
コード例 #2
0
def _load_vcp_from_ui_file(ui_file, opts):
    LOG.info("Loading VCP from UI file: yellow<{}>".format(ui_file))
    from qtpyvcp.utilities.config_loader import load_config_files
    cfg_files = [opts.config_file or '']
    cfg_files.extend(os.getenv('VCP_CONFIG_FILES', '').split(':'))
    cfg_files.append(qtpyvcp.DEFAULT_CONFIG_FILE)
    config = load_config_files(*cfg_files)
    kwargs = config['windows']['mainwindow'].get('kwargs', {})
    kwargs.update({'ui_file': ui_file})
    config['windows']['mainwindow']['kwargs'] = kwargs
    launch_application(opts, config)
コード例 #3
0
def _load_vcp_from_yaml_file(yaml_file, opts):
    LOG.info("Loading VCP from YAML file: yellow<{}>".format(yaml_file))
    from qtpyvcp.utilities.config_loader import load_config_files
    cfg_files = [opts.config_file or '']
    cfg_files.extend(os.getenv('VCP_CONFIG_FILES', '').split(':'))
    cfg_files.append(yaml_file)
    cfg_files.append(qtpyvcp.DEFAULT_CONFIG_FILE)
    config = load_config_files(*cfg_files)
    # add the YAML file dir to path so can import relative modules
    sys.path.insert(0, os.path.dirname(os.path.dirname(yaml_file)))
    launch_application(opts, config)
コード例 #4
0
def run(opts, config_file=None):
    """VCP Entry Point

    This method is used by individual VCPs to launch QtPyVCP. This
    method should NOT be called directly. Options are generated either
    from a specification in the VCP, or from a generic fallback generated
    by the `opt_parser` utility.

    Args:
        opts (OptDict) : Dictionary of command line options as generated
            by the opt_parser utility.
        config_file (str, optional) : A YAML format config file to load.
            If `config_file` is not None it will be merged with any other
            config files and the VCP will be loaded from that info, else
            the VCP will be loaded solely from the options passed in the
            options dict.
    """
    from qtpyvcp.utilities.opt_parser import apply_opts

    # apply command line options
    apply_opts(opts)

    if config_file is None:
        # we are probably running from a entry point or a bare .ui file
        from qtpyvcp.app.launcher import load_vcp
        load_vcp(opts)

    else:
        # almost certainly being called from a VCP's __init__.py file

        # list of YAML config files, in order of highest to lowest priority
        config_files = list()

        # cmd line or INI files should have highest priority
        if opts.config_file is not None:
            config_files.append(opts.config_file)

        # env files should have second highest priority
        env_cfgs = os.getenv('VCP_CONFIG_FILES')
        if env_cfgs is not None:
            config_files.extend(env_cfgs.strip(':').split(':'))

        # VCP specific config files
        config_files.append(config_file)

        # default config file has lowest priority
        config_files.append(qtpyvcp.DEFAULT_CONFIG_FILE)

        from qtpyvcp.utilities.config_loader import load_config_files
        config = load_config_files(*config_files)

        from qtpyvcp.app.launcher import launch_application
        launch_application(opts, config)
コード例 #5
0
ファイル: editvcp.py プロジェクト: silopolis/qtpyvcp
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))
コード例 #6
0
ファイル: editvcp.py プロジェクト: kcjengr/qtpyvcp
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')
コード例 #7
0
#import pydevd;pydevd.settrace()

base_ini_file = os.environ['INI_FILE_NAME']
ini_file_name = normalizePath(path=base_ini_file,
                              base=os.getenv('CONFIG_DIR', '~/'))
# ini_file_name = normalizePath(path='xyz.ini', base=os.getenv('CONFIG_DIR', '~/'))
INI_FILE = linuxcnc.ini(ini_file_name)
UNITS = INI_FILE.find('TRAJ', 'LINEAR_UNITS')
MACHINE = INI_FILE.find('PLASMAC', 'MACHINE')
PRESSURE = INI_FILE.find('PLASMAC', 'PRESSURE')

custom_config_yaml_file_name = normalizePath(path='custom_config.yml',
                                             base=os.getenv(
                                                 'CONFIG_DIR', '~/'))
cfg_dic = load_config_files(custom_config_yaml_file_name)

# we assume that things are sqlit unless we find custom_config.yml
# pointing to different type of DB
try:
    db_connect_str = cfg_dic['data_plugins']['plasmaprocesses']['kwargs'][
        'connect_string']
    # if no error then we found a db connection string. Use it.
    PLASMADB = PlasmaProcesses(connect_string=db_connect_str)
except:
    # no connect string found OR can't connect so assume sqlite on local machine
    PLASMADB = PlasmaProcesses(db_type='sqlite')

TOOLS = {}