There is a way of doing this but you will slow things down and you can't put the code inside a start_operation / commit_operation.
You pass control back and forth between your ruby script and the web dialog through the use of callbacks.
dialog.execute_script(script)
window.location.href = 'skp:ruby_callback@';
You need to rewrite your main loop and put the code into 2 functions instead of 1
Last line of first function creates the web dialog
When the web dialog has completed setting up then perform a callback
In the callback setup a timer that does not repeat and set time as 0.01 or something like that.
Inside the timer call the second function, at the end of the second function make a call to the dialog to update the progress bar.
require 'sketchup'
module YourSpace
module YourModule
def show_progress_bar(title, width, height, left, top, total)
build_html()
@progress_total = total
@dlg = UI;;WebDialog.new(title, false, "progress_bar_#{title}")
@dlg.set_size(width, height)
@dlg.set_position(left, top)
@dlg.set_html(@@html_code)
@dlg.set_on_close {
@dlg = nil
}
@dlg.add_action_callback('ruby_callback') { |dialog, params|
text = params.to_s
check = text[0..5]
if (check == 'loaded')
# if you want to do something after loading
end
UI.start_timer(0.01, false) {
your_second_fucntion()
}
}
@dlg.show()
end
def update_progress_bar(data)
if (data == @progress_total)
@dlg.close()
else
percentage = data / @progress_total.to_f
script = "from_ruby( '" << percentage.to_s << "' )"
@dlg.execute_script(script) if (@dlg != nil)
end
end
def build_html()
@@html_code = <<-HTML
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Progress Bar</title>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<style>
#my_progress {
width; 100%;
height; 20px;
position; relative;
border; 1px solid #ccc;
}
#my_bar {
width; 10px;
height; 100%;
position; absolute;
background-color; blue;
}
</style>
<body>
<div id="my_progress">
<div id="my_bar">
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
var progress_wd;
function from_ruby(data) {
var new_wd = progress_wd * parseFloat(data);
$('#my_bar').width(new_wd);
ruby_call(data);
}
function ruby_call(text) {
window.location.href = 'skp;ruby_callback@' + text;
}
$(document).ready(function() {
progress_wd = $('#my_progress').width() * 1.0;
ruby_call('loaded');
});
</script>
</body>
</html>
HTML
end
end
end