SFML community forums

Bindings - other languages => Python => Topic started by: bastien on July 13, 2011, 02:27:20 am

Title: pysfml-cython
Post by: bastien on July 13, 2011, 02:27:20 am
Project page: https://github.com/bastienleonard/pysfml-cython (https://github.com/bastienleonard/pysfml-cython)

Documentation: http://pysfml2-cython.readthedocs.org/ (http://pysfml2-cython.readthedocs.org/)

This binding is up to date (most of the time :roll:) and supports most features of SFML 2.
Currently there's no binary release, you have to compile the module yourself. If you download the current snapshot (in the downloads section on Github), you won't have to install Cython. I noticed in the past that I had forgotten to include some files in the snapshot, or that Github behaved strangely when replacing the it, so please tell me if something goes wrong when using it.
I guess that I will make the first binary release when SFML 2 has a binary release too.

Please read the documentation for more information on the binding, how to build it, etc. ;)
Title: pysfml2-cython
Post by: Laurent on July 13, 2011, 07:55:50 am
It's a good thing you made an annoucement for your binding, I was wondering which projects were still active.

It seems like your Python binding is the only one that's still active. So maybe it should be the official Python binding for SFML 2. What do you think?

Do you have any news from the other bindings?
Title: pysfml2-cython
Post by: bastien on July 17, 2011, 03:43:56 am
As far as I know, it's the only binding that's kept up-to-date. My main concern is about the API usability and bugs that probably lurk in methods that I never use.
So I don't know about making it the official binding, but it could help to make an announcement on the first page like you did for rbSFML. I think a lot of people don't know about this binding.
Title: pysfml2-cython
Post by: Laurent on July 17, 2011, 10:07:12 am
Quote
it could help to make an announcement on the first page like you did for rbSFML

Good idea.
Title: pysfml2-cython
Post by: Laurent on July 17, 2011, 11:18:56 am
Done!
Title: pysfml2-cython
Post by: Groogy on July 17, 2011, 11:20:12 am
I guess congratz are in order? :D
Title: pysfml2-cython
Post by: bastien on July 19, 2011, 02:11:29 pm
Thanks. ;)
Title: pysfml2-cython
Post by: plink on July 26, 2011, 09:59:39 am
Thanks for the project ! A up-to-date binding with sfml 2.0 and the smooth desactivation is working. (yeah !) :3 I'll do some test (everything is working in the examples, exept the shader example... I'll make a topic about it if I can't debug it.) I think it could be great if the worms.py example from the binding pySFML 1.6 will be recoded for the actual binding (I can do it).
Oh and I seen the documentation isn't complete, could I help you to complete it ?  :D
Title: pysfml2-cython
Post by: bastien on July 26, 2011, 03:09:01 pm
I couldn't test shaders on GNU/Linux, so now that I have compiled the latest version on Windows I'm going to try to fix the example. Apparently the runtime error is simply because set_current_texture() must be used instead of set_texture(). The example still doesn't look right though, but I've never really used shaders and there doesn't seem to be an obvious bug in the binding code, so I'm not sure what the problem is.
I don't remember the worms.py example, but I'll check it out.

I just realized that the Pong example doesn't behave like the C++ one, though. It's not obvious whether I made a mistake when porting it or if it's a bug in the binding. :?

The only part of the documentation that I expect to complete in the near future is the tutorial. Adding complete documentation of the classes and methods would be a lot of work, which would be mostly redundant and subject to change a lot before a SFML 2 is stabilized.
Title: pysfml2-cython
Post by: plink on July 27, 2011, 10:41:16 am
For the shader example (I'm on GNU/Linux, I forgot to said ^^') , one of the errors was from the blur.sfx, which won't load from the python file. I checked the blur.sfx file, and I converted the integer number in float number, like the edge.sfx file. The second error was indeed because set_texture() was used instead of set_current_texture(). It's work now !
I tried the pong example, but I don't see what's wrong exect that the game lag.
Ok for the doc :D

Thanks again for the binding !

