3
# examples/childwin.py -- demonstrate child windows.
5
# Copyright (C) 2008 David Bronke <whitelynx@gmail.com>
6
# Copyright (C) 2002 Peter Liljenberg <petli@ctrl-c.liu.se>
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
# Change path so we find Xlib
27
sys.path.insert(1, os.path.join(sys.path[0], '..'))
29
from Xlib import X, display, Xutil
33
def __init__(self, display):
36
# Find which screen to open the window on
37
self.screen = self.d.screen()
42
bgpm = self.screen.root.create_pixmap(
45
self.screen.root_depth
48
bggc = self.screen.root.create_gc(
49
foreground=self.screen.black_pixel,
50
background=self.screen.black_pixel
53
bgpm.fill_rectangle(bggc, 0, 0, bgsize, bgsize)
55
bggc.change(foreground=self.screen.white_pixel)
57
bgpm.arc(bggc, -bgsize / 2, 0, bgsize, bgsize, 0, 360 * 64)
58
bgpm.arc(bggc, bgsize / 2, 0, bgsize, bgsize, 0, 360 * 64)
59
bgpm.arc(bggc, 0, -bgsize / 2, bgsize, bgsize, 0, 360 * 64)
60
bgpm.arc(bggc, 0, bgsize / 2, bgsize, bgsize, 0, 360 * 64)
63
self.window = self.screen.root.create_window(
64
100, 100, 400, 300, 0,
65
self.screen.root_depth,
69
# special attribute values
70
background_pixmap=bgpm,
72
X.StructureNotifyMask |
75
colormap=X.CopyFromParent
80
self.WM_DELETE_WINDOW = self.d.intern_atom('WM_DELETE_WINDOW')
81
self.WM_PROTOCOLS = self.d.intern_atom('WM_PROTOCOLS')
83
self.window.set_wm_name('Xlib example: childwin.py')
84
self.window.set_wm_icon_name('childwin.py')
85
self.window.set_wm_class('childwin', 'XlibExample')
87
self.window.set_wm_protocols([self.WM_DELETE_WINDOW])
88
self.window.set_wm_hints(
89
flags=Xutil.StateHint,
90
initial_state=Xutil.NormalState
93
self.window.set_wm_normal_hints(
94
flags=(Xutil.PPosition | Xutil.PSize | Xutil.PMinSize),
99
# Map the window, making it visible
103
(self.childWidth, self.childHeight) = (20, 20)
104
self.childWindow = self.window.create_window(
105
20, 20, self.childWidth, self.childHeight, 0,
106
self.screen.root_depth,
110
# special attribute values
111
background_pixel=self.screen.white_pixel,
112
colormap=X.CopyFromParent,
114
self.childWindow.map()
117
# Main loop, handling events
121
e = self.d.next_event()
123
# Window has been destroyed, quit
124
if e.type == X.DestroyNotify:
127
# Button released, add or subtract
128
elif e.type == X.ButtonRelease:
130
print "Moving child window."
131
self.childWindow.configure(
132
x=e.event_x - self.childWidth / 2,
133
y=e.event_y - self.childHeight / 2
137
# Somebody wants to tell us something
138
elif e.type == X.ClientMessage:
139
if e.client_type == self.WM_PROTOCOLS:
141
if fmt == 32 and data[0] == self.WM_DELETE_WINDOW:
145
if __name__ == '__main__':
146
Window(display.Display()).loop()