finch/libgnt/pygnt/test.py

Sat, 28 Jul 2007 11:16:05 +0000

author
Sadrul Habib Chowdhury <sadrul@pidgin.im>
date
Sat, 28 Jul 2007 11:16:05 +0000
changeset 19173
467db4a9cc44
parent 18826
a276583c694c
child 19814
05ce6c570b47
permissions
-rwxr-xr-x

Add some more functions for GntTree. One point to note is that the key
for each row in a tree needs to be a GObject, which, really is quite simple
to do in python (examples coming up shortly).

There is a wrapper for gpointer, which I am going to remove shortly.

I also need to fix the install location. The way to go, I think, is to
change the configure script in libgnt/configure.ac. This involves checking
for python and doing things of that sort.

15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
1 #!/usr/bin/python
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
2 import gobject
15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
3 import gnt
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
4
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
5 class MyObject(gobject.GObject):
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
6 __gproperties__ = {
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
7 'mytype': (gobject.TYPE_INT, 'mytype', 'the type of the object',
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
8 0, 10000, 0, gobject.PARAM_READWRITE),
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
9 'string': (gobject.TYPE_STRING, 'string property', 'the string',
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
10 None, gobject.PARAM_READWRITE),
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
11 'gobject': (gobject.TYPE_OBJECT, 'object property', 'the object',
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
12 gobject.PARAM_READWRITE),
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
13 }
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
14
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
15 def __init__(self, type = 'string', value = None):
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
16 self.__gobject_init__()
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
17 self.set_property(type, value)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
18
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
19 def do_set_property(self, pspec, value):
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
20 if pspec.name == 'string':
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
21 self.string = value
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
22 self.type = gobject.TYPE_STRING
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
23 elif pspec.name == 'gobject':
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
24 self.gobject = value
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
25 self.type = gobject.TYPE_OBJECT
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
26 else:
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
27 raise AttributeError, 'unknown property %s' % pspec.name
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
28 def do_get_property(self, pspec):
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
29 if pspec.name == 'string':
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
30 return self.string
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
31 elif pspec.name == 'gobject':
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
32 return self.gobject
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
33 elif pspec.name == 'mytype':
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
34 return self.type
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
35 else:
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
36 raise AttributeError, 'unknown property %s' % pspec.name
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
37 gobject.type_register(MyObject)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
38
18826
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
39 def button_activate(button, tree):
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
40 list = tree.get_selection_text_list()
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
41 ent = tree.get_selection_data()
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
42 if ent.type == gobject.TYPE_STRING:
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
43 str = ""
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
44 for i in list:
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
45 str = str + i
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
46 entry.set_text("clicked!!!" + str)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
47 elif ent.type == gobject.TYPE_OBJECT:
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
48 ent.gobject.set_text("mwhahaha!!!")
15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
49
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
50 gnt.gnt_init()
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
51
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
52 win = gnt.Window()
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
53
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
54 entry = gnt.Entry("")
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
55 obj = MyObject()
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
56 obj.set_property('gobject', entry)
15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
57
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
58 win.add_widget(entry)
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
59 win.set_title("Entry")
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
60
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
61 button = gnt.Button("Click!")
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
62 win.add_widget(button)
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
63
18826
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
64 tree = gnt.Tree()
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
65 tree.set_property("columns", 1)
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
66 win.add_widget(tree)
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
67
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
68 # so random non-string values can be used as the key for a row in a GntTree!
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
69 last = None
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
70 for i in range(1, 100):
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
71 key = MyObject('string', str(i))
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
72 tree.add_row_after(key, [str(i)], None, last)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
73 last = key
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
74
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
75 tree.add_row_after(MyObject('gobject', entry), ["asd"], None, None)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
76 tree.add_row_after(MyObject('string', "b"), ["123"], MyObject('gobject', entry), None)
18826
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
77
a276583c694c Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15992
diff changeset
78 button.connect("activate", button_activate, tree)
15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
79
19173
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
80 tv = gnt.TextView()
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
81
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
82 win.add_widget(tv)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
83 tv.append_text_with_flags("What up!!", gnt.TEXT_FLAG_BOLD)
467db4a9cc44 Add some more functions for GntTree. One point to note is that the key
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18826
diff changeset
84
15992
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
85 win.show()
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
86
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
87 gnt.gnt_main()
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
88
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
89 gnt.gnt_quit()
76e7972b3ff9 python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
90

mercurial