Rendering_options pause start_timer?
-
I want to call a messagebox when the user clicks. On the mouse click, I first want to draw something on the screen (not included in this example code), but since the messagebox is modal, I have to keep some time in between to update the view before the messagebox appears. So far it would work by using
UI.start_timer
.But it seems changing the
Sketchup.active_model.rendering_options
pauses the timer until the cursor hovers the UI (toolbar etc.).
If you disable the lines marked with ###, the messagebox appears like normal. Why could that be?class TestTool def initialize @ip = Sketchup;;InputPoint.new @model = Sketchup.active_model end def onMouseMove(flags, x, y, view) @ip.pick(view, x, y) view.invalidate end def onLButtonDown(flags, x, y, view) @ip.pick(view, x, y) #@model.select_tool(nil) # no good workaround id = UI.start_timer(1, false){ UI.stop_timer(id) UI.messagebox("When did this messagebox appear?", MB_YESNOCANCEL) } end def draw(view) if @ip.valid? && @ip.display? @ip.draw view text = "text" c = @model.rendering_options['ForegroundColor'] @model.rendering_options['ForegroundColor'] = Sketchup;;Color.new("white") ### view.draw_text( view.screen_coords(@ip.position), text ) @model.rendering_options['ForegroundColor'] = c ### end end end Sketchup.active_model.select_tool(TestTool.new)
-
This is odd.
When I click on empty space the timer triggers as expected. (No text is displayed then.)
But when I click on geometry things get delayed. (Text is displayed.)
Don't know why this is.
But - I wouldn't set
@model.rendering_options['ForegroundColor']
in thedraw
event. The operation adds to the undo-stack. So if you do that in the draw event you're flooding the undo-stack and effectively zaps it.Because it adds to the undo stack I decided not use set forground colour to control the
draw_text
colour - because adding these events to the undo stack will just confuse the user and he/she tried to go back in the stack - even if you set it at the activation and deactivation of the tool. -
The
id
reference should be@id
, otherwise it's local to the method and may get GC'd.The first arg to
start_timer
should be aFloat
. -
Thanks for the replies and for the correction about @id. I changed both, but it doesn't solve the problem.
It seems the timer starts correctly and counts until the end, only the action (code block) isn't executed until the user hovers empty space or give focus to other UI elements.
@unknownuser said:
I wouldn't set @model.rendering_options['ForegroundColor'] in the draw event.
I agree (I didn't think about that), although I didn't notice it in Edit → Undo... I now chose to get along without text color.
Advertisement