[Mirra] Mirra and pygame
enrike
enrike at ixi-audio.net
Mon May 21 11:25:35 CEST 2007
hi again
I have been checking this and i dont like very much having to use
from mirra import *
because then I have to be doing graphics.Rect and so on everywhere and
this is a mayor change in the way I have been doing mirra up to now.
What do you think about doing something like
import pygame.locals as p
print p.K_m
It does work and allows to use pygame.locals within mirra with no mayor
changes.
enrike
dropmeaword at yahoo.com(e)k dio:
> Hello,
>
> Seems like importing pygame.local overrides the Mirra graphics namespace. The following is a short example that works ok:
>
> #!/usr/bin/env python
>
> from mirra import main
> from mirra.graphics import *
> from mirra import utilities
>
> class MirraApp(main.App):
> def setUp(self):
> self.caption = "namespace sample"
> self.size = 640, 480
> self.pos = 100,100
> self.fullScreen = 0
> self.frameRate = 15
>
> def start(self):
> self.txtdisplay = Text('some text', 300, 300, 1)
>
> for z in range(150):
> x = utilities.randint(0, self.width)
> y = utilities.randint(-150, 0)
> d = utilities.randint(5,10)
> Particle(x,y,z,d,d,color=(1,0,0,d))
>
> class WeeSquare(Rect):
>
> def step(self):
> self.y = 120
> self.x = 120
>
>
> if __name__ == '__main__': MirraApp()
>
>
>
> adding the import statement:
>
> from pygame.locals import *
>
> breaks the example, causing namespace conflicts. This is the error message you get at runtime:
>
> Traceback (most recent call last):
> File "E:\DOWNLO~1\DEVELO~1\python\INTERA~1\mirra\examples\mirra\main.py", line
> 259, in OnPaint
> if not self.init: self.initFrameRate()
> File "E:\DOWNLO~1\DEVELO~1\python\INTERA~1\mirra\examples\mirra\main.py", line
> 215, in initFrameRate
> self.app.start() # call start subclass method just before entering the main
> loop, to initialise objects etc...
> File "sam1.py", line 24, in start
> Particle(x,y,z,d,d,color=(1,0,0,d))
> TypeError: Argument must be rect style object
>
> Given that the key constants are in pygame.locals it's a pretty frequent import you are bound to use sooner or later. It's unfortunate that it breaks the mirra.graphics namespace. Both Rect and Text are defined in pygame.
>
> Changing the mirra.graphics import to
>
> from mirra import *
>
> And preceding the class names with the namespace where they belong solves the problem
>
> class WeeSquare(graphics.Rect):
>
> instead of
>
> class WeeSquare(Rect):
>
>
> but imho it's an inconvenience.
>
> Cheers,
> Luis.
>
>
>
>
>
>
>
>
>
> ____________________________________________________________________________________
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> http://answers.yahoo.com/dir/?link=list&sid=396546091
>
> _______________________________________________
> Mirra mailing list
> Mirra at goto10.org
> http://lists.goto10.org/cgi-bin/mailman/listinfo/mirra
>
More information about the Mirra
mailing list