Author: ArcRiley Date: 2007-12-30 22:49:53 +0000 (Sun, 30 Dec 2007) New Revision: 641
Added: trunk/pysoy/src/controllers/Window.pxi Modified: trunk/pysoy/examples/collide_blocks.py trunk/pysoy/src/_core-x11/Screen.pxi trunk/pysoy/src/_core-x11/Window.pxi trunk/pysoy/src/_core-x11/glx.pxd trunk/pysoy/src/_core-x11/soy._core.pxd trunk/pysoy/src/controllers/Controller.pxi trunk/pysoy/src/controllers/soy.controllers.pxd trunk/pysoy/src/controllers/soy.controllers.pyx Log: added window closure event and controller Modified: trunk/pysoy/examples/collide_blocks.py =================================================================== --- trunk/pysoy/examples/collide_blocks.py 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/examples/collide_blocks.py 2007-12-30 22:49:53 UTC (rev 641) @@ -26,6 +26,8 @@ key['V'] = soy.actions.Force(bks['teal'], 0, 0, 100) key['q'] = soy.actions.Quit() key[ 9 ] = soy.actions.Quit() # 9 = esc key +wcn = soy.controllers.Window(win) +wcn['close'] = soy.actions.Quit() if __name__ == '__main__' : while True: Modified: trunk/pysoy/src/_core-x11/Screen.pxi =================================================================== --- trunk/pysoy/src/_core-x11/Screen.pxi 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/_core-x11/Screen.pxi 2007-12-30 22:49:53 UTC (rev 641) @@ -58,6 +58,7 @@ self._screenID = sId else : raise('Requested screen %d not available' % sId) + self._wmDelWin = glx.XInternAtom(_display, "WM_DELETE_WINDOW", 0) _glxAttrs[0] = glx.GLX_RGBA _glxAttrs[1] = glx.GLX_DOUBLEBUFFER _glxAttrs[2] = glx.GLX_RED_SIZE @@ -189,12 +190,16 @@ (<Window> _windows.list[i])._eventMotion (_event.xmotion.time, _event.xmotion.x, _event.xmotion.y) + elif _event.type == glx.Expose : + if (<Window> _windows.list[i])._opened == -1 : + (<Window> _windows.list[i])._opened = 0 elif _event.type == glx.ConfigureNotify : (<Window> _windows.list[i])._resize(_event.xconfigure.width, _event.xconfigure.height) - elif _event.type == glx.Expose : - if (<Window> _windows.list[i])._opened == -1 : - (<Window> _windows.list[i])._opened = 0 + elif _event.type == glx.ClientMessage : + if _event.xclient.format == 32 and \ + _event.xclient.data.l[0] == self._wmDelWin : + (<Window> _windows.list[i])._eventWinClose() break _windows.unlock() Modified: trunk/pysoy/src/_core-x11/Window.pxi =================================================================== --- trunk/pysoy/src/_core-x11/Window.pxi 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/_core-x11/Window.pxi 2007-12-30 22:49:53 UTC (rev 641) @@ -81,6 +81,7 @@ glx.InputOutput, self._screen._xVisualInfo.visual, glx.CWBorderPixel | glx.CWColormap | glx.CWEventMask | _override, &_winAttr) + glx.XSetWMProtocols(_display, self._windowID, &self._screen._wmDelWin, 1) if self._screen._fullScreen != self and self._splash == 0 : _atom = glx.XInternAtom(_display, "WM_DELETE_WINDOW", True) glx.XSetWMProtocols(_display, self._windowID, &_atom, 1) @@ -206,6 +207,13 @@ # Nothing (yet) return + cdef void _eventWinClose(self) : + cdef int i + self._controllers.lock() + for i from 0 <= i < self._controllers.current : + (<soy.controllers.Controller> self._controllers.list[i])._eventWinClose() + self._controllers.unlock() + property title: '''Window's title string Modified: trunk/pysoy/src/_core-x11/glx.pxd =================================================================== --- trunk/pysoy/src/_core-x11/glx.pxd 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/_core-x11/glx.pxd 2007-12-30 22:49:53 UTC (rev 641) @@ -477,6 +477,23 @@ Window above Bool override_redirect + ctypedef union MessageData : + char b[20] + short s[10] + long l[5] + + + ctypedef struct XClientMessageEvent : + int type + unsigned long serial + Bool send_event + Display *display + Window window + Atom message_type + int format + MessageData data + + ctypedef union XEvent : int type XAnyEvent xany @@ -485,8 +502,8 @@ XMotionEvent xmotion XExposeEvent xexpose XConfigureEvent xconfigure + XClientMessageEvent xclient - cdef Display *XOpenDisplay ( char* ) cdef int XCloseDisplay ( Display* ) cdef char *DisplayString ( Display* ) Modified: trunk/pysoy/src/_core-x11/soy._core.pxd =================================================================== --- trunk/pysoy/src/_core-x11/soy._core.pxd 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/_core-x11/soy._core.pxd 2007-12-30 22:49:53 UTC (rev 641) @@ -45,6 +45,7 @@ cdef class Screen : cdef glx.Screen *_screen cdef int _screenID + cdef glx.Atom _wmDelWin cdef glx.XF86VidModeModeInfo _deskMode cdef glx.XVisualInfo *_xVisualInfo cdef object _fullScreen @@ -83,6 +84,7 @@ cdef void _eventButtonUp ( self, glx.Time, unsigned int, int, int ) cdef void _eventMotion ( self, glx.Time, int, int ) + cdef void _eventWinClose ( self ) cdef extern from "sys/time.h" : Modified: trunk/pysoy/src/controllers/Controller.pxi =================================================================== --- trunk/pysoy/src/controllers/Controller.pxi 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/controllers/Controller.pxi 2007-12-30 22:49:53 UTC (rev 641) @@ -30,3 +30,6 @@ cdef void _eventKeyUp(self, unsigned char _cde, unsigned char _sym) : return + + cdef void _eventWinClose(self) : + return Copied: trunk/pysoy/src/controllers/Window.pxi (from rev 637, trunk/pysoy/src/controllers/Keyboard.pxi) =================================================================== --- trunk/pysoy/src/controllers/Window.pxi (rev 0) +++ trunk/pysoy/src/controllers/Window.pxi 2007-12-30 22:49:53 UTC (rev 641) @@ -0,0 +1,80 @@ +# PySoy controllers.Window class +# +# Copyright (C) 2006,2007 Team PySoy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class Window (Controller) : + '''PySoy controllers.Window + + This controller responds to various soy.Window events (move, close, etc). + + Programmable keys are currently: + 'close' + + See soy.controllers.Controller for how to program controllers. + ''' + def __cinit__(self, window, *args, **kw) : + if not isinstance(window, soy._core.Window) : + raise TypeError('first argument must be of type soy.Window') + self._window = window + self._window._controllers.lock() + self._window._controllers.append(<void *>self) + self._window._controllers.unlock() + + def __dealloc__(self) : + cdef int _i + if not self._window : + return + self._window._controllers.lock() + self._window._controllers.remove(<void *>self) + self._window._controllers.unlock() + if self._acts_close : + py.Py_DECREF(<object> self._acts_close) + + def __str__(self) : + cdef int _i + ret = {} + if self._acts_close : + ret['close'] = <object> self._acts_close + return ret.__str__() + + def __repr__(self) : + return self.__str__() + + def __getitem__(self, key) : + if key == 'close' : + return <object> self._acts_close + else : + raise KeyError(key) + + def __setitem__(self, key, value) : + if type(key) != str : + raise KeyError('unsupported key, see help(soy.controllers.Window)') + if not isinstance(value, soy.actions.Action) : + raise TypeError('value not an instance of soy.actions.Action') + if key == 'close' : + if self._acts_close : + py.Py_DECREF(<object> self._acts_close) + self._acts_close = <void *> value + py.Py_INCREF(<object> self._acts_close) + else : + raise KeyError('%s unsupported, see help(soy.controllers.Window)' % key) + + + cdef void _eventWinClose(self) : + if self._acts_close : + (<soy.actions.Action> self._acts_close)._perform(0) Modified: trunk/pysoy/src/controllers/soy.controllers.pxd =================================================================== --- trunk/pysoy/src/controllers/soy.controllers.pxd 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/controllers/soy.controllers.pxd 2007-12-30 22:49:53 UTC (rev 641) @@ -24,8 +24,13 @@ cdef class Controller : cdef void _eventKeyDown ( self, unsigned char, unsigned char ) cdef void _eventKeyUp ( self, unsigned char, unsigned char ) + cdef void _eventWinClose ( self ) cdef class Keyboard (Controller) : cdef soy._core.Window _window cdef void* _acts_keycde[256] cdef void* _acts_keysym[256] + +cdef class Window (Controller) : + cdef soy._core.Window _window + cdef void* _acts_close Modified: trunk/pysoy/src/controllers/soy.controllers.pyx =================================================================== --- trunk/pysoy/src/controllers/soy.controllers.pyx 2007-12-30 22:44:01 UTC (rev 640) +++ trunk/pysoy/src/controllers/soy.controllers.pyx 2007-12-30 22:49:53 UTC (rev 641) @@ -28,3 +28,4 @@ include "Controller.pxi" include "Keyboard.pxi" +include "Window.pxi" _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn