Changeset 3641

Show
Ignore:
Timestamp:
18/10/08 19:15:39 (3 months ago)
Author:
dmeyer
Message:

create imlib2 sphinx doc

Location:
trunk
Files:
5 added
1 removed
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/doc/index.rst

    r3637 r3641  
    135135^^^^^^^^^^ 
    136136 
    137 This module has no description yet 
    138  
    139 * Detailed documentation is unavailable. 
     137kaa.imlib2 is a simple Python wrapper around imlib2 for fast image 
     138processing. 
     139 
     140* See `kaa.imlib2 documentation <imlib2/index.html>`_ for details. 
    140141* Download the latest `release of kaa.imlib2 
    141142  <http://sourceforge.net/project/showfiles.php?group_id=46652&package_id=216046>`_ 
  • trunk/imlib2/setup.py

    r3519 r3641  
    6161 
    6262setup(module      = 'imlib2', 
    63       version     = '0.2.3', 
     63      version     = '0.2.4', 
    6464      license     = 'LGPL', 
    6565      summary     = 'Python bindings for Imlib2', 
    66       epydoc      = [ 'doc/epydoc' ], 
    6766      rpminfo     = { 
    6867          'requires':       'python-kaa-base >= 0.1.2, imlib2 >= 1.2.1', 
  • trunk/imlib2/src/font.py

    r2604 r3641  
    8383        """ 
    8484        Get the font metrics for the specified text as rendered by the 
    85         current font. 
    86  
    87         Arguments: 
    88           text: the text for which to retrieve the metric. 
    89  
    90         Returns: a 4-tuple containing the width, height, horizontal advance, 
    91                  and vertical advance of the text when rendered. 
     85        current font. The given text is used to retrieve the 
     86        metric. The functions returns a 4-tuple containing the width, 
     87        height, horizontal advance, and vertical advance of the text 
     88        when rendered. 
    9289        """ 
    9390        return self._font.get_text_size(utf8(text)) 
     
    9693    def set_color(self, color): 
    9794        """ 
    98         Sets the default color for text rendered with this font. 
    99  
    100         Arguments: 
    101             color: a 3- or 4-tuple holding the red, green, blue, and alpha 
    102                    values of the color in which to render text with this 
    103                    font context.  If color is a 3-tuple, the implied alpha 
    104                    is 255. 
     95        Sets the default color for text rendered with this font. Color 
     96        is a 3- or 4-tuple holding the red, green, blue, and alpha 
     97        values of the color in which to render text with this font 
     98        context.  If color is a 3-tuple, the implied alpha is 255. 
    10599        """ 
    106100        if len(color) == 3: 
     
    123117        """ 
    124118        Set a text style. Based on the style different color parameter 
    125         need to be set. 
     119        need to be set. Depending on the style additional parameter 
     120        must be set: 
    126121 
    127         Arguments: 
    128             style:   the style to use (disable with TEXT_STYLE_PLAIN) 
    129             shadow:  shadow color for TEXT_STYLE_SHADOW, TEXT_STYLE_OUTLINE_SHADOW, 
    130                      TEXT_STYLE_FAR_SHADOW, TEXT_STYLE_OUTLINE_SOFT_SHADOW, 
    131                      TEXT_STYLE_SOFT_SHADOW and TEXT_STYLE_FAR_SOFT_SHADOW 
    132             outline: outline color for TEXT_STYLE_OUTLINE, TEXT_STYLE_SOFT_OUTLINE, 
    133                      TEXT_STYLE_OUTLINE_SHADOW and TEXT_STYLE_OUTLINE_SOFT_SHADOW 
    134             glow:    glow color 1 for TEXT_STYLE_GLOW 
    135             glow2:   glow color 2 for TEXT_STYLE_GLOW 
     122        * TEXT_STYLE_PLAIN 
     123        * TEXT_STYLE_SHADOW, requires shadow 
     124        * TEXT_STYLE_OUTLINE, requires outline 
     125        * TEXT_STYLE_SOFT_OUTLINE, requires outline 
     126        * TEXT_STYLE_GLOW, requires glow, glow2 
     127        * TEXT_STYLE_OUTLINE_SHADOW, requires shadow, outline 
     128        * TEXT_STYLE_FAR_SHADOW, requires shadow 
     129        * TEXT_STYLE_OUTLINE_SOFT_SHADOW, requires shadow, outline 
     130        * TEXT_STYLE_SOFT_SHADOW, requires shadow 
     131        * TEXT_STYLE_FAR_SOFT_SHADOW, requires shadow 
    136132        """ 
    137133        self.style = style 
  • trunk/imlib2/src/image.py

    r3521 r3641  
    5555class Image(object): 
    5656    """ 
    57     Imlib2 Image class.  The constructor can be called directly, or a new 
    58     Image object may be created via the new() and open() module functions. 
     57    Imlib2 Image class. The constructor can be called directly, or a 
     58    new Image object may be created via the new() and open() module 
     59    functions.  Instantiate the image from another Image instance, an 
     60    instance of the backend's image class or type, or a file name from 
     61    which to load the image. 
    5962    """ 
    6063 
     
    6265        """ 
    6366        Create a new Image object. 
    64  
    65         @param image_or_filename: Instantiate the image from another Image 
    66                instance, an instance of the backend's image 
    67                class or type, or a file name from which to load 
    68                the image. 
    6967        """ 
    7068        if type(image_or_filename) in types.StringTypes: 
     
    8684        """ 
    8785        Supports these attributes: 
    88  
    89          - B{size}: tuple containing the width and height of the image 
    90          - B{width}: width of the image 
    91          - B{height}: height of the image 
    92          - B{format}: format of the image if loaded from file (e.g. PNG, JPEG) 
    93          - B{rowstride}: number of bytes per row of pixels 
    94          - B{has_alpha}: True if the image has an alpha channel, False otherwise 
    95          - B{filename}: filename if loaded from file 
     86         - size: tuple containing the width and height of the image 
     87         - width: width of the image 
     88         - height: height of the image 
     89         - format: format of the image if loaded from file (e.g. PNG, JPEG) 
     90         - rowstride: number of bytes per row of pixels 
     91         - has_alpha: True if the image has an alpha channel, False otherwise 
     92         - filename: filename if loaded from file 
    9693        """ 
    9794        if attr in ('width', 'height', 'format', 'mode', 'filename', 'rowstride'): 
     
    121118    def get_raw_data(self, format = 'BGRA', write = False): 
    122119        """ 
    123         Returns raw image data for read only access. 
    124  
    125         @param format: pixel format of the raw data to be returned.  If 'format' is 
    126             not a supported format, ValueError is raised.  Format 
    127             can be any combination of RGB or RGBA. 
    128  
    129         @return: A buffer object representing the raw pixel data.  The buffer 
    130             will be a writable buffer if 'write' was True or if the 
    131             'format' was non-native (i.e. something other than BGRA).  If 
    132             'format' was BGRA and 'write' was True, you'll need to call 
    133             put_back_raw_data() when you're done writing to the buffer. 
     120        Returns raw image data for read only access. *format* is pixel 
     121        format of the raw data to be returned. If it is not a 
     122        supported format, ValueError is raised. Format can be any 
     123        combination of RGB or RGBA. The function returns a buffer 
     124        object representing the raw pixel data.  The buffer will be a 
     125        writable buffer if 'write' was True or if the 'format' was 
     126        non-native (i.e. something other than BGRA).  If 'format' was 
     127        BGRA and 'write' was True, you'll need to call 
     128        put_back_raw_data() when you're done writing to the buffer. 
    134129        """ 
    135130        if False in map(lambda x: x in 'RGBA', list(format)): 
     
    148143    def scale(self, (w, h), src_pos = (0, 0), src_size = (-1, -1)): 
    149144        """ 
    150         Scale the image and return a new image. 
    151  
    152         @param w,h: the width and height of the new image.  If either argument 
    153                 is -1, that dimension is calculated from the other dimension 
    154                 while retaining the original aspect ratio. 
    155  
    156         @return: a new Image instance representing the scaled image. 
     145        Scale the image and return a new image. If either width or 
     146        height is -1, that dimension is calculated from the other 
     147        dimension while retaining the original aspect ratio. 
    157148        """ 
    158149        src_w, src_h = src_size 
     
    176167    def crop(self, (x, y), (w, h)): 
    177168        """ 
    178         Crop the image and return a new image. 
    179  
    180         Arguments: 
    181           x, y, w, h: represents the left, top, width, height region in 
    182                       the image. 
    183  
    184         Returns: a new Image instance representing the cropped image. 
     169        return a new Image which is croped at x,y with the given size. 
    185170        """ 
    186171        return self.scale((w, h), (x, y), (w, h) ) 
     
    189174    def rotate(self, angle): 
    190175        """ 
    191         Rotate the image and return a new image. 
    192  
    193         @param angle: the angle in degrees by which to rotate the image. 
    194         @return: a new Image instance representing the rotated image. 
    195  
    196         @bug: imlib2's rotate works all wonky.  Doesn't act how I expect. 
     176        Rotate the image by the angle in degrees and return a new 
     177        image. Note: imlib2's rotate works all wonky.  Doesn't act how 
     178        expected for angles different than 90, 180 and 270. 
    197179        """ 
    198180        return Image(self._image.rotate(angle * math.pi / 180)) 
     
    201183    def orientate(self, orientation): 
    202184        """ 
    203         Performs 90 degree rotations on the image. 
    204  
    205         @param orientation: 
    206           - 0: no rotation; 
    207           - 1: rotate clockwise 90 degrees, 
    208           - 2: rotate clockwise 180 degrees; 
    209           - 3: rotates clockwise 270 degrees. 
    210         @return: None 
     185        Performs 90 degree rotations on the image. Possible values are 
     186        0 (no rotation), 1 (rotate clockwise 90 degrees), 2 (rotate 
     187        clockwise 180 degrees) and 3 (rotates clockwise 270 degrees). 
    211188        """ 
    212189        self._image.orientate(orientation) 
     
    217194        """ 
    218195        Flips the image on its horizontal axis. 
    219  
    220         @return: None. 
    221196        """ 
    222197        self._image.flip(True, False, False) 
     
    227202        """ 
    228203        Flips the image on its vertical axis. 
    229  
    230         @return: None. 
    231204        """ 
    232205        self._image.flip(False, True, False) 
     
    237210        """ 
    238211        Flips the image on along its diagonal. 
    239  
    240         @return: None. 
    241212        """ 
    242213        self._image.flip(False, False, True) 
     
    247218        """ 
    248219        Blur the image 
    249  
    250         @return: None. 
    251220        """ 
    252221        self._image.blur(radius) 
     
    257226        """ 
    258227        Sharpen the image 
    259  
    260         @return: None. 
    261228        """ 
    262229        self._image.sharpen(radius) 
     
    266233    def scale_preserve_aspect(self, (w, h)): 
    267234        """ 
    268         Scales the image while retaining the original aspect ratio and return 
    269         a new image. 
    270  
    271         Arguments: 
    272           w, h: the maximum size of the new image.  The new image will be as 
    273                 large as possible, using w, h as the upper limits, while 
    274                 retaining the original aspect ratio. 
    275  
    276         Returns: a new Image instance represented the scaled image. 
     235        Scales the image while retaining the original aspect ratio and 
     236        return a new image. The given size is the maximum size of the 
     237        new image.  The new image will be as large as possible, using 
     238        w, h as the upper limits, while retaining the original aspect 
     239        ratio. 
    277240        """ 
    278241        if 0 in (w, h): 
     
    304267        Copies a region within the image. 
    305268 
    306         Arguments: 
    307           src_pos: a tuple holding the x, y coordinates marking the top left 
    308                    of the region to be moved. 
    309              size: a tuple holding the width and height of the region to move. 
    310                    If either dimension is -1, then that dimension extends to 
    311                    the far edge of the image. 
    312           dst_pos: a tuple holding the x, y coordinates within the image 
    313                    where the region will be moved to. 
    314         @return: None 
     269        :param src_pos: a tuple holding the x, y coordinates marking the top left 
     270            of the region to be moved. 
     271        :param size: a tuple holding the width and height of the region to move. 
     272            If either dimension is -1, then that dimension extends to the far edge 
     273            of the image. 
     274        :param dst_pos: a tuple holding the x, y coordinates within the image 
     275            where the region will be moved to. 
    315276        """ 
    316277        self._image.copy_rect(src_pos, size, dst_pos) 
     
    324285        Blends one image onto another. 
    325286 
    326         @param src: the image being blended onto 'self' 
    327         @param dst_pos: a tuple holding the x, y coordinates where the source 
     287        :param src: the image being blended onto 'self' 
     288        :param dst_pos: a tuple holding the x, y coordinates where the source 
    328289            image will be blended onto the destination image. 
    329         @param src_pos: a tuple holding the x, y coordinates within the source 
     290        :param src_pos: a tuple holding the x, y coordinates within the source 
    330291            image where blending will start. 
    331         @param src_size: a tuple holding the width and height of the source 
     292        :param src_size: a tuple holding the width and height of the source 
    332293            image to be blended.  A value of -1 for either one 
    333294            indicates the full dimension of the source image. 
    334         @param alpha: the "layer" alpha that is applied to all pixels of the 
     295        :param alpha: the "layer" alpha that is applied to all pixels of the 
    335296            image.  If an individual pixel has an alpha of 128 and 
    336297            this value is 128, the resulting pixel will have an 
     
    339300            and 256 is a special value that means alpha blending is 
    340301            disabled. 
    341         @param merge_alpha: if True, the alpha channel is also blended.  If False, 
     302        :param merge_alpha: if True, the alpha channel is also blended.  If False, 
    342303            the destination image's alpha channel is untouched and 
    343304            the RGB values are compensated 
    344  
    345         @return: None. 
    346305        """ 
    347306 
     
    360319    def clear(self, (x, y) = (0, 0), (w, h) = (-1, -1)): 
    361320        """ 
    362         Clears the image at the specified rectangle, resetting all pixels in 
    363         that rectangle to fully transparent. 
    364  
    365         Arguments: 
    366           x, y: left and top coordinates of the rectangle to be cleared. 
    367                 Default is the top left corner. 
    368           w, h: width and height of the rectangle to be cleared.  If either 
    369                 value is -1 then the image is cleared to the far edge. 
    370  
    371         @return: None 
     321        Clears the image at the specified rectangle, resetting all 
     322        pixels in that rectangle to fully transparent. if either width 
     323        or height of the rectangle to be cleared is -1 then the image 
     324        is cleared to the far edge. Default values clear the whole image. 
    372325        """ 
    373326        x = max(0, min(self.width, x)) 
     
    393346                   alpha channel will be modified.  The mask is drawn to the 
    394347                   full width/height of maskimg. 
    395  
    396         @return: None 
    397348        """ 
    398349 
     
    404355        """ 
    405356        Creates a copy of the current image. 
    406  
    407         @return: a new Image instance with a copy of the current image. 
    408357        """ 
    409358        return Image(self._image.clone()) 
     
    412361    def set_font(self, font_or_font_name): 
    413362        """ 
    414         Sets the font context to font_or_font_name.  Subsequent calls to 
    415         draw_text() will be rendered using this font. 
    416  
    417         Arguments: 
    418           font_or_fontname: either a Font object, or a string containing the 
    419                             font's name and size.  This string is in the 
    420                             form "Fontname/Size" such as "Arial/16" 
    421  
    422  
    423         Returns: a Font instance represent the specified font.  If 
    424                  'font_or_fontname' is already a Font instance, it is simply 
    425                  returned back to the caller. 
     363        Sets the font context to font_or_font_name.  Subsequent calls 
     364        to draw_text() will be rendered using this font. 
     365        font_or_fontname is either a Font object, or a string 
     366        containing the font's name and size.  This string is in the 
     367        form 'Fontname/Size' such as 'Arial/16' 
     368 
     369        The function returns a Font instance represent the specified 
     370        font.  If 'font_or_fontname' is already a Font instance, it is 
     371        simply returned back to the caller. 
    426372        """ 
    427373        if type(font_or_font_name) in types.StringTypes: 
     
    434380    def get_font(self): 
    435381        """ 
    436         Gets the current Font context. 
    437  
    438         @return: A Font instance as created by set_font() or None if no font 
    439                  context is defined. 
     382        Gets the current Font context. Either the Font instance as 
     383        created by set_font() or None if no font context is defined. 
    440384        """ 
    441385        return self.font 
     
    448392        Draws text on the image. 
    449393 
    450         @param x, y: the left/top coordinates within the current image 
     394        :param x, y: the left/top coordinates within the current image 
    451395            where the text will be rendered. 
    452         @param text: a string holding the text to be rendered. 
    453         @param color: a 3- or 4-tuple holding the red, green, blue, and 
     396        :param text: a string holding the text to be rendered. 
     397        :param color: a 3- or 4-tuple holding the red, green, blue, and 
    454398            alpha values of the color in which to render the 
    455399            font.  If color is a 3-tuple, the implied alpha 
    456400            is 255.  If color is None, the color of the font 
    457401            context, as specified by set_font(), is used. 
    458         @param font_or_fontname: either a Font object, or a string containing the 
     402        :param font_or_fontname: either a Font object, or a string containing the 
    459403            font's name and size.  This string is in the 
    460404            form "Fontname/Size" such as "Arial/16".  If this 
    461405            parameter is none, the font context is used, as 
    462406            specified by set_font(). 
    463         @param style: The style to use. Id style is None, the style from 
     407        :param style: The style to use. Id style is None, the style from 
    464408            the font object will be used. 
    465409 
    466         @return: a 4-tuple representing the width, height, horizontal advance, 
     410        :return: a 4-tuple representing the width, height, horizontal advance, 
    467411            and vertical advance of the rendered text. 
    468412        """ 
     
    513457        Draws a rectangle on the image. 
    514458 
    515         @param x, y: the top left corner of the rectangle. 
    516         @param w, h: the width and height of the rectangle. 
    517         @param color: a 3- or 4-tuple holding the red, green, blue, and alpha 
     459        :param x, y: the top left corner of the rectangle. 
     460        :param w, h: the width and height of the rectangle. 
     461        :param color: a 3- or 4-tuple holding the red, green, blue, and alpha 
    518462            values of the color in which to draw the rectangle.  If 
    519463            color is a 3-tuple, the implied alpha is 255. 
    520         @param fill: whether the rectangle should be filled or not.  The default 
     464        :param fill: whether the rectangle should be filled or not.  The default 
    521465            is true. 
    522  
    523         @return: None 
    524466        """ 
    525467        if len(color) == 3: 
     
    532474        Draws an ellipse on the image. 
    533475 
    534         @param xc, yc: the x, y coordinates of the center of the ellipse. 
    535         @param a, b: the horizontal and veritcal amplitude of the ellipse. 
    536         @param color: a 3- or 4-tuple holding the red, green, blue, and alpha 
     476        :param xc, yc: the x, y coordinates of the center of the ellipse. 
     477        :param a, b: the horizontal and veritcal amplitude of the ellipse. 
     478        :param color: a 3- or 4-tuple holding the red, green, blue, and alpha 
    537479            values of the color in which to draw the ellipse.  If 
    538480            color is a 3-tuple, the implied alpha is 255. 
    539         @param fill: whether the ellipse should be filled or not.  The default 
     481        :param fill: whether the ellipse should be filled or not.  The default 
    540482            is true. 
    541  
    542         @return: None 
    543483        """ 
    544484        if len(color) == 3: 
     
    550490    def get_pixel(self, (x, y)): 
    551491        """ 
    552         Get the color for the specified pixel. 
    553  
    554         @param x, y: Coordinates of the pixel for which to return the color. 
    555         @return: a 4-tuple representing the color of the pixel.  The tuple is 
    556             in RGBA format, or (red, green, blue, alpha). 
     492        Get the color for the specified pixel as a 4-tuple 
     493        representing the color of the pixel.  The tuple is in RGBA 
     494        format, or (red, green, blue, alpha). 
    557495        """ 
    558496        return self._image.get_pixel((x,y)) 
     
    561499    def set_alpha(self, has_alpha): 
    562500        """ 
    563         Enable / disable the alpha layer. 
    564  
    565         @param has_alpha: if True, the alpha layer will be enabled, if 
    566             False disabled 
    567         @return: None 
     501        Enable / disable the alpha layer. If has_alpha is True, the 
     502        alpha layer will be enabled, if False disabled 
    568503        """ 
    569504        if has_alpha: 
     
    576511    def save(self, filename, format = None): 
    577512        """ 
    578         Saves the image to a file. 
    579  
    580         @param format: the format of the written file (jpg, png, etc.).  If format 
    581             is None, the format is gotten from the filename extension. 
    582  
    583         @return: None. 
     513        Saves the image to a file. The format for the written file 
     514        (jpg, png, etc.) is gotten from the filename extension if not 
     515        format is provided. 
    584516        """ 
    585517        if not format: 
     
    590522    def as_gdk_pixbuf(self): 
    591523        """ 
    592         Convert the image into a gdk.Pixbuf object 
    593  
    594         @return: the current image as a gdk.Pixbuf 
    595         @raise ImportError: if pygtk is unavailable. 
     524        Convert the image into a gdk.Pixbuf object. This function will 
     525        either return a gdk.Pixbuf object or raises an ImportError if 
     526        pygtk is unavailable. 
    596527        """ 
    597528        import gtk