File: example.py

package info (click to toggle)
herbstluftwm 0.9.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,164 kB
  • sloc: cpp: 20,691; python: 10,830; sh: 1,023; ansic: 622; makefile: 98
file content (35 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import herbstluftwm


def main(hlwm):
    hlwm.call('version')

    # if you pass a string to call, it will be tokenized automatically:
    hlwm.call('add new_tag')
    # but you can also pass a list to avoid whitespace issues:
    hlwm.call(['merge_tag', 'new_tag'])

    # hlwm.attr is a convenience wrapper for accessing attributes
    # 1. reading attributes
    old_name = hlwm.attr.tags.focus.name()
    print(f"The focused tag has the name '{old_name}'")
    # The attribute value is queried on (). Alternatively, string conversion
    # queries implicitly:
    print(f"The focused tag has the name '{hlwm.attr.tags.focus.name}'")

    # 2. writing attributes
    hlwm.attr.tags.focus.name = "TagFocus"
    # One can also use [...] notation, if needed:
    hlwm.attr.tags['by-name'].TagFocus.name = old_name

    # 3. creating attributes (attribute name must start with 'my_')
    hlwm.attr.tags.focus.my_altname = "Attribute Value"

    # the AttributeProxy objects can be used multiple times
    curtag = hlwm.attr.tags.focus
    curtag['my_other_attribute'] = 'value'
    assert curtag.my_other_attribute() == 'value'


if __name__ == '__main__':
    main(herbstluftwm.Herbstluftwm())