Qtile command.Client Demonstration

First lets connect to the current running qtile instance.

In[1]:

from libqtile.command import Client
c = Client()

Lets see what commands we have available at the root of the command tree.

In[2]:

c.commands()

Out[2]:

['addgroup',
 'commands',
 'critical',
 'debug',
 'delgroup',
 'doc',
 'error',
 'eval',
 'execute',
 'findwindow',
 'function',
 'groups',
 'info',
 'internal_windows',
 'items',
 'list_widgets',
 'next_urgent',
 'nextlayout',
 'pause',
 'prevlayout',
 'qtile_info',
 'qtilecmd',
 'restart',
 'screens',
 'shutdown',
 'simulate_keypress',
 'spawn',
 'spawncmd',
 'status',
 'switch_groups',
 'switchgroup',
 'sync',
 'to_next_screen',
 'to_prev_screen',
 'to_screen',
 'togroup',
 'warning',
 'windows']

Lets find out what these do.

In[3]:

for i in c.commands():
    print c.doc(i)
    print "\n 8< ----------\n"

Out[3]:

addgroup(group)

 8< ----------

commands()
Returns a list of possible commands for this object.
Used by __qsh__ for command completion and online help.

 8< ----------

critical()Set log level to CRITICAL

 8< ----------

debug()Set log level to DEBUG

 8< ----------

delgroup(group)

 8< ----------

doc(name)
Returns the documentation for a specified command name. Used by
__qsh__ to provide online help.

 8< ----------

error()Set log level to ERROR

 8< ----------

eval(code)
Evaluates code in the same context as this function.
Return value is (success, result), success being a boolean and
result being a string representing the return value of eval, or
None if exec was used instead.

 8< ----------

execute(cmd, args)
Executes the specified command, replacing the current process.


 8< ----------

findwindow(prompt='window: ', widget='prompt')

 8< ----------

function(function)Call a function with qtile instance as argument

 8< ----------

groups()
Return a dictionary containing information for all groups.

Example:

    groups()

 8< ----------

info()Set log level to INFO

 8< ----------

internal_windows()
Return info for each internal window (bars, for example).

 8< ----------

items(name)
Returns a list of contained items for the specified name. Used by
__qsh__ to allow navigation of the object graph.

 8< ----------

list_widgets()
List of all addressible widget names.

 8< ----------

next_urgent()

 8< ----------

nextlayout(group=None)
Switch to the next layout.

:group Group name. If not specified, the current group is assumed.

 8< ----------

pause()Drops into pdb

 8< ----------

prevlayout(group=None)
Switch to the prev layout.

:group Group name. If not specified, the current group is assumed.

 8< ----------

qtile_info()
Returns a dictionary of info on the Qtile instance.

 8< ----------

qtilecmd(prompt='command: ', widget='prompt', messenger='xmessage')
Execute a Qtile command using the client syntax.
Tab completeion aids navigation of the command tree.

prompt: Text to display at the prompt (default: "command: ").
widget: Name of the prompt widget (default: "prompt").
messenger: command to display output (default: "xmessage").
    Set this to None to disable.

 8< ----------

restart()
Restart qtile using the execute command.

 8< ----------

screens()
Return a list of dictionaries providing information on all screens.

 8< ----------

shutdown()
Quit Qtile.

 8< ----------

simulate_keypress(modifiers, key)
Simulates a keypress on the focused window.

:modifiers A list of modifier specification strings. Modifiers can
be one of "shift", "lock", "control" and "mod1" - "mod5".
:key Key specification.

Examples:

    simulate_keypress(["control", "mod2"], "k")

 8< ----------

spawn(cmd)
Run cmd in a shell.

Example:

    spawn("firefox")

 8< ----------

spawncmd(prompt='spawn: ', widget='prompt', command='%s', complete='cmd')
Spawn a command using a prompt widget, with tab-completion.

prompt: Text with which to prompt user (default: "spawn: ").
widget: Name of the prompt widget (default: "prompt").
command: command template (default: "%s").
complete: Tab completion function (default: "cmd")


 8< ----------

status()
Return "OK" if Qtile is running.

 8< ----------

