Commits

Anonymous committed b3ef519

move everything one level up

Comments (0)

Files changed (4)

test/test_wmctrl.py

+import py
+import subprocess
+import time
+from wmctrl import Window
+
+class Xchild(object):
+    cmd = None
+    ARGS = []
+    sleep = 0.1
+
+    def __init__(self, *args):
+        arglist = [self.CMD, '-name', self.NAME] + list(args)
+        self.child = subprocess.Popen(arglist)
+        time.sleep(self.sleep)
+
+    def __del__(self):
+        self.child.kill()
+
+class Apps:
+    class get_xclock(Xchild):
+        CMD = 'xclock'
+        NAME = 'xclock-for-pytest'
+
+    class get_xfontsel(Xchild):
+        CMD = 'xfontsel'
+        NAME = 'xfontsel-for-pytest'
+
+def get_win(name, *args):
+    get_app = getattr(Apps, 'get_%s' % name)        
+    xapp = get_app(*args)
+    win = Window.by_name(get_app.NAME)
+    return win[0], xapp
+
+def test_list():
+    xclock = Apps.get_xclock()
+    wins = Window.list()
+    names = [win.wm_name for win in wins]
+    assert xclock.NAME in names
+
+def test_attributes():
+    win, xclock = get_win('xclock', '-geometry', '100x200+0+0')
+    assert win.wm_name == xclock.NAME
+    assert win.wm_class == xclock.NAME + '.XClock'
+    assert win.w == 100
+    assert win.h == 200
+    # measure the width and the height of WM decorations
+    ofs_x = win.x
+    ofs_y = win.y
+    xclock.child.kill()
+    win, xclock = get_win('xclock', '-geometry', '+30+40')
+    assert win.x == 30 + ofs_x
+    assert win.y == 40 + ofs_y
+
+def test_activate():
+    orig = Window.get_active()
+    win, xfontsel = get_win('xfontsel', '-geometry', '+0+0')
+    win.activate()
+    time.sleep(0.5)
+    active = Window.get_active()
+    assert active.id == win.id
+    orig.activate()
+    time.sleep(0.5)
+    active = Window.get_active()
+    assert active.id == orig.id
+
+def test_resize_and_move():
+    win, xclock = get_win('xclock', '-geometry', '+0+0')
+    ofs_x = win.x
+    ofs_y = win.y
+    win.resize_and_move(10, 20, 30, 40)
+    win2 = Window.by_name(xclock.NAME)[0]
+    assert win.id == win2.id
+    assert win2.x == 10 + ofs_x
+    assert win2.y == 20 + ofs_y
+    assert win2.w == 30
+    assert win2.h == 40
+
+def check_geometry(geom):
+    win, xclock = get_win('xclock', '-geometry', geom)
+    win.resize_and_move(0, 0, 100, 200)
+    win.set_geometry(geom)
+    win2 = Window.by_name(xclock.NAME)[0]
+    assert win2.x == win.x
+    assert win2.y == win.y
+    assert win2.w == win.w
+    assert win2.h == win.h
+
+def test_geometry():
+    check_geometry('100x200+30+40')
+
+def test_geometry_negative():
+    py.test.skip('fixme')
+    check_geometry('100x200-30-40')
+
+import os
+from commands import getoutput
+from namedtuple import namedtuple
+
+BaseWindow = namedtuple('Window', 'id desktop pid x y w h wm_class host wm_name wm_window_role')
+
+class Window(BaseWindow):
+
+    @classmethod
+    def list(cls):
+        out = getoutput('wmctrl -l -G -p -x')
+        windows = []
+        for line in out.splitlines():
+            parts = line.split(None, len(Window._fields)-2)
+            parts = map(str.strip, parts)
+            parts[1:7] = map(int, parts[1:7])
+            parts.append(_wm_window_role(parts[0]))
+            windows.append(cls(*parts))
+        return windows
+
+    @classmethod
+    def by_name(cls, name):
+        return [win for win in cls.list() if win.wm_name == name]
+
+    @classmethod
+    def by_name_endswith(cls, name):
+        return [win for win in cls.list() if win.wm_name.endswith(name)]
+
+    @classmethod
+    def by_name_startswith(cls, name):
+        return [win for win in cls.list() if win.wm_name.startswith(name)]
+
+    @classmethod
+    def by_role(cls, role):
+        return [win for win in cls.list() if win.wm_window_role == role]
+
+    @classmethod
+    def by_class(cls, wm_class):
+        return [win for win in cls.list() if win.wm_class == wm_class]
+
+    @classmethod
+    def by_id(cls, id):
+        return [win for win in cls.list() if int(win.id, 16) == id]
+
+    @classmethod
+    def get_active(cls):
+        out = getoutput("xprop -root _NET_ACTIVE_WINDOW")
+        parts = out.split()
+        id = int(parts[-1], 16)
+        lst = cls.by_id(id)
+        if not lst:
+            return None
+        assert len(lst) == 1
+        return lst[0]
+
+    def activate(self):
+        os.system('wmctrl -id -a %s' % self.id)
+
+    def resize_and_move(self, x, y, w, h):
+        mvarg = '0,%d,%d,%d,%d' % (x, y, w, h)
+        os.system('wmctrl -i -r %s -e %s' % (self.id, mvarg))
+
+    def set_geometry(self, geometry):
+        dim, pos = geometry.split('+', 1)
+        w, h = map(int, dim.split('x'))
+        x, y = map(int, pos.split('+'))
+        self.resize_and_move(x, y, w, h)
+
+def _wm_window_role(winid):
+    out = getoutput('xprop -id %s WM_WINDOW_ROLE' % winid)
+    try:
+        _, value = out.split(' = ')
+    except ValueError:
+        # probably xprop returned an error
+        return ''
+    else:
+        return value.strip('"')
+

