finch/libgnt/pygnt/test.py

changeset 19173
467db4a9cc44
parent 18826
a276583c694c
child 19814
05ce6c570b47
equal deleted inserted replaced
18958:9655ffbc6c25 19173:467db4a9cc44
1 #!/usr/bin/python 1 #!/usr/bin/python
2 import gobject
2 import gnt 3 import gnt
3 4
5 class MyObject(gobject.GObject):
6 __gproperties__ = {
7 'mytype': (gobject.TYPE_INT, 'mytype', 'the type of the object',
8 0, 10000, 0, gobject.PARAM_READWRITE),
9 'string': (gobject.TYPE_STRING, 'string property', 'the string',
10 None, gobject.PARAM_READWRITE),
11 'gobject': (gobject.TYPE_OBJECT, 'object property', 'the object',
12 gobject.PARAM_READWRITE),
13 }
14
15 def __init__(self, type = 'string', value = None):
16 self.__gobject_init__()
17 self.set_property(type, value)
18
19 def do_set_property(self, pspec, value):
20 if pspec.name == 'string':
21 self.string = value
22 self.type = gobject.TYPE_STRING
23 elif pspec.name == 'gobject':
24 self.gobject = value
25 self.type = gobject.TYPE_OBJECT
26 else:
27 raise AttributeError, 'unknown property %s' % pspec.name
28 def do_get_property(self, pspec):
29 if pspec.name == 'string':
30 return self.string
31 elif pspec.name == 'gobject':
32 return self.gobject
33 elif pspec.name == 'mytype':
34 return self.type
35 else:
36 raise AttributeError, 'unknown property %s' % pspec.name
37 gobject.type_register(MyObject)
38
4 def button_activate(button, tree): 39 def button_activate(button, tree):
5 list = tree.get_selection_text_list() 40 list = tree.get_selection_text_list()
6 str = "" 41 ent = tree.get_selection_data()
7 for i in list: 42 if ent.type == gobject.TYPE_STRING:
8 str = str + i 43 str = ""
9 entry.set_text("clicked!!!" + str) 44 for i in list:
45 str = str + i
46 entry.set_text("clicked!!!" + str)
47 elif ent.type == gobject.TYPE_OBJECT:
48 ent.gobject.set_text("mwhahaha!!!")
10 49
11 gnt.gnt_init() 50 gnt.gnt_init()
12 51
13 win = gnt.Window() 52 win = gnt.Window()
14 53
15 entry = gnt.Entry("") 54 entry = gnt.Entry("")
55 obj = MyObject()
56 obj.set_property('gobject', entry)
16 57
17 win.add_widget(entry) 58 win.add_widget(entry)
18 win.set_title("Entry") 59 win.set_title("Entry")
19 60
20 button = gnt.Button("Click!") 61 button = gnt.Button("Click!")
25 win.add_widget(tree) 66 win.add_widget(tree)
26 67
27 # so random non-string values can be used as the key for a row in a GntTree! 68 # so random non-string values can be used as the key for a row in a GntTree!
28 last = None 69 last = None
29 for i in range(1, 100): 70 for i in range(1, 100):
30 tree.add_row_after(i, [str(i), ""], None, i-1) 71 key = MyObject('string', str(i))
31 tree.add_row_after(entry, ["asd"], None, None) 72 tree.add_row_after(key, [str(i)], None, last)
32 tree.add_row_after("b", ["123", ""], entry, None) 73 last = key
74
75 tree.add_row_after(MyObject('gobject', entry), ["asd"], None, None)
76 tree.add_row_after(MyObject('string', "b"), ["123"], MyObject('gobject', entry), None)
33 77
34 button.connect("activate", button_activate, tree) 78 button.connect("activate", button_activate, tree)
79
80 tv = gnt.TextView()
81
82 win.add_widget(tv)
83 tv.append_text_with_flags("What up!!", gnt.TEXT_FLAG_BOLD)
35 84
36 win.show() 85 win.show()
37 86
38 gnt.gnt_main() 87 gnt.gnt_main()
39 88

mercurial