switch_groups(groupa, groupb)
Switch position of groupa to groupb

 8< ----------

switchgroup(prompt='group: ', widget='prompt')

 8< ----------

sync()
Sync the X display. Should only be used for development.

 8< ----------

to_next_screen()
Move to next screen

 8< ----------

to_prev_screen()
Move to the previous screen

 8< ----------

to_screen(n)
Warp focus to screen n, where n is a 0-based screen number.

Example:

    to_screen(0)

 8< ----------

togroup(prompt='group: ', widget='prompt')
Move current window to the selected group in a propmt widget

prompt: Text with which to prompt user.
widget: Name of the prompt widget (default: "prompt").

 8< ----------

warning()Set log level to WARNING

 8< ----------

windows()
Return info for each client window.

 8< ----------

hmm, some docstrings could use some TLC. Patches Welcome!

In[4]:

c.windows()

Out[4]:

[{'float_info': {'h': 266, 'w': 482, 'x': 0, 'y': 18},
  'floating': False,
  'fullscreen': False,
  'group': 's',
  'height': 582,
  'id': 29360132,
  'maximized': False,
  'minimized': False,
  'name': 'craig@craig-eee:~/notebook/qtile',
  'width': 1024,
  'x': 0,
  'y': 18},
 {'float_info': {'h': 582, 'w': 1024, 'x': 0, 'y': 18},
  'floating': False,
  'fullscreen': False,
  'group': 'a',
  'height': 582,
  'id': 16777220,
  'maximized': False,
  'minimized': False,
  'name': 'craig@craig-eee:~/dev/blog',
  'width': 1024,
  'x': 0,
  'y': 18},
 {'float_info': {'h': 266, 'w': 482, 'x': 0, 'y': 18},
  'floating': False,
  'fullscreen': False,
  'group': 'hn',
  'height': 582,
  'id': 31457284,
  'maximized': False,
  'minimized': False,
  'name': 'Hacker News',
  'width': 1024,
  'x': 0,
  'y': 18},
 {'float_info': {'h': 582, 'w': 1024, 'x': 0, 'y': 18},
  'floating': False,
  'fullscreen': False,
  'group': 'www',
  'height': 582,
  'id': 25165941,
  'maximized': False,
  'minimized': False,
  'name': 'Client Demo - Mozilla Firefox',
  'width': 1024,
  'x': 0,
  'y': 18},
 {'float_info': {'h': 266, 'w': 482, 'x': 0, 'y': 18},
  'floating': False,
  'fullscreen': False,
  'group': 'irc',
  'height': 582,
  'id': 20971524,
  'maximized': False,
  'minimized': False,
  'name': 'weechat 0.4.0',
  'width': 1024,
  'x': 0,
  'y': 18},
 {'float_info': {'h': 1, 'w': 1, 'x': -1, 'y': -1},
  'floating': False,
  'fullscreen': False,
  'group': None,
  'height': 1,
  'id': 10485817,
  'maximized': False,
  'minimized': False,
  'name': '<no name>',
  'width': 1,
  'x': -1,
  'y': -1},
 {'float_info': {'h': 14, 'w': 14, 'x': 0, 'y': 0},
  'floating': False,
  'fullscreen': False,
  'group': None,
  'height': 14,
  'id': 12583166,
  'maximized': False,
  'minimized': False,
  'name': '<no name>',
  'width': 14,
  'x': 764,
  'y': 2}]

In[5]:

c.screens()

Out[5]:

[{'gaps': {'bottom': None,
   'left': None,
   'right': None,
   'top': (0, 0, 1024, 18)},
  'group': 'www',
  'height': 600,
  'index': 0,
  'width': 1024,
  'x': 0,
  'y': 0}]

In[6]:

c.groups()

Out[6]:

