The Dialog widget is very simple, and is actually just a window with a few things pre-packed into it for you. The call to create a new Dialog is:
Gtk::Dialog.new
It creates a window and then packs a vbox into the top, which contains a separator and then an hbox called the "action_area" into the bottom.
The Dialog widget can be used for pop-up messages to the user, and other similar tasks. Unlike the C version of GTK, there is only one way to create a new Dialog in Ruby-GNOME2, and that is to use the method described above.
You can add to the vbox area by packing, for instance, a label in it, try something like this:
Gtk::Dialog#vbox#pack_start( label, true, true, 0 )
As an example in using the dialog box, you could put two buttons in the action_area, a Cancel button and an Ok button, and a label in the vbox area, asking the user a question or giving an error, etc. Then you could attach a different signal to each of the buttons and perform the operation the user selects. I have provided you sample program with source below.
If the simple functionality provided by the default vertical and horizontal boxes in the two areas doesn't give you enough control for your application, then you can simply pack another layout widget into the boxes provided. For example, you could pack a table into the vertical box.
There are only a few methods to choose from when dealing with a Dialog widget. They are listed below:
Gtk::Dialog#action_area Gtk::Dialog#add_button( button_text, id ) Gtk::Dialog#add_action_widget( widget, id ) Gtk::Dialog#action_area( widget, spacing, expand, fill, padding ) Gtk::Dialog#vbox # Syntax sugar, does same thing Gtk::Dialog#has_separator=( separator ) Gtk::Dialog#set_has_separator( separator ) Gtk::Dialog#has_separator? #Retruns a boolean true or false, true is having a separator. Gtk::Dialog#response Gtk::Dialog#run Gtk::Dialog#default_response= Gtk::Dialog#set_default_response Gtk::Dialog#set_response_sensitive
The first method, #action_area, is a hbox that is packed into the bottom of the Dialog. You will usually find buttons here, such as Ok or Cancel. It has all the same methods as any other vbox. The next method, #add_button, adds a button to the action_area, with the label button_text. The next method is #add_action_widget, which adds an activatable widget to the action_area. If you want a non-activatable widget, simply pack it into the action_area using our next method, #action_area. You pack items into the action_area just like you would a regular Gtk::Box. This bring us to Gtk::Label#vbox, which works just like you think it would. It uses the exact same arguments as any other vbox. The next two methods define whether your dialog has a separator or not, with the sole argument being a boolean true or false. Following those, we come to the method that determines if your dialog has a separator in it. It will return true or false, depending on whether or not you have a separator.
Prev | Next |