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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#!/usr/bin/env python
import unittest
import gtk
from kiwi.ui.delegates import Delegate, GladeDelegate
from utils import refresh_gui
class A:
def on_foo__clicked(self, *args):
self.x = "FOO in A"
class B:
def on_foo__clicked(self, *args):
self.x = "FOO in B"
def on_bar__clicked(self, *args):
self.y = "BAR in B"
class C:
def on_foo__clicked(self, *args):
self.x = "FOO in C"
class X(A,B,C):
def on_foo__clicked(self, *args):
self.x = "FOO in X"
class Y:
def on_foo__clicked(self, *args):
self.x = "FOO in Y"
class Foo(X,Y,Delegate):
widget = ["foo"]
def __init__(self):
self.win = gtk.Window()
self.foo = gtk.Button("CLICK ME AND BE HAPPY")
self.bar = gtk.Button("CLICK ME AND BE HAPPY")
v = gtk.VBox()
v.add(self.foo)
v.add(self.bar)
self.win.add(v)
self.x = self.y = "NOOO"
Delegate.__init__(self, toplevel=self.win,
delete_handler=self.quit_if_last)
def on_foo__clicked(self, *args):
self.x = "FOO in Foo"
def on_bar__clicked(self, *args):
self.y = "BAR in B"
class ClickCounter(Delegate):
"""In this delegate we count the number of clicks we do"""
def __init__(self):
self.win = gtk.Window()
self.button = gtk.Button('Click me!')
self.win.add(self.button)
Delegate.__init__(self, toplevel=self.win,
delete_handler=self.quit_if_last)
self.clicks = 0
def on_button__clicked(self, *args):
self.clicks += 1
class GladeClickCounter(GladeDelegate):
def __init__(self):
GladeDelegate.__init__(self, gladefile="simple_button",
delete_handler=self.quit_if_last)
self.clicks = 0
def on_button__clicked(self, *args):
self.clicks += 1
class DelegateTest(unittest.TestCase):
def testButtons(self):
f = Foo()
refresh_gui()
f.foo.clicked()
refresh_gui()
self.assertEqual(f.x, "FOO in Foo")
f.bar.clicked()
refresh_gui()
self.assertEqual(f.y, "BAR in B")
def testClickCounter(self):
clickcounter = ClickCounter()
refresh_gui()
# one for the boys
clickcounter.button.clicked()
self.assertEqual(clickcounter.clicks, 1)
# one for the girls
clickcounter.button.clicked()
self.assertEqual(clickcounter.clicks, 2)
def testClickCounterGlade(self):
clickcounter = GladeClickCounter()
refresh_gui()
# one for the boys
clickcounter.button.clicked()
self.assertEqual(clickcounter.clicks, 1)
# one for the girls
clickcounter.button.clicked()
self.assertEqual(clickcounter.clicks, 2)
if __name__ == '__main__':
unittest.main()
|