Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > debugging using tk.rb

Reply
Thread Tools

debugging using tk.rb

 
 
Wybo Dekker
Guest
Posts: n/a
 
      10-19-2006
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...
--
Wybo

 
Reply With Quote
 
 
 
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      10-20-2006
From: Wybo Dekker <(E-Mail Removed)>
Subject: debugging using tk.rb
Date: Thu, 19 Oct 2006 20:06:23 +0900
Message-ID: <(E-Mail Removed)>
> 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}).
--
Hidetoshi NAGAI ((E-Mail Removed))

 
Reply With Quote
 
 
 
 
Wybo Dekker
Guest
Posts: n/a
 
      10-21-2006
--------------020500060107000900040603
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hidetoshi NAGAI wrote:
> From: Wybo Dekker <(E-Mail Removed)>
> Subject: debugging using tk.rb
> Date: Thu, 19 Oct 2006 20:06:23 +0900
> Message-ID: <(E-Mail Removed)>
>> 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 PigBoxig', 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--

 
Reply With Quote
 
David Vallner
Guest
Posts: n/a
 
      10-21-2006
--------------enig3C280F49FB32548E30C73F12
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Wybo Dekker wrote:
> When I use () instead of {}: evloop =3D Thread.new(Tk.mainloop)
> then it starts normally, but there is no difference with just Tk.mainlo=

op.
>


Duh. Ruby is a strictly evaluated language, arguments to a function call
are evaluated before the call. Tk.mainloop hangs the interpreter before
Thread.new is ever called.

(You might want to spend some time on learning Ruby syntax and what the
difference between those brackets is.)

David Vallner



--------------enig3C280F49FB32548E30C73F12
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD4DBQFFOgnYy6MhrS8astoRAnNmAJi0HuxZNMlPNHb8E4qKPR w+/Dg0AJsHWmYL
/Limaic05DvoQuwbHWRb5Q==
=oQTx
-----END PGP SIGNATURE-----

--------------enig3C280F49FB32548E30C73F12--

 
Reply With Quote
 
dblack@wobblini.net
Guest
Posts: n/a
 
      10-21-2006
Hi --

On Sat, 21 Oct 2006, David Vallner wrote:

> Wybo Dekker wrote:
>> When I use () instead of {}: evloop = Thread.new(Tk.mainloop)
>> then it starts normally, but there is no difference with just Tk.mainloop.
>>

>
> Duh.


The discourse on this list seems to have drifted toward the impatient,
critical, and judgmental. Could it perhaps drift back toward
collegiality, based on the fact that we're all involved in the ongoing
process of grasping and productively using various technologies?


David

--
David A. Black | http://www.velocityreviews.com/forums/(E-Mail Removed)
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

 
Reply With Quote
 
Wybo Dekker
Guest
Posts: n/a
 
      10-21-2006
(E-Mail Removed) wrote:
> Hi --
>
> On Sat, 21 Oct 2006, David Vallner wrote:
>
>> Wybo Dekker wrote:
>>> When I use () instead of {}: evloop = Thread.new(Tk.mainloop)
>>> then it starts normally, but there is no difference with just
>>> Tk.mainloop.
>>>

>>
>> Duh.

>
> The discourse on this list seems to have drifted toward the impatient,
> critical, and judgmental. Could it perhaps drift back toward
> collegiality, based on the fact that we're all involved in the ongoing
> process of grasping and productively using various technologies?
>
>
> David


thanks, David Black, for your support.
The problem is, I'm one of those non-professional users who can, with
their limited knowledge, do a lot with Ruby without understanding all
it's ins and outs. For instance, I have no experience with threads at
all, so when I am suggested a solution using those, I just try, and if
it works I have another reason to study threads in detail. Before that
I'm stupid enough to think that Thread.new{...}, which did nothing, may
have been a typo...

--
Wybo

 
Reply With Quote
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      10-21-2006
From: Wybo Dekker <(E-Mail Removed)>
Subject: Re: debugging using tk.rb
Date: Sat, 21 Oct 2006 17:12:05 +0900
Message-ID: <(E-Mail Removed)>
> For example, running the Pig Latin Generator from Dave's book
> (attached): if I try to debug the pig method with
> `break PigBoxig', 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


I see. But unfortunately, there is no solution.
The callback process of Ruby/Tk is a little complex.
Longjmp must be handled very carefully, because it may break
consistency of Ruby's stack, Tcl/Tk's stack, and Tcl/Tk's
internal status.
If not, such like as your trouble, longjmp causes SEGV easily.

# Which version of Ruby/Tk do you use?

> 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)


That is fail of converting a event parameter to an object.
Tcl/Tk returns a string "??" for an undefined parameter on a event.
In that case, Tcl/Tk returns a "??" for the parameter which is
expected as an integer.
It may be a bug on Ruby/Tk.
Could you show me your definition of binding?

# Probably, you will be able to avoid the trouble
# by using "%" substiturion arguments.
--
Hidetoshi NAGAI ((E-Mail Removed))

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I skip debugging Ajax when debugging my code? AAaron123 ASP .Net 3 07-28-2009 04:07 PM
Debugging C vs debugging C++ jacob navia C Programming 11 10-27-2006 07:19 PM
Using Netbean IDE for writing/compiling/debugging apps without using Project bagarow@yahoo.com Java 6 05-11-2006 02:53 PM
Using remote debugging SimonH ASP .Net 2 02-03-2005 05:27 PM
No Debugging of C# Server-Side Script, but Code-Behind Debugging Works Johann Blake ASP .Net 1 01-05-2004 03:01 PM



Advertisments