Author: tack
Date: Tue Jan 16 15:13:29 2007
New Revision: 2405
Modified:
trunk/display/src/x11.py
trunk/display/src/x11window.c
Log:
X11Window now supports wrapping an existing X11 window by window id; allow
passing string display names to X11Window constructor.
Modified: trunk/display/src/x11.py
==============================================================================
--- trunk/display/src/x11.py (original)
+++ trunk/display/src/x11.py Tue Jan 16 15:13:29 2007
@@ -175,6 +175,10 @@
_default_x11_display = X11Display()
display = _default_x11_display
+ if isinstance(display, basestring):
+ # display provided is a name, so create X11Display based on that
+ display = X11Display(display)
+
assert(type(display) == X11Display)
return display
@@ -182,9 +186,29 @@
class X11Window(object):
def __init__(self, display = None, window = None, **kwargs):
+ """
+ Create a new X11 window or wrap an existing X11 window. If display
+ is None, it will use the default display (based on the DISPLAY
+ environment variable). If window is an integer, it will wrap an
+ existing X11 window. The window parameter may also be a lower
+ level _X11.X11Window object.
+
+ If window is none, then a new window will be created, and the
+ following kwargs apply:
+ size: 2-tuple of width and height for the window (required)
+ title: A string representing the window's title (optional)
+ parent: An existing X11Window object of which the new window will
+ be a subwindow.
+ """
display = _get_display(display)
if window:
- self._window = window
+ if isinstance(window, int):
+ # Create new X11Window object based on existing window id.
+ self._window = _X11.X11Window(display._display, (-1, -1),
window = window)
+ elif isinstance(window, _X11.X11Window):
+ self._window = window
+ else:
+ raise ValueError, "window parameter must be an integer."
else:
assert("size" in kwargs)
if "title" in kwargs:
Modified: trunk/display/src/x11window.c
==============================================================================
--- trunk/display/src/x11window.c (original)
+++ trunk/display/src/x11window.c Tue Jan 16 15:13:29 2007
@@ -83,7 +83,7 @@
}
PyObject *
-X11Window_PyObject__new(PyTypeObject *type, PyObject * args, PyObject * kwargs)
+X11Window_PyObject__new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
X11Window_PyObject *self, *py_parent;
X11Display_PyObject *display;
@@ -115,25 +115,29 @@
XLockDisplay(self->display);
- screen = DefaultScreen(self->display);
- attr.backing_store = NotUseful;
- attr.border_pixel = 0;
- attr.background_pixmap = None;
- attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask |
- StructureNotifyMask | PointerMotionMask | KeyPressMask |
FocusChangeMask;
- attr.bit_gravity = StaticGravity;
- attr.win_gravity = StaticGravity;
- attr.override_redirect = False;
- attr.colormap = DefaultColormap(self->display, screen);
-
- self->window = XCreateWindow(self->display, parent, 0, 0,
- w, h, 0, DefaultDepth(self->display, screen),
InputOutput,
- DefaultVisual(self->display, screen),
- CWBackingStore | CWColormap | CWBackPixmap |
CWWinGravity |
- CWBitGravity | CWEventMask | CWOverrideRedirect,
&attr);
+ if (PyMapping_HasKeyString(kwargs, "window")) {
+ self->window = (Window)PyInt_AsLong(PyDict_GetItemString(kwargs,
"window"));
+ } else {
+ screen = DefaultScreen(self->display);
+ attr.backing_store = NotUseful;
+ attr.border_pixel = 0;
+ attr.background_pixmap = None;
+ attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask |
+ StructureNotifyMask | PointerMotionMask | KeyPressMask |
FocusChangeMask;
+ attr.bit_gravity = StaticGravity;
+ attr.win_gravity = StaticGravity;
+ attr.override_redirect = False;
+ attr.colormap = DefaultColormap(self->display, screen);
+
+ self->window = XCreateWindow(self->display, parent, 0, 0,
+ w, h, 0, DefaultDepth(self->display, screen),
InputOutput,
+ DefaultVisual(self->display, screen),
+ CWBackingStore | CWColormap | CWBackPixmap |
CWWinGravity |
+ CWBitGravity | CWEventMask | CWOverrideRedirect,
&attr);
- if (window_title)
- XStoreName(self->display, self->window, window_title);
+ if (window_title)
+ XStoreName(self->display, self->window, window_title);
+ }
self->ptr = PyInt_FromLong(self->window);
_make_invisible_cursor(self);
XUnlockDisplay(self->display);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog