Howdy All,
I have a situation regarding threading that I'm hoping that you gurus can
advise on,...
I'm doing a UI where I spawn a second, threaded process....the child process
affects the parent process by altering the parent's behaviour and/or animation
timing.
Using modules "threading" and "functools"..
from threading import Thread
from functools import wraps
ProcessA does a standard .ui load, and presents a "revolving door" type of
interface for selection. It is similar (though not identical) to one used at
http://video.pbs.org/
ProcessB is spawned thusly:
task1(self)
for i in range(0, 10):
print(".")
...which calls:
@run_async
def task1(form):
print("task 1")
for i in range(0, 1000):
for j in range(1, 2):
cmd = ("rect = QtCore.QRect( form.pix_%d.geometry() )"
% j)
exec(cmd)
x = rect.x()
y = rect.y()
w = rect.width()
h = rect.height()
x = x - 1
cmd = ("form.pix_%d.setGeometry(%d,%d,%d,%d)" %
(j,x,y,w,h) )
exec(cmd)
form.update()
time.sleep(.02)
which in turn runs:
def run_async(func):
@wraps(func)
def async_func(*args, **kwargs):
func_hl = Thread(target = func, args = args, kwargs = kwargs)
func_hl.start()
return func_hl
return async_func
"ProcessB" uses these...to basic translate some graphical elements back and
forth along the X-axis
to give the UI an animated, lively look,....not unlike many CNN logo treatments
on TV,etc...
They are simple, transparent "planes".
"ProcessA" translates/revolves it's elements via QTimeLine using a 24-step
animation cycle
that is offset for each subsequent window element. Code snippets look like
this:
self.tl = QtCore.QTimeLine(1000)
self.tl.setFrameRange(0, 30)
self.connect(self.tl, QtCore.SIGNAL("frameChanged(int)"),
self.FocusFadeOutToBlack )
ETC
ETC
self.connect(self.tl, QtCore.SIGNAL("finished"), self.FocusFinishFadeOut )
self.tl.start()
The problem that occurs....is that while ProcessB is translating it's simple
graphical elements,
the user hits a button that tells ProcessA to "move to the next window".
ProcessA must move
the window to an exact location,...which it does when ProcessB is *not*
running. But when
ProcessB *is* running,...the windows in ProcessA fall short of their end
location. I'm thinking
that the "sleep" command in ProcessB may also be affecting ProcessA's timing,
something
sure is.
From what I've read....threading process should work independently of each
other,
and shouldn't cause any "crosstalk" as it were. Not having ProcessB's
animating graphical
elements really takes away a lot of the UI's sparkle. Again,..if I don't spawn
ProcessB,
ProcessA works right every time.
Can anybody shed any light, experience, or knowledge regarding this phenomena?
Thank you very much,
Cheers,
Jim
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt