~ubuntu-branches/ubuntu/trusty/python-sfml/trusty

« back to all changes in this revision

Viewing changes to examples/embedding/main.cpp

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2013-12-09 17:50:52 UTC
  • mfrom: (1.1.3) (8.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131209175052-11v6drpb6g3yksst
Tags: 1.5.1.is.1.3+dfsg-1
* New upstream version 1.3 (from python-sfml.org)
  - This is a complete rewrite of the Python bindings for SFML2, and
    the new maintainer is using a different version numbering scheme.
* Added myself to the list of uploaders
* Change package priority from extra to optional
* Bumped standards version (to 3.9.5) and debhelper compat (to 9)
* Added Python 3 and documentation packages
* Improve package description for debug packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pySFML - Python bindings for SFML
 
4
// Copyright 2012-2013, Jonathan De Wachter <dewachter.jonathan@gmail.com>
 
5
//
 
6
// This software is released under the LGPLv3 license.
 
7
// You should have received a copy of the GNU Lesser General Public License
 
8
// along with this program. If not, see <http://www.gnu.org/licenses/>.
 
9
//
 
10
////////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// Including Python.h first is mandatory!
 
13
#include <Python.h>
 
14
 
 
15
#include <unistd.h>
 
16
#include <iostream>
 
17
 
 
18
// Make sure to include the SFML headers before the pySFML ones
 
19
#include <SFML/Graphics.hpp>
 
20
#include <pysfml/graphics_api.h>
 
21
 
 
22
int main(int argc, char *argv[])
 
23
{
 
24
    // Initialization (mandatory stuff)
 
25
    Py_SetProgramName(argv[0]);
 
26
    Py_Initialize();
 
27
 
 
28
    // Add the current path to sys.path to find our script
 
29
    char cwd[1024];
 
30
    if (!getcwd(cwd, sizeof(cwd))) {
 
31
        std::cout << "Couldn't get the current path" << std::endl;
 
32
        return EXIT_FAILURE; }
 
33
    PyObject *sys = PyImport_ImportModule("sys");
 
34
    PyObject *path = PyObject_GetAttrString(sys, "path");
 
35
    PyList_Append(path, PyString_FromString(cwd));
 
36
 
 
37
    // Import our script that creates a texture
 
38
    PyObject* script = PyImport_ImportModule("script");
 
39
    if(!script)
 
40
        PyErr_Print();
 
41
 
 
42
    // Retrieve the texture
 
43
    PyTextureObject *texture;
 
44
    texture = (PyTextureObject*)PyObject_GetAttrString(script, "texture");
 
45
 
 
46
    // Create a window and display the texture for five seconds
 
47
    sf::RenderWindow window(sf::VideoMode(640, 480), "pySFMl - Embedding Python");
 
48
 
 
49
    window.clear();
 
50
    window.draw(sf::Sprite(*texture->p_this));
 
51
    window.display();
 
52
 
 
53
    sf::sleep(sf::seconds(5));
 
54
 
 
55
    // Then, terminate properly...
 
56
    Py_Finalize();
 
57
 
 
58
    return EXIT_SUCCESS;
 
59
}