diff options
author | James Henstridge <james@daa.com.au> | 2002-01-24 13:18:29 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2002-01-24 13:18:29 +0000 |
commit | 9955b65b5c76cad3eae12de5598a3cbc80249c64 (patch) | |
tree | 139f03634f3d12d1f6fa63b76d5a4309e648596d /examples/pygtk-demo | |
parent | fadc94e6f6dedb49c0f8e4749228125dd1dc8bd9 (diff) | |
download | pygtk-9955b65b5c76cad3eae12de5598a3cbc80249c64.tar.gz |
add examples translated by Michelle Campeotto.
2002-01-24 James Henstridge <james@daa.com.au>
* examples/pygtk-demo/demos/colorsel.py:
* examples/pygtk-demo/demos/dialogs.py:
* examples/pygtk-demo/demos/panes.py:
* examples/pygtk-demo/demos/sizegroup.py: add examples translated
by Michelle Campeotto.
Diffstat (limited to 'examples/pygtk-demo')
-rw-r--r-- | examples/pygtk-demo/demos/colorsel.py | 82 | ||||
-rw-r--r-- | examples/pygtk-demo/demos/dialogs.py | 133 | ||||
-rw-r--r-- | examples/pygtk-demo/demos/panes.py | 116 | ||||
-rw-r--r-- | examples/pygtk-demo/demos/sizegroup.py | 108 |
4 files changed, 439 insertions, 0 deletions
diff --git a/examples/pygtk-demo/demos/colorsel.py b/examples/pygtk-demo/demos/colorsel.py new file mode 100644 index 00000000..b04e4c24 --- /dev/null +++ b/examples/pygtk-demo/demos/colorsel.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +"""Color Selector + +GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is a +prebuilt dialog containing a GtkColorSelection.""" + +description = "Color Selector" + +import gtk + +window = None +color = None +da = None + +def change_color_cb(w): + global window, color, da + + dialog = gtk.ColorSelectionDialog("Changing color") + dialog.set_transient_for(window) + colorsel = dialog.colorsel + + colorsel.set_previous_color(color) + colorsel.set_current_color(color) + colorsel.set_has_palette(gtk.TRUE) + + response = dialog.run() + + if response == gtk.RESPONSE_OK: + color = colorsel.get_current_color() + da.modify_bg(gtk.STATE_NORMAL, color) + + dialog.destroy() + +def main(): + global window, color, da + + # How do I get a GdkColor? + # GdkColormap.alloc() wants a GtkColor, not strings nor (r, g, b) and + # gtk.gdk.Color isn't implemented... + #color = gtk.gdk.Color() + #color.red = 0 + #color.blue = 0xFFFF + #color.green = 0 + + window = gtk.Window() + window.set_title("Color selection") + window.set_border_width(8) + if __name__ == '__main__': + window.connect('destroy', lambda win: gtk.main_quit()) + + vbox = gtk.VBox() + vbox.set_border_width(8) + window.add(vbox) + + # Create the color swatch area + + frame = gtk.Frame() + frame.set_shadow_type(gtk.SHADOW_IN) + vbox.pack_start(frame, gtk.TRUE, gtk.TRUE, 8) + + da = gtk.DrawingArea() + da.set_size_request(200, 200) + color = da.get_style().white + da.modify_bg(gtk.STATE_NORMAL, color) + frame.add(da) + + alignment = gtk.Alignment(1.0, 0.5, 0.0, 0.0) + + button = gtk.Button("_Change the above color") + alignment.add(button) + + vbox.pack_start(alignment, gtk.TRUE, gtk.TRUE) + + button.connect('clicked', change_color_cb) + button.set_flags(gtk.CAN_DEFAULT) + button.grab_default() + + window.show_all() + + if __name__ == '__main__': gtk.main() + +if __name__ == '__main__': main() diff --git a/examples/pygtk-demo/demos/dialogs.py b/examples/pygtk-demo/demos/dialogs.py new file mode 100644 index 00000000..c6d6825b --- /dev/null +++ b/examples/pygtk-demo/demos/dialogs.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python +"""Dialog and Message Boxes + +Dialog widgets are used to pop up a transient window for user feedback.""" + +description = "Dialog and Message Boxes" + +import gtk + +window = None +entry1 = None +entry2 = None +counter = 1 + +def message_dialog_clicked(w): + global window, counter + + dialog = gtk.MessageDialog(window, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_INFO, gtk.BUTTONS_OK, + "This message box has been popped up %d time%s." % + (counter, counter > 1 and 's' or '')) + dialog.run() + dialog.destroy() + counter += 1 + +def interactive_dialog_clicked(w): + global window, entry1, entry2 + + dialog = gtk.Dialog("Interactive Dialog", window, 0, + (gtk.STOCK_OK, gtk.RESPONSE_OK, + "_Non-stock button", gtk.RESPONSE_CANCEL)) + + hbox = gtk.HBox(gtk.FALSE, 8) + hbox.set_border_width(8) + dialog.vbox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 0) + + stock = gtk.image_new_from_stock( + gtk.STOCK_DIALOG_QUESTION, + gtk.ICON_SIZE_DIALOG) + hbox.pack_start(stock, gtk.FALSE, gtk.FALSE, 0) + + table = gtk.Table(2, 2) + table.set_row_spacings(4) + table.set_col_spacings(4) + hbox.pack_start(table, gtk.TRUE, gtk.TRUE, 0) + + label = gtk.Label("Entry _1") + label.set_use_underline(gtk.TRUE) + table.attach_defaults(label, 0, 1, 0, 1) + local_entry1 = gtk.Entry() + local_entry1.set_text(entry1.get_text()) + table.attach_defaults(local_entry1, 1, 2, 0, 1) + label.set_mnemonic_widget(local_entry1) + + label = gtk.Label("Entry _2") + label.set_use_underline(gtk.TRUE) + table.attach_defaults(label, 0, 1, 1, 2) + local_entry2 = gtk.Entry() + local_entry2.set_text(entry2.get_text()) + table.attach_defaults(local_entry2, 1, 2, 1, 2) + label.set_mnemonic_widget(local_entry2) + + dialog.show_all() + + response = dialog.run() + + if response == gtk.RESPONSE_OK: + entry1.set_text(local_entry1.get_text()) + entry2.set_text(local_entry2.get_text()) + + dialog.destroy() + +def main(): + global window, entry1, entry2 + + window = gtk.Window() + window.set_title("Dialogs") + window.set_border_width(8) + if __name__ == '__main__': + window.connect('destroy', lambda win: gtk.main_quit()) + + frame = gtk.Frame("Dialogs") + window.add(frame) + + vbox = gtk.VBox(gtk.FALSE, 8) + vbox.set_border_width(8) + frame.add(vbox) + + # Standard message dialog + hbox = gtk.HBox(gtk.FALSE, 8) + vbox.pack_start(hbox) + button = gtk.Button("_Message Dialog") + button.connect('clicked', message_dialog_clicked) + hbox.pack_start(button, gtk.FALSE, gtk.FALSE, 0) + vbox.pack_start(gtk.HSeparator(), gtk.FALSE, gtk.FALSE, 0) + + # Interactive dialog + hbox = gtk.HBox(gtk.FALSE, 8) + vbox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 0) + vbox2 = gtk.VBox() + + button = gtk.Button("_Interactive Dialog") + button.connect('clicked', interactive_dialog_clicked) + hbox.pack_start(vbox2, gtk.FALSE, gtk.FALSE, 0) + vbox2.pack_start(button, gtk.FALSE, gtk.FALSE, 0) + + table = gtk.Table(2, 2) + table.set_row_spacings(4) + table.set_col_spacings(4) + hbox.pack_start(table, gtk.FALSE, gtk.FALSE, 0) + + label = gtk.Label("Entry _1") + label.set_use_underline(gtk.TRUE) + table.attach_defaults(label, 0, 1, 0, 1) + + entry1 = gtk.Entry() + table.attach_defaults(entry1, 1, 2, 0, 1) + label.set_mnemonic_widget(entry1) + + label = gtk.Label("Entry _2") + label.set_use_underline(gtk.TRUE) + table.attach_defaults(label, 0, 1, 1, 2) + + entry2 = gtk.Entry() + table.attach_defaults(entry2, 1, 2, 1, 2) + label.set_mnemonic_widget(entry2) + + window.show_all() + + if __name__ == '__main__': gtk.main() + +if __name__ == '__main__': main() diff --git a/examples/pygtk-demo/demos/panes.py b/examples/pygtk-demo/demos/panes.py new file mode 100644 index 00000000..a6009fde --- /dev/null +++ b/examples/pygtk-demo/demos/panes.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python +"""Paned Widgets + +The GtkHPaned and GtkVPaned Widgets divide their content area into two panes +with a divider in between that the user can adjust. A separate child is placed +into each pane. +There are a number of options that can be set for each pane. This test contains +both a horizontal (HPaned) and a vertical (VPaned) widget, and allows you to +adjust the options for each side of each widget.""" + +description = "Paned Widgets" + +import gtk + +def toggle_resize(w, child): + paned = child.parent + + if child == paned.children()[0]: + paned.remove(child) + paned.pack1(child, w.get_active(), 0) + else: + paned.remove(child) + paned.pack2(child, w.get_active(), 0) + +def toggle_shrink(w, child): + paned = child.parent + + if child == paned.children()[0]: + paned.remove(child) + paned.pack1(child, 0, w.get_active()) + else: + paned.remove(child) + paned.pack2(child, 0, w.get_active()) + +def create_pane_options(paned, frame_label, label1, label2): + frame = gtk.Frame(frame_label) + frame.set_border_width(4) + + table = gtk.Table(3, 2, gtk.TRUE) + frame.add(table) + + label = gtk.Label(label1) + table.attach_defaults(label, 0, 1, 0, 1) + + check_button = gtk.CheckButton("_Resize") + check_button.connect('toggled', toggle_resize, paned.children()[0]) + table.attach_defaults(check_button, 0, 1, 1, 2) + + check_button = gtk.CheckButton("_Shrink") + check_button.set_active(gtk.TRUE) + check_button.connect('toggled', toggle_shrink, paned.children()[0]) + table.attach_defaults(check_button, 0, 1, 2, 3) + + label = gtk.Label(label2) + table.attach_defaults(label, 1, 2, 0, 1) + + check_button = gtk.CheckButton("_Resize") + check_button.set_active(gtk.TRUE) + check_button.connect('toggled', toggle_resize, paned.children()[1]) + table.attach_defaults(check_button, 1, 2, 1, 2) + + check_button = gtk.CheckButton("_Shrink") + check_button.set_active(gtk.TRUE) + check_button.connect('toggled', toggle_shrink, paned.children()[1]) + table.attach_defaults(check_button, 1, 2, 2, 3) + + return frame + +def main(): + window = gtk.Window() + window.set_title("Paned Widgets") + window.set_border_width(0) + if __name__ == '__main__': + window.connect('destroy', lambda win: gtk.main_quit()) + + vbox = gtk.VBox(gtk.FALSE, 0) + window.add(vbox) + + vpaned = gtk.VPaned() + vbox.pack_start(vpaned, gtk.TRUE, gtk.TRUE) + vpaned.set_border_width(5) + + hpaned = gtk.HPaned() + vpaned.add1(hpaned) + + frame = gtk.Frame() + frame.set_shadow_type(gtk.SHADOW_IN) + frame.set_size_request(60, 60) + hpaned.add1(frame) + + button = gtk.Button("_Hi there") + frame.add(button) + + frame = gtk.Frame() + frame.set_shadow_type(gtk.SHADOW_IN) + frame.set_size_request(80, 60) + hpaned.add2(frame) + + frame = gtk.Frame() + frame.set_shadow_type(gtk.SHADOW_IN) + frame.set_size_request(60, 80) + vpaned.add2(frame) + + # Now create toggle buttons to control sizing + + vbox.pack_start(create_pane_options(hpaned, "Horizontal", "Left", "Right"), + gtk.FALSE, gtk.FALSE, 0) + + vbox.pack_start(create_pane_options(vpaned, "Vertical", "Top", "Bottom"), + gtk.FALSE, gtk.FALSE, 0) + + window.show_all() + + if __name__ == '__main__': gtk.main() + +if __name__ == '__main__': main() diff --git a/examples/pygtk-demo/demos/sizegroup.py b/examples/pygtk-demo/demos/sizegroup.py new file mode 100644 index 00000000..c40ce383 --- /dev/null +++ b/examples/pygtk-demo/demos/sizegroup.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +"""Size Groups + +GtkSizeGroup provides a mechanism for grouping a number of widgets together so +they all request the same amount of space. This is typically useful when you +want a column of widgets to have the same size, but you can't use a GtkTable +widget. + +Note that size groups only affect the amount of space requested, not the size +that the widgets finally receive. If you want the widgets in a GtkSizeGroup to +actually be the same size, you need to pack them in such a way that they get +the size they request and not more. For example, if you are packing your +widgets into a table, you would not include the GTK_FILL flag.""" + +description = "Size Groups" + +import gtk + +def create_option_menu(options): + menu = gtk.Menu() + for str in options: + menu_item = gtk.MenuItem(str) + menu_item.show() + gtk.MenuShell.append(menu, menu_item) + + option_menu = gtk.OptionMenu() + option_menu.set_menu(menu) + + return option_menu + +def add_row(table, row, size_group, label_text, options): + label = gtk.Label(label_text) + label.set_use_underline(gtk.TRUE) + label.set_alignment(0, 1) + table.attach(label, 0, 1, row, row + 1, gtk.EXPAND + gtk.FILL, 0, 0, 0) + + option_menu = create_option_menu(options) + label.set_mnemonic_widget(option_menu) + size_group.add_widget(option_menu) + table.attach(option_menu, 1, 2, row, row + 1, 0, 0, 0, 0) + +def toggle_grouping(check_button, size_group): + # gtk.SIZE_GROUP_NONE is not generally useful, but is useful + # here to show the effect of gtk.SIZE_GROUP_HORIZONTAL by + # contrast. + if check_button.get_active(): + size_group.set_mode(gtk.SIZE_GROUP_HORIZONTAL) + else: + size_group.set_mode(gtk.SIZE_GROUP_NONE) + +def main(): + color_options = ["Red", "Green", "Blue"] + dash_options = ["Solid", "Dashed", "Dotted"] + end_options = ["Square", "Round", "Arrow"] + + window = gtk.Dialog("GtkSizeGroups", None, 0, + (gtk.STOCK_CLOSE, gtk.RESPONSE_NONE)) + window.set_resizable(gtk.FALSE) + window.connect('response', lambda w, d: window.destroy()) + if __name__ == '__main__': + window.connect('destroy', lambda win: gtk.main_quit()) + + vbox = gtk.VBox(gtk.FALSE, 5) + window.vbox.pack_start(vbox, gtk.TRUE, gtk.TRUE, 0) + vbox.set_border_width(5) + + size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) + + # Create one frame holding color options + + frame = gtk.Frame("Color options") + vbox.pack_start(frame, gtk.TRUE, gtk.TRUE, 0) + + table = gtk.Table(2, 2, gtk.FALSE) + table.set_border_width(5) + table.set_row_spacings(5) + table.set_col_spacings(10) + frame.add(table) + + add_row(table, 0, size_group, "_Foreground", color_options) + add_row(table, 1, size_group, "_Background", color_options) + + # And another frame holding line style options + + frame = gtk.Frame("Line options") + vbox.pack_start(frame, gtk.FALSE, gtk.FALSE, 0) + + table = gtk.Table(2, 2, gtk.FALSE) + table.set_border_width(5) + table.set_row_spacings(5) + table.set_col_spacings(10) + frame.add(table) + + add_row(table, 0, size_group, "_Dashing", dash_options) + add_row(table, 1, size_group, "_Line ends", end_options) + + # And a check button to turn grouping on and off + + check_button = gtk.CheckButton("_Enable grouping") + vbox.pack_start(check_button, gtk.FALSE, gtk.FALSE, 0) + check_button.set_active(gtk.TRUE) + check_button.connect('toggled', toggle_grouping, size_group) + + window.show_all() + + if __name__ == '__main__': gtk.main() + +if __name__ == '__main__': main() |