{'a': {'floating_info': {'clients': [], 'group': 'a', 'name': 'floating'},
  'focus': 'craig@craig-eee:~/dev/blog',
  'layout': 'max',
  'name': 'a',
  'screen': None,
  'windows': ['craig@craig-eee:~/dev/blog']},
 'd': {'floating_info': {'clients': [], 'group': 'd', 'name': 'floating'},
  'focus': None,
  'layout': 'max',
  'name': 'd',
  'screen': None,
  'windows': []},
 'f': {'floating_info': {'clients': [], 'group': 'f', 'name': 'floating'},
  'focus': None,
  'layout': 'max',
  'name': 'f',
  'screen': None,
  'windows': []},
 'g': {'floating_info': {'clients': [], 'group': 'g', 'name': 'floating'},
  'focus': None,
  'layout': 'max',
  'name': 'g',
  'screen': None,
  'windows': []},
 'hn': {'floating_info': {'clients': [], 'group': 'hn', 'name': 'floating'},
  'focus': 'Hacker News',
  'layout': 'max',
  'name': 'hn',
  'screen': None,
  'windows': ['Hacker News']},
 'irc': {'floating_info': {'clients': [], 'group': 'irc', 'name': 'floating'},
  'focus': 'weechat 0.4.0',
  'layout': 'max',
  'name': 'irc',
  'screen': None,
  'windows': ['weechat 0.4.0']},
 's': {'floating_info': {'clients': [], 'group': 's', 'name': 'floating'},
  'focus': 'craig@craig-eee:~/notebook/qtile',
  'layout': 'max',
  'name': 's',
  'screen': None,
  'windows': ['craig@craig-eee:~/notebook/qtile']},
 'www': {'floating_info': {'clients': [], 'group': 'www', 'name': 'floating'},
  'focus': 'Client Demo - Mozilla Firefox',
  'layout': 'max',
  'name': 'www',
  'screen': 0,
  'windows': ['Client Demo - Mozilla Firefox']}}

In[7]:

c.bar['top'].info()

Out[7]:

{'position': 'top',
 'widgets': [{'name': 'GroupBox', 'offset': 0, 'width': 126},
  {'name': 'Sep', 'offset': 126, 'width': 1},
  {'name': 'CurrentLayout', 'offset': 127, 'width': 29},
  {'name': 'Sep', 'offset': 156, 'width': 1},
  {'name': 'Prompt', 'offset': 157, 'width': 0},
  {'name': 'TextBox', 'offset': 157, 'width': 0},
  {'name': 'Notify', 'offset': 157, 'width': 0},
  {'name': 'WindowName', 'offset': 157, 'width': 573},
  {'name': 'Sep', 'offset': 730, 'width': 1},
  {'name': 'Volume', 'offset': 731, 'width': 29},
  {'name': 'Systray', 'offset': 760, 'width': 18},
  {'name': 'Battery', 'offset': 778, 'width': 36},
  {'name': 'She', 'offset': 814, 'width': 50},
  {'name': 'CPUGraph', 'offset': 864, 'width': 20},
  {'name': 'MemoryGraph', 'offset': 884, 'width': 20},
  {'name': 'Clock', 'offset': 904, 'width': 120}],
 'width': 1024,
 'window': 10485779}

In[8]:

c.items('group')

Out[8]:

(True, ['a', 'www', 'd', 'g', 'f', 's', 'hn', 'irc'])

OK, so what about internal stuff.

In[9]:

c.eval('self.groupMap')

Out[9]:

(True,
 "{'a': <libqtile.group._Group object at 0xa48f56c>, 'www': <libqtile.group._Group object at 0xa3e94ac>, 'd': <libqtile.group._Group object at 0xa49b24c>, 'g': <libqtile.group._Group object at 0xa49b90c>, 'f': <libqtile.group._Group object at 0xa49b56c>, 's': <libqtile.group._Group object at 0xa499e8c>, 'hn': <libqtile.group._Group object at 0xa3edacc>, 'irc': <libqtile.group._Group object at 0xa3e9ccc>}")

In[10]:

c.eval('self.config.__dict__')

Out[10]:

