~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to .pc/python3.patch/Xlib/xobject/colormap.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
# Xlib.xobject.colormap -- colormap object
 
2
#
 
3
#    Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
 
4
#
 
5
#    This program is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    This program 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
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this program; if not, write to the Free Software
 
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
from Xlib import error
 
20
from Xlib.protocol import request
 
21
 
 
22
import resource
 
23
 
 
24
import re
 
25
import string
 
26
 
 
27
rgb_res = [
 
28
    re.compile(r'\Argb:([0-9a-fA-F]{1,4})/([0-9a-fA-F]{1,4})/([0-9a-fA-F]{1,4})\Z'),
 
29
    re.compile(r'\A#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])\Z'),
 
30
    re.compile(r'\A#([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])\Z'),
 
31
    re.compile(r'\A#([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])\Z'),
 
32
    re.compile(r'\A#([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])\Z'),
 
33
    ]
 
34
 
 
35
class Colormap(resource.Resource):
 
36
    __colormap__ = resource.Resource.__resource__
 
37
 
 
38
    def free(self, onerror = None):
 
39
        request.FreeColormap(display = self.display,
 
40
                             onerror = onerror,
 
41
                             cmap = self.id)
 
42
 
 
43
        self.display.free_resource_id(self.id)
 
44
 
 
45
    def copy_colormap_and_free(self, scr_cmap):
 
46
        mid = self.display.allocate_resource_id()
 
47
        request.CopyColormapAndFree(display = self.display,
 
48
                                    mid = mid,
 
49
                                    src_cmap = src_cmap)
 
50
 
 
51
        cls = self.display.get_resource_class('colormap', Colormap)
 
52
        return cls(self.display, mid, owner = 1)
 
53
 
 
54
    def install_colormap(self, onerror = None):
 
55
        request.InstallColormap(display = self.display,
 
56
                                onerror = onerror,
 
57
                                cmap = self.id)
 
58
 
 
59
    def uninstall_colormap(self, onerror = None):
 
60
        request.UninstallColormap(display = self.display,
 
61
                                  onerror = onerror,
 
62
                                  cmap = self.id)
 
63
 
 
64
    def alloc_color(self, red, green, blue):
 
65
        return request.AllocColor(display = self.display,
 
66
                                  cmap = self.id,
 
67
                                  red = red,
 
68
                                  green = green,
 
69
                                  blue = blue)
 
70
 
 
71
    def alloc_named_color(self, name):
 
72
        for r in rgb_res:
 
73
            m = r.match(name)
 
74
            if m:
 
75
                rs = m.group(1)
 
76
                r = string.atoi(rs + '0' * (4 - len(rs)), 16)
 
77
 
 
78
                gs = m.group(2)
 
79
                g = string.atoi(gs + '0' * (4 - len(gs)), 16)
 
80
 
 
81
                bs = m.group(3)
 
82
                b = string.atoi(bs + '0' * (4 - len(bs)), 16)
 
83
 
 
84
                return self.alloc_color(r, g, b)
 
85
 
 
86
        try:
 
87
            return request.AllocNamedColor(display = self.display,
 
88
                                           cmap = self.id,
 
89
                                           name = name)
 
90
        except error.BadName:
 
91
            return None
 
92
 
 
93
    def alloc_color_cells(self, contiguous, colors, planes):
 
94
        return request.AllocColorCells(display = self.display,
 
95
                                       contiguous = contiguous,
 
96
                                       cmap = self.id,
 
97
                                       colors = colors,
 
98
                                       planes = planes)
 
99
 
 
100
    def alloc_color_planes(self, contiguous, colors, red, green, blue):
 
101
        return request.AllocColorPlanes(display = self.display,
 
102
                                        contiguous = contiguous,
 
103
                                        cmap = self.id,
 
104
                                        colors = colors,
 
105
                                        red = red,
 
106
                                        green = green,
 
107
                                        blue = blue)
 
108
 
 
109
    def free_colors(self, pixels, plane_mask, onerror = None):
 
110
        request.FreeColors(display = self.display,
 
111
                           onerror = onerror,
 
112
                           cmap = self.id,
 
113
                           plane_mask = plane_mask,
 
114
                           pixels = pixels)
 
115
 
 
116
    def store_colors(self, items, onerror = None):
 
117
        request.StoreColors(display = self.display,
 
118
                            onerror = onerror,
 
119
                            cmap = self.id,
 
120
                            items = items)
 
121
 
 
122
    def store_named_color(self, name, pixel, flags, onerror = None):
 
123
        request.StoreNamedColor(display = self.display,
 
124
                                onerror = onerror,
 
125
                                flags = flags,
 
126
                                cmap = self.id,
 
127
                                pixel = pixel,
 
128
                                name = name)
 
129
 
 
130
    def query_colors(self, pixels):
 
131
        r = request.QueryColors(display = self.display,
 
132
                                cmap = self.id,
 
133
                                pixels = pixels)
 
134
        return r.colors
 
135
 
 
136
    def lookup_color(self, name):
 
137
        return request.LookupColor(display = self.display,
 
138
                                   cmap = self.id,
 
139
                                   name = name)