| 1 | # .require. mono |
|---|
| 2 | # .compile-only. |
|---|
| 3 | # .args. -c |
|---|
| 4 | """ |
|---|
| 5 | A small example of using the GTK GUI library. |
|---|
| 6 | |
|---|
| 7 | How to compile: |
|---|
| 8 | cobra -c -pkg:gtk-sharp-2.0 390-GTK.cobra |
|---|
| 9 | |
|---|
| 10 | URLs of interest: |
|---|
| 11 | http://www.mono-project.com/GtkSharp |
|---|
| 12 | http://www.mono-project.com/GtkSharp:_Hello_World |
|---|
| 13 | http://www.mono-project.com/GtkSharpBeginnersGuide |
|---|
| 14 | http://go-mono.org/docs/index.aspx?tlink=5@N%3aGtk (Mono Gtk Namespace Docs) |
|---|
| 15 | http://en.wikipedia.org/wiki/Gtk_Sharp |
|---|
| 16 | |
|---|
| 17 | Credit: |
|---|
| 18 | Adapted from http://www.mono-project.com/GtkSharp:_Hello_World |
|---|
| 19 | |
|---|
| 20 | Misc: |
|---|
| 21 | Other GUI libraries include System.Windows.Forms and Cocoa#. |
|---|
| 22 | """ |
|---|
| 23 | |
|---|
| 24 | @args 2.0gtk-sharp-2.0 |
|---|
| 25 | |
|---|
| 26 | use Gtk |
|---|
| 27 | |
|---|
| 28 | class ToggleButtons |
|---|
| 29 | |
|---|
| 30 | def main |
|---|
| 31 | ToggleButtons().run |
|---|
| 32 | |
|---|
| 33 | def onDeleteEvent(obj, args as DeleteEventArgs) |
|---|
| 34 | Application.quit |
|---|
| 35 | |
|---|
| 36 | def onExitButtonEvent(obj, args as EventArgs) |
|---|
| 37 | Application.quit |
|---|
| 38 | |
|---|
| 39 | def run |
|---|
| 40 | Application.init |
|---|
| 41 | |
|---|
| 42 | window = Window('Toggle Buttons') |
|---|
| 43 | listen window.deleteEvent, ref .onDeleteEvent |
|---|
| 44 | window.borderWidth = 0 |
|---|
| 45 | |
|---|
| 46 | box1 = VBox(false, 10) |
|---|
| 47 | window.add(box1) |
|---|
| 48 | box1.show |
|---|
| 49 | |
|---|
| 50 | box2 = VBox(false, 10) |
|---|
| 51 | box2.borderWidth = 10 |
|---|
| 52 | box1.packStart(box2, true, true, 0) |
|---|
| 53 | box2.show |
|---|
| 54 | |
|---|
| 55 | toggleButt = ToggleButton('Button 1') |
|---|
| 56 | box2.packStart(toggleButt, true, true, 0) |
|---|
| 57 | toggleButt.show |
|---|
| 58 | |
|---|
| 59 | toggleButt = ToggleButton('Button 2') |
|---|
| 60 | toggleButt.active = true |
|---|
| 61 | box2.packStart(toggleButt, true, true, 0) |
|---|
| 62 | toggleButt.show |
|---|
| 63 | |
|---|
| 64 | separator = HSeparator() |
|---|
| 65 | box1.packStart(separator, false, true, 0) |
|---|
| 66 | separator.show |
|---|
| 67 | |
|---|
| 68 | box3 = VBox(false, 10) |
|---|
| 69 | box3.borderWidth = 10 |
|---|
| 70 | box1.packStart(box3, false, true, 0) |
|---|
| 71 | |
|---|
| 72 | button = Button('Close') |
|---|
| 73 | listen button.clicked, ref .onExitButtonEvent |
|---|
| 74 | |
|---|
| 75 | box3.packStart(button, true, true, 0) |
|---|
| 76 | button.canDefault = true |
|---|
| 77 | button.grabDefault |
|---|
| 78 | button.show |
|---|
| 79 | |
|---|
| 80 | window.showAll |
|---|
| 81 | |
|---|
| 82 | Application.run |
|---|