Ruby + UI.dialog question.

View: New views
6 Messages — Rating Filter:   Alert me  

Ruby + UI.dialog question.

by drukepple :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a question about UI.dialog and/or some general Ruby usage.  I
apologize for asking about Ruby stuff here, but this particular problem
seems tied directly to the use of UI.dialog, although I'm pretty sure the
issue is actually a Ruby one on my part (I've been fine Googling for other
Ruby issues, but this one seems pretty niche).

Here's some stripped down code that works:

TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
|dialog|
  dialog.parameters = {'username'   => "moo"}
  dialog.wait_for_input do |params|
    puts params["username"]
  end
end

But then I go to try and actually use something with my params hash, like
putting it into a variable declared earlier:

username = ""
TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
|dialog|
  dialog.parameters = {'username'   => "moo"}
  dialog.wait_for_input do |params|
    username = params["username"]
  end
end
puts username


Now I get a task that seems to hang, which when forced to quit will report
the following error in Console:

TextMate[13634] *** -[NSMachPort handlePortMessage:]: dropping incoming DO
message because the connection or ports are invalid

Really don't know what to do with this. Sorry, I'm not good enough at either
TextMate's extra features, nor at Ruby.  I'm sure this is just a combination
of both of those deficiencies.

Thanks,
Dru


_______________________________________________
textmate mailing list
textmate@...
http://lists.macromates.com/listinfo/textmate

Re: Ruby + UI.dialog question.

by Matt Neuburg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 9/24/09 6:35 PM, in article C6E16C5A.77B8%dru@..., "Dru
Kepple" <dru@...> wrote:

> Here's some stripped down code that works:
>
> TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
> |dialog|
>   dialog.parameters = {'username'   => "moo"}
>   dialog.wait_for_input do |params|
>     puts params["username"]
>   end
> end
>
> But then I go to try and actually use something with my params hash, like
> putting it into a variable declared earlier:
>
> username = ""
> TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
> |dialog|
>   dialog.parameters = {'username'   => "moo"}
>   dialog.wait_for_input do |params|
>     username = params["username"]
>   end
> end
> puts username

Read the docs. :) Okay, there aren't really docs, but there is a very
helpful comment explaining how to use wait_for_input:

          # wait for the user to press a button (with performButtonClick: or
returnArguments: action)
          # or the close box. Returns a dictionary containing the return
argument values.
          # If a block is given, wait_for_input will pass the return
arguments to the block
          # in a continuous loop. The block must return true to continue the
loop, false to break out of it.

So, you're blocking because that's what the block does. It's just doing what
you told it to do. But for your purposes, you don't need a block. Just
capture the result of the call. So, for example (using a built-in nib
example):

require "#{ENV['TM_SUPPORT_PATH']}/lib/ui"
nib = "#{ENV['TM_SUPPORT_PATH']}/nibs/RequestString.nib"
username = ""
TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
|dialog|
  dialog.parameters = {'string' => "Matt"}
  username = dialog.wait_for_input
end
puts username["returnArgument"]

Hope that gives you enough to move forward... m.

--
matt neuburg, phd = matt@..., <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings




_______________________________________________
textmate mailing list
textmate@...
http://lists.macromates.com/listinfo/textmate

Re: Ruby + UI.dialog question.

by drukepple :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Matt Neuburg <matt@...>
> Read the docs. :) Okay, there aren't really docs, but there is a very
> helpful comment explaining how to use wait_for_input:

Yeah, no docs is part of the problem.  Didn't think to go deep sea diving to
the source code, though.  Nice tip.
 
> Hope that gives you enough to move forward... m.

Thank you thank you thank you!

Yes, I was fully expecting it to just be doing what I was telling it to do,
and that I was doing something wrong.  Big help... I'm relatively new to
Ruby and things like UI/IB, and I only get to work on this stuff
incrementally, so it can be frustrating for sure.

Enjoy a virtual beer on me.

Thanks again,
Dru


_______________________________________________
textmate mailing list
textmate@...
http://lists.macromates.com/listinfo/textmate

Re: Ruby + UI.dialog question.

by Jeff Keen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm actually have the same issue.  Once the .nib gets loaded in TextMate, everything locks up.  I can move the custom window around, but I can't type into the input boxes, close the window, or click any of the buttons.

The change that that was mentioned—removing the block from the dialog.wait_for_input—did not have any effect. I have, however, figured out that if I change my bundle command's output from "Replace Selected Text" to "Show As HTML", the window loads and works properly. Having that output type isn't functional for what I'm trying to do, though.

Is having "Show As HTML" as the bundle command output a requirement when using TextMate::UI.dialog to load a custom .nib?

Jeff

drukepple wrote:
I have a question about UI.dialog and/or some general Ruby usage.  I
apologize for asking about Ruby stuff here, but this particular problem
seems tied directly to the use of UI.dialog, although I'm pretty sure the
issue is actually a Ruby one on my part (I've been fine Googling for other
Ruby issues, but this one seems pretty niche).

Here's some stripped down code that works:

TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
|dialog|
  dialog.parameters = {'username'   => "moo"}
  dialog.wait_for_input do |params|
    puts params["username"]
  end
end

But then I go to try and actually use something with my params hash, like
putting it into a variable declared earlier:

username = ""
TextMate::UI.dialog(:nib => nib, :parameters => {}, :center => true) do
|dialog|
  dialog.parameters = {'username'   => "moo"}
  dialog.wait_for_input do |params|
    username = params["username"]
  end
end
puts username


Now I get a task that seems to hang, which when forced to quit will report
the following error in Console:

TextMate[13634] *** -[NSMachPort handlePortMessage:]: dropping incoming DO
message because the connection or ports are invalid

Really don't know what to do with this. Sorry, I'm not good enough at either
TextMate's extra features, nor at Ruby.  I'm sure this is just a combination
of both of those deficiencies.

Thanks,
Dru


_______________________________________________
textmate mailing list
textmate@lists.macromates.com
http://lists.macromates.com/listinfo/textmate

Re: Ruby + UI.dialog question.

by Allan Odgaard-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 28 Oct 2009, at 23:25, Jeff Keen wrote:

> [...] Is having "Show As HTML" as the bundle command output a  
> requirement when using TextMate::UI.dialog to load a custom .nib?

It is generally a requirement that the command runs “detached” which  
commands with HTML output does by default. Regular commands can also  
be detached http://wiki.macromates.com/HowTo/RunCommandInBackground

However, detaching means that TM will not wait for the command to  
complete, and that means any output other than ‘discard’ does not make  
sense.

Dialog 1.x allows you to run a nib as modal, which should then allow  
you to “block” but still have input go to the dialog (but the rest of  
TM will still be locked, as it is waiting for your command to complete).


_______________________________________________
textmate mailing list
textmate@...
http://lists.macromates.com/listinfo/textmate

Re: Ruby + UI.dialog question.

by drukepple :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----Original Message-----
From: textmate-bounces+dru=summitprojects.com@... [mailto:textmate-bounces+dru=summitprojects.com@...] On Behalf Of Allan Odgaard
It is generally a requirement that the command runs "detached" which commands with HTML output does by default. Regular commands can also be detached http://wiki.macromates.com/HowTo/RunCommandInBackground

_______________________________________________



Thanks, Allan!  I've been trying to figure this one out for a while.  Got it working very easily, thanks to the Ruby module.  I've got a lot to learn when it comes to this stuff.  I appreciate that you're so available on the mailing list.

+dru

_______________________________________________
textmate mailing list
textmate@...
http://lists.macromates.com/listinfo/textmate