Question about load_handler parameter from load_from_url
-
It looks to me like it should work by "pushing" a message via
.[execute_script](http://code.google.com/apis/sketchup/docs/ourdoc/webdialog.html#execute_script)
to the webdialog from within theonPercentChange
method. -
That's what I was hoping, but what is the argument that you are passing doing? In the prototype on the api page, it shows that you have to pass an argument, and then it's basically just printing that p argument. What is p supposed to be conceptually?
class LoadHandler def onPercentChange(p) Sketchup;;set_status_text("LOADING; " + p.to_i.to_s + "%") end def cancelled? # You could, for example, show a messagebox after X seconds asking if the # user wants to cancel the download. If this method returns true, then # the download cancels. return false end def onSuccess Sketchup;;set_status_text('') end def onFailure(error_message) # A real implementation would probably not use a global variable, # but this demonstrates storing any error we receive. $last_error = error_message Sketchup;;set_status_text('') end end
-
I assume a Float value from 0 to 100 representing the percent of the transfer that is complete. Although it may go from 0 to 1, also.
You don't pass the value - SketchUp calls onPercentChange and provides the value to you.
Also,
p
is a bad name for a variable since it is already a shortcut for the .inspect method - come on, Google. -
How frequently does SketchUp call it? Can I control the interval? Or is it just that I specify the interval at which it does something inside of the onPercentchange method?
-
@shoff said:
How frequently does SketchUp call it?
We on the Ruby end of things have no idea - that is something controlled internally in SketchUp.
@shoff said:
Can I control the interval?
No. All you can do is perform some action with the value given to you in the onPercentChange parameter.
def onPercentChange(the_percent) @your_dialog.execute_script("update_progressbar('#{the_precent}');") end
- assumes you have a JavaScript function named "update_progressbar()" available in your WebDialog.
-
hmmm. Yeah, i did something very similar to your onPercentChange definition, and it doesn't look like SketchUp is calling it. I know my javascript works because if I call load_handler.onPercentChange(foo) where foo is a number, then my progress bar updates. When you run load_from_url with the optional load_handler parameter, is SketchUp calling onPercentChange for you?
-
I think I figured out the problem. onPercentChange doesn't work on a mac. Just tried my code on a PC, and it worked. Guess that means bug report...kind of wish I tested that sooner, would have saved me a lot of time.
-
John, did you file a bug report? Here's the link:
-
Yes he did.
-
Yeah, I posted a bug report. One more thing worth mentioning for anybody that finds this thread later. When I said that it worked on a PC, I got it to work using Sketchup.status_text=, but it wouldn't work using WebDialog.execute_script. I wrote a little script to slowly count from 1 to 100 and call my javascript each time, so that I could make sure that it wasn't some silly mistake on my end, and that worked fine. So, my assumption is that execute_script is taking forever to get called inside of onPercentChange even for the PC.
-
This could be done from the JavaScript too. You could use the onPercentChange to simply set a variable, then use a timer in JS to poll the Ruby script for the value of the variable.
Advertisement