view/pixman.py

Go to the documentation of this file.
00001 # vim: expandtab
00002 # Copyright (c) 2007 Cristian L. Vlasceanu
00003 #
00004 # Permission is hereby granted, free of charge, to any person
00005 # obtaining a copy of this software and associated documentation
00006 # files (the "Software"), to deal in the Software without
00007 # restriction, including without limitation the rights to use,
00008 # copy, modify, merge, publish, distribute, sublicense, and/or
00009 # sell copies of the Software, and to permit persons to whom
00010 # the Software is furnished to do so, subject to the following
00011 # conditions:
00012 # 
00013 # The above copyright notice and this permission notice shall be
00014 # included in all copies or substantial portions of the Software.
00015 # 
00016 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00017 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00018 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00019 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00023 # OR OTHER DEALINGS IN THE SOFTWARE.
00024 # 
00025 # NOTE: The above applies solely to Python source code provided 
00026 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00027 #
00028 import gtk
00029 import os
00030 import pixmaps
00031 
00032 
00033 class PixMan(object):
00034         """
00035         Pixbuf Manager
00036         """
00037         def __init__(self, w):
00038                 self.__pixbufs = { }
00039                 self.__w = w
00040                 self.create_from_data("arrow", pixmaps.right_arrow)
00041                 self.create_from_file("brkpnt", "stop.png")
00042 
00043 
00044         def create_from_data(self, name, pixdata, width = 20, height = 20):
00045                 try:
00046                         pixbuf = gtk.gdk.pixbuf_new_from_xpm_data(pixdata)
00047                 except:
00048                         colormap = self.__w.get_colormap()
00049                         pix, mask = gtk.gdk.pixmap_colormap_create_from_xpm_d(
00050                                 None,
00051                                 colormap, 
00052                                 None, 
00053                                 pixdata)
00054                         pixbuf = gtk.gdk.Pixbuf(
00055                                 gtk.gdk.COLORSPACE_RGB,
00056                                 True,
00057                                 8,
00058                                 20,
00059                                 20)
00060                         pixbuf.get_from_drawable(mask, colormap, 0, 0, 0, 0, -1, -1)
00061                 self.__pixbufs[name] = pixbuf
00062 
00063         
00064         def create_from_file(self, name, filename):
00065                 topPath = os.environ["ZTOP"]
00066                 try:
00067                         #from Open Clipart project:
00068                         filename = topPath + "/view/" + filename
00069                         pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
00070                         self.__pixbufs[name] = pixbuf
00071                 except:
00072                         pass
00073 
00074 
00075         def get_pixbuf(self, name):
00076                 #return self.__pixbufs[name]
00077                 try:
00078                         return self.__pixbufs[name]
00079                 except KeyError:
00080                         return None
00081                         
00082         
00083         def compose(self, first, second):
00084                 "Compose two pixbufs"
00085                 pixbuf = first.copy()
00086                 second.composite(
00087                         pixbuf, 0, 0, 
00088                         first.props.width, first.props.height,
00089                         0, 0, 
00090                         1.0, 1.0, #scale
00091                         gtk.gdk.INTERP_HYPER, 
00092                         127)
00093                 return pixbuf
00094