1
# Xlib.xobject.colormap -- colormap object
3
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
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.
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.
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
19
from Xlib import error
20
from Xlib.protocol import request
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'),
35
class Colormap(resource.Resource):
36
__colormap__ = resource.Resource.__resource__
38
def free(self, onerror = None):
39
request.FreeColormap(display = self.display,
43
self.display.free_resource_id(self.id)
45
def copy_colormap_and_free(self, scr_cmap):
46
mid = self.display.allocate_resource_id()
47
request.CopyColormapAndFree(display = self.display,
51
cls = self.display.get_resource_class('colormap', Colormap)
52
return cls(self.display, mid, owner = 1)
54
def install_colormap(self, onerror = None):
55
request.InstallColormap(display = self.display,
59
def uninstall_colormap(self, onerror = None):
60
request.UninstallColormap(display = self.display,
64
def alloc_color(self, red, green, blue):
65
return request.AllocColor(display = self.display,
71
def alloc_named_color(self, name):
76
r = string.atoi(rs + '0' * (4 - len(rs)), 16)
79
g = string.atoi(gs + '0' * (4 - len(gs)), 16)
82
b = string.atoi(bs + '0' * (4 - len(bs)), 16)
84
return self.alloc_color(r, g, b)
87
return request.AllocNamedColor(display = self.display,
93
def alloc_color_cells(self, contiguous, colors, planes):
94
return request.AllocColorCells(display = self.display,
95
contiguous = contiguous,
100
def alloc_color_planes(self, contiguous, colors, red, green, blue):
101
return request.AllocColorPlanes(display = self.display,
102
contiguous = contiguous,
109
def free_colors(self, pixels, plane_mask, onerror = None):
110
request.FreeColors(display = self.display,
113
plane_mask = plane_mask,
116
def store_colors(self, items, onerror = None):
117
request.StoreColors(display = self.display,
122
def store_named_color(self, name, pixel, flags, onerror = None):
123
request.StoreNamedColor(display = self.display,
130
def query_colors(self, pixels):
131
r = request.QueryColors(display = self.display,
136
def lookup_color(self, name):
137
return request.LookupColor(display = self.display,