Hi, From: mhm26 / drexel.edu (matt) Subject: Ruby Tk - dialog windows Date: Tue, 15 Jun 2004 04:53:41 +0900 Message-ID: <13383d7a.0406141151.2adf579f / posting.google.com> > Hi - I'm trying to make `modal' windows. I'm confused about how to > use TkDialog, though, is there any good documentation? I need a > window that will not let someone go to the `parent' window, can > display stuff just like a TkToplevel or TkRoot... Please read dialog1.rb and dialog2.rb included in the 'Ruby/Tk widget demos'. But if you want a more complex modal window, you should use 'grab'. The step is (1) show the modal window (toplevel widget), (2) set grab to the modal window, (3) wait TkVariable access on the window and release grab from the window, OR destroy the window (release grab automatically). (please read ruby/ext/tk/sample/tkcombobox.rb). ------<dialog1.rb>--------------------------------- # # a dialog box with a local grab (called by 'widget') # class TkDialog_Demo1 < TkDialog ############### private ############### def title "Dialog with local grab" end def message 'This is a modal dialog box. It uses Tk\'s "grab" command to create a "local grab" on the dialog box. The grab prevents any pointer-related events from getting to any other windows in the application until you have answered the dialog by invoking one of the buttons below. However, you can still interact with other applications.' end def bitmap 'info' end def default_button 0 end def buttons # ["Dismiss", "", "Show Code"] ["OK", "Cancel", "Show Code"] end end ret = TkDialog_Demo1.new('message_config'=>{'wraplength'=>'4i'}).value case ret when 0 print "You pressed OK\n" when 1 print "You pressed Cancel\n" when 2 showCode 'dialog1' end --------------------------------------------------- ------<tkcombobox.rb:part>------------------------- def _button_proc(dir = true) @btn.relief(:sunken) x = @frame.winfo_rootx y = @frame.winfo_rooty if dir @top.geometry("+#{x}+#{y + @frame.winfo_height}") else @btn.image(@@up_btn_bmp) @top.geometry("+#{x}+#{y - @top.winfo_reqheight}") end @top.deiconify @lst.focus if (idx = values.index(@ent.value)) @lst.see(idx - 1) @lst.activate(idx) @lst.selection_set(idx) elsif @lst.size > 0 @lst.see(0) @lst.activate(0) @lst.selection_set(0) end @top.grab begin @var.tkwait if (idx = @var.to_i) >= 0 @ent.value = @lst.get(idx) end @top.withdraw @btn.relief(:raised) @btn.image(@@down_btn_bmp) rescue ensure begin @top.grab(:release) @ent.focus rescue end end end private :_button_proc --------------------------------------------------- -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)