Exemple #1
0
def test_validate():
    xc = xcore.XCore()
    f = confreader.Config(os.path.join(tests_dir, "configs", "basic.py"), xc)
    f.load()
    f.keys[0].key = "nonexistent"
    with pytest.raises(confreader.ConfigError):
        f.validate()

    f.keys[0].key = "x"
    f = confreader.Config(os.path.join(tests_dir, "configs", "basic.py"), xc)
    f.load()
    f.keys[0].modifiers = ["nonexistent"]
    with pytest.raises(confreader.ConfigError):
        f.validate()
    f.keys[0].modifiers = ["shift"]
Exemple #2
0
def make_qtile(options):
    log_level = getattr(logging, options.log_level)
    init_log(log_level=log_level, log_color=stdout.isatty())
    kore = libqtile.backend.get_core(options.backend)

    if not path.isfile(options.configfile):
        try:
            makedirs(path.dirname(options.configfile), exist_ok=True)
            from shutil import copyfile
            default_config_path = path.join(path.dirname(__file__), "..",
                                            "resources", "default_config.py")
            copyfile(default_config_path, options.configfile)
            logger.info('Copied default_config.py to %s', options.configfile)
        except Exception as e:
            logger.exception('Failed to copy default_config.py to %s: (%s)',
                             options.configfile, e)

    config = confreader.Config(options.configfile, kore=kore)

    # XXX: the import is here because we need to call init_log
    # before start importing stuff
    from libqtile.core import session_manager
    return session_manager.SessionManager(
        kore,
        config,
        fname=options.socket,
        no_spawn=options.no_spawn,
        state=options.state,
    )
Exemple #3
0
def make_qtile(options):
    kore = libqtile.backend.get_core(options.backend)

    if not path.isfile(options.configfile):
        try:
            makedirs(path.dirname(options.configfile), exist_ok=True)
            from shutil import copyfile

            default_config_path = path.join(path.dirname(__file__), "..",
                                            "resources", "default_config.py")
            copyfile(default_config_path, options.configfile)
            logger.info("Copied default_config.py to %s", options.configfile)
        except Exception as e:
            logger.exception("Failed to copy default_config.py to %s: (%s)",
                             options.configfile, e)

    config = confreader.Config(options.configfile)

    # XXX: the import is here because we need to call init_log
    # before start importing stuff
    from libqtile.core.manager import Qtile

    return Qtile(
        kore,
        config,
        no_spawn=options.no_spawn,
        state=options.state,
        socket_path=options.socket,
    )
Exemple #4
0
def test_falls_back():
    f = confreader.Config(os.path.join(tests_dir, "configs", "basic.py"))
    f.load()

    # We just care that it has a default, we don't actually care what the
    # default is; don't assert anything at all about the default in case
    # someone changes it down the road.
    assert hasattr(f, "follow_mouse_focus")
Exemple #5
0
def check_config(args):
    print("checking qtile config file {}".format(args.configfile))

    # need to do all the checking in a tempdir because we need to write stuff
    # for stubtest
    with tempfile.TemporaryDirectory() as tempdir:
        tmp_path = path.join(tempdir, "config.py")
        shutil.copy(args.configfile, tmp_path)

        # are the top level config variables the right type?
        type_check_config_vars(tempdir, "config")

        # are arguments passed to qtile APIs correct?
        type_check_config_args(tmp_path)

    # can we load the config?
    config = confreader.Config(args.configfile)
    config.load()
    config.validate()
    print("config file can be loaded by qtile")
Exemple #6
0
def check_config(args):
    print("checking qtile config file {}".format(args.configfile))

    # need to do all the checking in a tempdir because we need to write stuff
    # for stubtest
    with tempfile.TemporaryDirectory() as tempdir:
        shutil.copytree(path.dirname(args.configfile), tempdir, dirs_exist_ok=True)
        tmp_path = path.join(tempdir, path.basename(args.configfile))

        # are the top level config variables the right type?
        module_name = path.splitext(path.basename(args.configfile))[0]
        type_check_config_vars(tempdir, module_name)

        # are arguments passed to qtile APIs correct?
        type_check_config_args(tmp_path)

    # can we load the config?
    config = confreader.Config(args.configfile)
    config.load()
    config.validate()
    print("config file can be loaded by qtile")
Exemple #7
0
    def load_config(self):
        try:
            self.config.load()
            self.config.validate()
        except Exception as e:
            logger.exception('Error while reading config file (%s)', e)
            self.config = confreader.Config()
            from libqtile.widget import TextBox
            widgets = self.config.screens[0].bottom.widgets
            widgets.insert(0, TextBox('Config Err!'))

        if hasattr(self.core, "wmname"):
            self.core.wmname = getattr(self.config, "wmname", "qtile")

        self.dgroups = DGroups(self, self.config.groups, self.config.dgroups_key_binder)

        if self.config.widget_defaults:
            _Widget.global_defaults = self.config.widget_defaults
        if self.config.extension_defaults:
            _Extension.global_defaults = self.config.extension_defaults

        for installed_extension in _Extension.installed_extensions:
            installed_extension._configure(self)

        for i in self.groups:
            self.groups_map[i.name] = i

        for grp in self.config.groups:
            if isinstance(grp, ScratchPadConfig):
                sp = ScratchPad(grp.name, grp.dropdowns, grp.label)
                sp._configure([self.config.floating_layout],
                              self.config.floating_layout, self)
                self.groups.append(sp)
                self.groups_map[sp.name] = sp

        self.config.mouse += (Click([], "Button1", focus="after"),)
