Пример #1
0
    def __init__(self,
                 command: CommandInterface = None,
                 *,
                 current_node: GraphType = None) -> None:
        """An interactive client that resolves calls through the gives client

        Exposes the command graph API in such a way that it can be traversed
        directly on this object.  The command resolution for this object is
        done via the command interface.

        Parameters
        ----------
        command: CommandInterface
            The object that is used to resolve command graph calls, as well as
            navigate the command graph.
        current_node: CommandGraphNode
            The current node that is pointed to in the command graph.  If not
            specified, the command graph root is used.
        """
        if command is None:
            command = IPCCommandInterface(Client(find_sockfile()))
        self._command = command
        if current_node is None:
            self._current_node = CommandGraphRoot()  # type: GraphType
        else:
            self._current_node = current_node
Пример #2
0
def main() -> None:
    "Runs tool according to specified arguments."
    description = 'Simple tool to expose qtile.command functionality to shell.'
    epilog = textwrap.dedent('''\
    Examples:
     qtile-cmd
     qtile-cmd -o cmd
     qtile-cmd -o cmd -f prev_layout -i
     qtile-cmd -o cmd -f prev_layout -a 3 # prev_layout on group 3
     qtile-cmd -o group 3 -f focus_back''')
    fmt = argparse.RawDescriptionHelpFormatter

    parser = argparse.ArgumentParser(description=description,
                                     epilog=epilog,
                                     formatter_class=fmt)
    parser.add_argument('--object',
                        '-o',
                        dest='obj_spec',
                        nargs='+',
                        help='Specify path to object (space separated).  '
                        'If no --function flag display available commands.  '
                        'Use `cmd` to specify root command.')
    parser.add_argument('--function',
                        '-f',
                        default="help",
                        help='Select function to execute.')
    parser.add_argument('--args',
                        '-a',
                        nargs='+',
                        default=[],
                        help='Set arguments supplied to function.')
    parser.add_argument(
        '--info',
        '-i',
        action='store_true',
        help=
        'With both --object and --function args prints documentation for function.'
    )
    parser.add_argument("--socket", "-s", help='Path of the Qtile IPC socket.')
    args = parser.parse_args()

    if args.obj_spec:
        sock_file = args.socket or find_sockfile()
        ipc_client = Client(sock_file)
        cmd_object = IPCCommandInterface(ipc_client)
        cmd_client = InteractiveCommandClient(cmd_object)
        obj = get_object(cmd_client, args.obj_spec)

        if args.function == "help":
            print_commands("-o " + " ".join(args.obj_spec), obj)
        elif args.info:
            print(get_formated_info(obj, args.function, args=True,
                                    short=False))
        else:
            ret = run_function(obj, args.function, args.args)
            if ret is not None:
                pprint.pprint(ret)
    else:
        print_base_objects()
        sys.exit(1)
Пример #3
0
    def __init__(self,
                 command: CommandInterface = None,
                 *,
                 current_node: GraphType = None) -> None:
        """A client that resolves calls through the command object interface

        Exposes a similar API to the command graph, but performs resolution of
        objects.  Any navigation done on the command graph is resolved at the
        point it is invoked.  This command resolution is done via the command
        interface.

        Parameters
        ----------
        command: CommandInterface
            The object that is used to resolve command graph calls, as well as
            navigate the command graph.
        current_node: CommandGraphNode
            The current node that is pointed to in the command graph.  If not
            specified, the command graph root is used.
        """
        if command is None:
            command = IPCCommandInterface(Client(find_sockfile()))
        self._command = command
        if current_node is None:
            self._current_node = CommandGraphRoot()  # type: GraphType
        else:
            self._current_node = current_node
