AUTO_LT_SYNC
[tore.git] / pytx / test.py
blob3e06a69ae32fab96222ca1134256ac6791f43b3d
1 #!/usr/bin/python
2 import pytx, traceback
3 from random import uniform
4 from time import sleep
5 from sys import stderr as err
7 def log(x):
8 print >> err, str((x))
10 def test(f):
11 def wrapper(*args, **kwargs):
12 try: return f(*args, **kwargs)
13 except:
14 traceback.print_exc()
15 log("error: " + str(f))
16 return wrapper
18 # FIXME: make fail nicely if text_cb are not defined
19 class Temp(pytx.List):
20 def __init__(self, flags):
21 pytx.List.__init__(self, flags)
23 def text_cb(self, data):
24 return [str(i) for i in data]
26 @test
27 def idle_cb(self, bla = False):
28 if bla:
29 for i in range(100):
30 self.add(i, [chr(int(uniform(97,102))), "penny smells", i])
31 self.sort()
32 self.draw()
34 @test
35 def bind_cb(self, ch, key):
36 if ch == 100: pass
39 cols, ascd = self.sort_get()
40 if 0 < ch-48 < len(self.widths) + 1:
41 self.sort_set(ch-49, ascd)
42 if ch-48 == 0:
43 self.sort_set(cols, not ascd)
44 self.sort()
45 self.draw()
46 self.draw()
48 @test
49 def rsze_cb(self):
50 self.widths_set([5,15,5])
51 self.titles_set(["chars", "strings", "ints"])
53 def test1():
54 b1 = pytx.Box(pytx.ROOT|pytx.VERT|pytx.BORDER)
55 b2 = pytx.Box(pytx.HORZ|pytx.BORDER)
56 l1 = Temp(pytx.FOCUS|pytx.SCROLL|pytx.TITLES|pytx.HIGHLIGHT|pytx.SEPARATOR|pytx.BORDER)
57 l2 = Temp(pytx.BORDER)
58 l3 = Temp(pytx.BORDER)
59 b1.add(l1)
60 b1.add(b2)
61 b2.add(l2)
62 b2.add(l3)
63 pytx.adjust()
65 l1.idle_cb(bla=True)
66 l2.idle_cb()
68 pytx.operate()
70 if __name__ == "__main__":
71 pytx.init()
72 test1()
73 pytx.free()