|
From: Alex T. <al...@tw...> - 2006-12-18 16:00:11
|
Alec Bennett wrote:
> One more question and then I'm reasonably homefree:
>
> Any clue how to set a component from a sub thread?
>
> In other words, say I launch this thread from the class that's running my gui:
>
> class somethread ( threading.Thread ):
>
> def run ( self ):
>
> self.components.nowplaying.file = "somefile.jpg"
>
> somethread().start()
>
>
> Currently the "self" doesn't reach the PyCard gui. I confess to still
> being confused by "self", which is probably the problem.
>
> Here's how my gui is launched, if it mattes:
>
> class MyBackground(model.Background):
> def on_initialize(self, event):
>
>
> I've been trying things like MyBackground.components.nowplaying.file =
> "somefile.jpg", but that's probably moronic.
>
>
Not necessarily moronic, depending on the context :-)
Did you look at samples/chat.py, which does some simple threading (but
in a different way).
It does the equivalent of
(sorry, this is untested, I'm in the process of switching computers, and
can't actually run anything in Python right now :-)
class somethread:
def __init__ (self, parent):
self.parent = parent
def run (self):
self.parent.components..nowplaying.file = "somefile.jpg"
class MyBackground(model.Background):
def on_initialize( self, event ):
-- this 'self' is the background, and it is passed to
'somethread' as the parameter 'parent'
thethread = somethread(self)
thethread.start()
--
Alex Tweedly mailto:al...@tw... www.tweedly.net
|