Snippet. Vala. Showing a Message DialogThe class MessageDialog in the GTK package of Vala is a convenience widget that provides the possibility to present a dialog with an image representing the type of message (Error, Information, Question, etc.) alongside some message text. var dialog = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Hello from Vala!"); dialog.set_title("Message Dialog"); dialog.run(); dialog.destroy(); The class MessageDialog is an extension of the class Dialog and can easily be created from there. However, MessageDialog is useful for routine messages and will save you lots of typing. Possible Types of MessageDialogFour different types of MessageDialog are readily available. // Error var dialog_error = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "This is an error message"); // Info var dialog_info = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is an info message"); // Question var dialog_question = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "This is a question message requiring a choice."); // Warning var dialog_warning = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "This is a warning message"); Possible Flags of MessageDialogFlags allow MessageDialog to have different behaviour. The following flags are available:
// Modal var dialog_info = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is an info message"); // Destroyable with parent var dialog_info = new Gtk.MessageDialog(parent,Gtk.DialogFlags.DESTROY_WITH_PARENT,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is an info message"); // Modal and Destroyable var dialog_info = new Gtk.MessageDialog(parent,Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is an info message"); Possible Buttons of MessageDialogDifferent pre-ready buttons can be placed visible in MessageDialog. // No Buttons var dialog = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.NONE, "This is a dialog with no buttons"); // Button OK var dialog_ok = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is a dialog with OK button"); // Button Close var dialog_close = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, "This is a dialog with Close button"); // Button Cancel var dialog_cancel = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.CANCEL, "This is a dialog with Cancel button"); // Buttons Yes and No var dialog_yes_no = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.YES_NO, "This is a dialog with Yes and No buttons"); Updated on: 03 Dec 2024 |
|