(True,
 "{'fname': '/home/craig/.config/qtile/config.py', 'keys': [Key(['mod4'], x), Key(['mod4'], Tab), Key(['mod4', 'mod1'], Tab), Key(['mod4'], grave), Key(['mod4'], 1), Key(['mod4', 'shift'], 1), Key(['mod4'], 2), Key(['mod4', 'shift'], 2), Key(['mod4'], 3), Key(['mod4', 'shift'], 3), Key(['mod4'], Left), Key(['mod4'], Right), Key(['mod4', 'control'], Left), Key(['mod4', 'control'], Right), Key(['mod4'], Up), Key(['mod4'], Down), Key(['mod4', 'mod1'], Up), Key(['mod4', 'mod1'], Down), Key(['mod4'], h), Key(['mod4'], l), Key(['mod4'], j), Key(['mod4'], k), Key(['mod4'], v), Key(['mod4'], F12), Key(['mod4', 'shift'], l), Key(['mod4', 'shift'], h), Key(['mod4', 'shift'], Return), Key(['mod4', 'shift'], space), Key(['mod4', 'shift'], k), Key(['mod4', 'shift'], j), Key(['mod4', 'control'], l), Key(['mod4', 'control'], h), Key(['mod4', 'control'], k), Key(['mod4', 'control'], j), Key(['mod4'], Return), Key(['mod4'], backslash), Key(['mod4'], space), Key(['mod4'], n), Key(['mod4', 'mod1'], n), Key(['mod4', 'mod1'], m), Key(['mod4'], BackSpace), Key([], XF86AudioRaiseVolume), Key([], XF86AudioLowerVolume), Key([], XF86AudioMute), Key(['mod4'], period), Key(['mod4'], comma), Key(['mod4'], a), Key(['mod4', 'shift'], a), Key(['mod4'], s), Key(['mod4', 'shift'], s), Key(['mod4'], d), Key(['mod4', 'shift'], d), Key(['mod4'], f), Key(['mod4', 'shift'], f), Key(['mod4'], g), Key(['mod4', 'shift'], g), Key(['mod4'], q), Key(['mod4', 'control'], q), Key(['mod4', 'shift'], q), Key(['mod4', 'mod1'], q), Key(['mod4'], t), Key(['mod4', 'shift'], t), Key(['mod4'], w), Key(['mod4', 'control'], w), Key(['mod4', 'shift'], w), Key(['mod4', 'mod1'], w), Key(['mod4'], r), Key(['mod4', 'shift'], r), Key(['mod4'], e), Key(['mod4', 'control'], e), Key(['mod4', 'shift'], e), Key(['mod4', 'mod1'], e)], 'dgroups_app_rules': [<libqtile.config.Rule object at 0xa49bc2c>, <libqtile.config.Rule object at 0xa49bccc>, <libqtile.config.Rule object at 0xa49bd2c>, <libqtile.config.Rule object at 0xa49bd0c>, <libqtile.config.Rule object at 0xa49bcec>], 'follow_mouse_focus': False, 'screens': [<libqtile.config.Screen object at 0xa475f2c>, <libqtile.config.Screen object at 0xa475f0c>, <libqtile.config.Screen object at 0xa475fac>], 'dgroups_key_binder': None, 'layouts': [<libqtile.layout.max.Max object at 0xa47558c>, <libqtile.layout.stack.Stack object at 0xa47564c>, <libqtile.layout.tile.Tile object at 0xa4756cc>, <libqtile.layout.tree.TreeTab object at 0xa47578c>, <libqtile.layout.ratiotile.RatioTile object at 0xa47580c>, <libqtile.layout.xmonad.MonadTall object at 0xa4758cc>, <libqtile.layout.zoomy.Zoomy object at 0xa47594c>, <libqtile.layout.floating.Floating object at 0xa4759ac>], 'floating_layout': <libqtile.layout.floating.Floating object at 0xa475a8c>, 'groups': [<libqtile.config.Group object at 0xa475dec>, <libqtile.config.Group object at 0xa48012c>, <libqtile.config.Group object at 0xa4802ec>, <libqtile.config.Group object at 0xa4804ac>, <libqtile.config.Group object at 0xa48066c>, <libqtile.config.Group object at 0xa480fac>, <libqtile.config.Group object at 0xa4831cc>, <libqtile.config.Group object at 0xa48352c>, <libqtile.config.Group object at 0xa48372c>, <libqtile.config.Group object at 0xa483a8c>], 'widget_defaults': {'padding': 4, 'margin_y': 1, 'margin_x': 1, 'fontshadow': '000000', 'font': 'ProFont', 'margin': 0}, 'main': <function main at 0xa46ab8c>, 'mouse': [Drag(['mod4'], Button1), Drag(['mod4'], Button3), Click(['mod4'], Button2)], 'cursor_warp': False, 'auto_fullscreen': True}")

