sdlterm/cython/sdlterm.pyx
changeset 47 537d7c6b48a2
child 48 1f00e90fd72a
equal deleted inserted replaced
46:2b43a7f38c34 47:537d7c6b48a2
       
     1 # distutils: language = c++
       
     2 # distutils: sources = src/sdlterm.cc
       
     3 # distutils: include_dirs = /usr/include/SDL src
       
     4 # distutils: libraries = SDL SDL_ttf
       
     5 # distutils: define_macros = _GNU_SOURCE=1 _REENTRANT
       
     6 # distutils: extra_compile_args = --std=c++0x
       
     7 # cython: language_level=3
       
     8 
       
     9 from libcpp cimport bool
       
    10 
       
    11 
       
    12 cdef extern from "sdlterm.h":
       
    13     enum EventType:
       
    14         pass
       
    15 
       
    16     union Event:
       
    17         EventType type
       
    18 
       
    19     cdef cppclass Terminal:
       
    20         Terminal() except +
       
    21 
       
    22         void select_font(char *fname_regular, char *fname_bold, int ptsize)
       
    23         void resize(int pxwidth, int pxheight)
       
    24 
       
    25         void erase()
       
    26         void putch(int x, int y, Py_UNICODE ch)
       
    27         void commit()
       
    28 
       
    29         int prepare_attr(int fg, int bg, int style)
       
    30         void set_attr(int value)
       
    31 
       
    32         void set_cursor(int x, int y)
       
    33         void show_cursor(bool visible)
       
    34 
       
    35         void get_next_event(Event event)
       
    36 
       
    37 
       
    38 cdef class SDLTerminal:
       
    39     cdef Terminal *thisptr      # hold a C++ instance which we're wrapping
       
    40 
       
    41     def __cinit__(self):
       
    42         self.thisptr = new Terminal()
       
    43     def __dealloc__(self):
       
    44         del self.thisptr
       
    45 
       
    46     def select_font(self, fname_regular, fname_bold, ptsize):
       
    47         fname_regular = fname_regular.encode('utf8')
       
    48         fname_bold = fname_bold.encode('utf8')
       
    49         self.thisptr.select_font(fname_regular, fname_bold, ptsize)
       
    50     def resize(self, width, height):
       
    51         self.thisptr.resize(width, height)
       
    52 
       
    53     def erase(self):
       
    54         self.thisptr.erase()
       
    55     def putch(self, x, y, ch):
       
    56         self.thisptr.putch(x, y, ch)
       
    57     def commit(self):
       
    58         self.thisptr.commit()
       
    59 
       
    60     def get_next_event(self):
       
    61         cdef Event event
       
    62         self.thisptr.get_next_event(event)
       
    63         return dict()
       
    64