moving a stack blocks other events

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

moving a stack blocks other events

Post by xfratboy » Sun Sep 04, 2011 9:33 pm

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?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: moving a stack blocks other events

Post by Mark » Mon Sep 05, 2011 1:27 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Re: moving a stack blocks other events

Post by xfratboy » Mon Sep 05, 2011 1:51 pm

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,

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: moving a stack blocks other events

Post by BvG » Mon Sep 05, 2011 3:35 pm

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
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Re: moving a stack blocks other events

Post by xfratboy » Tue Sep 06, 2011 3:13 am

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.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 10:09 am

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: moving a stack blocks other events

Post by Mark » Tue Sep 06, 2011 10:21 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 10:56 am

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!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: moving a stack blocks other events

Post by Klaus » Tue Sep 06, 2011 11:10 am

sturgis wrote:...I grew up in albuquirky, so I recognize it when I see it!
:D :D :D

xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Re: moving a stack blocks other events

Post by xfratboy » Tue Sep 06, 2011 4:16 pm

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).

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 5:00 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: moving a stack blocks other events

Post by Mark » Tue Sep 06, 2011 5:11 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 6:11 pm

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 6:15 pm

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!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: moving a stack blocks other events

Post by sturgis » Tue Sep 06, 2011 7:07 pm

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?

Post Reply