Edit: oh I didn't notice the french topic ^^'
Title: pysfml2-cython
Post by: Ghost on August 07, 2011, 03:31:21 am
I just tried to compile the module. But apparently theres a file missing:
vcvarsall.bat
Is the snapshot broken or am I doing something wrong?
Any advice/response is appreciated.
Title: pysfml2-cython
Post by: bastien on August 10, 2011, 12:17:19 am
This file needs to be executed before using the Visual Studio command-line tool. If you want to use Visual Studio, you should use the command-line prompt (I don't the remember the exact name) in Visual Studio's entry in the start menu.

If you want to use another compiler, you need to pass an option like --compiler=minwgw32 when invoking the setup script.
Title: pysfml2-cython
Post by: th1z on August 14, 2011, 03:44:24 pm
I tried to compile this under linux, but i am getting errors.
Could somebody help me?
These are the first few lines of the output:

Code: [Select]

python2 ./setup.py build_ext --inplace
running build_ext
skipping 'sf.cpp' Cython extension (up-to-date)
building 'sf' extension
gcc -pthread -fno-strict-aliasing -march=x86-64 -mtune=generic -O2 -pipe -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fPIC -I/usr/include/python2.7 -c sf.cpp -o build/temp.linux-x86_64-2.7/sf.o
sf.cpp:378:3: error: ‘RenderImage’ in namespace ‘sf’ does not name a type
sf.cpp: In function ‘int __pyx_pf_2sf_5Sound___cinit__(PyObject*, PyObject*, PyObject*)’:
sf.cpp:9420:168: error: no matching function for call to ‘sf::Sound::Sound(sf::SoundBuffer&, int&, float&, float&, sf::Vector3f&)’
sf.cpp:9420:168: note: candidates are:
/usr/local/include/SFML/Audio/Sound.hpp:68:5: note: sf::Sound::Sound(const sf::Sound&)
/usr/local/include/SFML/Audio/Sound.hpp:68:5: note:   candidate expects 1 argument, 5 provided
/usr/local/include/SFML/Audio/Sound.hpp:60:5: note: sf::Sound::Sound(const sf::SoundBuffer&)
/usr/local/include/SFML/Audio/Sound.hpp:60:5: note:   candidate expects 1 argument, 5 provided
/usr/local/include/SFML/Audio/Sound.hpp:52:5: note: sf::Sound::Sound()
/usr/local/include/SFML/Audio/Sound.hpp:52:5: note:   candidate expects 0 arguments, 5 provided
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_4Font_5get_image(PyObject*, PyObject*)’:
sf.cpp:13603:84: error: ‘class sf::Font’ has no member named ‘GetImage’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_6smooth___get__(PyObject*)’:
sf.cpp:14253:15: error: ‘class sf::Image’ has no member named ‘IsSmooth’
sf.cpp: In function ‘int __pyx_pf_2sf_5Image_6smooth_1__set__(PyObject*, PyObject*)’:
sf.cpp:14305:57: error: ‘class sf::Image’ has no member named ‘SetSmooth’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_5load_from_screen(PyObject*, PyObject*, PyObject*)’:
sf.cpp:14581:46: error: ‘class sf::Image’ has no member named ‘CopyScreen’
sf.cpp:14593:46: error: ‘class sf::Image’ has no member named ‘CopyScreen’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_7load_from_pixels(PyObject*, PyObject*, PyObject*)’:
sf.cpp:14840:39: error: ‘class sf::Image’ has no member named ‘LoadFromPixels’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_8get_maximum_size(PyObject*, PyObject*)’:
sf.cpp:14915:39: error: ‘GetMaximumSize’ is not a member of ‘sf::Image’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_9bind(PyObject*, PyObject*)’:
sf.cpp:14954:57: error: ‘class sf::Image’ has no member named ‘Bind’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_14get_tex_coords(PyObject*, PyObject*)’:
sf.cpp:15589:71: error: ‘class sf::Image’ has no member named ‘GetTexCoords’
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Image_17update_pixels(PyObject*, PyObject*, PyObject*)’:
sf.cpp:15841:59: error: ‘class sf::Image’ has no member named ‘UpdatePixels’
sf.cpp:15862:59: error: ‘class sf::Image’ has no member named ‘UpdatePixels’
sf.cpp: In function ‘int __pyx_pf_2sf_6Sprite___cinit__(PyObject*, PyObject*, PyObject*)’:
sf.cpp:18958:217: error: no matching function for call to ‘sf::Sprite::Sprite(sf::Image&, sf::Vector2f&, sf::Vector2f&, float&, sf::Color&)’


Am i doing something wrong?
Or do i use the wrong sfml2 version? (Should be the newest github version)
Title: pysfml2-cython
Post by: bastien on August 15, 2011, 01:08:11 am
You're not wrong, I need to update the binding. I just fixed a problem with my GNU/Linux installation and I'm going to try to do this ASAP.
Title: pysfml2-cython
Post by: lattyware on August 15, 2011, 08:31:13 pm
Just as a note, I recently discovered you can't load images before the window is created, or the images show up as solid white instead of the image. Not sure if this is intentional or a bug, but it's not consistant with the old bindings, and I spend quite some time figuring out what the issue was, while porting across a project from the old bindings, so it might be worth noting this in the binding's docs.

Edit: I actually found out the problem was that if you let the images you load go out of scope, they will not be kept around by the sprite. So keep a reference to any images you want to use, besides the sprite.
Title: pysfml2-cython
Post by: bastien on August 19, 2011, 08:08:07 pm
I updated the binding, it should work correctly now. The documentation isn't updated yet.

Quote from: "lattyware"
Just as a note, I recently discovered you can't load images before the window is created, or the images show up as solid white instead of the image. Not sure if this is intentional or a bug, but it's not consistant with the old bindings, and I spend quite some time figuring out what the issue was, while porting across a project from the old bindings, so it might be worth noting this in the binding's docs.


Thanks, I'll test that.
Title: pysfml2-cython
Post by: lattyware on August 22, 2011, 05:23:00 am
Quote
File "sf.pyx", line 1773, in sf.Sprite.__cinit__ (sf.cpp:19704)
TypeError: Argument 'texture' has incorrect type (expected sf.Texture, got sf.Image)


Now getting this error with the updated bindings, both Linux and Windows.

Edit: I see this is an intentional change. Might want to update the docs.

I tried replacing:

Code: [Select]
self.sprite.set_image(image, True)

with:

Code: [Select]
self.sprite.texture = texture
self.sprite.resize(texture.width, texture.height)


But the resize does not appear to work.

(Just as I finish my Ludum Dare entry >.>)

Also, if you didn't see my last edit, I found it wasn't the order, but rather that the sprite doesn't act as a reference to the image. So you can't do sf.Sprite(sf.Image.load_from_file("blah.jpg")) as the image will not be kept in memory, which you could do in the 1.6 bindings.

Not a bug, but as I say, worth noting as it might catch people out.
Title: pysfml2-cython
Post by: bastien on August 24, 2011, 06:10:52 pm
Ah, sorry. It should work now, except that it's set_texture().
I will change Sprite to keep a reference to the texture, and I will probably also change all classes where it's possible. I want to avoid problems if SFML changes the C++ object internally, but maybe I'm just paranoid. :?
Title: pysfml2-cython
Post by: bastien on August 24, 2011, 06:40:11 pm
New URL for the documentation: http://pysfml2-cython.readthedocs.org/
Title: pysfml2-cython
Post by: lattyware on August 25, 2011, 05:26:09 pm
Quote from: "bastien"
Ah, sorry. It should work now, except that it's set_texture().
I will change Sprite to keep a reference to the texture, and I will probably also change all classes where it's possible. I want to avoid problems if SFML changes the C++ object internally, but maybe I'm just paranoid. :?


Cheers for all the effort. It's entirely up to you if you want to keep the reference or not, I'd just reccomend adding a note to the docs if it doesn't, as it's not standard python behaviour, and not how the bindings used to work. It's not exactly hard to work around if you know it's there.
Title: pysfml2-cython
Post by: .teri on September 05, 2011, 12:04:24 pm
Quote from: "bastien"
Ah, sorry. It should work now, except that it's set_texture().
I will change Sprite to keep a reference to the texture, and I will probably also change all classes where it's possible. I want to avoid problems if SFML changes the C++ object internally, but maybe I'm just paranoid. :?


Always is necessary keep a reference when a class use another class in a binding, like sf::Sound with sf::SoundBuffer or sf::Sprite and sf::Texture.
Title: pysfml2-cython
Post by: Rukiri on October 03, 2011, 02:06:05 am
I don't know why but I keep getting, no module named SF.

I've installed PYSFML perfectly and got the egg info, and placed all the include and libs where they needed to be.  I even tried tricking python with the pythonpath.

I've spoken to a few others and they've been having a hard time getting python to work with sfml.

I also keep getting unrecognized command line option -mno-cygwin
Title: pysfml2-cython
Post by: bastien on October 03, 2011, 07:27:06 pm
Just to be sure, are you using this binding on Github or the official PySFML binding on sfml-dev.org?

Sadly, my Windows installation doesn't work anymore, and I don't really know when I'll be able to reinstall it, so I can't really test it on Windows. :?
Title: pysfml2-cython
Post by: Rukiri on October 04, 2011, 01:41:51 am
I got it from the github, there's errors like crazy.  I'm actually installing fedora 15 because of this headache..

I wonder if your binding was generally for linux?  as the mno thing comes only in linux..  I got ruby working so it has to be the binding..

I tried both versions and didn't get either to work.
Title: pysfml2-cython
Post by: bastien on October 04, 2011, 04:24:45 am
I develop on GNU/Linux, but I could build and run the examples on Windows without any problem.
Normally it's pretty straightforward to build it with MinGW. You build SFML 2 first, then you add the SFML headers and libs to the corresponding folders of MinGW. Then you should be able to build pysfml2-cython with a command-line like python setup.py build_ext --inplace --compiler=mingw32.
Then you should have the module built in the current directory.

To test it quickly you can cd to the examples directory and type “PYTHONPATH=..” and then execute some of them (for the pong and shaders examples, it's PYTHONPATH=..\.. of course). Or just import sf from the command line and create a window or something.
Title: pysfml2-cython
Post by: Rukiri on October 04, 2011, 05:27:53 am
(http://i53.tinypic.com/4tkf49.png)

This is the one thing I can't fix.. anything GCC or MinGW related works fine but -mno-cgywin doesn't..
Title: pysfml2-cython
Post by: bastien on October 04, 2011, 06:19:18 pm
The bug has been reported, actually: http://bugs.python.org/issue12641

A quick fix would be to edit the distutils/cygwinccompiler.py file in your Python installation to remove the -mno-cygwin option. Here in the Python repo: http://hg.python.org/cpython/file/f39b26ca7f3d/Lib/distutils/cygwinccompiler.py#l294
Title: pysfml2-cython
Post by: bastien on October 06, 2011, 09:30:22 pm
I just added some support for the WindowHandle class, which required some ugly cast between integers and pointers. It compiles on GNU/Linux, but please let me know if you encounter a problem on Windows or Mac, since the WindowHandle will behave differently there.
Also, let me know if you actually use the window handle with Python programs, so we can see if I can make interaction with system-specific APIs easier.
Title: pysfml2-cython
Post by: Kaoron on October 11, 2011, 11:23:46 am
Hey, glad to see your python binding is still alive and up to date !

Just a little naming issue i think : sf looks like a very short name to import for a module, it looks collision-prone and is not very informative on the library used at first glance (what does sf stands for ? sfml ? sourceforge ? soundfile ? somefoo ?).

I'd think pysfml would be a better name to import, letting users shortcut to sf if they want.

Thanks for your work !
Title: pysfml2-cython
Post by: bastien on October 12, 2011, 02:12:35 am
It's because both C++ SFML and PySFML 1.x use sf as the namespace.
You're right that it's probably not the best module name, but I'm still reluctant to change it, as everyone is used to sf.

If I changed the name, it would probably simply be sfml though. The “py” is redundant for a Python module.
Title: pysfml2-cython
Post by: kolofsson on October 13, 2011, 10:51:54 am
Hello

I would like to make a game using SFML. I've been told that I should not use C++ if I'm not experienced in using this language. As I've done most programming in PHP, it was suggested for me to use Python. I wonder if you could assist me with the following:

1. What functionalities of the C++ SFML have been left out in pysfml2? Is the network package present? If not, is it still possible to make an online game using pysfml2?

2. Would it be problematic to make a multiplatform game using pysfml2? I'm planning to do main coding on Windows, but would like to release linux and OSX versions.

3. What IDE do you recommend for python on Windows? I'd prefer something lightweight.

4. I'm totally new to python. Are programs made in python regular exe files? What is the speed comparison between C++ SFML and pysfml? Will users have to install anything to be able to run my game?

Thanks for your help!
Title: pysfml2-cython
Post by: bastien on October 13, 2011, 01:02:35 pm
Hello,

1. Currently streaming isn't available, but it's mainly because I've never needed it personally. Also, I think someone said he was going to write it.
Network features are available in standard Python packages like socket. There are also more complex frameworks like Twisted.

2. Some people have problems building it on Windows. I'll try to upload a Windows binary one of these days, when I have access to Windows.
PySFML is as portable as SFML itself.

3. Emacs and Vim are very popular among Python programmers, but it takes some time to use them efficiently. You don't really need any advanced feature from your editor for Python, so feel free to use whatever editor you're comfortable with, and learn more complex tools later. I've used PyScripter for some time, since it's included with PortablePython.

4. Technically, python programs are .pyc files that are automatically generated when you run e.g. python main.py. Python translates the source to a faster binary language, then executes it.
I expect the speed of SFML and PySFML's classes to be roughly the same, as they are both written in C++ (well, my binding is written in Cython, but it gets translated to C++ before getting compiled and I didn't see any performance problem so far). Your Python code will be slower, and there are also some things that might cause problems for performance-intensive applications. For example, Python objects have to be allocated dynamically, while in C++ you can often create them on the stack.
Users will have to install Python and PySFML, unless you provide them with an installer.
Title: pysfml2-cython
Post by: kolofsson on October 13, 2011, 07:12:50 pm
Thanks for a prompt answer. Two comments:

1. Vim? There's a joke: how to generate a random keyboard input? place a user in front of Vim and tell them to exit the program. Vim is waay to hardcore for me. Seriously, there's no good IDE that would have everything in one place?

2. Is there a way to avoid installing Python and still be able to run python applications? For example, the .NET apps require to put a few libraries in the executable folder and that's it.
Title: pysfml2-cython
Post by: Geoff on October 14, 2011, 09:37:24 am
Hello,

1.Personnaly I like to use Eclipse with PyDev plugin. You can benefit of all functionalities of eclipse and it's a multi-platform IDE.
Moreover, pydev debugger works well.

2.PyInstaller is a software that allow to create exe file with all that you need, for multiple target (windows, linux, osx...) so you don't need to have python installed on your computer, but I didn't try.
Title: pysfml2-cython
Post by: kolofsson on October 15, 2011, 10:52:58 pm
Hi Bastien!

I tried to compile the latest PySFML2 from your github page. I have VC++ 2010 Express installed on Windows 7 x64. I've got an error:

Code: [Select]
C:\Users\Przemek\Downloads\PySFML 2-0.0.1\PySFML 2-0.0.1>setup.py build_ext
running build_ext
building 'sf' extension
error: Unable to find vcvarsall.bat


I checked the PATH variable in my command line and I'm sure that C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC was added (this is where the vcvarsall.bat resides).

Going further, I followed a hint on some website to change line 243 of C:\Python27\Lib\distutils\msvc9compiler.py to toolskey = "VS100COMNTOOLS"

This is the result of the compilation:

Code: [Select]
running build_ext
building 'sf' extension
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tpsf.cpp /Fobuild\temp.win32-2.7\Release\sf.obj
sf.cpp
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
sf.cpp(560) : error C2039: 'Texture' : is not a member of 'sf'
sf.cpp(560) : error C2143: syntax error : missing ';' before '*'
sf.cpp(560) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
sf.cpp(560) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
sf.cpp(705) : error C2039: 'RenderTexture' : is not a member of 'sf'
sf.cpp(705) : error C2143: syntax error : missing ';' before '*'
sf.cpp(705) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
sf.cpp(705) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
sf.cpp(1003) : error C2039: 'Texture' : is not a member of 'sf'
sf.cpp(1003) : error C2065: 'Texture' : undeclared identifier
sf.cpp(1003) : error C2059: syntax error : ','
sf.cpp(1798) : error C2039: 'IsButtonPressed' : is not a member of 'sf::Mouse'
sf.cpp(1798) : error C3861: 'IsButtonPressed': identifier not found
sf.cpp(1896) : error C2039: 'GetPosition' : is not a member of 'sf::Mouse'
sf.cpp(1896) : error C3861: 'GetPosition': identifier not found
sf.cpp(1908) : error C2039: 'GetPosition' : is not a member of 'sf::Mouse'
sf.cpp(1908) : error C3861: 'GetPosition': identifier not found
sf.cpp(2069) : error C2039: 'SetPosition' : is not a member of 'sf::Mouse'
sf.cpp(2069) : error C3861: 'SetPosition': identifier not found
sf.cpp(2081) : error C2039: 'SetPosition' : is not a member of 'sf::Mouse'
sf.cpp(2081) : error C3861: 'SetPosition': identifier not found
sf.cpp(2134) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2134) : error C2039: 'IsConnected' : is not a member of 'sf'
sf.cpp(2134) : error C3861: 'IsConnected': identifier not found
sf.cpp(2188) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2188) : error C2039: 'GetButtonCount' : is not a member of 'sf'
sf.cpp(2188) : error C3861: 'GetButtonCount': identifier not found
sf.cpp(2278) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2278) : error C2039: 'HasAxis' : is not a member of 'sf'
sf.cpp(2278) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2278) : error C2039: 'Axis' : is not a member of 'sf'
sf.cpp(2278) : error C2065: 'Axis' : undeclared identifier
sf.cpp(2278) : error C2146: syntax error : missing ')' before identifier '__pyx_v_axis'
sf.cpp(2278) : error C2059: syntax error : ')'
sf.cpp(2278) : error C3861: 'HasAxis': identifier not found
sf.cpp(2368) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2368) : error C2039: 'IsButtonPressed' : is not a member of 'sf'
sf.cpp(2368) : error C3861: 'IsButtonPressed': identifier not found
sf.cpp(2458) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2458) : error C2039: 'GetAxisPosition' : is not a member of 'sf'
sf.cpp(2458) : error C3083: 'Joystick': the symbol to the left of a '::' must be a type
sf.cpp(2458) : error C2039: 'Axis' : is not a member of 'sf'
sf.cpp(2458) : error C2065: 'Axis' : undeclared identifier
sf.cpp(2458) : error C2146: syntax error : missing ')' before identifier '__pyx_v_axis'
sf.cpp(2458) : error C2059: syntax error : ')'
sf.cpp(2458) : error C3861: 'GetAxisPosition': identifier not found
sf.cpp(2512) : error C3083: 'Keyboard': the symbol to the left of a '::' must be a type
sf.cpp(2512) : error C2039: 'IsKeyPressed' : is not a member of 'sf'
sf.cpp(2512) : error C3083: 'Keyboard': the symbol to the left of a '::' must be a type
sf.cpp(2512) : error C2882: 'Key' : illegal use of namespace identifier in expression
sf.cpp(2512) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Title: pysfml2-cython
Post by: bastien on October 16, 2011, 07:44:11 pm
Are you using the latest SFML version from Github? The Texture class is somewhat recent.
Title: pysfml2-cython
Post by: DomtronVox on October 16, 2011, 08:56:27 pm
First I'd like to thank you  for creating PYSFML and giving me more display library options :P.