Пример #4
0
def test_do_cd(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("0") == 'layout[0]'
    assert sh.do_cd("..") == '/'
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("0/wibble") == 'No such path.'
Пример #5
0
def test_ls(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_ls("") == "bar/     group/   layout/  screen/  widget/  window/"
    assert sh.do_ls("layout") == "group/   window/  screen/  0/     "

    assert sh.do_cd("layout") == "layout"
    assert sh.do_ls("") == "group/   window/  screen/  0/     "
    assert sh.do_ls("screen") == "layout/  window/  bar/   "
Пример #6
0
def test_columnize(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.columnize(["one", "two"]) == "one  two"

    sh.termwidth = 1
    assert sh.columnize(["one", "two"], update_termwidth=False) == "one\ntwo"

    sh.termwidth = 15
    v = sh.columnize(["one", "two", "three", "four", "five"], update_termwidth=False)
    assert v == 'one    two  \nthree  four \nfive '
Пример #7
0
def test_call(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.process_line("status()") == "OK"

    v = sh.process_line("nonexistent()")
    assert v == "Command does not exist: nonexistent"

    v = sh.process_line("status(((")
    assert v == "Invalid command: status((("

    v = sh.process_line("status(1)")
    assert v.startswith("Command exception")
Пример #8
0
def test_complete(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh._complete("c", "c") == [
        "cd",
        "commands",
        "critical",
    ]

    assert sh._complete("cd l", "l") == ["layout/"]
    assert sh._complete("cd layout/", "layout/") == [
        "layout/" + x for x in ["group", "window", "screen", "0"]
    ]
    assert sh._complete("cd layout/", "layout/g") == ["layout/group/"]
Пример #9
0
def cmd_obj(args) -> None:
    "Runs tool according to specified arguments."

    if args.obj_spec:
        sock_file = args.socket or find_sockfile()
        ipc_client = Client(sock_file)
        cmd_object = IPCCommandInterface(ipc_client)
        cmd_client = InteractiveCommandClient(cmd_object)
        obj = get_object(cmd_client, args.obj_spec)

        if args.function == "help":
            print_commands("-o " + " ".join(args.obj_spec), obj)
        elif args.info:
            print(get_formated_info(obj, args.function, args=True, short=False))
        else:
            ret = run_function(obj, args.function, args.args)
            if ret is not None:
                pprint.pprint(ret)
    else:
        print_base_objects()
        sys.exit(1)
Пример #10
0
    def qtile(self):
        if self._qtile is None and qtile_support is True:
            self._qtile = CommandClient(
                command=IPCCommandInterface(Client(find_sockfile())))

        return self._qtile
Пример #11
0
def test_help(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_help("nonexistent").startswith("No such command")
    assert sh.do_help("help")
Пример #12
0
# SOFTWARE.
import nest_asyncio
nest_asyncio.apply()
from typing import List  # noqa: F401
import os
import sys
import subprocess

from libqtile.config import Key, Screen, Group, Drag, Click, Match
from libqtile.lazy import lazy
from libqtile import layout, hook, bar, widget
from libqtile.ipc import find_sockfile, Client 
from libqtile.command_client import InteractiveCommandClient 
from libqtile.command_interface import IPCCommandInterface                                                                    

client = InteractiveCommandClient(IPCCommandInterface(Client(find_sockfile())))

from helper import run
from controls import next_keyboard
from apperance import widget_defaults, extension_defaults
from apperance import top_bar, bottom_bar
from debug_logging import logger

# This has to be run this before screens are defined, so that it correctly picks up the order and resulotion
# run("xrandr --output DVI-D-1 --mode 1600x1200 --left-of HDMI-2 --output HDMI-2 --mode 2560x1080 --output HDMI-1 --mode 1920x1080 --right-of HDMI-2")

mod = "mod4"
alt = 'mod1'
username = "******"

def bring_group_to_front(group_name):
Пример #13
0
 def __init__(self):
     self.color = 0
     self.client = InteractiveCommandClient(
         IPCCommandInterface(IPCClient(find_sockfile())))
Пример #14
0
from libqtile.ipc import find_sockfile, Client as IPCClient
from libqtile.command_client import InteractiveCommandClient
from libqtile.command_interface import IPCCommandInterface

if __name__ == '__main__':
    client = InteractiveCommandClient(
        IPCCommandInterface(IPCClient(find_sockfile())))
    # does not work:
    print(client.display_kb())
    # print(getattr(client, 'display_kb')())