Page 1 of 2

moving a stack blocks other events

Posted: Sun Sep 04, 2011 9:33 pm
by xfratboy
Can someone help me understand why moving a stack (grabbing it's title bar and moving it around the screen) causes things to pause? For example, if I have a repeat loop or animation/move going on when the window/stack is repositioned the move/animation will freeze until I release the mouse. The same is true for repeat loops. Aside from changing the decorations to empty (hence preventing the stack from being moved), is there a way around this?

Re: moving a stack blocks other events

Posted: Mon Sep 05, 2011 1:27 am
by Mark
Hi,

The only way around this problem is to write your own window moving routine, which would have to leave sufficient time to the engine to do other tasks.

Kind regards,

Mark

Re: moving a stack blocks other events

Posted: Mon Sep 05, 2011 1:51 pm
by xfratboy
I've played around a bit with the MoveStack handler but that doesn't help because the MoveStack only triggers once the stack is moved. I'm wondering if you could elaborate some on what you mean by :
...write your own window moving routine,

Re: moving a stack blocks other events

Posted: Mon Sep 05, 2011 3:35 pm
by BvG
you need to disable the window title bar (see "decorations" property), and then add code that allows people to grab your stack. for example a fake title bar with code to change the location of the stack. This code makes the stack move to the mouse location:

Code: Select all

on mouseDown
   set the loc of this stack to the screenmouseloc
end mouseDown

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 3:13 am
by xfratboy
Humm. Thanks for the feedback. I wish there was a better way to keep things moving & running in a stack while still being able to reposition the stack around on the screen.

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 10:09 am
by sturgis
If you put the following handler in your stack it will help some.

Code: Select all

on moveStack
   wait 10 milliseconds with messages
end moveStack
As long as the stack is being actively moved so that the movestack message is triggered it works fine. However, not moving while holding the mouse button down on the title bar will still cause a halt.

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 10:21 am
by Mark
Hi Sturgis,

I tried this with some animated objects, which use the move command. It doesn't work for me. I wouldn't waste time trying to make it work and would just make the window non-movable or create a custom title bar to move the stack.

Kind regards,

Mark

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 10:56 am
by sturgis
Yeah, that would be the best bet. I put together a simple clock that uses a send in time and it works ok under the circumstances I specified, but even then its a bit 'quirky.'

I grew up in albuquirky, so I recognize it when I see it!

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 11:10 am
by Klaus
sturgis wrote:...I grew up in albuquirky, so I recognize it when I see it!
:D :D :D

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 4:16 pm
by xfratboy
Well, an even bigger problem with this arises when I have a device attached to the serial port. When the window is dragged around, the transmission of data/commands to the device seems to buffer-up and/or lose packets of info, sometimes even locking up the serial device (which is a custom piece of medical equipment). I'll test your suggestion sturgis, but holding the mouse down seems to cause problems no matter what solution I've tried (except for setting the decorations to empty).

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 5:00 pm
by sturgis
Yeah, doubt theres a solution when using the default titlebar. Or at least not one i'm knowledgeable enough to figure out.

For info on writing your own theres a lesson that has some code for a window move at http://lessons.runrev.com/s/lessons/m/2 ... ndow-shape
Some really great lessons to be had there.

The stock script won't achieve the affect you want but if you modify the mousemove handler to include a wait with messages it will probably work ok.

Code: Select all

on mouseMove 
   lock screen
   if sgDragging is true then 
      set the left of this stack to item 1 of globalloc(the mouseLoc) - sgLeftOffset 
      set the top of this stack to item 2 of globalloc(the mouseLoc) - sgTopOffset 
      
      -- added by me. Despite being 0 ms, gives enough time for other messages to kick in
      -- 10 milliseconds wait makes it a bit jumpy on my system but 0 seems to work well. 
      wait 0 milliseconds with messages 
      
   end if 
   unlock screen 
end mouseMove

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 5:11 pm
by Mark
Hi St4urgis,

I tested a script like yours and it didn't work. Other move messages, which together animate a number of objects, were blocked. Have you tested your script?

Kind regards,

Mark

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 6:11 pm
by sturgis
With animations, I haven't. I was kinda hoping the script would help with the serial issue mentioned by xfratboy.

I just did a test using an arduino (I'm clueless about the animation stuff, but am getting better at the serial)

Using the serialcallascii script example for the arduino (changed rate to 115200) and my stack to connect to it and send and receive data, it seems to work really well.

Heres my script for talking to the arduino (all of it, the readloop being the key part here, but posting all)
Its very specific to what i'm trying to learn now, but still might be helpful.

Code: Select all

local tReading,tOut
on openCard
   -- I set my parameters to match the arduino script
   set the serialcontrolstring to "baud=115200 parity=N data=8 stop=1" 
   doconnect -- call connect handler
end openCard

on closecard
   if tReading then dodisconnect -- call disconnect handler
end closecard

command toggleConnect 
    -- this is a called by a button to toggle connection status. 
    -- I turn it off when I want to upload a new script, back on to test.
   if tReading then
      dodisconnect
   set the label of button "tConB" to "Disconnected"
   else
      doconnect
      set the label of button "tConB" to "Connected"
      end if
end toggleConnect

 -- just sends an A. 
 --I have a script or two for the arduino that grab the A and figure out what to do with it
command turnon
   if tReading then  write "A" to file "COM3:"
end turnon

--same as above. sends o
command turnoff
   if tReading then write "o" to file "COM3:"
end turnoff

--sends b
command makeBlink
   if tReading then write "b" to file "COM3:"
end makeBlink

--connects, toggles a connection flag (tReading), starts readloop.
command doconnect 
   put true into tReading
   open file "COM3:" for update
   set the label of button "tConB" to "Connected"
   readLoop
end doconnect

-- disconnects, sets flag to false so readloop will exit
command dodisconnect
   put false into tReading
   close file "COM3:"
   set the label of button "tConB" to "Disconnected"
end dodisconnect

--if tReading then
--reads from com3 till empty.  
--if theres something there, put it into my field. 
--calls itself in 50 milliseconds
command readLoop
   if tReading then
      read from file "COM3:" until empty
      if it is not empty then put it after tOut
      send readLoop to me in 50 milliseconds
   else
      put empty into tOut -- "outField"
   end if
   if the number of lines in tOut > 20 then
      delete line 1 to -21 of tOut -- just limits the amount of data to show
   end if
   lock screen
   put tOut into field "outField" -- puts the data into the field
   unlock screen
end readLoop
Then there is the script I mentioned. If you put it in a graphic (for testing I just made an opaque graphic)
and put the following (from the lesson linked earlier) as its script, (with the added wait 0 with messages) data comes in at a regular pace whether i'm dragging the window (by my graphic handle) or not.

I don't know enough about how move works to know what the holdup might be with that, hopefully someone else will chime in and be able to help.

Code: Select all

local sgDragging, sgLeftOffset, sgTopOffset

on mouseDown 
    put item 1 of the mouseLoc into sgLeftOffset 
    put item 2 of the mouseLoc into sgTopOffset 
    wait 0 milliseconds with messages
    put true into sgDragging 
end mouseDown

on mouseMove 
    lock screen
    if sgDragging is true then 
        set the left of this stack to item 1 of globalloc(the mouseLoc) - sgLeftOffset 
        set the top of this stack to item 2 of globalloc(the mouseLoc) - sgTopOffset 
    end if 
    unlock screen 
end mouseMove

on mouseRelease 
    put false into sgDragging 
end mouseRelease

on mouseUp 
    put false into sgDragging 
end mouseUp

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 6:15 pm
by sturgis
Disclaimer-- From the above I had this:

Code: Select all

   if the number of lines in tOut > 20 then
      delete line 1 to -21 of tOut -- just limits the amount of data to show
   end if
Have NO clue why I did it that way, don't think it does what I wanted. Must have been tired at the time!

Re: moving a stack blocks other events

Posted: Tue Sep 06, 2011 7:07 pm
by sturgis
It seems to work ok while moving stuff around. I did a very simple stack, 3 buttons, 1, 2, and 3.

I put the following script in button 1.

Code: Select all

command moveButton
   if tDir is empty then put "up" into tDir
   lock moves
   if tDir is "down" then 
      move button 2 from 100,100 to 100,300 in 2 seconds without waiting
      move button 3 from 200,100 to 200,300 in 2 seconds without waiting
      put "up" into tDir
   else
      move button 2 from 100,300 to 100,100 in 2 seconds without waiting
      move button 3 from 200,300 to 200,100 in 2 seconds without waiting
      put "down" into tDir
   end if
   unlock moves
end moveButton
On clicking button 1, buttons 2 and 3 start to move. I have a graphic on the stack as my handle, during the move I drag the stack around, and nothing freezes.

Are you using the "without waiting" stuff on the end of the move statements?