Second, I have some questions and wanted to point out something that I and maybe other people have a problem with.  

Does PYSFML have native functions for render 3d or would I need to create a projection class/algorithm(I have no clue how 3D works in SFML). I'm looking for a well maintained display library for both 2d and 3d rendering and works with python. I looked at pyopengl but saw a number of complaints that it wasn't maintained.

I built SFML and PYSFML yesterday and ran into an odd problem. SMFL "sudo make install" (a little bump was forgetting the sudo and not reading the big error msg >.<) installed the SFML .so's in the wrong directory. I'm on Ubuntu 10.4 LTS and for some reason "make install" placed the .so's in /usr/local/lib instead of /usr/lib. When I ran the PYSMFL examples sf.so couldn't find the needed libraries. So I had to manually copy all the SFML .so's over to the correct directory. Would this just be a problem with my computer?
Anyway I hope this helps someone in the same predicament.

Thanks
Title: pysfml2-cython
Post by: kolofsson on October 16, 2011, 09:55:44 pm
Um, sorry, you mean the latest SFML no PySFML :oops:

Tell me please, where should I put the headers and libraries of SFML so that the MSVC compiler sees them? I guess this is what I'm doing wrong.
Title: pysfml2-cython
Post by: bastien on October 17, 2011, 10:49:41 am
Quote from: "DomtronVox"
First I'd like to thank you  for creating PYSFML and giving me more display library options :P.


Thanks. ;)

Quote from: "DomtronVox"
Second, I have some questions and wanted to point out something that I and maybe other people have a problem with.  

Does PYSFML have native functions for render 3d or would I need to create a projection class/algorithm(I have no clue how 3D works in SFML). I'm looking for a well maintained display library for both 2d and 3d rendering and works with python. I looked at pyopengl but saw a number of complaints that it wasn't maintained.


With C++ SFML, you can call OpenGL functions if needed.
I chose to not support this currently, mainly because I have very little experience OpenGL. Basically there's no support for the Window package in SFML, you can only use the higher-level classes like RenderWindow.
I think you should look into Pyglet or Pygame. Pyglet is a modern library kind of like SFML, and Pygame is based on SDL.

Quote from: "DomtronVox"
I built SFML and PYSFML yesterday and ran into an odd problem. SMFL "sudo make install" (a little bump was forgetting the sudo and not reading the big error msg >.<) installed the SFML .so's in the wrong directory. I'm on Ubuntu 10.4 LTS and for some reason "make install" placed the .so's in /usr/local/lib instead of /usr/lib. When I ran the PYSMFL examples sf.so couldn't find the needed libraries. So I had to manually copy all the SFML .so's over to the correct directory. Would this just be a problem with my computer?
Anyway I hope this helps someone in the same predicament.

Thanks


On GNU/Linux, it's common to use /usr/local for stuff that you install yourself, so I think it's normal. Otherwise, it may conflict with files installed by the package manager someday. The only problem is that you may need to tell GCC to look for headers in /usr/local/include and the dynamic loader to look for .so in /usr/local/lib. In my case (Arch Linux), I had to add the path in /etc/ld.so.conf.d/.

Quote from: "kolofsson"
Um, sorry, you mean the latest SFML no PySFML :oops:

Tell me please, where should I put the headers and libraries of SFML so that the MSVC compiler sees them? I guess this is what I'm doing wrong.


I don't really know, there should be a directory in Program Files that contains directories named something like include/headers and lib/libraries.
But from my experience Visual Studio's installation is pretty bloated, I remember it took me some time to find them.
Title: pysfml2-cython
Post by: bastien on October 17, 2011, 05:39:58 pm
Exceptions now contain the error message with full details (the same message SFML would normally write on the console).
Title: pysfml2-cython
Post by: kolofsson on October 17, 2011, 07:17:49 pm
I'm sorry, this is a little frustrating.

1. I downloaded the fresh SFML from github
2. I compiled Release and Debug in VC++2010.
3. I put all lib files in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
4. I put all dll files in C:\Windows\System32 (no idea if this is right)
5. I downloaded fresh PySFML from girhub
6. I installed cython (no sf.cpp in your newest build)
7. I run setup.py, same list of errors as in the post before.

