summaryrefslogtreecommitdiff
path: root/efl/ecore_x/efl.ecore_x_window.pxi
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-01-04 12:47:40 +0100
committerDave Andreoli <dave@gurumeditation.it>2015-01-04 12:47:40 +0100
commit863efc19ebe9d0da3b7ed387cd257657ad39c3dd (patch)
tree5f9eb781d53746cd18654c2493bd0aa7b7f3a2db /efl/ecore_x/efl.ecore_x_window.pxi
parent1910563604d65bc76b377fec75d9b5570585d239 (diff)
Move ecore_x out of the ecore extension
Now ecore do not more looks like an alien with his __init__ hack and his different module/package structure This broke ecore.x users as the extension is now efl.ecore_x Sorry to bother but I still think that ecore_x should not be implemented in python, if this hurt you please let me know
Diffstat (limited to 'efl/ecore_x/efl.ecore_x_window.pxi')
-rw-r--r--efl/ecore_x/efl.ecore_x_window.pxi466
1 files changed, 466 insertions, 0 deletions
diff --git a/efl/ecore_x/efl.ecore_x_window.pxi b/efl/ecore_x/efl.ecore_x_window.pxi
new file mode 100644
index 0000000..d67581b
--- /dev/null
+++ b/efl/ecore_x/efl.ecore_x_window.pxi
@@ -0,0 +1,466 @@
1# Copyright (C) 2007-2015 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18cdef class Window:
19 def __init__(self, Window parent=None, int x=0, int y=0, int w=1, int h=1,
20 input=False, argb=False, override_redirect=False):
21 """Create a new X window.
22
23 :param parent: window to use as parent, or None to use the
24 root window.
25 :param x: horizontal position.
26 :param y: vertical position.
27 :param w: horizontal size.
28 :param h: vertical size.
29 :param input: if should be an input-only window or not.
30 :param argb: if window should be ARGB.
31 :param override_redirect: if override redirect attribute must be set.
32 """
33 cdef Ecore_X_Window p_xid, xid
34 if parent is <Window>None:
35 p_xid = 0
36 else:
37 p_xid = parent.xid
38
39 if not input and not argb and not override_redirect:
40 xid = ecore_x_window_new(p_xid, x, y, w, h)
41 elif argb:
42 if not override_redirect:
43 xid = ecore_x_window_argb_new(p_xid, x, y, w, h)
44 else:
45 xid = ecore_x_window_override_argb_new(p_xid, x, y, w, h)
46 elif input:
47 xid = ecore_x_window_input_new(p_xid, x, y, w, h)
48 elif override_redirect:
49 xid = ecore_x_window_override_new(p_xid, x, y, w, h)
50 else:
51 raise ValueError("not able to create window!")
52
53 self._set_xid(xid)
54
55 cdef int _set_xid(self, Ecore_X_Window xid) except 0:
56 if self.xid == 0:
57 self.xid = xid
58 return 1
59 else:
60 raise ValueError("object already wraps an X Window.")
61
62 def __str__(self):
63 cdef int x, y, w, h, visible
64 cdef unsigned int parent
65
66 ecore_x_window_geometry_get(self.xid, &x, &y, &w, &h)
67 parent = ecore_x_window_parent_get(self.xid)
68 visible = ecore_x_window_visible_get(self.xid)
69 return "%s(xid=%#x, parent=%#x, x=%d, y=%d, w=%d, h=%d, visible=%s)" % \
70 (self.__class__.__name__, self.xid, parent, x, y, w, h,
71 bool(visible))
72
73 def __repr__(self):
74 cdef int x, y, w, h
75 cdef unsigned int parent
76
77 ecore_x_window_geometry_get(self.xid, &x, &y, &w, &h)
78 parent = ecore_x_window_parent_get(self.xid)
79 return "%s(%#x, xid=%#x, parent=%#x, x=%d, y=%d, w=%d, h=%d)" % \
80 (self.__class__.__name__, <unsigned long><void *>self,
81 self.xid, parent, x, y, w, h)
82
83 def __richcmp__(self, other, int op):
84 if op == 2: # equal
85 if self is other:
86 return 1
87 else:
88 return self.xid == int(other)
89 else:
90 return 0
91
92 def __int__(self):
93 return self.xid
94
95 def __long__(self):
96 return self.xid
97
98 def delete(self):
99 "Deletes the current window."
100 if self.xid != 0:
101 ecore_x_window_free(self.xid)
102 self.xid = 0
103
104 def delete_request_send(self):
105 "Sends a delete request to this window."
106 ecore_x_window_delete_request_send(self.xid)
107
108 def root_get(self):
109 ":rtype: Window"
110 cdef Ecore_X_Window xid
111 xid = ecore_x_window_root_get(self.xid)
112 return Window_from_xid(xid)
113
114 def reparent(self, Window new_parent=None, int x=0, int y=0):
115 """Moves this window to within another window at a given position.
116
117 :param new_parent: window to use as parent, or None to use the root
118 window.
119 :param x: horizontal position within the new parent.
120 :param y: vertical position within the new parent.
121 """
122 cdef Ecore_X_Window p_xid
123 if new_parent is <Window>None:
124 p_xid = 0
125 else:
126 p_xid = new_parent.xid
127 ecore_x_window_reparent(self.xid, p_xid, x, y)
128
129 def parent_set(self, Window new_parent=None):
130 """Set window parent.
131
132 :param new_parent: window to use as parent, or None to use the root
133 window.
134 :see: same as :py:meth:`reparent` with both x and y being 0.
135 """
136 cdef Ecore_X_Window p_xid
137 if new_parent is <Window>None:
138 p_xid = 0
139 else:
140 p_xid = new_parent.xid
141 ecore_x_window_reparent(self.xid, p_xid, 0, 0)
142
143 def parent_get(self):
144 ":rtype: Window"
145 cdef Ecore_X_Window xid
146 xid = ecore_x_window_parent_get(self.xid)
147 return Window_from_xid(xid)
148
149 property parent:
150 def __set__(self, value):
151 self.parent_set(value)
152
153 def __get__(self):
154 return self.parent_get()
155
156 def show(self):
157 """Shows this window.
158
159 Synonymous to "mapping" a window in X Window System terminology.
160 """
161 ecore_x_window_show(self.xid)
162
163 def hide(self):
164 """Hides a window.
165
166 Synonymous to "unmapping" a window in X Window System terminology.
167 """
168 ecore_x_window_hide(self.xid)
169
170 def visible_set(self, value):
171 if value:
172 self.show()
173 else:
174 self.hide()
175
176 def visible_get(self):
177 ":rtype: bool"
178 return bool(ecore_x_window_visible_get(self.xid))
179
180 def focus(self):
181 "Give focus to this windows."
182 ecore_x_window_focus(self.xid)
183
184 def focus_at_time(self, Ecore_X_Time time):
185 """Sets the focus this window at a specific time.
186
187 :param time: time specification, see :py:meth:`current_time_get`.
188 """
189 ecore_x_window_focus_at_time(self.xid, time)
190
191 def ignore_set(self, int setting):
192 ecore_x_window_ignore_set(self.xid, bool(setting))
193
194 def raise_(self):
195 "Raises this window."
196 ecore_x_window_raise(self.xid)
197
198 def lower(self):
199 "Lowers this window."
200 ecore_x_window_lower(self.xid)
201
202 def move(self, int x, int y):
203 """Set window position.
204
205 :param x: horizontal.
206 :param y: vertical.
207 """
208 ecore_x_window_move(self.xid, x, y)
209
210 def pos_set(self, int x, int y):
211 """Set window position.
212
213 :param x: horizontal.
214 :param y: vertical.
215
216 .. note:: alias for :py:meth:`move`
217 """
218 ecore_x_window_move(self.xid, x, y)
219
220 def pos_get(self):
221 ":rtype: tuple of int"
222 cdef int x, y, w, h
223 ecore_x_window_geometry_get(self.xid, &x, &y, &w, &h)
224 return (x, y)
225
226 property pos:
227 def __set__(self, spec):
228 self.pos_set(*spec)
229
230 def __get__(self):
231 return self.pos_get()
232
233 def resize(self, int w, int h):
234 """Set window size.
235
236 :param w: horizontal.
237 :param h: vertical.
238 """
239 ecore_x_window_resize(self.xid, w, h)
240
241 def size_set(self, int w, int h):
242 """Set window size.
243
244 :param w: horizontal.
245 :param h: vertical.
246
247 .. note:: alias for :py:meth:`resize`
248 """
249 ecore_x_window_resize(self.xid, w, h)
250
251 def size_get(self):
252 ":rtype: tuple of int"
253 cdef int w, h
254 ecore_x_window_size_get(self.xid, &w, &h)
255 return (w, h)
256
257 property size:
258 def __set__(self, spec):
259 self.size_set(*spec)
260
261 def __get__(self):
262 return self.size_get()
263
264 def move_resize(self, int x, int y, int w, int h):
265 """Set both position and size.
266
267 :param x: horizontal position.
268 :param y: vertical position.
269 :param w: horizontal size.
270 :param h: vertical size.
271 """
272 ecore_x_window_move_resize(self.xid, x, y, w, h)
273
274 def geometry_set(self, int x, int y, int w, int h):
275 """Set both position and size.
276
277 :param x: horizontal position.
278 :param y: vertical position.
279 :param w: horizontal size.
280 :param h: vertical size.
281 """
282 ecore_x_window_move_resize(self.xid, x, y, w, h)
283
284 def geometry_get(self):
285 ":rtype: tuple of int"
286 cdef int x, y, w, h
287 ecore_x_window_geometry_get(self.xid, &x, &y, &w, &h)
288 return (x, y, w, h)
289
290 property geometry:
291 def __set__(self, spec):
292 self.geometry_set(*spec)
293
294 def __get__(self):
295 return self.geometry_get()
296
297 def border_width_set(self, int width):
298 """Sets the width of the border of this window.
299
300 :param width: border width, in pixels.
301 """
302 ecore_x_window_border_width_set(self.xid, width)
303
304 def border_width_get(self):
305 ":rtype: int"
306 return ecore_x_window_border_width_get(self.xid)
307
308 property border_width:
309 def __set__(self, spec):
310 self.border_width_set(*spec)
311
312 def __get__(self):
313 return self.border_width_get()
314
315 def depth_get(self):
316 ":rtype: int"
317 return ecore_x_window_depth_get(self.xid)
318
319 property depth:
320 def __get__(self):
321 return self.depth_get()
322
323 def configure(self, int mask, int x, int y, int w, int h, int border_width,
324 Window sibling, int stack_mode):
325 cdef Ecore_X_Window sibling_xid
326 if sibling is <Window>None:
327 sibling_xid = 0
328 else:
329 sibling_xid = sibling.xid
330 ecore_x_window_configure(self.xid, <Ecore_X_Window_Configure_Mask>mask,
331 x, y, w, h, border_width, sibling_xid,
332 stack_mode)
333
334 def cursor_show(self):
335 ecore_x_window_cursor_show(self.xid, 1)
336
337 def cursor_hide(self):
338 ecore_x_window_cursor_show(self.xid, 0)
339
340 def cursor_set(self, Ecore_X_Cursor cursor):
341 ecore_x_window_cursor_set(self.xid, cursor)
342
343 def pointer_warp(self, int x, int y):
344 ecore_x_pointer_warp(self.xid, x, y)
345
346 def pointer_xy_get(self):
347 cdef int x, y
348 ecore_x_pointer_xy_get(self.xid, &x, &y);
349 return (x, y)
350
351 def defaults_set(self):
352 """Sets the default properties for the given window.
353
354 The default properties set for the window are WM_CLIENT_MACHINE and
355 _NET_WM_PID.
356 """
357 ecore_x_window_defaults_set(self.xid)
358
359 def killall_children(self):
360 "Kill all clients with subwindows under this window."
361 ecore_x_killall(self.xid)
362
363 def kill(self):
364 "Kill this specific client"
365 ecore_x_kill(self.xid)
366
367 def background_color_set(self, int r, int g, int b):
368 """Set background color.
369
370 :param r: red (0...65536, 16 bits)
371 :param g: green (0...65536, 16 bits)
372 :param b: blue (0...65536, 16 bits)
373 """
374 ecore_x_window_background_color_set(self.xid, r, g, b)
375
376 def area_clear(self, int x, int y, int w, int h):
377 "Paints the specified area with background's color or pixmap."
378 ecore_x_window_area_clear(self.xid, x, y, w, h)
379
380 def area_expose(self, int x, int y, int w, int h):
381 "Like :py:meth:`area_clear`, but generates exposures."
382 ecore_x_window_area_expose(self.xid, x, y, w, h)
383
384 def override_set(self, int setting):
385 ecore_x_window_override_set(self.xid, bool(setting))
386
387 def argb_get(self):
388 ":rtype: bool"
389 return bool(ecore_x_window_argb_get(self.xid))
390
391 def gravity_set(self, int gravity):
392 ecore_x_window_gravity_set(self.xid, <Ecore_X_Gravity>gravity)
393
394 def pixel_gravity_set(self, int gravity):
395 ecore_x_window_pixel_gravity_set(self.xid, <Ecore_X_Gravity>gravity)
396
397 def event_mask_set(self, int mask):
398 ecore_x_event_mask_set(self.xid, <Ecore_X_Event_Mask>mask)
399
400 def event_mask_unset(self, int mask):
401 ecore_x_event_mask_unset(self.xid, <Ecore_X_Event_Mask>mask)
402
403 def icccm_hints_set(self, int accepts_focus, int initial_state,
404 int icon_pixmap, int icon_mask, int icon_window,
405 int window_group, int is_urgent):
406 """Set ICCCM window hints.
407
408 :param accepts_focus: if window accepts focus or not.
409 :param initial_state: one of ECORE_X_WINDOW_STATE_HINT_*.
410 :param icon_pixmap: pixmap id to be used as icon.
411 :param icon_mask: pixmap id to be used as icon mask.
412 :param icon_window: window id to be used as icon.
413 :param window_group: window id representing the group.
414 :param is_urgent: if window is urgent or not.
415 """
416 ecore_x_icccm_hints_set(self.xid, accepts_focus,
417 <Ecore_X_Window_State_Hint>initial_state,
418 icon_pixmap, icon_mask, icon_window,
419 window_group, is_urgent)
420
421 def icccm_hints_get(self):
422 """Get ICCCM window hints.
423
424 :see: :py:meth:`icccm_hints_set`
425 :return: tuple with: accepts_focus, initial_state, icon_pixmap,
426 icon_mask, icon_window, window_group, is_urgent
427 """
428 cdef Eina_Bool accepts_focus, is_urgent
429 cdef int initial_state, icon_pixmap, icon_mask, \
430 icon_window, window_group
431 ecore_x_icccm_hints_get(self.xid, &accepts_focus,
432 <Ecore_X_Window_State_Hint *>&initial_state,
433 <Ecore_X_Pixmap *>&icon_pixmap,
434 <Ecore_X_Pixmap *>&icon_mask,
435 <Ecore_X_Window *>&icon_window,
436 <Ecore_X_Window *>&window_group,
437 &is_urgent)
438 return (bool(accepts_focus), initial_state, icon_pixmap, icon_mask,
439 icon_window, window_group, bool(is_urgent))
440
441 def type_set(self, int type):
442 ecore_x_netwm_window_type_set(self.xid, <Ecore_X_Window_Type>type)
443
444 def state_set(self, states):
445 # building list
446 cdef Ecore_X_Window_State *_states
447 _states = <Ecore_X_Window_State *>PyMem_Malloc(len(states) * sizeof(Ecore_X_Window_State))
448 for i in xrange(len(states)):
449 _states[i] = states[i]
450
451 ecore_x_netwm_window_state_set(self.xid, _states, len(states))
452 PyMem_Free(<void*>_states)
453
454 def keyboard_grab(self):
455 return bool(ecore_x_keyboard_grab(self.xid))
456
457def Window_from_xid(unsigned long xid):
458 """Create a Python wrapper for given window id.
459
460 :param xid: window id.
461 :rtype: L{Window}
462 """
463 cdef Window w
464 w = Window.__new__(Window)
465 w._set_xid(xid)
466 return w