Example #1
0
def get_wmctrl_output():
    """
    Parses the output of wmctrl and returns a list of ordered dicts.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -lGpx"
    lines = [line for line in process.get_simple_cmd_output(cmd).split("\n") if line]

    res = []
    for line in lines:
# 0x05e000c7  0 4402   2562 298  638  540  truecrypt.Truecrypt   jabba-uplink TrueCrypt
        pieces = line.split()
        d = OrderedDict()
        #d['wid'] = int(pieces[0], 16)  # converted to decimal
        d['wid'] = pieces[0]
        d['desktop'] = int(pieces[1])
        d['pid'] = int(pieces[2])
        d['geometry'] = [int(x) for x in pieces[3:7]]
        d['window_class'] = pieces[7]
        d['client_machine_name'] = pieces[8]
        d['window_title'] = ' '.join(pieces[9:])
        res.append(d)
    #
    return res
Example #2
0
def get_wmctrl_output():
    """
    Parses the output of wmctrl and returns a list of ordered dicts.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -lGpx"
    lines = [
        line for line in process.get_simple_cmd_output(cmd).split("\n") if line
    ]

    res = []
    for line in lines:
        # 0x05e000c7  0 4402   2562 298  638  540  truecrypt.Truecrypt   jabba-uplink TrueCrypt
        pieces = line.split()
        d = OrderedDict()
        #d['wid'] = int(pieces[0], 16)  # converted to decimal
        d['wid'] = pieces[0]
        d['desktop'] = int(pieces[1])
        d['pid'] = int(pieces[2])
        d['geometry'] = [int(x) for x in pieces[3:7]]
        d['window_class'] = pieces[7]
        d['client_machine_name'] = pieces[8]
        d['window_title'] = ' '.join(pieces[9:])
        res.append(d)
    #
    return res
Example #3
0
def activate_window_by_id(wid):
    """
    Put the focus on and activate the the window with the given ID.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    os.system('xdotool windowactivate {wid}'.format(wid=wid))
Example #4
0
def activate_window_by_id(wid):
    """
    Put the focus on and activate the the window with the given ID.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    os.system('xdotool windowactivate {wid}'.format(wid=wid))
Example #5
0
 def _decorator(fn):
     if not fs.which(fpath):
         print "Error: {f} doesn't exist".format(f=fpath)
         print "Traceback: {func}() in {src}".format(func=fn.__name__, src=__file__)
         sys.exit(1)
     #
     def step_func(*args, **kwargs):
         return fn(*args, **kwargs)
     return step_func
Example #6
0
def toggle_fullscreen(wid_hexa):
    """
    Toggle the given window to fullscreen.

    The window id is a hexa string.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -i -r {wid} -b toggle,maximized_vert,maximized_horz".format(wid=wid_hexa)
    os.system(cmd)
Example #7
0
def toggle_fullscreen(wid_hexa):
    """
    Toggle the given window to fullscreen.

    The window id is a hexa string.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -i -r {wid} -b toggle,maximized_vert,maximized_horz".format(
        wid=wid_hexa)
    os.system(cmd)
Example #8
0
def get_window_title_by_id(wid):
    assert fs.which("xwininfo"), "the program xwininfo was not found."
    #
    result = get_simple_cmd_output('xwininfo -id {id}'.format(id=wid))
    for line in StringIO(result):
        line = line.rstrip("\n")
        match = re.search(r'^xwininfo: Window id:.*"(.*)"$', line)
        if match:
            return match.group(1)
    #
    return None
Example #9
0
def get_window_title_by_id(wid):
    assert fs.which("xwininfo"), "the program xwininfo was not found."
    #
    result = get_simple_cmd_output('xwininfo -id {id}'.format(id=wid))
    for line in StringIO(result):
        line = line.rstrip("\n")
        match = re.search(r'^xwininfo: Window id:.*"(.*)"$', line)
        if match:
            return match.group(1)
    #
    return None
Example #10
0
def get_active_window_id(hexa=False):
    """
    Window ID of the active window.

    The return value is a string. By default, the ID is in decimal
    format. If hexa is True, the return value is hexadecimal.
    In both cases, the return value is a string.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    wid = get_simple_cmd_output('xdotool getactivewindow').strip()
    if not hexa:
        return wid
    else:
        return hex(int(wid))
Example #11
0
def get_active_window_id(hexa=False):
    """
    Window ID of the active window.

    The return value is a string. By default, the ID is in decimal
    format. If hexa is True, the return value is hexadecimal.
    In both cases, the return value is a string.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    wid = get_simple_cmd_output('xdotool getactivewindow').strip()
    if not hexa:
        return wid
    else:
        return hex(int(wid))
Example #12
0
def test_get_window_title_by_id():
    # TODO
    assert fs.which('xwininfo') is not None
Example #13
0
def test_get_window_title_by_id():
    # TODO
    assert fs.which('xwininfo') is not None
Example #14
0
def test_lock_screen():
    # TODO
    assert fs.which('gnome-screensaver-command') is not None
Example #15
0
def test_get_active_window_id():
    # TODO
    assert fs.which('xdotool') is not None
Example #16
0
def toggle_fullscreen():
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    wid = window.get_active_window_id(hexa=True)
    cmd = "wmctrl -i -r {wid} -b toggle,maximized_vert,maximized_horz".format(wid=wid)
    os.system(cmd)
Example #17
0
 def test_which(self):
     if sys.platform.startswith('linux'):
         cmd = 'bash'
         assert '/bin/bash' in fs.which(cmd)     # can be /usr/bin/bash too
     else:
         print "# test_which is passed on this podium (TODO)"
Example #18
0
def test_is_linux():
    if fs.which('bash') == '/bin/bash':
        assert platform.is_linux()
Example #19
0
def test_toggle_fullscreen():
    # TODO
    assert fs.which('wmctrl') is not None
def test_lock_screen():
    # TODO
    assert fs.which("gnome-screensaver-command") is not None
Example #21
0
def test_get_active_window_id():
    # TODO
    assert fs.which('xdotool') is not None
Example #22
0
def test_is_linux():
    if fs.which('bash') == '/bin/bash':
        assert podium.is_linux()
Example #23
0
def test_is_linux():
    if fs.which('bash') == '/bin/bash':
        assert podium.is_linux()
Example #24
0
 def test_which(self):
     if sys.platform.startswith('linux'):
         cmd = 'bash'
         assert '/bin/bash' in fs.which(cmd)     # can be /usr/bin/bash too
     else:
         print "# test_which is passed on this podium (TODO)"