What am I doing wrong? Has anybody actually compiled this under Windows? As I've got the SFML.NET binding up and running, I'm really considering dumping my Python attempts. It's a shame, cause I really like python after first few looks.
Title: pysfml2-cython
Post by: bastien on October 17, 2011, 08:12:25 pm
It looks like you didn't add the headers.
Yes, I think system32 is the right directory for DLLs.
Title: pysfml2-cython
Post by: kolofsson on October 17, 2011, 11:59:26 pm
Quote from: "bastien"
It looks like you didn't add the headers.
Yes, I think system32 is the right directory for DLLs.


Ok I added the includes. Now it gives me this error:

"failed to load and parse the manifest, file not found"

EDIT: Now I edited the python the way I found on some web page (adding /MANIFEST to args of some program) and the compilation finished, I guess. When I try to run a program made with SFML, I get this error:
Code: [Select]
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\pysfml2\bastienleonard-pysfml2-cython-ca7f88f\examples\pong\main.py", line 9, in <module>
    import sf
ImportError: DLL load failed: File not found
Title: pysfml2-cython
Post by: DomtronVox on October 18, 2011, 03:59:14 am
Thanks for the quick response.

I have some experience with pygame but I'm not sure of the speed. I have read it's not fast enough to handle projections very well (and it doesn't have native 3d rendering). I have never looked at pyglet. I'll do some research into it.

Thanks for the information!
Title: pysfml2-cython
Post by: bastien on October 18, 2011, 06:51:40 pm
Quote from: "kolofsson"
Quote from: "bastien"
It looks like you didn't add the headers.
Yes, I think system32 is the right directory for DLLs.


Ok I added the includes. Now it gives me this error:

"failed to load and parse the manifest, file not found"

EDIT: Now I edited the python the way I found on some web page (adding /MANIFEST to args of some program) and the compilation finished, I guess. When I try to run a program made with SFML, I get this error:
Code: [Select]
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\pysfml2\bastienleonard-pysfml2-cython-ca7f88f\examples\pong\main.py", line 9, in <module>
    import sf
ImportError: DLL load failed: File not found


sf.dll needs to be in the Python path. The simplest way is to put it the current directory just before you execute the program. Or you can modify the PYTHONPATH environment variable.

Or you can run python setup.py install, and it should be available for all the programs. But I would do this only after testing the binding.
Title: pysfml2-cython
Post by: kolofsson on October 18, 2011, 09:00:00 pm
Quote from: "bastien"


sf.dll needs to be in the Python path. The simplest way is to put it the current directory just before you execute the program. Or you can modify the PYTHONPATH environment variable.

Or you can run python setup.py install, and it should be available for all the programs. But I would do this only after testing the binding.


sf.dll? I only got sf.pyd as a result of my compilation. I put standard c++ libraries as well as the sf.pyd in the same folder as pong.py. The compiler still can't find the sf module... :(
Title: pysfml2-cython
Post by: bastien on October 19, 2011, 07:27:47 am
You're right, it's .pyd on Windows apparently. What happens if you open a command prompt, go to the path where sf.pyd is, type “python”, and then type “import sf” interactively?
Title: pysfml2-cython
Post by: kolofsson on October 19, 2011, 06:14:46 pm
Quote from: "bastien"
You're right, it's .pyd on Windows apparently. What happens if you open a command prompt, go to the path where sf.pyd is, type “python”, and then type “import sf” interactively?


calling "python" in cmd does not work for me, I had to enter full path:

Code: [Select]

E:\pysfml2\bastienleonard-pysfml2-cython-ca7f88f\build\lib.win32-2.7>c:\Python27\python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: Nie mo┐na odnalečŠ okreťlonego modu│u.
>>>


Last line says: Can't find specified module
Title: pysfml2-cython
Post by: bastien on October 19, 2011, 08:38:08 pm
That's strange. Last try: did you also copy the DLLs that are in SFML/extlibs? (I don't see a “DLL loaded failed” message when importing a non-existing module, so my guess is that a dependency can't be loaded.)
Title: pysfml2-cython
Post by: kolofsson on October 19, 2011, 08:46:57 pm
Quote from: "bastien"
That's strange. Last try: did you also copy the DLLs that are in SFML/extlibs? (I don't see a “DLL loaded failed” message when importing a non-existing module, so my guess is that a dependency can't be loaded.)


OMG it worked  :shock:

The pong example runs now. Also, when I type "import sf" with extlibs in the folder, it does not return error. This was one hell of a job to make this binding work. I guess it would be much easier with VC2008 or MinGW. But still, some binaries would be really appreciated and save quite some time, instead of compiling it all.

Thanks for help and feedback.
Title: pysfml2-cython
Post by: bastien on October 20, 2011, 02:51:45 pm
Yeah, I'll try to add a binary release for Windows as soon as possible, now that the binding seems to be stable. I already tried to cross-compile it, but I have trouble testing things with Wine.
Title: pysfml2-cython
Post by: mitsuharu on October 21, 2011, 07:03:59 am
For those running Win7 64bit with 64bit Python, I've found that you must place the SFML dlls in C:/Windows/SysWow64 to get everything working.  That put me back a couple hours trying to get my Windows box the same as my Mac.

I built SFML with MinGW (much easier than trying to do it with visual studio).
Title: pysfml2-cython
Post by: kolofsson on October 24, 2011, 06:50:38 pm
Hi Bastien

A question about debugging. As we know, SFML can be compiled as Release or Debug, and for development process it is advisable to use the Debug libraries (I don't know why exactly, I guess more debug info is being produced during runtime).

Should we use the Debug libraries in PySFML too? Will it work? Is there any reason why we should/should not use them? Is compiling the bindings for Debug libraries as simple as removing the "-d" suffix from SFML lib filenames? Are you planning to include Debug libs in the binding so that there are two output files: sf.pyd and sfd.pyd?
Title: pysfml2-cython
Post by: bastien on October 24, 2011, 09:16:21 pm
I haven't tried to debug PySFML applications, just the binding itself, and the users will normally never need to do that.
I never use debuggers for Python, except for really weird cases.

Currently, I'm using SFML compiled in release mode, but I guess you can use any version you want. The only upside I can see for using a debug version is if you plan to debug the library itself, and in some cases it might be possible that some low-level bugs occur only when some compiler optimizations are activated. I think this irrelevant for Python users.

I can't see which options are provided to cython by default when it's invoked by the setup.py script, but in practice I find that it provides enough information when an error occurs.
Looking at cython's command-line options, it looks like you can only disable doc strings, or add line directives to see where the error comes from the source file. Both are probably useless for most users since I don't use doc strings.
When I'll make a stable release, I'll try the various options to see if can significantly reduce the module size, though.

In the end, if you just want to debug your application, you can probably just use whatever Python debugger you prefer. I remember that I used Winpdb for debugging multi-threaded programs. There's also the standard module pdb (http://docs.python.org/library/pdb.html). Personally, I find that print statements are enough most of the time. It's not like in C where you often just get “Segmentation fault” as an error message. ;-)
Title: pysfml2-cython
Post by: kolofsson on October 24, 2011, 09:46:42 pm
Ah, very well. No special debug libs means one thing less to care about :P. So far my apps did not require special debugging, so I haven't really figured out what SFML debug libs do. If you say that regular python debugger will do, that's just perfect.

Well, I think I'm going to dedicate more time to learn Python and maybe start off a little project in PySFML. I'm really overwhelmed by Python philosophy :). I just hope you won't get bored too soon and that you keep updating and upgrading PySFML (e.g. reference/documentation).
Title: pysfml2-cython
Post by: bastien on October 24, 2011, 11:56:45 pm
I keep updating it because people want it, don't hesitate to message me if something needs to be improved.
Title: pysfml2-cython
Post by: bastien on October 26, 2011, 11:00:14 pm
I just compiled something that looks like a Win32 module, but I can't get it to work with Wine (it tells it can't find dependent DLLs, even when they are in the current directory).
Can someone test it on Windows and tell me if it works? Here is the direct link: https://github.com/downloads/bastienleonard/pysfml2-cython/sf.pyd
Title: pysfml2-cython
Post by: kolofsson on October 27, 2011, 09:40:24 am
Quote from: "bastien"
I just compiled something that looks like a Win32 module, but I can't get it to work with Wine (it tells it can't find dependent DLLs, even when they are in the current directory).
Can someone test it on Windows and tell me if it works? Here is the direct link: https://github.com/downloads/bastienleonard/pysfml2-cython/sf.pyd


I will test it as soon as I get hom from work. I can see you only put sf.pyd file. It makes no difference which SFML libs I use with it? (revision / compiler). I presume that when compiling the pyd file, you needed to have the dlls present, right? Maybe it would be good to include them in the package with the binding, so that the end-user does not have to compile SFML on his own.
Title: pysfml2-cython
Post by: kolofsson on October 27, 2011, 08:23:25 pm
OK I tested your sf.pyd and it tells me that "import sf failed, module was not found". I've no idea what's wrong with your file :P.

I put my own sf.pyd on the web, accessible here:

http://grebocin.com/upload/sf.pyd

Also, I put the whole Pong example, with SFML dlls, extlibs, sf.pyd and main.py:

http://grebocin.com/upload/pong.zip

Perhaps this may be of help for all PySFML starters.
Title: pysfml2-cython
Post by: bastien on October 27, 2011, 09:27:54 pm
When I try your Pong example with my sf.pyd, I get this:

Code: [Select]
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    import sf


Could you copy-paste here the command-lines that are issued when you build the binding? I guess I missed something to include the standard libraries.
Also, for some reason the SFML libs I cross-compiled aren't even detected by Wine.
Title: pysfml2-cython
Post by: kolofsson on October 27, 2011, 11:19:47 pm
Quote from: "bastien"
When I try your Pong example with my sf.pyd, I get this:

