[Develop] Question: How to "import app"
Ben Dean-Kawamura
ben at pculture.org
Wed Dec 19 15:15:41 EST 2007
Hi Marian, thanks for sending your email. Getting remote controls working
with Miro would be pretty awesome. You also have very funny timing, because
we discussed this topic this morning in our developer's call.
Basically this is a flaw in Miro's architecture right now. We have lots of
circular dependencies when importing modules, so changing the order of imports
(especially app) can cause things to break. We're planning on fixing this
problem in trunk, but this might not help you, since you probably want a fix
that will work with the 1.0 branch.
I can think of several options:
1) Don't import app at the top level, instead import it in the functions that
use it. This is the quick and dirty way, it will probably get out of hand
if you need to access app in more than a few places.
2) Create a new module for your code. Have that one import app. This seems
cleaner to me, but then you have to worry about hooking into the eventloop.
If you import your module from eventloop, you'll get the same problems.
Instead, I think the way to do it is to edit app.py and look for the
finalizeStartup() method. At the end of that method, call
eventloop.addTimeout(delay, yourmodule.somemethod, "LIRC Poll"). That will
arange to call your function whenever we have some spare time in the
eventloop. At the end of that method you can call eventloop.addTimeout()
again to ensure that it keeps runing.
I'm assuming you're working in the 1.0 branch here. If you're working in
trunk, things get slightly more complicated because I'm about to check in some
changes to the startup code. In that case you'll want to change the
finalizeStartup() method in startup.py instead. I think you probably want to
work in 1.0, since it's a more stable codebase at this point.
Ben
On Wed, Dec 19, 2007 at 08:48:49PM +0100, Marian Dubiel wrote:
> Hi everybody,
>
> it would be nice if someone could help me with a problem I have.
>
> I want to implement remote control in miro with lirc. Therefore I use
> pylirc to get the commands from my remote.
> Because I don't wanna spend much time on it, I followed a quick and
> dirty approach and hacked the necessary code into the "eventloop.py"
> (because pylirc uses polling to retrieve the commands from the remote
> and by using "Eventloop.loop()", I don't have to write my own loop In a
> seperate thread).
>
> This works fine so far, I get the commands from my remote control. Now I
> want to execute the right commands, so I looked into "keyboard.py" and
> found the necessary methods like
> "app.controller.playbackController.playPause()".
> To use these methods however, I have to import "app".
> If I add the statement "import app" to the import statements in the
> "eventloop.py" file I get this stack trace when starting up miro:
>
> ---------------------------------- SNIPPET
> ----------------------------------
> Traceback (most recent call last):
> File "/usr/bin/miro.real", line 24, in <module>
> import gtcache
> File "/var/lib/python-support/python2.5/miro/gtcache.py", line 22, in
> <module>
> import config
> File "/var/lib/python-support/python2.5/miro/config.py", line 25, in
> <module>
> import eventloop
> File "/var/lib/python-support/python2.5/miro/eventloop.py", line 28,
> in <module>
> import app
> File "/var/lib/python-support/python2.5/miro/app.py", line 24, in <module>
> import views
> File "/var/lib/python-support/python2.5/miro/views.py", line 19, in
> <module>
> import feed
> File "/var/lib/python-support/python2.5/miro/feed.py", line 20, in
> <module>
> from item import *
> File "/var/lib/python-support/python2.5/miro/item.py", line 20, in
> <module>
> from gtcache import gettext as _
> ImportError: cannot import name gettext
> -------------------------------------------------------------------------
>
> Unfortunately, I am not familiar with python at all, so I have no idea
> if the error occurres because of a restriction in the architecture of
> miro or if this is a "problem" with python (maybe I have to use the
> import statement in another way).
> Several other files import app, so why does that not work in
> eventloop.py. Is there another way to get the object I need for
> controlling the player?
>
> Thank you for reading my request and I thank you all for this cool
> application.
>
> Best regards
>
> Marian Dubiel
> _______________________________________________
> Develop mailing list
> Develop at pculture.org
> http://participatoryculture.org/mailman/listinfo/develop
More information about the Develop
mailing list