Pastey Phix/Gtk demo
- Posted by irv Jan 29, 2021
------------------------------------------------------------------------ --# GtkExpander, widget data key/value pairs -------------------------------------------------------------------------- include GtkWindow.e include GtkBox.e include GtkLabel.e include GtkButtonBox.e include GtkButton.e include GtkMessageDialog.e include GtkExpander.e constant docs = ` Widgets have a <b>Data</b> space which you can use to declare and pass multiple key/value pairs` constant -- answers are encrypted to avoid overturning the legumes; q1 = "What is purple and conquered the world?", a1 = "PGk+QWxleGFuZGVyIHRoZSBHcmFwZSE8L2k+", q2 = "What lies at the bottom of the ocean and twitches?", a2 = "PGk+QSBuZXJ2b3VzIHdyZWNrLjwvaT4=", q3 = "Why is Christmas just like another day at the office?", a3 = "WW91IGRvIGFsbCBvZiB0aGUgd29yayBhbmQgdGhlIGZhdCBndXkKaW4gdGhlIHN1aXQgZ2V0cyBhbGwgdGhlIGNyZWRpdC4=" Window win = new() win.name = "Main Window" win.title = `GtkExpander and Data Passing` win.border_width = 10 win.connect("destroy","Quit") Box pan = new() pan.name = "Main Window Panel" pan.orientation = vertical pan.spacing = 10 win.add(pan) Label lbl = new() lbl.name = "Main Window Label" lbl.markup = docs pan.add(lbl) Button btn1 = new() btn1.name = "Main Window Button #1" btn1.icon = "dialog-question" btn1.label = "Question _1" btn1.tooltip_text = "World History" btn1.connect("clicked","ShowMe") btn1.set_data("Question",q1) btn1.set_data("Answer",a1) Button btn2 = new() btn2.name = "Main Button #2" btn2.icon = "dialog-question" btn2.label = "Question _2" btn2.tooltip_text = "Science" btn2.connect("clicked","ShowMe") btn2.set_data("Question",q2) btn2.set_data("Answer",a2) Button btn3 = new() btn3.name = "Main Button #3" btn3.icon = "dialog-question" btn3.label = "Question _3" btn3.tooltip_text = "Business" btn3.connect("clicked","ShowMe") btn3.set_data("Question",q3) btn3.set_data("Answer",a3) ButtonBox box = new() box.name = "Main Window ButtonBox" box.spacing = 5 pan.pack_end(box) box.add({btn1,btn2,btn3}) win.show_all() gtk_main() ------------------------------------- public function ShowMe(atom ctl) ------------------------------------- Object x = widget_from_handle(ctl) -- convert 'handle' to 'Widget'; object title = x.tooltip_text object question = x.get_data("Question") -- get data items by name; object answer = x.get_data("Answer") question = peek_string(question) answer = decode_base64(peek_string(answer)) -- now we build our own custom dialog; Label ans = new() ans.markup = answer ans.font = "courier bold 18" Box bx = new() bx.add(ans) bx.margin_top = 20 bx.border_width = 10 Expander expd = new() expd.label = "Click here to see the answer..." expd.add(bx) expd.show_all() MessageDialog dlg = new({win,QUESTION}) dlg.title = title dlg.markup = question dlg.add(expd) object response = dlg.run() delete(ans) -- order of deletion is important; delete(bx) -- gtk will issue warnings if you do it wrong; delete(expd) delete(dlg) return 1 end function
1. Comment by irv Jan 30, 2021
I dare you to compare this with any IUP program and tell me that this code is not easier to understand!