Code: [Select]
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    import sf


Could you copy-paste here the command-lines that are issued when you build the binding? I guess I missed something to include the standard libraries.
Also, for some reason the SFML libs I cross-compiled aren't even detected by Wine.


Maybe my libs require having installed the Visual C++ redistributable? I build an executable of the pong example with PyInstaller and it put all the necessary DLLs in the folder. I gave it to my friend who has "bare" windows and it worked for him, so it should work for you too in Wine. Check it out here:

http://grebocin.com/upload/main.zip

Regarding the compilation output, here it is:

http://grebocin.com/upload/output.txt

Could you please deal with the conversion from Double to Float warnings? Why do you even use floats if SFML uses doubles? Does python have doubles? If not, could you at least convert these via a function so there is no warning? Thanks :).
Title: pysfml2-cython
Post by: bastien on October 28, 2011, 12:02:55 am
I forgot you're using Visual Studio. :/
SFML uses floats, pure Python only has the equivalent of double (although they are called floats in Python). So in the end there's no way to prevent the user to use double precision, but I don't think that's a real problem. The warnings come from the code generated by Cython, I can't control them directly.

By the way, normally you can create an installer with “python setup.py bdist_wininst”.
Title: pysfml2-cython
Post by: bastien on November 06, 2011, 11:47:46 am
Finally I built it from scratch in a virtual machine, here is a ZIP that should contain everything you need: https://github.com/downloads/bastienleonard/pysfml2-cython/python2-sfml2-cython-win32.zip

I'm especially interested to know if it works on machines that don't have SFML installed.
Title: pysfml2-cython
Post by: kolofsson on November 06, 2011, 10:35:47 pm
Hey Bastien I've got a question. When I run PySFML apps I have 2 windows - the black console window and the proper app window. Is there a way to get rid of the console window? In SFML there was a special library for that, it would initialize the main function so that the console window does not appear.

Also, I can't find the implementation of sf::Window::EnableVerticalSync. Is it possible to enable vertical sync in PySFML? I see it's only possible to limit the framerate to a fixed value, but how should I know the refresh rate of a given display mode? If I set it to 60, it will be incorrect for those who have 75 of 100 Hz.
Title: pysfml2-cython
Post by: bastien on November 07, 2011, 12:00:57 am
Quote from: "kolofsson"
Hey Bastien I've got a question. When I run PySFML apps I have 2 windows - the black console window and the proper app window. Is there a way to get rid of the console window? In SFML there was a special library for that, it would initialize the main function so that the console window does not appear.


Using pythonw.exe instead of python.exe as the interpreter should fix it. The simplest way is to rename your entry point file to .pyw (for example, main.pyw). The Windows installer associates .pyw files to launched with pythonw.exe. This problem doesn't happen on Unix.

Quote from: "kolofsson"
Also, I can't find the implementation of sf::Window::EnableVerticalSync. Is it possible to enable vertical sync in PySFML? I see it's only possible to limit the framerate to a fixed value, but how should I know the refresh rate of a given display mode? If I set it to 60, it will be incorrect for those who have 75 of 100 Hz.


You're right, I just added it in the Git repo: http://pysfml2-cython.readthedocs.org/en/latest/graphics.html#sf.RenderWindow.vertical_sync_enabled

I'm not really happy with these boolean attributes that you can set but not get, I guess I'm going to add getters myself. But it would be simpler if SFML had methods to do that directly.
Title: pysfml2-cython
Post by: kolofsson on November 18, 2011, 02:17:38 pm
Hey Bastien. I've been looking into Pygame and it looks nice so I'm wondering if you could tell me why did you decide to make PySFML. Was it speed, ease of use, more capabilities or SFML? If you ever used Pygame, what are the pros and cons in relation to PySFML?

Also, if you could look at my multithreading question post, I would be greatful.
Title: pysfml2-cython
Post by: bastien on November 18, 2011, 05:36:14 pm
Pygame is nice, I've used it for some time but it's based on SDL and it doesn't totally solve its problems.
Generally speaking, SDL's API gives you access to the screen as an array of pixels where you do every effect with the CPU, which doesn't really make sense nowadays. You used to have to implement scrolling and zooming manually.

