home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gnome-python.idb / usr / freeware / lib / python1.5 / site-packages / GdkImlib.py.z / GdkImlib.py
Encoding:
Python Source  |  1999-07-16  |  5.9 KB  |  155 lines

  1. #
  2. # GdkImlib: An interface to gdk_imlib to go with gtk.py.  It wraps the
  3. #           native module _gdkimlib.  It is sugested that you import it as
  4. #           "import GdkImlib".
  5. #
  6. # Author: James Henstridge <james@daa.com.au>
  7. #
  8. # To use GdkImlib, create an instance of the GdkImlib.Image class.  The
  9. # constructor takes a filename as its one argument.  Then call the render
  10. # method (optionally with width and height arguments), and finally call
  11. # the make_pixamp method to get a GTK pixmap widget with the image loaded.
  12. #
  13. # For extra information, read the rest of this file, and Imlib's documentation.
  14. #
  15.  
  16. import _gdkimlib
  17.  
  18. from gtk import GtkPixmap
  19.  
  20. #some constants ...
  21. RT_PLAIN_PALETTE       = 0
  22. RT_PLAIN_PALETTE_FAST  = 1
  23. RT_DITHER_PALETTE      = 2
  24. RT_DITHER_PALETTE_FAST = 3
  25. RT_PLAIN_TRUECOL       = 4
  26. RT_DITHER_TRUECOL      = 5
  27.  
  28. _gdkimlib.gdk_imlib_init()
  29.  
  30. class Image:
  31.     def __init__(self, filename="", _obj=None):
  32.         if _obj: self._im = _obj; return
  33.         self._im = _gdkimlib.gdk_imlib_load_image(filename)
  34.     def __getattr__(self, attr):
  35.         attrs = {
  36.             'rgb_width':  _gdkimlib.gdk_imlib_get_rgb_width,
  37.             'rgb_height': _gdkimlib.gdk_imlib_get_rgb_height,
  38.             'filename':   _gdkimlib.gdk_imlib_get_filename
  39.         }
  40.         if attrs.has_key(attr):
  41.             return attrs[attr](self._im)
  42.         raise AttributeError, attr
  43.     def render(self, width=None, height=None):
  44.         return _gdkimlib.gdk_imlib_render(self._im,
  45.                           width or self.rgb_width,
  46.                           height or self.rgb_height)
  47.     def get_image_border(self):
  48.         return _gdkimlib.gdk_imlib_get_image_border(self._im)
  49.     def set_image_border(self, left=0, right=0, top=0, bottom=0):
  50.         _gdkimlib.gdk_imlib_set_image_border(self._im, (left, right,
  51.                                 top, bottom))
  52.     def get_image_shape(self):
  53.         return _gdkimlib.gdk_imlib_get_image_shape(self._im)
  54.     def set_image_shape(self, red, green, blue):
  55.         _gdkimlib.gdk_imlib_set_image_shape(self._im,(red,green,blue))
  56.     def save_image_to_eim(self, file):
  57.         _gdkimlib.gdk_imlib_save_image_to_eim(self._im, file)
  58.     def add_image_to_eim(self, file):
  59.         _gdkimlib.gdk_imlib_add_image_to_eim(self._im, file)
  60.     def save_image_to_ppm(self, file):
  61.         _gdkimlib.gdk_imlib_save_image_to_ppm(self._im, file)
  62.     def set_image_modifier(self, gamma, brightness, contrast):
  63.         _gdkimlib.gdk_imlib_set_image_modifier(self._im,
  64.                            (gamma, brightness, contrast))
  65.     def set_image_red_modifier(self, gamma, brightness, contrast):
  66.         _gdkimlib.gdk_imlib_set_image_red_modifier(self._im,
  67.                            (gamma, brightness, contrast))
  68.     def set_image_blue_modifier(self, gamma, brightness, contrast):
  69.         _gdkimlib.gdk_imlib_set_image_red_modifier(self._im,
  70.                            (gamma, brightness, contrast))
  71.     def set_image_green_modifier(self, gamma, brightness, contrast):
  72.         _gdkimlib.gdk_imlib_set_image_red_modifier(self._im,
  73.                            (gamma, brightness, contrast))
  74.     def get_image_modifier(self):
  75.         return _gdkimlib.gdk_imlib_get_image_modifier(self._im)
  76.     def get_image_red_modifier(self):
  77.         return _gdkimlib.gdk_imlib_get_image_red_modifier(self._im)
  78.     def get_image_green_modifier(self):
  79.         return _gdkimlib.gdk_imlib_get_image_green_modifier(self._im)
  80.     def get_image_blue_modifier(self):
  81.         return _gdkimlib.gdk_imlib_get_image_blue_modifier(self._im)
  82.     def set_image_red_curve(self, curve):
  83.         _gdkimlib.gdk_imlib_set_image_red_curve(self._im, curve)
  84.     def set_image_green_curve(self, curve):
  85.         _gdkimlib.gdk_imlib_set_image_green_curve(self._im, curve)
  86.     def set_image_blue_curve(self, curve):
  87.         _gdkimlib.gdk_imlib_set_image_blue_curve(self._im, curve)
  88.     def get_image_red_curve(self):
  89.         return _gdkimlib.gdk_imlib_get_image_red_curve(self._im)
  90.     def get_image_green_curve(self):
  91.         return _gdkimlib.gdk_imlib_get_image_green_curve(self._im)
  92.     def get_image_blue_curve(self):
  93.         return _gdkimlib.gdk_imlib_get_image_blue_curve(self._im)
  94.     def apply_modifiers_to_rgb(self):
  95.         _gdkimlib.gdk_imlib_apply_modifiers_to_rgb(self._im)
  96.     def changed_image(self):
  97.         _gdkimlib.gdk_imlib_changed_image(self._im)
  98.     def flip_image_horizontal(self):
  99.         _gdkimlib.gdk_imlib_flip_image_horizontal(self._im)
  100.     def flip_image_vertical(self):
  101.         _gdkimlib.gdk_imlib_flip_image_vertical(self._im)
  102.     def rotate_image(self, d):
  103.         _gdkimlib.gdk_imlib_rotate_image(self._im, d)
  104.     def clone_image(self):
  105.         return Image(_obj=_gdkimlib.gdk_imlib_clone_image(self._im))
  106.     def clone_scaled_image(self, width, height):
  107.         return Image(_obj=_gdkimlib.gdk_imlib_clone_scaled_image(
  108.             self._im, width, height))
  109.     def crop_image(self, x, y, w, h):
  110.         _gdkimlib.gdk_imlib_crop_image(self._im, x, y, w, h)
  111.     def save_image(self, file):
  112.         return _gdkimlib.gdk_imlib_save_image(self._im, file)
  113.     def crop_and_clone_image(self, x, y, w, h):
  114.         return Image(_obj=_gdkimlib.gdk_imlib_crop_and_clone_image(
  115.             self._im, x, y, w, h))
  116.     def make_pixmap(self):
  117.         return GtkPixmap(_obj=
  118.                  _gdkimlib.gdk_imlib_make_pixmap(self._im))
  119.     def get_pixmap(self):
  120.         return _gdkimlib.gdk_imlib_get_pixmap(self._im)
  121.  
  122. def create_image_from_data(data, alpha, width, height):
  123.     # alpha can be None
  124.     return Image(_obj=_gdkimlib.gdk_imlib_create_image_from_data(
  125.         data, alpha, width, height))
  126.  
  127. def create_image_from_drawable(drawable, mask, x, y, width, height):
  128.     return Image(_obj=_gdkimlib.gdk_imlib_create_image_from_drawable(
  129.         drawable, mask, x, y, width, height))
  130.  
  131. def get_render_type():
  132.     return _gdkimlib.gdk_imlib_get_render_type()
  133. def set_render_type(rend_type):
  134.     _gdkimlib.gdk_imlib_set_render_type(rend_type)
  135. def load_colors(file):
  136.     return _gdkimlib.gdk_imlib_load_colors(file)
  137. def free_colors():
  138.     _gdkimlib.gdk_imlib_free_colors()
  139. def get_fallback():
  140.     return _gdkimlib.gdk_imlib_get_fallback()
  141. def set_fallback(fallback):
  142.     _gdkimlib.gdk_imlib_set_fallback(fallback)
  143. def get_sysconfig():
  144.     return _gdkimlib.gdk_imlib_get_sysconfig()
  145. def best_color_match(r, g, b):
  146.     return _gdkimlib.gdk_imlib_best_color_match(r, g, b)
  147.  
  148. # these are to help with apps that use imlib a lot.  They push/pop
  149. # imlib's visual/colormap combination ...
  150. def push_visual():
  151.     _gdkimlib.gdk_imlib_push_visual()
  152. def pop_visual():
  153.     _gdkimlib.gdk_imlib_pop_visual()
  154.  
  155.