#!/usr/bin/env python # example paned.py import gtk class PanedExample: # Create the list of "messages" def create_list(self): # Create a new scrolled window, with scrollbars only if needed scrolled_window = gtk.GtkScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) # Create a new list and put it in the scrolled window list = gtk.GtkList() scrolled_window.add_with_viewport (list) list.show() # Add some messages to the window for i in range(10): buffer = "Message #%d" % i list_item = gtk.GtkListItem(buffer) list.add(list_item) list_item.show() return scrolled_window # Add some text to our text widget - this is a callback that is invoked # when our window is realized. We could also force our window to be # realized with gtk_widget_realize, but it would have to be part of a # hierarchy first def realize_text(self, text): text.freeze() text.insert(None, text.get_style().black, None, "From: pathfinder@nasa.gov\n" "To: mom@nasa.gov\n" "Subject: Made it!\n" "\n" "We just got in this morning. The weather has been\n" "great - clear but cold, and there are lots of fun sights.\n" "Sojourner says hi. See you soon.\n" " -Path\n") text.thaw() # Create a scrolled text area that displays a "message" def create_text(self): # Create a table to hold the text widget and scrollbars table = gtk.GtkTable(2, 2, gtk.FALSE) # Put a text widget in the upper left hand corner. Note the use of # SHRINK in the y direction text = gtk.GtkText() table.attach(text, 0, 1, 0, 1, gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND | gtk.SHRINK, 0, 0) text.show() # Put a HScrollbar in the lower left hand corner hscrollbar = gtk.GtkHScrollbar(text.get_hadjustment()) table.attach(hscrollbar, 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0) hscrollbar.show() # And a VScrollbar in the upper right vscrollbar = gtk.GtkVScrollbar(text.get_vadjustment()) table.attach(vscrollbar, 1, 2, 0, 1, gtk.FILL, gtk.EXPAND | gtk.FILL | gtk.SHRINK, 0, 0) vscrollbar.show() # Add a handler to put a message in the text widget when it is realized text.connect("realize", self.realize_text) return table def __init__(self): window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) window.set_title("Paned Windows") window.connect("destroy", gtk.mainquit) window.set_border_width(10) window.set_usize(450, 400) # create a vpaned widget and add it to our toplevel window vpaned = gtk.GtkVPaned() window.add(vpaned) vpaned.set_handle_size(10) vpaned.set_gutter_size(15) vpaned.show() # Now create the contents of the two halves of the window list = self.create_list() vpaned.add1(list) list.show() text = self.create_text() vpaned.add2(text) text.show() window.show() def main(): gtk.mainloop() return 0 if __name__ == "__main__": PanedExample() main()