With SFML, you can use effects like zoom or rotation on any drawable, or use views to apply effects to the entire scene, and it will use 3D acceleration behind the scenes. You can also use shaders easily.
With Pygame, as far as I know, the closest thing is a limited module (http://www.pygame.org/docs/ref/transform.html). It's not well integrated in the API.

The upside for Pygame is that SDL is very stable and portable, and if you really don't need the features of SFML, you know your program will run everywhere. Personally, my open source driver on GNU/Linux became able to handle even basic 2D stuff only fairly recently with OpenGL/SFML. Somewhat paradoxically, SDL's software rendering seems to work a lot better with crappy driver support.
Title: pysfml2-cython
Post by: kolofsson on November 20, 2011, 04:27:48 pm
I've been looking at sf.Event documentation in the docs and I think this is missing:

Code: [Select]
       CLOSED: 'Closed',
        RESIZED: 'Resized',
        LOST_FOCUS: 'Lost focus',
        GAINED_FOCUS: 'Gained focus',
        TEXT_ENTERED: 'Text entered',
        KEY_PRESSED: 'Key pressed',
        KEY_RELEASED: 'Key released',
        MOUSE_WHEEL_MOVED: 'Mouse wheel moved',
        MOUSE_BUTTON_PRESSED: 'Mouse button pressed',
        MOUSE_BUTTON_RELEASED: 'Mouse button released',
        MOUSE_MOVED: 'Mouse moved',
        MOUSE_ENTERED: 'Mouse entered',
        MOUSE_LEFT: 'Mouse left',
        JOYSTICK_BUTTON_PRESSED: 'Joystick button pressed',
        JOYSTICK_BUTTON_RELEASED: 'Joystick button released',
        JOYSTICK_MOVED: 'Joystick moved',
        JOYSTICK_CONNECTED: 'Joystick connected',
        JOYSTICK_DISCONNECTED: 'Joystick disconnected'
Title: pysfml2-cython
Post by: bastien on November 20, 2011, 10:55:34 pm
It's documented here: http://pysfml2-cython.readthedocs.org/en/latest/events.html#sf.Event.NAMES
Title: pysfml2-cython
Post by: thisdyingsoul on November 28, 2011, 12:54:39 pm
Hello, first let me thank you for this excelent game lib and for port it for python/cython  :D

Isn´t  a good idea make the cython-sfml methods with cpdef  instead of def ?
If someone code with cython and import the lib , they can take advantage of c-speed method call.

Thank you in advance.
Title: pysfml2-cython
Post by: bastien on November 28, 2011, 08:29:02 pm
In practice, the generated code is stil in C++, but obviously it needs to call the C/Python API. The vast majority of the methods are just there to map to the C++ equivalent. If someone really wanted to use raw C++, I guess he would call SFML directly.

I thought that cpdef would duplicate every method, but maybe I'm wrong. I should test it and see if it increases the module size.
Cython's documentation says that cdef/cpdef methods are virtual (here (http://docs.cython.org/src/userguide/extension_types.html#c-methods)), i.e. you will automatically call the most specific method of an object. So I'm not sure whether it bypasses Python method resolution, I thought this was the only thing it could do to make calls faster. :?
Title: pysfml2-cython
Post by: thisdyingsoul on November 28, 2011, 08:55:10 pm
Well, I try this:
(in a pyx file)
Code: [Select]

cdef class Obj:      
    def python_method(self):    
        #operations
        pass
   
    cpdef cpython_method(self):
        #operations
        pass

import time

cdef Obj obj = Obj()

i = time.clock()

#cdef int x

for x in range(1000000):
    obj.python_method()

f = time.clock()

print "python_method %f" % (f-i)

i = time.clock()

for x in range(1000000):
    obj.cpython_method()

f = time.clock()

print "cpython_method %f" % (f-i)


I expected a fast loop with cpython_method, but there was only a little speed up. Then uncomment this "#cdef int x" and Voilá. Great speed up!(At least here, hundred of times faster).

I think this is nice i.e. for things like moving the main draw loop (that use Sprite.Draw)  in a cython 'for loop'.( Or any other loop that use a lot of python (slow)method calls)
Title: pysfml2-cython
Post by: bastien on November 30, 2011, 03:52:01 am
I have uploaded a new zip file with the standard libs statically linked, it should include all the dependencies now: https://github.com/downloads/bastienleonard/pysfml2-cython/python2-sfml2-cython-win32-nodeps.zip

For some reason, I couldn't the extra_link_args option the setup script, even though it's documented here: http://docs.python.org/distutils/setupscript.html#other-options
Does someone know if extra_link_args works on Windows? (In practice, modify the code to something like setup(extra_link_args=[], **kwargs) in setup.py.)

Quote from: "thisdyingsoul"
Well, I try this:
(in a pyx file)
Code: [Select]

cdef class Obj:      
    def python_method(self):    
        #operations
        pass
   
    cpdef cpython_method(self):
        #operations
        pass

import time

cdef Obj obj = Obj()

i = time.clock()

#cdef int x

for x in range(1000000):
    obj.python_method()

f = time.clock()

print "python_method %f" % (f-i)

i = time.clock()

for x in range(1000000):
    obj.cpython_method()

f = time.clock()

print "cpython_method %f" % (f-i)


I expected a fast loop with cpython_method, but there was only a little speed up. Then uncomment this "#cdef int x" and Voilá. Great speed up!(At least here, hundred of times faster).

I think this is nice i.e. for things like moving the main draw loop (that use Sprite.Draw)  in a cython 'for loop'.( Or any other loop that use a lot of python (slow)method calls)


Thanks, I'll look into that one of these days.
Title: pysfml2-cython
Post by: bastien on January 27, 2012, 02:03:12 am
I have updated the binding for the latest version. The main change is the new graphics API. Some stuff still needs to be done, see TODO.txt. The documentation and the examples haven't been updated yet.

I had to rewrite a lot of things, so some parts may be broken. Please report any problem you encounter.
Title: pysfml2-cython
Post by: bastien on January 31, 2012, 04:58:59 am
By the way, one important change is that I removed Drawable. To create your own drawable, you now just need to add the draw() method in your class (see the C++ documentation for now).
Title: pysfml2-cython
Post by: dfanz0r on January 31, 2012, 06:49:41 am
i tried to build the latest version of this, and it fails when trying to build it.

http://pastebin.com/Jeh50YWY
Title: pysfml2-cython
Post by: bastien on January 31, 2012, 05:32:39 pm
Are you using the snapshot in the downloads? Sorry, it wasn't up to date. I updated a new one, but currently I'm focusing more on making a “stable” release along with SFML 2. I still need to do some changes in the source, then I'll update the documentation.
Title: pysfml2-cython
Post by: dfanz0r on January 31, 2012, 10:04:08 pm
It wasn't the snapshot, i pulled directly from GitHub.
Title: pysfml2-cython
Post by: bastien on February 01, 2012, 12:45:01 am
Ah, I see. These two functions are declared as extern in the Cython, and they clash with either their own declaration in sf.cpp, or with those in hack.hpp (but that seems odd).
The problem is that Cython doesn't seem to have any mechanism to make a function not static, but not exported in the DLL either. So I'm just using “extern” and hope that it won't cause too much trouble. On GNU/Linux, I tried to override the linkage with linker args or scripts, with no success.

Could you look for the declaration/definition of wrap_render_states() in sf.cpp and copy them here? Or just copy the whole file.
Title: pysfml2-cython
Post by: dfanz0r on February 01, 2012, 07:04:04 am
here i just uploaded the whole file to mediafire
http://www.mediafire.com/?2zk3ivsuvcjnq32
Title: pysfml2-cython
Post by: bastien on February 01, 2012, 08:46:21 pm
So it gets declared this way:

Code: [Select]
__PYX_EXTERN_C DL_IMPORT(struct __pyx_obj_2sf_RenderStates) *wrap_render_states_instance(sf::RenderStates *);

It looks like you just need to add DL_IMPORT in hacks.hpp's prototypes.
Title: pysfml2-cython
Post by: dfanz0r on February 01, 2012, 09:04:50 pm
and i do that how exactly?
Title: pysfml2-cython
Post by: bastien on February 01, 2012, 09:47:36 pm
I have added the changes in the repo. See if it builds now.
Title: pysfml2-cython
Post by: dfanz0r on February 01, 2012, 09:54:34 pm
It didnt work, im still getting the same error.
Title: pysfml2-cython
Post by: bastien on February 01, 2012, 10:07:07 pm
Can you paste it again? I don't know if the two previous changes didn't do anything or if only replace_error_handler() causes problems now.
Title: pysfml2-cython
Post by: dfanz0r on February 02, 2012, 12:07:20 am
here is the output now

http://pastebin.com/yBe2zWtg
Title: pysfml2-cython
Post by: bastien on February 02, 2012, 12:52:55 am
I fixed a syntax mistake that I did with the last change, but I don't know if that was the problem.
Title: pysfml2-cython
Post by: dfanz0r on February 02, 2012, 01:03:50 am
It builds now but i cant really use it, as it crashes in my own test program and all of the included tests. My test uses your module to create the window and keep track of fps but uses pyOpenGl to render.

here is the build log for the build:
http://pastebin.com/8aRUUjuN

My test creates a window then it just crashes python. The other tests its spits out some errors
this is from lowleveldrawable.py:

Traceback (most recent call last):
  File "E:\pysfml2-cython\lowleveldrawable.py", line 7, in <module>
    class LowLevelDrawable(sf.Drawable):
AttributeError: 'module' object has no attribute 'Drawable'

Everything works fine in the windows build in the downloads page.
Title: pysfml2-cython
Post by: bastien on February 02, 2012, 01:10:27 am
I haven't updated most examples yet, so the last error is normal.
It's difficult for me to guess where the errors exactly come from, as I'm not used to build DLLs on Windows. I know that the Cython developers almost don't use Windows, so this could be a bug in Cython as well.

The thing is, the functions that cause problems shouldn't end up in the DLL in the first place. As far as I know, Cython doesn't allow to make symbols available across compilation units without exporting them in the DLL. At worst, it should be pretty easy to edit sf.cpp manually to remove DL_IMPORT from those functions declarations (but keep the argument of DL_IMPORT(), it should be the return type).

For what it's worth, I didn't have these problems with MinGW when I last built the binding for Windows, and I was already using the same hacks. I was getting crashes at the end of the program with MinGW, however, but I believe the former binding already had that problem.

Currently, I'm focusing on porting all the C++ features (I still need to make Shape inheritance work and port the streaming features), and updating the documentation. I'll try to build the binding on Windows as soon as possible.
Title: pysfml2-cython
Post by: dfanz0r on February 02, 2012, 01:47:11 am
Ok, for now i can just use the prebuilt version all im using now is clock window and event. I will need the Audio streaming stuff later on though. Will soon be looking into keyboard and joysticks too. Network would be useful at some point down the road but its not really needed for a while.
Title: pysfml2-cython
Post by: gtoast on February 03, 2012, 01:43:18 pm
I'm having trouble getting pysfml2 to build. I'm on Mac OS X Lion using python2.7 via Macports. I've successfully installed SFML2 and been able to run examples but I when I try to build pysfml2 I get a bunch of warnings and a failure to find the sfml-[blah] libraries.

Code: [Select]

...tons and tons of warnings...
363 warnings generated.
/Developer/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -pipe -O2 -fwrapv -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c hacks.cpp -o build/temp.macosx-10.7-x86_64-2.7/hacks.o
/Developer/usr/bin/clang++ -bundle -undefined dynamic_lookup -L/opt/local/lib build/temp.macosx-10.7-x86_64-2.7/sf.o build/temp.macosx-10.7-x86_64-2.7/hacks.o -L/Users/cdimara/Development/SFML/build-release/lib/sfml-graphics.framework -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-system -o /Users/cdimara/Development/pysfml2-cython/sf.so
ld: library not found for -lsfml-graphics
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/Developer/usr/bin/clang++' failed with exit status 1
Full error log (http://pastebin.com/fedX4Lsr)

Any thoughts on what I'm doing wrong?
Title: pysfml2-cython
Post by: gtoast on February 04, 2012, 03:41:50 pm
Figured it out.

Though its not really detailed on the either the SFML2 or the PySFML2 install page, you need to make sure you uncheck the box saying build frameworks when you generate your unix make files in cmake for SFML2.

After that things work fine.
Title: pysfml2-cython
Post by: dfanz0r on February 04, 2012, 11:04:41 pm
I found something that would probably be good to fix

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Clock.php

In the documentation for SFML 2 it says Clock.restart() should return the time since the clock was started.

Can you make this return that time also? It should be a pretty quick fix.
Title: pysfml2-cython
Post by: dfanz0r on February 06, 2012, 03:54:11 am
Ok so i have built it in MinGW this time it builds, and i think it runs fine.

The newer version doesn't seem to want to play nicely with another cython module im using for speeding up openGL some. The older build worked fine with it. Any idea's?
Title: pysfml2-cython
Post by: Razzeeyy on February 17, 2012, 12:37:17 pm
Excuse me, but do this binding works with python3?
I'm just confused by the 'cython' word.
AFAIK Cython is just different interpreter for python, isn't it? or it provides a bit different syntax too?
Title: pysfml2-cython
Post by: bastien on February 22, 2012, 06:19:29 pm
Quote from: "dfanz0r"
Ok, for now i can just use the prebuilt version all im using now is clock window and event. I will need the Audio streaming stuff later on though. Will soon be looking into keyboard and joysticks too. Network would be useful at some point down the road but its not really needed for a while.


Keyboard and joysticks should work fine. Network classes aren't ported because their features are available in the Python standard library. I'll add streaming as soon as possible.

Quote from: "dfanz0r"
I found something that would probably be good to fix

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Clock.php

In the documentation for SFML 2 it says Clock.restart() should return the time since the clock was started.

Can you make this return that time also? It should be a pretty quick fix.


Thanks, I made the change as soon as I read your message.

Quote from: "gtoast"
Figured it out.

Though its not really detailed on the either the SFML2 or the PySFML2 install page, you need to make sure you uncheck the box saying build frameworks when you generate your unix make files in cmake for SFML2.

After that things work fine.


It looks like it's mentioned here: http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php

Quote
CMAKE_INSTALL_FRAMEWORK_PREFIX (Mac OS X only)
This is the install path for frameworks. By default, it is defined to the root library, i.e. /Library/Frameworks folder. As stated for CMAKE_INSTALL_PREFIX it is not mandatory to install files after compiling, but it is cleaner to install them.
This path is used to install on your system sndfile.framework (a required dependency not provided by Apple) and SFML as frameworks if BUILD_FRAMEWORKS is selected.


Quote from: "dfanz0r"
Ok so i have built it in MinGW this time it builds, and i think it runs fine.

The newer version doesn't seem to want to play nicely with another cython module im using for speeding up openGL some. The older build worked fine with it. Any idea's?


I've tried to use this module for OpenGL calls myself, so I need to know which tools you're using.
I now have a working Visual Studio installation, hopefully I'll be able to make it easier to build the module with it.

Quote from: "Razzeeyy"
Excuse me, but do this binding works with python3?
I'm just confused by the 'cython' word.
AFAIK Cython is just different interpreter for python, isn't it? or it provides a bit different syntax too?


Cython is a tool used to create CPython 2/3 extension modules. I have modified the documentation to be more clear about that.
Title: pysfml2-cython
Post by: bastien on February 28, 2012, 04:13:12 am
I have added a Windows installer for Python 2.7 32-bit. Feedback is welcome.
I have removed the source snapshot with Cython-generated files, as it was mainly intended to make the compilation easier for Windows users.

For version numbers, I think I'm just going to increase the revision number every time I generate a new installer. When SFML is released, I will use the same major and minor numbers as SFML, and I will use the revision number for pySFML-related changes. So if you're using SFML 2.1, you'll need pySFML 2.1.x.
Title: pysfml2-cython
Post by: bastien on February 28, 2012, 08:34:27 pm
By the way, I still have crashes at program exit (I was hoping that the problem comes from MinGW). Currently, I'm not focusing on it too much since it's not a big problem when you're trying out a library in its early stage.
I'm curious to know if everyone has this problem, and if it comes from SFML's cleanup or something else. I almost never have this kind of crash on GNU/Linux.
Title: pysfml2-cython
Post by: bastien on March 05, 2012, 11:21:02 am
I have fixed the Python 3 build, but you need to call the patch.py script to fix a file generated by Cython. See the updated documentation : http://pysfml2-cython.readthedocs.org/en/latest/building.html#building-a-python-3-module

I also added Python 3 and 64 bits Windows installers.
Title: pysfml2-cython
Post by: dfanz0r on March 07, 2012, 11:29:23 pm
Ill try this new version out, and see if it fixes some of the issues i was having before.
Title: pysfml2-cython
Post by: bastien on March 17, 2012, 12:01:43 am
I have renamed the module to sfml. It's more explicit and may avoid clashes.
If you want to keep it shorter, use “import sfml as sf” from now on.
Title: Re: pysfml2-cython
Post by: MarekkPie on March 25, 2012, 11:06:01 pm
Is there anything in pySFML 2.0 that doesn't map nicely to the C++ version? I am wanting to test it out, but the documentation is a bit lacking in specificity.
Title: Re: pysfml2-cython
Post by: bastien on April 02, 2012, 07:08:55 pm
Is there anything in pySFML 2.0 that doesn't map nicely to the C++ version? I am wanting to test it out, but the documentation is a bit lacking in specificity.

Read the tutorial for an overview. I'm eager to know if something important is missed out. I guess I should add a page for C++ developers as well.
Title: Re: pysfml2-cython
Post by: matpow2 on April 11, 2012, 09:07:53 pm
I'm not sure if this has been mentioned already, but the module is missing a way to manipulate the audio 'listener'.

If it could be added, that would be nice, thanks.
Title: Re: pysfml2-cython
Post by: bastien on April 20, 2012, 06:22:21 am
Thanks for pointing that out, I've added it.
Title: Re: pysfml2-cython
Post by: bastien on April 24, 2012, 12:23:28 pm
I tried to make an updated installer using the SFML 2.0 RC release, but I can't get to load the binding with it. python27.dll can't get loaded; if I try to load it with Dependency walker, the only actual problem seems to be that I'm mismatching 32 bits with 64 bits (I'm on a 64 bits OS). This seems pretty weird since the release is for 32 bits, and I'm using 32 bits Python to build a 32 bits module.
I'll try to build SFML myself, since it worked last time. By the way, can someone confirm that the installers work on 32 bits systems?
Title: Re: pysfml2-cython
Post by: bastien on May 09, 2012, 12:17:53 am
Currently, the module doesn't compile because of a bug in Cython: http://trac.cython.org/cython_trac/ticket/767 (http://trac.cython.org/cython_trac/ticket/767)
It's already been fixed in the Git repo, so I guess the update will come soon.

(I'm having some problems with building SFML (http://en.sfml-dev.org/forums/index.php?topic=7843.msg52413#msg52413), but I'll try to fix that and make a new release soon.)
Title: Re: pysfml2-cython
Post by: bastien on May 13, 2012, 12:51:00 am
I have finally added two new installers, as well as a source release that doesn't require Cython: https://github.com/bastienleonard/pysfml2-cython/downloads (https://github.com/bastienleonard/pysfml2-cython/downloads)
As usual, feedback is welcome.

The “crash at the end of the program” is still there. I'll try to fix it for the next release.
Title: Re: pysfml2-cython
Post by: danman on May 15, 2012, 07:31:27 pm
I've got problems with pysfml2-cython on both python3 and python2 versions :

Code: [Select]
alexandre@danman:~/Documents$ python
Python 3.2.3 (default, Apr 23 2012, 23:14:44)
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sfml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/lib/python3.2/site-packages/sfml.cpython-32mu.so: undefined symbol: wrap_render_target_instance
>>>

Do you have an idea ? i've checked the files but I didn't find this symbol, it must be autogenerated by cython itself .
Title: Re: pysfml2-cython
Post by: bastien on May 15, 2012, 10:56:13 pm
I explained the problem here: http://groups.google.com/group/cython-users/browse_thread/thread/5bc84c723b057c35 (http://groups.google.com/group/cython-users/browse_thread/thread/5bc84c723b057c35)

I uploaded a source release a day ago, if that's sufficient you can simply use that: https://github.com/bastienleonard/pysfml2-cython/downloads (https://github.com/bastienleonard/pysfml2-cython/downloads)

If you really want to build from Git, you need to modify the generated sfml.cpp file.
You need all these declarations:

Code: [Select]
__PYX_EXTERN_C DL_EXPORT(PyObject) *wrap_time_instance(sf::Time *);
__PYX_EXTERN_C DL_EXPORT(PyObject) *wrap_render_target_instance(sf::RenderTarget *);
__PYX_EXTERN_C void set_error_message(char*);
__PYX_EXTERN_C DL_EXPORT(PyObject) *wrap_chunk_instance(sf::SoundStream::Chunk*, int);

I don't know if it's the same exact problem everywhere, but on my system I get the first declaration and not the others. So you can look for the wrap_time_instance() declaration, and copy-paste the others after it.
Title: Re: pysfml2-cython
Post by: danman on May 16, 2012, 04:07:28 pm
It works fine, thank you ;)
Title: Re: pysfml2-cython
Post by: rojohound on May 17, 2012, 08:25:50 pm
Hi,
I think I found an issue.  When drawing with sfml.RenderStates the transform is ignored.

