~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to strigiclient/lib/searchclient/gtkgui.py

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2011-09-20 08:50:25 UTC
  • mto: (1.1.20 upstream) (5.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110920085025-wszfu6x8rshrjq0e
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import pygtk
 
4
pygtk.require('2.0')
 
5
import gtk
 
6
 
 
7
class HelloWorld:
 
8
 
 
9
    # This is a callback function. The data arguments are ignored
 
10
    # in this example. More on callbacks below.
 
11
    def hello(self, widget, data=None):
 
12
        print "Hello World"
 
13
 
 
14
    def delete_event(self, widget, event, data=None):
 
15
        # If you return FALSE in the "delete_event" signal handler,
 
16
        # GTK will emit the "destroy" signal. Returning TRUE means
 
17
        # you don't want the window to be destroyed.
 
18
        # This is useful for popping up 'are you sure you want to quit?'
 
19
        # type dialogs.
 
20
        print "delete event occurred"
 
21
 
 
22
        # Change FALSE to TRUE and the main window will not be destroyed
 
23
        # with a "delete_event".
 
24
        return False
 
25
 
 
26
    def destroy(self, widget, data=None):
 
27
        print "destroy signal occurred"
 
28
        gtk.main_quit()
 
29
 
 
30
    def __init__(self):
 
31
        # create a new window
 
32
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 
33
        self.window.connect("delete_event", self.delete_event)
 
34
        self.window.connect("destroy", self.destroy)
 
35
        self.window.set_border_width(0)
 
36
 
 
37
        # create a layout
 
38
        table = gtk.Table(2, 1, True)
 
39
        self.window.add(table)
 
40
 
 
41
        # create a textentry object
 
42
        self.textentry = gtk.Entry(max=0)
 
43
        self.textentry.connect("changed", self.enter_callback, self.textentry)
 
44
        table.attach(self.textentry, 0, 1, 0, 1)
 
45
 
 
46
        # Creates a new button with the label "Hello World".
 
47
        self.textview = gtk.TextView()
 
48
    
 
49
        # When the button receives the "clicked" signal, it will call the
 
50
        # function hello() passing it None as its argument.  The hello()
 
51
        # function is defined above.
 
52
        #self.button.connect("clicked", self.hello, None)
 
53
    
 
54
        # This will cause the window to be destroyed by calling
 
55
        # gtk_widget_destroy(window) when "clicked".  Again, the destroy
 
56
        # signal could come from here, or the window manager.
 
57
        #self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
 
58
    
 
59
        # This packs the button into the window (a GTK container).
 
60
        table.attach(self.textview, 0, 1, 1, 2)
 
61
    
 
62
        # The final step is to display this newly created widgets.
 
63
        self.textentry.show()
 
64
        self.textview.show()
 
65
        table.show()
 
66
        self.window.show()
 
67
 
 
68
    def enter_callback(self, widget, entry):
 
69
        text = entry.get_text()
 
70
        buffer = self.textview.get_buffer()
 
71
        #tag = buffer.create_tag("hyperlink", foreground='blue')
 
72
        #tag.connect('event', self.hyperlink_handler)
 
73
        buffer.set_text("")
 
74
        buffer.insert_at_cursor(text)
 
75
        buffer.insert_at_cursor("\n")
 
76
        buffer.insert_at_cursor(text)
 
77
 
 
78
    def hyperlink_handler(tag, textview, event, iter):
 
79
        if event.type == gtk.gdk.BUTTON_RELEASE:
 
80
            print tag
 
81
 
 
82
    def main(self):
 
83
        # All PyGTK applications must have a gtk.main(). Control ends here
 
84
        # and waits for an event to occur (like a key press or mouse event).
 
85
        gtk.main()
 
86
 
 
87
# If the program is run directly or passed as an argument to the python
 
88
# interpreter then create a HelloWorld instance and show it
 
89
if __name__ == "__main__":
 
90
    hello = HelloWorld()
 
91
    hello.main()