I'm on archlinux and then I use the package python-sfml-git .
Please, see my last edit
And for the error, with a sf.RenderWindow basic (without inheritance) I don't have this error.
My code :
mport sfml as sf
from Render import Render
from EventManager import EventManager
from Image import Image
class Window(Render, sf.RenderWindow):
"""This class create a window
Cette classe créé une fenêtre"""
def __init__(self, videoMode, title, parent=0, framerateLimit=60,\
backgroundColor = sf.Color.BLACK, backgroundImage = Image()):
sf.RenderWindow.__init__(self, videoMode, title)
Render.__init__(self, parent, sf.Rectangle(sf.Vector2(),\
videoMode.size), backgroundColor, backgroundImage)
self._isStaticToView = False
self.position = (0,0)
self.framerate_limit = framerateLimit
self._event = EventManager(self)
#self.resetView()
#self.clear(backgroundColor)
def updateFocus(self):
return;
def update(self):
"""Update the Window. It Update all event, and update framerate.
It Draw and display also all widgets child"""
if self.isDrawing:
self._event.update()
self._framerate = 1/(self.event.elapsedTime*10**-6)
if self.event.isResize:
Widget.resizeWidget(self.event.defaultWindowSize,\
self.event.newWindowSize)
Widget.widgetFocus = None
Updatable._focusIsChecked = False
self.clear(self.backgroundColor)
if self.event.isMouseInRect(self.rectOnScreen):
Updatable.updateFocus(self)
Widget.update(self, self)
self.display()
#It's not the most importante
def getEventFromRootParent(self):
return self._event
def _setSize(self, size):
Widget.size = size
sf.RenderWindow.size = size
self._imageBackground.scale = sf.Vector2f(\
size.x/self._imageBackground.local_bounds,\
size.y/self._imageBackground.local_bounds)
def getPosOnScreen(self, *args):
return sf.Vector2f(0,0)
def setPos(self, position, *args):
Widget.setPos(position, False)
self.position = position
def _setView(self,view):
sf.RenderWindow.view.__set__(self, view)
Render._setView(self,view)
def _resizeWidget(self, pos, size):
self._size = size
size = Widget.size
event = property(lambda self:self._event)
framerate = property(lambda self:1/self._event.elapsedTime*0.001)
setPosOnScreen = setPos
and Render (abstrate class)
import sfml as sf
from Image import Image
from Widget import Widget
from copy import copy
import functions
class Render(Widget):
"""Basic virtual class for all Render's class"""
def __init__(self, parent, rect, backgroundColor=sf.Color.BLACK,\
title=str(), backgroundImage=Image()):
Widget.__init__(self,parent, rect)
self.canFocus = False
self.backgroundColor = backgroundColor
def show(self, render):
raise NotImplementedError
def moveView(self, move):
newView = self.view
newView.move(move.x, move.y)
self.view = newView
def zoomView(self,zoom):
newView = self.view
newView.zoom(zoom)
self.view = newView
def resizeView(self, size):
self.view.size(size)
self.view = self.view
def resetView(self):
self.view = self.default_view
def setViewSize(self, size):
newView = self.view
newView.size = size
self.view = newView
def setViewPosition(self, pos):
viewCopy = self.view
viewCopy.center = sf.Vector2(pos - self.view.size / 2)
self.view = viewCopy
def setViewport(self, viewport):
viewCopy = self.view
viewCopy.viewport = viewport
self.view = viewCopy
def getViewPosition(self):
return sf.Vector2(self.view.center[0],self.view.center[1]) + \
sf.Vector2(self.view.size[0],self.view.size[1]) / 2
def getSommeViewPosition(self):
render = Widget.getRender()
rect = self.getViewRectWithZoom()
if isinstance(render,Render):
return sf.Vector2(render.getSommeViewPosition() +\
sf.Vector2(rect.left, rect.top))
else:
return sf.Vector2(rect.left, rect.top)
def getViewRect(self):
return sf.Rectangle(self.getViewPosition(), self.view.size)
def getViewRectWithZoom(self):
viewRect = self.getViewRect()
scale = self.getViewScale()
return sf.Rectangle(\
sf.Vector2(viewRect.left*scale.left, viewRect.top*scale.top),\
sf.Vector2(viewRect.width * scale.width,\
viewRect.height * scale.height))
def getRender(self):
return self
def isInView(self,rect):
return functions.rectCollision(rect,self.view.viewport)
def getViewScale(self):
return sf.Rectangle(sf.Vector2(self.viewport.left*self.view.size.x+1,\
self.viewport.top * self.view.size.y + 1),\
sf.Vector2(self.viewport.width / \
(self.view.size.x / self.size.x),\
self.viewport.height / (self.view.size.y / self.size.y)))
def _setBackgroundImage(self, backgroundImage):
self._backgroundImage = backgroundImage
self._backgroundImage.pos = sf.Vector2(0,0)
self._backgroundImage.size = self.size
self._backgroundImage.setParent(self.parent, 0)
def _setView(self, view):
back = self.getViewRectWithZoom()
back = sf.Vector2(back.left, back.top)
sf.RenderTarget.view.__set__(self,view)
for child in self._child:
if isinstance(child,Widget) and child.isStaticToView:
child.setPos(child.pos - back)
def _setViewport(self, rect):
newView = copy(self.view)
newView.viewport = rect
self.view = newView
def _setTitle(self, title):
self._title = title
size = Widget.size
backgroundImage = property(lambda self:self._backgroundImage,\
lambda self,image: self._setBackgroundImage(image))
viewport = property(\
lambda self:sf.RenderTarget.view.__get__(self).viewport,\
lambda self,rect : self._setViewport(rect))
title = property(lambda self:self._title,\
lambda self,title : self._setTitle(title))
view = property(lambda self:sf.RenderTarget.view.__get__(self),\
lambda self,view : self._setView(view))
The most importante here are : constructors, updates functions and properties.