I modified the sprite.py example to make the sprite be drawn mirrored, but it's drawing as if there is no transform.  I made the equivalent in C++ and it works there.
#! /usr/bin/env python2
# -*- coding: utf-8 -*-

import sfml as sf


def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'Sprite example')
    window.framerate_limit = 60
    running = True
    texture = sf.Texture.load_from_file('python-logo.png')
    sprite = sf.Sprite(texture)
   
    # This should cause a reflection on the x axis.
    render_state = sf.RenderStates(transform=sf.Transform(-1,0,0,
                                                           0,1,0,
                                                           0,0,1))
   
    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False
       
        window.clear(sf.Color.WHITE)
        window.draw(sprite, render_state)
        window.display()
   
    window.close()


if __name__ == '__main__':
    main()
 
Title: Re: pysfml2-cython
Post by: bastien on May 17, 2012, 10:55:51 pm
I think I fixed it, but now I get a totally white screen. I get the same thing with in C++, however. I also uploaded a bugfix source release (0.1.1). Tell me that works for you.
Title: Re: pysfml2-cython
Post by: bastien on May 17, 2012, 11:15:55 pm
I also added a tutorial for people who know C++ SFML and want to learn pySFML: http://pysfml2-cython.readthedocs.org/en/latest/cppdev-tutorial.html (http://pysfml2-cython.readthedocs.org/en/latest/cppdev-tutorial.html)

As well as a “caveats” page: http://pysfml2-cython.readthedocs.org/en/latest/caveats.html#caveats (http://pysfml2-cython.readthedocs.org/en/latest/caveats.html#caveats)
Title: Re: pysfml2-cython
Post by: rojohound on May 17, 2012, 11:48:51 pm
0.1.1 fixed it.  Thanks!
The white screen is my fault, when mirrored the sprite is being drawn off screen, but now I can mess around with the transformation to get it positioned correctly.

One other slight annoyance is sf.Transform() raises an error about needing 9 parameters,  what I'd like it to do is just use an identity matrix.  The workaround I've been using is sf.Transform(1,0,0,0,1,0,0,0,1).
I made a fix to sfml.pyx line 612 so that the Transform __init__ class has default values for it's parameters.
    def __init__(self, float a00=1, float a01=0, float a02=0,
                  float a10=0, float a11=1, float a12=0,
                  float a20=0, float a21=0, float a22=1):
