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):
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?'
20
print "delete event occurred"
22
# Change FALSE to TRUE and the main window will not be destroyed
23
# with a "delete_event".
26
def destroy(self, widget, data=None):
27
print "destroy signal occurred"
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)
38
table = gtk.Table(2, 1, True)
39
self.window.add(table)
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)
46
# Creates a new button with the label "Hello World".
47
self.textview = gtk.TextView()
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)
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)
59
# This packs the button into the window (a GTK container).
60
table.attach(self.textview, 0, 1, 1, 2)
62
# The final step is to display this newly created widgets.
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)
74
buffer.insert_at_cursor(text)
75
buffer.insert_at_cursor("\n")
76
buffer.insert_at_cursor(text)
78
def hyperlink_handler(tag, textview, event, iter):
79
if event.type == gtk.gdk.BUTTON_RELEASE:
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).
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__":