In[11]:

c.eval('[x.name for x in self.groups]')

Out[11]:

(True, "['a', 's', 'd', 'f', 'g', 'www', 'irc', 'hn']")

In[12]:

c.eval('self.currentWindow.name')

Out[12]:

(True, 'Client Demo - Mozilla Firefox')

OK, so lets start doing things.

In[15]:

starting_group = c.group.info()['name']
print starting_group
www

In[16]:

c.addgroup("this is a test")

Out[16]:

False

I need this because I have a hook that changes to new groups automatically ;-)

In[17]:

if starting_group != c.group.info()['name']:
    c.group[starting_group].toscreen()

In[18]:

c.groups()['this is a test']

Out[18]:

{'floating_info': {'clients': [],
  'group': 'this is a test',
  'name': 'floating'},
 'focus': None,
 'layout': 'max',
 'name': 'this is a test',
 'screen': None,
 'windows': []}

In[19]:

c.window.commands()

Out[19]:

['bring_to_front',
 'commands',
 'disable_floating',
 'disable_fullscreen',
 'disable_maximimize',
 'disable_minimize',
 'doc',
 'down_opacity',
 'enable_floating',
 'enable_fullscreen',
 'enable_maximize',
 'enable_minimize',
 'get_position',
 'get_size',
 'info',
 'inspect',
 'items',
 'kill',
 'match',
 'move_floating',
 'opacity',
 'resize_floating',
 'set_position_floating',
 'set_size_floating',
 'static',
 'toggle_floating',
 'toggle_fullscreen',
 'toggle_maximize',
 'toggle_minimize',
 'togroup',
 'up_opacity']

In[20]:

c.group.commands()

Out[20]:

['commands',
 'doc',
 'info',
 'items',
 'next_window',
 'prev_window',
 'setlayout',
 'switch_groups',
 'toscreen',
 'unminimise_all']

In[21]:

c.window.togroup("this is a test")
c.group["this is a test"].toscreen()
c.groups()['this is a test']

Out[21]:

{'floating_info': {'clients': [],
  'group': 'this is a test',
  'name': 'floating'},
 'focus': 'Client Demo - Mozilla Firefox',
 'layout': 'max',
 'name': 'this is a test',
 'screen': 0,
 'windows': ['Client Demo - Mozilla Firefox']}

In[22]:

c.window.info()

Out[22]:

{'float_info': {'h': 582, 'w': 1024, 'x': 0, 'y': 18},
 'floating': False,
 'fullscreen': False,
 'group': 'this is a test',
 'height': 582,
 'id': 25165941,
 'maximized': False,
 'minimized': False,
 'name': 'Client Demo - Mozilla Firefox',
 'width': 1024,
 'x': 0,
 'y': 18}

In[23]:

print c.window.doc('set_size_floating')
print c.window.doc('set_position_floating')

Out[23]:

set_size_floating(w, h)
Set window dimensions to w and h
set_position_floating(x, y)
Move window to x and y

In[24]:

from pprint import pprint
window_width = 800
window_height = 500
left = (c.screen.info()['width'] - window_width) / 2
top = (c.screen.info()['height']  - window_height) / 2
c.window.enable_floating()
c.window.set_size_floating(window_width, window_height)
c.window.set_position_floating(left, top)
pprint(c.window.info())

Out[24]:

{'float_info': {'h': 582, 'w': 1024, 'x': 112, 'y': 50},
 'floating': True,
 'fullscreen': False,
 'group': 'this is a test',
 'height': 500,
 'id': 25165941,
 'maximized': False,
 'minimized': False,
 'name': 'Client Demo - Mozilla Firefox',
 'width': 800,
 'x': 112,
 'y': 50}
Contents © 2013 Craig Barnes [FSF Associate Member] Creative Commons Licence - Powered by Nikola
Share