[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] py2exe oceangui problem
- To: pygame-users@xxxxxxxx
- Subject: [pygame] py2exe oceangui problem
- From: David Gustafson <daveg@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 7 Apr 2009 08:37:43 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 07 Apr 2009 11:37:45 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=lzhB4EgY7waBNlPgQ6FjwetkwsFmWXlQI3xrzjOfxcI=; b=JPOCBuWLladMcAIXXkUZb0hacOUyLcw8K7ksnApdNM1xlgSAJQV5CcjNfN22flyow/ dvExrYj68bsQrx/OQiGb7rw8c1ZHdT2eYT/4AHPvsEOOch/dfNyvOvS9EXUo1NzGKm78 kUB+Kq/Qrh0gAzMDsbqDDNJdppRFTYlvT9/js=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; b=fJzrWaibcR5rdZolMl1LWj+wbT/Lt5CP5L+lEDXgsoXiTz9sn7Lo+gzxNjuJRHNfNg Y2YuEOf3bqp8Y+AXEAA8hq/5/eX/0ieAV8evS31Ej5Bxm9+lDj4nHBWF1dwoST4vX2mb iayJi9rKLEhN8mzMIpLN8CxDgdSAzGhzLex98=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I'm having a problem and I wonder if anyone has any insight. I have a
program that works runs properly but when I use py2exe to create an
executable and then attempt to run that executable from the dist dir I
get:
D:\code\test\dist>twisted_ocean_client.exe
D:\code\test\dist\library.zip\twisted\spread\pb.py:30:
DeprecationWarning: the md5 module is deprecated; use hashlib instead
D:\code\test\dist\library.zip\ocempgui\draw\String.py:71:
RuntimeWarning: use font: DLL load failed: The specified module could
not be found
.
Traceback (most recent call last):
File "twisted_ocean_client.py", line 279, in <module>
File "twisted_ocean_client.py", line 227, in __init__
File "twisted_ocean_client.py", line 239, in drawButton
File "ocempgui\widgets\Button.pyc", line 83, in __init__
File "ocempgui\widgets\Button.pyc", line 97, in set_text
File "ocempgui\widgets\Label.pyc", line 124, in __init__
File "ocempgui\widgets\Label.pyc", line 158, in set_text
File "ocempgui\widgets\BaseWidget.pyc", line 961, in <lambda>
File "ocempgui\widgets\BaseWidget.pyc", line 527, in set_dirty
File "ocempgui\widgets\BaseWidget.pyc", line 875, in update
File "ocempgui\widgets\BaseWidget.pyc", line 792, in draw
File "ocempgui\widgets\Label.pyc", line 318, in draw_bg
File "D:\Python26\share\ocempgui\themes\default\DefaultEngine.py",
line 682, in draw_label
rtext = self.draw_string (label.text, label.state, cls, st)
File "D:\Python26\share\ocempgui\themes\default\DefaultEngine.py",
line 287, in draw_string
return String.draw_string (text, name, size, alias, color, st)
File "ocempgui\draw\String.pyc", line 169, in draw_string
File "ocempgui\draw\String.pyc", line 135, in create_font
File "ocempgui\draw\String.pyc", line 71, in create_file_font
File "pygame\__init__.pyc", line 70, in __getattr__
NotImplementedError: font module not available
D:\code\test\dist>
Here is the code it is compiling and I can run it directly with python.
----------
import pygame
import sys
from pygame import QUIT, event
from pygame import error as PygameError
from pygame import time as PygameTime
from random import randint
from ocempgui.widgets import *
from ocempgui.widgets.Constants import *
from ocempgui.object import BaseObject
from ocempgui.widgets import Button, Renderer
from twisted.internet._threadedselect import install
install()
from twisted.spread import pb
from twisted.internet import reactor
REPORT = pygame.locals.USEREVENT + 4
SCORE = pygame.locals.USEREVENT + 5
def main_loop():
events = pygame.event.get ()
for ev in events:
if ev.type == pygame.QUIT:
sys.exit ()
re.distribute_events (*events)
re.refresh ()
pygame.time.delay (15)
class CustomTwistedRenderer (Renderer):
"""TwistedRenderer () -> TwistedRenderer
A Renderer that allows the easy integration with Twisted.
Because Twisted's threadedselectreactor *must* be shut down before
the main loop shuts down, this Renderer will keep running until
explicitly told to stop.
Before starting the main loop, this Renderer will check to see if it
has a Twisted reactor attached to it. This is an attribute set like
any of the normal Renderer attributes:
self.reactor = reactor
If self.reactor is None (default), this will behave like a normal
Renderer. If self.reactor has been set, the QUIT signal will call
reactor.stop(), and then wait for reactor.addSystemEventTrigger to
call self.stop(). This function will then stop the main loop.
Usage
-----
Install the threadedselectreactor instead of the default reactor:
from twisted.internet.threadedselectreactor import install
install()
from twisted.internet import reactor
In the main section of your program, where you create the Renderer,
just set TwistedRenderer's reactor:
re = TwistedRenderer()
re.reactor = reactor
Everything else is handled internally by TwistedRenderer.
Attributes:
reactor - The twisted reactor attached to the TwistedRenderer.
"""
def __init__ (self):
Renderer.__init__ (self)
self._reactor = None
self._running = False
def start (self):
"""T.start () -> None
Overrides default start() to use self._running. If a reactor is
attached, interleave self.waker
"""
self._running = 1
if self._reactor != None:
self._reactor.interleave (self.waker)
self._loop()
def stop (self):
"""T.stop () -> None
Tells the internal loop to stop running.
"""
self._running = False
def set_reactor (self, reactor):
"""T.set_reactor (...) -> None
Sets the internal reactor.
"""
if not hasattr (reactor, 'interleave'):
raise AttributeError ("interleave() method not found in %s" %
reactor)
self._reactor = reactor
self._reactor.addSystemEventTrigger ('after', 'shutdown', self.stop)
def waker (self, func):
"""T.waker (...) -> None
Used in threadedselectreactor.interleave.
"""
event.post (event.Event (SIG_TWISTED, data=func))
def distribute_events (self, *events):
"""T.distribute_events (...) -> None
Overrides default distribute_events() to check for a reactor. If
a reactor is found, the QUIT signal will call reactor.stop(). If
there's no reactor attached, a QUIT signal will simply set
self._running to False.
"""
for event in events:
if event.type == QUIT:
if self._reactor != None:
self._reactor.stop ()
else:
self._running = False
elif event.type == SIG_TWISTED:
event.data ()
else:
Renderer.distribute_events (self, (event))
return True
def _loop (self):
"""T._loop () -> None
Overrides default _loop() so that it will not stop until
self._running is false.
"""
# Emit the tick event every 10 ms.
PygameTime.set_timer (SIG_TICK, 10)
delay = PygameTime.delay
event_get = event.get
pump = event.pump
while self._running:
pump ()
# Get events and distribute them.
events = event_get ()
main_loop()
if not self.distribute_events (*events):
return # QUIT event
if self.timer > 0:
delay (1000 / self.timer)
reactor = property (lambda self: self._reactor,
lambda self, var: self.set_reactor (var),
doc = "The twisted reactor attached to the Renderer.")
class NetController (BaseObject, pb.Referenceable):
def __init__ (self, re):
"""
The network controller. Can call remote PB methods, and because
it inherits from pb.Referenceable, can also contain remote
methods callable by the server.
Make sure you set the internal _signals before setting the
manager, otherwise the signals won't get connected to the event
manager.
"""
BaseObject.__init__ (self)
self._signals[SCORE] = []
self.connect_signal (SCORE, self.add_one)
self.manager = re.active_layer[2]
# Set up twisted connection.
self.factory = pb.PBClientFactory ()
d = self.factory.getRootObject ()
d.addCallback (self.setRoot)
reactor.connectTCP ('localhost', 8008, self.factory)
self.root = None
def setRoot (self, root):
self.root = root
reactor.callLater (0, self.resetter)
def add_one (self, data):
# Call the server's score method and update score by 1. Although
# data is passed to this method, it isn't used. Note that it
# sends self as an arg, so that the server can call a remote
# method on this object.
if self.root:
self.root.callRemote ('score', self, 1)
def resetter (self):
# This method is called by the reactor every 5 seconds to reset
# the score on the server.
if self.root:
self.root.callRemote ('reset', self)
self.emit (REPORT, 0)
reactor.callLater (5, self.resetter)
def remote_report (self, score):
# This method is called by the server and emits a REPORT event
# which is picked up by the JumpingButton object.
self.emit (REPORT, score)
def notify (self, event):
self.run_signal_handlers (event.signal, event.data)
class JumpingButton (BaseObject):
def __init__ (self, re):
"""
The Jumping Button game. When the button is clicked, it emits a
SCORE event, which is picked up by the network controller. It
listens for a REPORT event and updates the score display with
the value given by the server.
"""
BaseObject.__init__ (self)
self._signals[REPORT] = []
self.connect_signal (REPORT, self.adjustScore)
self.manager = re.active_layer[2]
# create gui elements
self.btn = self.drawButton ((20, 20))
self.scoreLabel = Label ("Current score: ")
re.add_widget (self.btn)
re.add_widget (self.scoreLabel)
def clicked (self, data):
x = randint (1, 550 - self.btn.width)
y = randint (1, 470 - self.btn.height)
self.btn.topleft = (x, y)
self.emit (SCORE, data.pos)
def drawButton (self, loc):
button = Button ("Click me!")
button.topleft = loc
button.connect_signal (SIG_MOUSEDOWN, self.clicked)
return button
def adjustScore (self, score):
self.scoreLabel.text = "Current score: %s" % score
def notify (self, event):
self.run_signal_handlers (event.signal, event.data)
# Initialize pygame window
pygame.init ()
screen = pygame.display.set_mode ((200, 200));
screen.fill ((255, 200, 100))
# Create the Renderer to use for the UI elements.
re = CustomTwistedRenderer ()
# Bind it to a part of the screen, which it will use to draw the widgets.
# Here we use the complete screen.
re.screen = screen
# Create a button, place it at x=10, y=30, bind a callback to its
# clicking action and add it to the Renderer instance.
# Some variables we will need in the main loop for drawing a rect.
re.reactor = reactor
re.create_screen (550, 470)
re.title = "Jumping Button"
re.color = (234, 228, 223)
net = NetController (re)
game = JumpingButton (re)
def main_loop():
events = pygame.event.get ()
for ev in events:
if ev.type == pygame.QUIT:
sys.exit ()
re.distribute_events (*events)
re.refresh ()
pygame.time.delay (15)
re.start()
--
Doubt is not a pleasant condition, but certainty is absurd.
-- Voltaire