wmctrl/test/test_wmctrl.py

-import py
-import subprocess
-import time
-from wmctrl import Window
-
-class Xchild(object):
-    cmd = None
-    ARGS = []
-    sleep = 0.1
-
-    def __init__(self, *args):
-        arglist = [self.CMD, '-name', self.NAME] + list(args)
-        self.child = subprocess.Popen(arglist)
-        time.sleep(self.sleep)
-
-    def __del__(self):
-        self.child.kill()
-
-class Apps:
-    class get_xclock(Xchild):
-        CMD = 'xclock'
-        NAME = 'xclock-for-pytest'
-
-    class get_xfontsel(Xchild):
-        CMD = 'xfontsel'
-        NAME = 'xfontsel-for-pytest'
-
-def get_win(name, *args):
-    get_app = getattr(Apps, 'get_%s' % name)        
-    xapp = get_app(*args)
-    win = Window.by_name(get_app.NAME)
-    return win[0], xapp
-
-def test_list():
-    xclock = Apps.get_xclock()
-    wins = Window.list()
-    names = [win.wm_name for win in wins]
-    assert xclock.NAME in names
-
-def test_attributes():
-    win, xclock = get_win('xclock', '-geometry', '100x200+0+0')
-    assert win.wm_name == xclock.NAME
-    assert win.wm_class == xclock.NAME + '.XClock'
-    assert win.w == 100
-    assert win.h == 200
-    # measure the width and the height of WM decorations
-    ofs_x = win.x
-    ofs_y = win.y
-    xclock.child.kill()
-    win, xclock = get_win('xclock', '-geometry', '+30+40')
-    assert win.x == 30 + ofs_x
-    assert win.y == 40 + ofs_y
-
-def test_activate():
-    orig = Window.get_active()
-    win, xfontsel = get_win('xfontsel', '-geometry', '+0+0')
-    win.activate()
-    time.sleep(0.5)
-    active = Window.get_active()
-    assert active.id == win.id
-    orig.activate()
-    time.sleep(0.5)
-    active = Window.get_active()
-    assert active.id == orig.id
-
-def test_resize_and_move():
-    win, xclock = get_win('xclock', '-geometry', '+0+0')
-    ofs_x = win.x
-    ofs_y = win.y
-    win.resize_and_move(10, 20, 30, 40)
-    win2 = Window.by_name(xclock.NAME)[0]
-    assert win.id == win2.id
-    assert win2.x == 10 + ofs_x
-    assert win2.y == 20 + ofs_y
-    assert win2.w == 30
-    assert win2.h == 40
-
-def check_geometry(geom):
-    win, xclock = get_win('xclock', '-geometry', geom)
-    win.resize_and_move(0, 0, 100, 200)
-    win.set_geometry(geom)
-    win2 = Window.by_name(xclock.NAME)[0]
-    assert win2.x == win.x
-    assert win2.y == win.y
-    assert win2.w == win.w
-    assert win2.h == win.h
-
-def test_geometry():
-    check_geometry('100x200+30+40')
-
-def test_geometry_negative():
-    py.test.skip('fixme')
-    check_geometry('100x200-30-40')
-