Exemple #8
0
def load_config(name):
    f = confreader.Config(configs_dir / name)
    f.load()
    return f
Exemple #9
0
def make_qtile():
    from argparse import ArgumentParser
    parser = ArgumentParser(
        description='A full-featured, pure-Python tiling window manager.',
        prog='qtile',
    )
    parser.add_argument(
        '--version',
        action='version',
        version=VERSION,
    )
    parser.add_argument(
        "-c",
        "--config",
        action="store",
        default=path.expanduser(
            path.join(getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile',
                      'config.py')),
        dest="configfile",
        help='Use the specified configuration file',
    )
    parser.add_argument("-s",
                        "--socket",
                        action="store",
                        default=None,
                        dest="socket",
                        help='Path of the Qtile IPC socket.')
    parser.add_argument("-n",
                        "--no-spawn",
                        action="store_true",
                        default=False,
                        dest="no_spawn",
                        help='Avoid spawning apps. (Used for restart)')
    parser.add_argument('-l',
                        '--log-level',
                        default='WARNING',
                        dest='log_level',
                        choices=('DEBUG', 'INFO', 'WARNING', 'ERROR',
                                 'CRITICAL'),
                        help='Set qtile log level')
    parser.add_argument(
        '--with-state',
        default=None,
        dest='state',
        help='Pickled QtileState object (typically used only internally)',
    )
    options = parser.parse_args()
    log_level = getattr(logging, options.log_level)
    init_log(log_level=log_level)
    kore = xcore.XCore()

    try:
        if not path.isfile(options.configfile):
            try:
                makedirs(path.dirname(options.configfile), exist_ok=True)
                from shutil import copyfile
                default_config_path = path.join(path.dirname(__file__), "..",
                                                "resources",
                                                "default_config.py")
                copyfile(default_config_path, options.configfile)
                logger.info('Copied default_config.py to %s',
                            options.configfile)
            except Exception as e:
                logger.exception(
                    'Failed to copy default_config.py to %s: (%s)',
                    options.configfile, e)

        config = confreader.Config.from_file(options.configfile, kore=kore)
    except Exception as e:
        logger.exception('Error while reading config file (%s)', e)
        config = confreader.Config()
        from libqtile.widget import TextBox
        widgets = config.screens[0].bottom.widgets
        widgets.insert(0, TextBox('Config Err!'))

    # XXX: the import is here because we need to call init_log
    # before start importing stuff
    from libqtile.core import session_manager
    return session_manager.SessionManager(
        kore,
        config,
        fname=options.socket,
        no_spawn=options.no_spawn,
        state=options.state,
    )
Exemple #10
0
def test_basic():
    f = confreader.Config(os.path.join(tests_dir, "configs", "basic.py"))
    f.load()
    assert f.keys
Exemple #11
0
def test_syntaxerr():
    f = confreader.Config(os.path.join(tests_dir, "configs", "syntaxerr.py"))
    with pytest.raises(confreader.ConfigError):
        f.load()
Exemple #12
0
def make_qtile():
    from argparse import ArgumentParser
    parser = ArgumentParser(
        description='A full-featured, pure-Python tiling window manager.',
        prog='qtile',
    )
    parser.add_argument(
        '--version',
        action='version',
        version=VERSION,
    )
    parser.add_argument(
        "-c",
        "--config",
        action="store",
        default=path.expanduser(
            path.join(getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile',
                      'config.py')),
        dest="configfile",
        help='Use the specified configuration file',
    )
    parser.add_argument("-s",
                        "--socket",
                        action="store",
                        default=None,
                        dest="socket",
                        help='Path to Qtile comms socket.')
    parser.add_argument("-n",
                        "--no-spawn",
                        action="store_true",
                        default=False,
                        dest="no_spawn",
                        help='Avoid spawning apps. (Used for restart)')
    parser.add_argument('-l',
                        '--log-level',
                        default='WARNING',
                        dest='log_level',
                        choices=('DEBUG', 'INFO', 'WARNING', 'ERROR',
                                 'CRITICAL'),
                        help='Set qtile log level')
    parser.add_argument(
        '--with-state',
        default=None,
        dest='state',
        help='Pickled QtileState object (typically used only internally)',
    )
    options = parser.parse_args()
    log_level = getattr(logging, options.log_level)
    init_log(log_level=log_level)

    try:
        config = confreader.Config.from_file(options.configfile)
    except Exception as e:
        logger.exception('Error while reading config file (%s)', e)
        config = confreader.Config()
        from libqtile.widget import TextBox
        widgets = config.screens[0].bottom.widgets
        widgets.insert(0, TextBox('Config Err!'))
    # XXX: the import is here becouse we need to call init_log
    # before start importing stuff
    from libqtile import manager
    return manager.Qtile(
        config,
        fname=options.socket,
        no_spawn=options.no_spawn,
        state=options.state,
    )