Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: python-sfml  (Read 23848 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: python-sfml
« Reply #15 on: May 01, 2013, 09:28:52 am »
Any news on 1.3?

Also, could you provide packages for both ubuntu 12.04 (lts) and 13.04 (newest)? That would be amazing as for example I use 13.04 on desktop but 12.04 on my server and I want to write a little server in python using sfml sockets.

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #16 on: May 01, 2013, 02:35:34 pm »
Yay ! Happy to know that the Python binding is finally approaching a stable version :-) !
The python bindings are relatively stable since v1.1.  The installation from source wasn't always straight forward although I did always encourage using packages and installers I provided instead.

Good luck with the final changes. Could you please publish python-sfml on PyPi ? (so we can install it with "pip" which would be *way* easier).
Thanks! The newest version bundles a C/Cython API so it has dependencies but I will look at how I can add it to pypi :)

Any news on 1.3?

Also, could you provide packages for both ubuntu 12.04 (lts) and 13.04 (newest)? That would be amazing as for example I use 13.04 on desktop but 12.04 on my server and I want to write a little server in python using sfml sockets.
As you can see here (https://launchpad.net/~sonkun/+archive/sfml-experimental/+packages) this is my 8th attempts in compiling the source package on their server. It works locally... but I have to figure out why it doesn't pass on launchpad...

I just woke up, I'm working on releasing 1.3.. so by the end of the day! :)
Interested in using SFML with Python ? Try out its Python binding!

halflings

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: python-sfml
« Reply #17 on: May 02, 2013, 04:52:46 pm »
Are the packages stable now ? (and which ppa should be used: ppa:sonkun/sfml-development ? )

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: python-sfml
« Reply #18 on: May 02, 2013, 10:37:46 pm »
Hi, please, why can't we create a sprite without a texture ? (with a default constructor like sfml) ? I want to create by default a sprite without a texture... We can't also create a default Texture without source...
« Last Edit: May 02, 2013, 10:44:00 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #19 on: May 03, 2013, 01:48:00 pm »
Are the packages stable now ? (and which ppa should be used: ppa:sonkun/sfml-development ? )
I put a note here regarding the packages repository: http://en.sfml-dev.org/forums/index.php?topic=11338.0

Quote
Warning2: For Python users, I'm experiencing issues with packaging the latest pySFML version, so you'll be better off using the previous stable version (1.2) which is based on SFML2-RC (in sonkun/sfml-stable) But don't worry, first the API differences are small (so it won't take a long time to update your code), and second, as soon as it's done, you can easily update to SFML2 by installing sonkun/sfml-development).

It should be done soon. I've got free time this afternoon so I'll rewrite the setup.py.

Hi, please, why can't we create a sprite without a texture ? (with a default constructor like sfml) ? I want to create by default a sprite without a texture... We can't also create a default Texture without source...
Creating an empty texture would result an invalid and unusable texture, in your class constructor, do:

self.texture = None

But you're right for the sprite default constructor unable to take no argument. It'll be fixed in the next release, meantime, here's a workaround:

sprite = sf.Sprite(sf.Texture.create(1.1)) # create a sprite from a dummy texture
sprite.texture = None # remove the internal texture
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: python-sfml
« Reply #20 on: May 03, 2013, 04:19:37 pm »
Hi again,

I have an error when I want to iterate on sf.RenderWindow.events :
AttributeError: 'code' object has no attribute 'on_resize'
I use the last source update...

Thank you.

édit : Sorry again, but in the source, why sf.RenderWindow isn't inheritate from sf.RenderTarget ?  I need this... Thank you again :)
« Last Edit: May 03, 2013, 04:47:42 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #21 on: May 03, 2013, 04:45:49 pm »
Hi again,

I have an error when I want to iterate on sf.RenderWindow.events :
AttributeError: 'code' object has no attribute 'on_resize'
I use the last source update...

Thank you.

