diff --git a/Nasal/canvas/gui.nas b/Nasal/canvas/gui.nas index 9bc469d71..cf6a1b2b8 100644 --- a/Nasal/canvas/gui.nas +++ b/Nasal/canvas/gui.nas @@ -16,8 +16,9 @@ loadGUIFile("styles/DefaultStyle.nas"); loadWidget("Button"); loadWidget("Label"); loadWidget("ScrollArea"); +loadDialog("MessageBox"); -var style = DefaultStyle.new("AmbianceClassic"); +var style = DefaultStyle.new("AmbianceClassic", "Humanity"); var WindowButton = { new: func(parent, name) { @@ -101,6 +102,10 @@ var Window = { me._node.remove(); me._node = nil; }, + setTitle: func(title) + { + return me.set("title", title); + }, # Create the canvas to be used for this Window # # @return The new canvas diff --git a/Nasal/canvas/gui/Style.nas b/Nasal/canvas/gui/Style.nas index 244177c26..5b7c1813b 100644 --- a/Nasal/canvas/gui/Style.nas +++ b/Nasal/canvas/gui/Style.nas @@ -1,14 +1,16 @@ gui.Style = { - new: func(name) + new: func(name, name_icon_theme) { var root_node = props.globals.getNode("/sim/gui/canvas", 1) .addChild("style"); - var path = getprop("/sim/fg-root") ~ "/gui/styles/" ~ name; + var gui_path = getprop("/sim/fg-root") ~ "/gui"; + var style_path = gui_path ~ "/styles/" ~ name; var m = { parents: [gui.Style], - _path: path, - _node: io.read_properties(path ~ "/style.xml", root_node), + _path: style_path, + _dir_icons: gui_path ~ "/icons/" ~ name_icon_theme, + _node: io.read_properties(style_path ~ "/style.xml", root_node), _colors: {} }; diff --git a/Nasal/canvas/gui/dialogs/MessageBox.nas b/Nasal/canvas/gui/dialogs/MessageBox.nas new file mode 100644 index 000000000..3dec44c20 --- /dev/null +++ b/Nasal/canvas/gui/dialogs/MessageBox.nas @@ -0,0 +1,170 @@ +var MessageBox = { + Ok: 0x0001, + Cancel: 0x0002, + Yes: 0x0004, + No: 0x0008, + new: func + { + return { + parents: [MessageBox], + _title: "Message", + _standard_buttons: MessageBox.Ok + }; + }, + setTitle: func(title) + { + me._title = title; + }, + setImage: func(img) + { + if( img != nil and img.find('/') < 0 ) + me._img = style._dir_icons ~ "/" ~ img ~ ".png"; + else + me._img = img; + return me; + }, + setText: func(text) + { + me._text = text; + return me; + }, + setStandardButtons: func(mask) + { + me._standard_buttons = mask; + return me; + }, + exec: func(cb = nil) + { + var MARGIN = 8; # TODO implement margin in C++ layouting code + var dlg = canvas.Window.new([250,100], "dialog") + .setTitle(me._title); + var root = dlg.getCanvas(1) + .set("background", style.getColor("bg_color")) + .createGroup(); + var vbox = VBoxLayout.new(); + dlg.setLayout(vbox); + vbox.addSpacing(MARGIN); + + var text_box = HBoxLayout.new(); + vbox.addItem(text_box); + + text_box.addSpacing(MARGIN); + + if( me._img != nil ) + { + text_box.addItem( + gui.widgets.Label.new(root, style, {}) + .setFixedSize(48, 48) + .setImage(me._img) + ); + } + + var label_text = gui.widgets.Label.new(root, style, {wordWrap: 1}) + .setText(me._text); + text_box.addItem(label_text, 1); + text_box.addSpacing(MARGIN); + + vbox.addStretch(1); + + var button_box = HBoxLayout.new(); + vbox.addItem(button_box); + + button_box.addStretch(1); + foreach(var button; [me.Ok, me.Cancel, me.Yes, me.No]) + { + if( !(me._standard_buttons & button) ) + continue; + + (func{ + var b_id = button; + button_box.addItem( + gui.widgets.Button.new(root, style, {}) + .setText(me._button_names[button]) + .listen("clicked", func { + dlg.del(); + if( cb != nil ) + cb(b_id); + }) + ); + })(); + } + button_box.addSpacing(MARGIN); + + vbox.addSpacing(MARGIN); + + return me; + }, + show: func(title, text, icon = nil, cb = nil, buttons = nil) + { + var msg_box = MessageBox.new(); + msg_box.setTitle(title); + msg_box.setText(text); + + if( buttons == nil ) + buttons = MessageBox.Ok; + msg_box.setStandardButtons(buttons); + + if( icon != nil ) + msg_box.setImage(icon); + + return msg_box.exec(cb); + }, + # Show an error/critical message in a message box + # + # @param title + # @param text + # @param cb Dialog close callback + # @param buttons Mask indicating the buttons to show + # (default: MessageBox.Ok) + critical: func(title, text, cb = nil, buttons = nil) + { + MessageBox.show(title, text, "dialog-error", cb, buttons); + }, + # Show a warning message in a message box + # + # @param title + # @param text + # @param cb Dialog close callback + # @param buttons Mask indicating the buttons to show + # (default: MessageBox.Ok) + warning: func(title, text, cb = nil, buttons = nil) + { + MessageBox.show(title, text, "dialog-warning", cb, buttons); + }, + # Show an informative message in a message box + # + # @param title + # @param text + # @param cb Dialog close callback + # @param buttons Mask indicating the buttons to show + # (default: MessageBox.Ok) + information: func(title, text, cb = nil, buttons = nil) + { + MessageBox.show(title, text, "dialog-info", cb, buttons); + }, + # Show a question in a message box + # + # @param title + # @param text + # @param cb Dialog close callback + # @param buttons Mask indicating the buttons to show + # (default: MessageBox.Yes | MessageBox.No) + question: func(title, text, cb = nil, buttons = nil) + { + MessageBox.show( + title, + text, + "dialog-question", + cb, + buttons or MessageBox.Yes | MessageBox.No + ); + }, +# private: + _button_names: {} +}; + +# Standard button names +MessageBox._button_names[ MessageBox.Ok ] = "Ok"; +MessageBox._button_names[ MessageBox.Cancel ] = "Cancel"; +MessageBox._button_names[ MessageBox.Yes ] = "Yes"; +MessageBox._button_names[ MessageBox.No ] = "No"; diff --git a/Nasal/canvas/gui/styles/DefaultStyle.nas b/Nasal/canvas/gui/styles/DefaultStyle.nas index 9663207fe..14a02b8ae 100644 --- a/Nasal/canvas/gui/styles/DefaultStyle.nas +++ b/Nasal/canvas/gui/styles/DefaultStyle.nas @@ -1,7 +1,10 @@ var DefaultStyle = { - new: func(name) + new: func(name, name_icon_theme) { - return { parents: [gui.Style.new(name), DefaultStyle] }; + return { + parents: [ gui.Style.new(name, name_icon_theme), + DefaultStyle ] + }; }, createWidget: func(parent, type, cfg) { diff --git a/gui/icons/Humanity/AUTHORS b/gui/icons/Humanity/AUTHORS new file mode 100644 index 000000000..7baeebe66 --- /dev/null +++ b/gui/icons/Humanity/AUTHORS @@ -0,0 +1,20 @@ +#################### +ABOUT: # +#################### + +Humanity is designed and developed by : + Daniel Foré , + K.Vishnoo Charan Reddy, + Jonian Guveli . + +GNOME icons and Humanity icons are all licensed under the GPL. + +This package is licensed under GNU General Public License version 2. + +Icons based or directly from GNOME and other GNOME projects, licensed GPL. + You can visit the GNOME website here: + http://www.gnome.org/ + +Icons based on Tango sources or taken from the Tango project are public domain. + You can visit the Tango project website here: + http://tango.freedesktop.org/Tango_Desktop_Project diff --git a/gui/icons/Humanity/dialog-error.png b/gui/icons/Humanity/dialog-error.png new file mode 100644 index 000000000..60f29f0a4 Binary files /dev/null and b/gui/icons/Humanity/dialog-error.png differ diff --git a/gui/icons/Humanity/dialog-info.png b/gui/icons/Humanity/dialog-info.png new file mode 100644 index 000000000..184eeda88 Binary files /dev/null and b/gui/icons/Humanity/dialog-info.png differ diff --git a/gui/icons/Humanity/dialog-question.png b/gui/icons/Humanity/dialog-question.png new file mode 100644 index 000000000..ce7fdcd44 Binary files /dev/null and b/gui/icons/Humanity/dialog-question.png differ diff --git a/gui/icons/Humanity/dialog-warning.png b/gui/icons/Humanity/dialog-warning.png new file mode 100644 index 000000000..7247b3e25 Binary files /dev/null and b/gui/icons/Humanity/dialog-warning.png differ