wmctrl/wmctrl.py

-import os
-from commands import getoutput
-from namedtuple import namedtuple
-
-BaseWindow = namedtuple('Window', 'id desktop pid x y w h wm_class host wm_name wm_window_role')
-
-class Window(BaseWindow):
-
-    @classmethod
-    def list(cls):
-        out = getoutput('wmctrl -l -G -p -x')
-        windows = []
-        for line in out.splitlines():
-            parts = line.split(None, len(Window._fields)-2)
-            parts = map(str.strip, parts)
-            parts[1:7] = map(int, parts[1:7])
-            parts.append(_wm_window_role(parts[0]))
-            windows.append(cls(*parts))
-        return windows
-
-    @classmethod
-    def by_name(cls, name):
-        return [win for win in cls.list() if win.wm_name == name]
-
-    @classmethod
-    def by_name_endswith(cls, name):
-        return [win for win in cls.list() if win.wm_name.endswith(name)]
-
-    @classmethod
-    def by_name_startswith(cls, name):
-        return [win for win in cls.list() if win.wm_name.startswith(name)]
-
-    @classmethod
-    def by_role(cls, role):
-        return [win for win in cls.list() if win.wm_window_role == role]
-
-    @classmethod
-    def by_class(cls, wm_class):
-        return [win for win in cls.list() if win.wm_class == wm_class]
-
-    @classmethod
-    def by_id(cls, id):
-        return [win for win in cls.list() if int(win.id, 16) == id]
-
-    @classmethod
-    def get_active(cls):
-        out = getoutput("xprop -root _NET_ACTIVE_WINDOW")
-        parts = out.split()
-        id = int(parts[-1], 16)
-        lst = cls.by_id(id)
-        if not lst:
-            return None
-        assert len(lst) == 1
-        return lst[0]
-
-    def activate(self):
-        os.system('wmctrl -id -a %s' % self.id)
-
-    def resize_and_move(self, x, y, w, h):
-        mvarg = '0,%d,%d,%d,%d' % (x, y, w, h)
-        os.system('wmctrl -i -r %s -e %s' % (self.id, mvarg))
-
-    def set_geometry(self, geometry):
-        dim, pos = geometry.split('+', 1)
-        w, h = map(int, dim.split('x'))
-        x, y = map(int, pos.split('+'))
-        self.resize_and_move(x, y, w, h)
-
-def _wm_window_role(winid):
-    out = getoutput('xprop -id %s WM_WINDOW_ROLE' % winid)
-    try:
-        _, value = out.split(' = ')
-    except ValueError:
-        # probably xprop returned an error
-        return ''
-    else:
-        return value.strip('"')
-