~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to .pc/python3.patch/examples/childwin.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150813081419-hdefinnghp2iydkx
Tags: 0.14+20091101-3
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
3
# examples/childwin.py -- demonstrate child windows.
 
4
#
 
5
#       Copyright (C) 2008 David Bronke <whitelynx@gmail.com>
 
6
#       Copyright (C) 2002 Peter Liljenberg <petli@ctrl-c.liu.se>
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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
 
21
 
 
22
 
 
23
import sys
 
24
import os
 
25
 
 
26
# Change path so we find Xlib
 
27
sys.path.insert(1, os.path.join(sys.path[0], '..'))
 
28
 
 
29
from Xlib import X, display, Xutil
 
30
 
 
31
# Application window
 
32
class Window:
 
33
        def __init__(self, display):
 
34
                self.d = display
 
35
 
 
36
                # Find which screen to open the window on
 
37
                self.screen = self.d.screen()
 
38
 
 
39
                # background pattern
 
40
                bgsize = 20
 
41
 
 
42
                bgpm = self.screen.root.create_pixmap(
 
43
                        bgsize,
 
44
                        bgsize,
 
45
                        self.screen.root_depth
 
46
                        )
 
47
 
 
48
                bggc = self.screen.root.create_gc(
 
49
                        foreground=self.screen.black_pixel,
 
50
                        background=self.screen.black_pixel
 
51
                        )
 
52
 
 
53
                bgpm.fill_rectangle(bggc, 0, 0, bgsize, bgsize)
 
54
 
 
55
                bggc.change(foreground=self.screen.white_pixel)
 
56
 
 
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)
 
61
 
 
62
                # Actual window
 
63
                self.window = self.screen.root.create_window(
 
64
                        100, 100, 400, 300, 0,
 
65
                        self.screen.root_depth,
 
66
                        X.InputOutput,
 
67
                        X.CopyFromParent,
 
68
 
 
69
                        # special attribute values
 
70
                        background_pixmap=bgpm,
 
71
                        event_mask=(
 
72
                                X.StructureNotifyMask |
 
73
                                X.ButtonReleaseMask
 
74
                                ),
 
75
                        colormap=X.CopyFromParent
 
76
                        )
 
77
 
 
78
                # Set some WM info
 
79
 
 
80
                self.WM_DELETE_WINDOW = self.d.intern_atom('WM_DELETE_WINDOW')
 
81
                self.WM_PROTOCOLS = self.d.intern_atom('WM_PROTOCOLS')
 
82
 
 
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')
 
86
 
 
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
 
91
                        )
 
92
 
 
93
                self.window.set_wm_normal_hints(
 
94
                        flags=(Xutil.PPosition | Xutil.PSize | Xutil.PMinSize),
 
95
                        min_width=50,
 
96
                        min_height=50
 
97
                        )
 
98
 
 
99
                # Map the window, making it visible
 
100
                self.window.map()
 
101
 
 
102
                # Child window
 
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,
 
107
                        X.CopyFromParent,
 
108
                        X.CopyFromParent,
 
109
 
 
110
                        # special attribute values
 
111
                        background_pixel=self.screen.white_pixel,
 
112
                        colormap=X.CopyFromParent,
 
113
                        )
 
114
                self.childWindow.map()
 
115
 
 
116
 
 
117
        # Main loop, handling events
 
118
        def loop(self):
 
119
                current = None
 
120
                while 1:
 
121
                        e = self.d.next_event()
 
122
 
 
123
                        # Window has been destroyed, quit
 
124
                        if e.type == X.DestroyNotify:
 
125
                                sys.exit(0)
 
126
 
 
127
                        # Button released, add or subtract
 
128
                        elif e.type == X.ButtonRelease:
 
129
                                if e.detail == 1:
 
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
 
134
                                                )
 
135
                                        self.d.flush()
 
136
 
 
137
                        # Somebody wants to tell us something
 
138
                        elif e.type == X.ClientMessage:
 
139
                                if e.client_type == self.WM_PROTOCOLS:
 
140
                                        fmt, data = e.data
 
141
                                        if fmt == 32 and data[0] == self.WM_DELETE_WINDOW:
 
142
                                                sys.exit(0)
 
143
 
 
144
 
 
145
if __name__ == '__main__':
 
146
        Window(display.Display()).loop()