Disable OnLButtonUp when onLButtonDoubleClick
-
Hi,
In class Tool, Is it possible to disable the method OnLButtonUp or OnLButtonDown when you call the method onLButtonDoubleClick
Thank you in advance for your answers
ChrisP
-
I do not think so. You can use a timer to defer execution for a fraction of a second, and then a DoubleClick can cancel the timer.
-
@jim said:
I do not think so. You can use a timer to defer execution for a fraction of a second, and then a DoubleClick can cancel the timer.
Will only work on SU8 or later as the timer in previous versions was bugged, rounding everything down - the minimum you could defer would be a second in them versions.
-
What is order of UI::Tool class callbacks called by Sketchup, when a user double clicks the Left Mouse Button, including onKeyDown() and onKeyUP() ?
-
Seems LButtonDown and LButtonUp always and only occur once each, followed by onLButtonDoubleClick if there was an one.
Here's the double-click output from the script below:
` onLButtonDown
onLButtonUp
onLButtonDoubleClick
-------------------------`
class TestTool def onKeyUp key, repeat, flags, view puts ;onKeyUp add_newline(Time.now) end def onKeyDown key, repeat, flags, view puts ;onKeyDown add_newline(Time.now) end def onLButtonDoubleClick flags, x, y, view puts ;onLButtonDoubleClick add_newline(Time.now) end def onLButtonDown flags, x, y, view puts ;onLButtonDown add_newline(Time.now) end def onLButtonUp flags, x, y, view puts ;onLButtonUp add_newline(Time.now) end def add_newline(t) UI.start_timer(1) { puts "-" * 25 } end end Sketchup.active_model.select_tool TestTool.new
-
Dan is to prohibit the use of onKeyDown ()and onkeyup ()when a user double clicks the Left Mouse Button.
As Jim says, the solution is perhaps to calculate the delay between two onKeyUp (), if the delay is small consider that a double click to invoke a method equivalent onLButtonDoubleClick. if not call the method onKeyUp () and / or onKeyDown ()
-
Thanks Jim
What do you think about this
class TestTool def onLButtonDown flags, x, y, view puts "-" *25 puts ;onLButtonDown @id = UI.start_timer(1,false){call_method(flags ="single", x, y, view)} end def onLButtonUp flags, x, y, view puts ;onLButtonUp end def onLButtonDoubleClick flags, x, y, view UI.stop_timer @id puts ;onLButtonDoubleClick call_method(flags ="double", x, y, view) end def call_method(flags, x, y, view) if flags == "single" UI.stop_timer @id puts "Call method for onLButtonDown" puts "Call method for onLButtonUp" else puts "Call method for onLButtonDoubleClick" end puts "-" *25 end end Sketchup.active_model.select_tool TestTool.new
should be able to reduce the UI.start_timerto less than 1 second....
-
It works, you can use onLButtonDoubleClick without calling onLButtonDown & onLButtonUp
The delay time is 0.2 it works well for me but it is possible that changes depending on the computerFor SU8
class TestTool def onLButtonDown(flags, x, y, view) puts "-" *25 puts ;onLButtonDown @ip = UI.start_timer(0.2,false){call_method(flags, x, y, view)} end def onLButtonUp(flags, x, y, view) puts ;onLButtonUp end def onLButtonDoubleClick(flags, x, y, view) UI.stop_timer @ip puts ;onLButtonDoubleClick puts "Call method for onLButtonDoubleClick" puts "-" *25 end def call_method(flags, x, y, view) puts "Call method for onLButtonDown" puts "Call method for onLButtonUp" puts "-" *25 end end Sketchup.active_model.select_tool TestTool.new
For SU6 & SU7
class TestTool def onLButtonDown(flags, x, y, view) puts ;onLButtonDown # for test call_method(flags, x, y, view) end def onLButtonUp flags, x, y, view puts ;onLButtonUp # for test end def onLButtonDoubleClick(flags, x, y, view) UI.stop_timer @id puts ;onLButtonDoubleClick # for test puts "Call method onLButtonDoubleClick" # for test puts "-" * 25 # for test end def call_method(flags, x, y, view) start_time = Time.now elapsed_time = 0 loop do elapsed_time = Time.now - start_time # for test puts elapsed_time if elapsed_time >= 0.20 ###### delay time ###### @id = UI.start_timer(0,false){ puts "Call similar method for onLButtonDown" puts "Call similar method for onLButtonUp" puts "-" * 25 # for test } break end end end end Sketchup.active_model.select_tool TestTool.new
ChrisP
-
@c.plassais said:
The delay time is 0.2 it works well for me but it is possible that changes depending on the computer
Under Windows this can be configured by the user. Registry setting. Expect one can set it under OSX - but I have no idea where you'd get the setting.
-
In the script, it's just the time allowed to detect the double click
Advertisement