From: Wybo Dekker Date: 2006-10-21T17:12:05+09:00 Subject: Re: debugging using tk.rb --------------020500060107000900040603 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hidetoshi NAGAI wrote: > From: Wybo Dekker > Subject: debugging using tk.rb > Date: Thu, 19 Oct 2006 20:06:23 +0900 > Message-ID: <45375C11.8000003@servalys.nl> >> Is it possible to use the debug library while using tk.rb? >> It seems to work only as long as the Tk mainloop is not entered... > > # Maybe, the following cannot help you ... > > If it is the reason of the trouble that "Tk.mainloop" doesn't > return while the root (main) window is alive, please try to start > "Tk.mainloop" in a Thread (e.g. evloop = Thread.new{Tk.mainloop}). when I do that literally, the script exits immediately, without any messages. When I use () instead of {}: evloop = Thread.new(Tk.mainloop) then it starts normally, but there is no difference with just Tk.mainloop. For example, running the Pig Latin Generator from Dave's book (attached): if I try to debug the pig method with `break PigBox:pig', then hitting the `Pig It' button should stop me in the pig method, but that doesn't happen. (I can, however) circumvent this by setting the break point on the line number). And when I hit the `Exit' button, an error message pops up: FATAL FATAL while executing "rb_out c00002" invoked from within ".w00000.w00004 invoke" ("uplevel" body line 1) invoked from within "uplevel #0 [list $w invoke]" (procedure "tk::ButtonUp" line 22) invoked from within "tk::ButtonUp .w00000.w00004" (command bound to event) One of my real, rather complex, applications says, as soon as I enter the Tk-window with my mouse: /home/wybo/bin/adm/admin:4:$: << File.dirname(__FILE__) files (rdb:1) b ~/bin/admin_transaction.rb:108 Set breakpoint 1 at ~/bin/admin_transaction.rb:108 (rdb:1) c /usr/local/lib/ruby/1.8/tk/event.rb:443: `invalid value for Integer: "??"' (ArgumentError) from /usr/local/lib/ruby/1.8/tk.rb:1323:in `catch' from /usr/local/lib/ruby/1.8/tk.rb:1323:in `callback' from /usr/local/lib/ruby/1.8/tk.rb:1557:in `mainloop' from /usr/local/lib/ruby/1.8/tk.rb:1557:in `mainloop' from /home/wybo/bin/adm/admin:1248 /usr/local/lib/ruby/1.8/tk/event.rb:443: TkUtil.eval_cmd(cmd, *(ex_args << klass.new(*klass.scan_args(keys, arg)))) (rdb:1) I suspect that this error message is caused by the use of rio(??) (for the creation of temporary files) -- Wybo --------------020500060107000900040603 Content-Type: text/plain; name="tktest" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tktest" #!/usr/local/bin/ruby require 'tk' class PigBox def pig(word) leadingCap = word =~ /^A-Z/ word.downcase! res = case word when /^aeiouy/ word+"way" when /^([^aeiouy]+)(.*)/ $2+$1+"ay" else word end leadingCap ? res.capitalize : res end def showPig @text.value = @text.value.split.collect{|w| pig(w)}.join(" ") end def initialize ph = { 'padx' => 10, 'pady' => 10 } # common options p = proc {showPig} @text = TkVariable.new root = TkRoot.new { title "Pig" } top = TkFrame.new(root) TkLabel.new(top) {text 'Enter Text:' ; pack(ph) } @entry = TkEntry.new(top, 'textvariable' => @text) @entry.pack(ph) TkButton.new(top) {text 'Pig It'; command p; pack ph} TkButton.new(top) {text 'Exit'; command {proc exit}; pack ph} top.pack('fill'=>'both', 'side' =>'top') end end PigBox.new evloop = Thread.new(Tk.mainloop) #Tk.mainloop --------------020500060107000900040603--