Title: Re: pysfml2-cython
Post by: bastien on May 18, 2012, 12:25:51 am
You can also use Transform.IDENTITY (http://pysfml2-cython.readthedocs.org/en/latest/graphics.html#sfml.Transform.IDENTITY).
Title: Re: pysfml2-cython
Post by: rojohound on May 18, 2012, 08:40:04 pm
Transform.IDENTITY will work, I knew I was missing something.  That makes it more readable as well.
Title: Re: pysfml2-cython
Post by: bastien on May 20, 2012, 02:47:09 am
I just noticed now that SFML's default constructor creates an identity transform, so yeah it makes sense to support it in pySFML.
Title: Re: pysfml2-cython
Post by: bastien on May 20, 2012, 02:10:43 pm
Just noticed that this website has installers for the latest source release, and it supports 2.6 as well as native 64 bits: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml2 (http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml2)
Title: Re: pysfml2-cython
Post by: bastien on June 19, 2012, 01:22:04 am
Just noticed that this website has installers for the latest source release, and it supports 2.6 as well as native 64 bits: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml2 (http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml2)

I installed his installer for 32 bits 2.7 for a quick test, and the bug-at-program-exit seems now gone. Can anyone confirm this?
Title: Re: pysfml2-cython
Post by: bastien on August 05, 2012, 10:32:09 pm
The default font has been removed, like in C++ SFML.

The Cython bug that required to edit the sfml.cpp file should be fixed with this commit, but I haven't been able to try it yet: https://github.com/cython/cython/commit/01adf0000e88b70eaf3a7315cfeaf80aa4e21bc1 (https://github.com/cython/cython/commit/01adf0000e88b70eaf3a7315cfeaf80aa4e21bc1)
I'm not sure whether this is included in the 0.17 beta.
Title: Re: pysfml2-cython
Post by: bastien on August 12, 2012, 07:31:56 pm
The source releases have been updated. I have also created a “rc-compatible” branch that should work with SFML 2.0 RC. This branch has the same API, i.e. it's still BACK_SPACE instead of BACK and there's no default font. I'll upload RC-compatible source releases when I'm sure it actually builds with the RC. Could someone test it?
Title: Re: pysfml2-cython
Post by: bastien on August 15, 2012, 10:43:03 pm
I have uploaded the SFML 2.0 RC-compatible source.
Title: Re: pysfml2-cython
Post by: therocode on August 18, 2012, 03:13:25 pm
How are you meant to install pysfml2-cython? On the documentation you have instructions for building the module, not installing. So I had to guess my way and I can't get it to work. :(

I am on windows 7 and downloaded the source. Then I tried to build the module by "python.exe setup.py built_ext" and I had sfml 2.0 installed from before. Then in the compile process it couldn't find SFML/graphics.h etc. So I had to edit the setup.py file and add a -IC:\program files (x86)\SFML\include to get it to compile. Then it didn't find the lib files when linking and I had to copy the sfml lib files to python27/libs. and _then_ it compiled.

But the problem when running was this:

Traceback (most recent call last):
  File "C:\projects\ponkt\mejn.py", line 3, in <module>
    import sfml as sf
ImportError: DLL load failed: The specified module could not be found.

and I opened the .pyd file in dependency walker and I could see that it didn't find sfml-graphics-2.dll etc. And I tried everything from copying them to the folder from where I ran the python application, into system32, changing PYTHONPATH etc etc and nothing seems to work and I am getting a bit frustrated. :( So I came here to ask if someone has a solution to this problem.

thanks in advance.
Title: Re: pysfml2-cython
Post by: bastien on August 19, 2012, 06:11:50 pm
I recommend using these installers that should work out of the box: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml (http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml)
They have been recently updated,  by the way.

For the headers and libraries directories, you can pass them as arguments to the setup.py script. I guess there's a mechanism such as environment variables to avoid having to pass them every time, but that's how I did it when I built the installers myself anyway.

For the DLL missing at launch problem, it can be very annoying because the loading of the DLL may fail because of some dependent DLL failing to load. I remember that I had to copy the correct OpenGL DLL in my current folder because the wrong one was being loaded. The problem disappeared when using the installer I just built.

To be honest, I almost never use Windows for programming, and I don't have a hard and fast for debugging this kind of problem.
Title: Re: pysfml2-cython
Post by: bastien on August 19, 2012, 06:36:15 pm
I have changed the Github name from pysfml2-cython to pysfml-cython. This is probably going to create a lot of dead links, but I prefer to do it now than whenever pySFML 3 gets released.
Title: Re: pysfml-cython
Post by: therocode on August 20, 2012, 09:31:39 am
The installers didn't work unfortunately. :/ They say I need python 2.7 installed and that it isn't in the registry. But I do have python 2.7 installed. And then I don't get to do anything. How do I get python registered?
Title: Re: pysfml-cython
Post by: bastien on August 20, 2012, 01:29:40 pm
Is it the same 32/64 bits version as the installer? I'll try the new installers to see if I get the same problem.
Title: Re: pysfml-cython
Post by: therocode on August 20, 2012, 01:55:32 pm
Oh, I tried the 32 bit version now and it worked. :)
Title: Re: pysfml-cython
Post by: therocode on August 21, 2012, 03:15:49 pm
Hi again. xD

Well, I did as I said in the last post, get the installation to work. But it seems that there are more problems.
I am coding something with another person and we are collaborating with svn.

The problem we are having is that we can't even set up a window becasue it seems like stuff are missing from the SFML api. This is our code:

#-*- coding: utf-8 -*-i
import sfml as sf

window = sf.RenderWindow()
window.create(sf.VideoMode(800, 600), "title")
window.setFramerateLimit(60)

and we get the following error:

AttributeError: 'sfml.RenderWindow' object has no attribute 'setFramerateLimit'

So it is as if RenderWindow does not contain it. We tried different stuff and isOpen() is also missing from RenderWindow. So we try to use Window instead of RenderWindow. But then it says that the module doesn't have "Window". But it still has RenderWindow. So something is not right. xD

We are collaborating as said, and one of us is on linux and the other one on windows, and both have a quite fresh snapshot of SFML 2.0 and both have pysfml 0.2.1 and we are getting identical errors. Any ideas?
Title: Re: pysfml-cython
Post by: rojohound on August 25, 2012, 10:50:42 pm
@kaveldun
The naming is a bit different than the actual SFML api, but it's all in the documentation linked from the first page.  Instead of "setFramerateLimit" you would use "framerate_limit".

@bastien
Everything seem to be working great except I'm getting an error when using the image constructor.
>>> sfml.Image(100,100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sfml.pyx", line 1833, in sfml.Image.__init__ (src\sfml.cpp:23432)
AttributeError: 'sfml.Image' object has no attribute 'stream'
Title: Re: pysfml-cython
Post by: therocode on August 26, 2012, 09:36:26 pm
Oh right. Thanks. xD

Didn't expect the API to be named differently.
Title: Re: pysfml-cython
Post by: trilavia on December 15, 2012, 10:16:28 am
Does this binding work fully with python 3.3? Or only python 2?
Title: Re: pysfml-cython
Post by: bastien on December 25, 2012, 10:03:36 pm
Github has removed the downloads feature: https://github.com/blog/1302-goodbye-uploads (https://github.com/blog/1302-goodbye-uploads)
For now, you can still access the old downloads with this URL (note that the installers are outdated and should be downloaded here (http://www.lfd.uci.edu/~gohlke/pythonlibs/#pysfml)): https://github.com/bastienleonard/pysfml-cython/downloads

Since Cython now builds the module without hassle, I think I'm going to stop packaging these source releases. (The goal was to make it so that you don't have to install Cython to build from the source. You can still download the source from Github, but you won't have the Cython-generated file.)
Do you think it was actually useful?

@bastien
Everything seem to be working great except I'm getting an error when using the image constructor.
>>> sfml.Image(100,100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sfml.pyx", line 1833, in sfml.Image.__init__ (src\sfml.cpp:23432)
AttributeError: 'sfml.Image' object has no attribute 'stream'

Sorry, I only saw this part of your message now. It's fixed now.

Does this binding work fully with python 3.3? Or only python 2?

As far as I can tell, it should work fine. I'll test it as soon as I update my system.
Title: Re: pysfml-cython
Post by: netrick on February 15, 2013, 03:16:12 pm
Any chance for network module? I know that python itself has socketing library but sfml sockets are much more convenient. For example python-sfml2 has network bindings.
Title: Re: pysfml-cython
Post by: bastien on February 19, 2013, 11:03:45 pm
Any chance for network module? I know that python itself has socketing library but sfml sockets are much more convenient. For example python-sfml2 has network bindings.

Which feature would you like, for example? Currently, my opinion is that if you want more than bare sockets, you'll probably be better off using a network-centric Python library like Twisted.
Title: Re: pysfml-cython
Post by: netrick on March 01, 2013, 08:38:20 pm
Any chance for network module? I know that python itself has socketing library but sfml sockets are much more convenient. For example python-sfml2 has network bindings.

Which feature would you like, for example? Currently, my opinion is that if you want more than bare sockets, you'll probably be better off using a network-centric Python library like Twisted.

Well, twisted and other good network python libs don't support python3.
Title: Re: pysfml-cython
Post by: basteln on May 23, 2014, 09:55:32 am
What's the status on this project? I tried to install it on OSX, but it always crashed on startup (I used the most recent github source with SFML 2.0). Is it still maintained, or am I better off using the pySFML bindings?  :)