for event in window.events: print(event) works for me. What branch did you compile ?
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: python-sfml
« Reply #22 on: May 03, 2013, 04:48:23 pm »
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.
« Last Edit: May 03, 2013, 05:00:01 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #23 on: May 03, 2013, 06:14:38 pm »
Ohh, an ArchLinux user :p I'm afraid these scripts aren't updated...(I need to contact their author). Officially, version 1.3 isn't released yet, I just made the Windows installers and uploaded a snapshot of the website as the main audience is Windows users.

RenderWindow doens't inherit from RenderTarget because of a Python limitation. A pure Python class can't inherit from two extension Python classes at the same time. Here both, sf.Window and sf.RenderTarget are extension classes.

Are you having issues with isinstance or issubclass functions ? I recently read the abc module documentation, I think it could solve this issue.

And sorry, I don't get it, what's wrong with your code ? (then I'll read it^^)
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: python-sfml
« Reply #24 on: May 03, 2013, 06:49:06 pm »
But I nead this inheritance... Indeed, in the "Render" class, I write on the sf.RenderTarget.view, and if the Windows doesn't have the same view of sf.RenderTarget....

But the Leonard binding have this inheritance, why ?

And sorry for this question but what are the differences between pur and extension python classes

edit : Ah.... Leonard choose the sf.RenderTarget as root class for sf.RenderWindow. I think is better  (because  sf.Window is only useful for sf.RenderWindow (when sf.RenderTarget is useful for sf.RenderTexture and Window). And the script for archlinux is good : it take the last source, compile it and install.

edit2 : you can let this way for inheritance : I find a way with super :) .

Please, can you teste this code for me ? The script is "test.py" writing with python3 . Thank you :)



[attachment deleted by admin]
« Last Edit: May 03, 2013, 08:12:06 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #25 on: May 04, 2013, 01:20:19 am »
I can't test this code since you import stuff you don't provide. Avoid posting long code and don't hesitate to mail me to send me code you want me to test.

Also, prefer opening a new topic when you have an issue instead of putting everything here because first, it's meant for giving your opinions on the bindings, second, it help others search for similar issues (the subject summarizing your issue and being referenced by search engines).

Quote
And sorry for this question but what are the differences between pur and extension python classes .
A extension class is a Python class written in C unlike pure Python classes which are written in Python.

Quote
edit : Ah.... Leonard choose the sf.RenderTarget as root class for sf.RenderWindow. I think is better  (because  sf.Window is only useful for sf.RenderWindow (when sf.RenderTarget is useful for sf.RenderTexture and Window).
How is sf.RenderTarget a better choice ?  Actually the reason is because he doesn't implement sf.Window.

Quote
And the script for archlinux is good : it take the last source, compile it and install.
Oh... :) Then I'm glad!

I speak French too so you can carry on posting on the French forum (if you want of course :])
Interested in using SFML with Python ? Try out its Python binding!

halflings

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: python-sfml
« Reply #26 on: May 04, 2013, 02:01:39 am »
Is it safe to switch to sfml-development now ? :-p

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #27 on: May 04, 2013, 02:53:43 am »
Is it safe to switch to sfml-development now ? :-p

Very very soon! :p I just found out package "cython3" is available for Raring Ringtail so I'll take its source package, and will distribute for older versions which should remove my issue. When targeting Python 3, I relied on Cython installed in Python 2 and the setup.py became hard to understand and maintain because of other stuff I added to make it flexible (platform-specific behavior, cython needed or not, cython available, cython available in other Python version).

Now, I know where I'm going: Cython IS mandatory and must be installed in the targeted Python version. :)
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: python-sfml
« Reply #28 on: May 04, 2013, 11:02:38 am »
The sources were in attachments x) (src.zip...).
Well sorry for the desagrements and for my bad english (I post here because this forum is more active than the french forum ;) ).
I will open a new topic :)

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: python-sfml
« Reply #29 on: May 07, 2013, 09:59:53 am »
Sorry, still no Debian/Ubuntu packages available... I rewrote the setup.py and I already tried a thousand time to package but it still gives weird errors. I'm following both Debian and Ubuntu python packaging policy and their helper scripts don't install things at the right place...
Interested in using SFML with Python ? Try out its Python binding!