It is currently Mon Sep 01, 2014 5:50 pm




Post new topic Reply to topic  [ 4 posts ] 
 Using for loop to move a container 
Author Message
Trooper
Trooper

Joined: Mon Jun 11, 2012 4:13 pm
Posts: 24
Post Using for loop to move a container
I have been having issues using a timer to move a container up and down not by just appearing at its new location but moving into place at a certain rate during the mouseEntered event so I went with a for loop as shown:

import time
y = 297

for y in range(107,197):
system.gui.moveComponent(event.source, 196, y)
y = y - 1
time.sleep(1)
if y == 107:
break

This doesn't work for me either even though it seems like it should, what it does is pause a second before moving the container to the final position of (196,107). Do you know why that is? Do you have a better method of doing this?


Fri Aug 03, 2012 10:02 am
Profile
General
General

Joined: Tue May 31, 2011 6:27 am
Posts: 313
Location: Minnesota
Post Re: Using for loop to move a container
Your range starts at 107, so the second iteration y is 108 and the conditional for breaking the loop is met.

Seems like you'd be able to simplify that a bit too...
Code:
import time
y = 297 # why is this declared up here? is this used elsewhere?
x = 196

# get your range and reverse it
range_of_movement = range(107,197)
range_of_movement.reverse()

# move through each value in the range
for y in range_of_movement:
   system.gui.moveComponent(event.source, x, y)
   time.sleep(1)   


Fri Aug 03, 2012 10:39 am
Profile
Trooper
Trooper

Joined: Mon Jun 11, 2012 4:13 pm
Posts: 24
Post Re: Using for loop to move a container
I tried this but my loop froze


Fri Aug 03, 2012 10:56 am
Profile
Moderator
Moderator

Joined: Fri Dec 04, 2009 9:02 am
Posts: 177
Post Re: Using for loop to move a container
The event script is running on the same thread as the GUI. So when you call time.sleep(), it's actually preventing the screen from being repainted.

What I would recommend is instead using a timer component with a property change event handler on it. Then, every time the timers property changes, it moves the proper component a certain number of pixels using system.gui.moveComponent(). This continues until the component has been gradually moved to the new position.

Hope that made sense...


Fri Aug 03, 2012 3:41 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: