Changeset 4359

Show
Ignore:
Timestamp:
09/30/08 03:44:37 (3 months ago)
Author:
Blackhex
Message:

ScreenshotsPlugin:

  • [[Screenshot()]] macro now keeps aspect when one dimension is not specified.
  • Display of matrix view screenshots with preserved aspect via CSS.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • screenshotsplugin/0.11/tracscreenshots/core.py

    r4344 r4359  
    11# -*- coding: utf8 -*- 
    22 
    3 import sets, re, os, os.path, shutil, mimetypes, unicodedata, Image 
     3import sets, re, os, os.path, shutil, mimetypes, unicodedata, Image, ImageOps 
    44from datetime import * 
    55 
     
    607607    def _create_image(self, orig_name, path, name, ext, width, height): 
    608608        image = Image.open(orig_name) 
    609         image = image.resize((width, height), Image.BICUBIC
     609        image = image.resize((width, height), Image.ANTIALIAS
    610610        image.save(os.path.join(path, '%s-%sx%s%s' % (name, width, height, 
    611611          ext))) 
  • screenshotsplugin/0.11/tracscreenshots/htdocs/css/matrix-view.css

    r4355 r4359  
    1515} 
    1616 
     17div.screenshots div.tr, div.screenshots div.td 
     18{ 
     19  margin: 0em; 
     20  padding: 0em; 
     21} 
     22 
     23 
     24div.screenshots div.images div.image 
     25{ 
     26  border: 2px solid #b00; 
     27  margin: 0em; 
     28  padding: 0em; 
     29  text-align: center; 
     30} 
     31 
     32div.screenshots div.images div.image a 
     33{ 
     34  display: block; 
     35  padding: 0em; 
     36  margin: 0em; 
     37  border: none; 
     38  vertical-align: middle; 
     39} 
     40 
    1741div.screenshots div.images div.image img 
    1842{ 
    19   border: 2px solid #b00
     43  vertical-align: middle
    2044} 
    2145 
     
    3155} 
    3256 
    33 /* Controls style. */ 
     57/* Global controls style. */ 
    3458div.screenshots div.controls 
    3559{ 
     
    3761} 
    3862 
    39 div.screenshots div.controls td a 
     63div.screenshots div.images div.controls 
    4064{ 
    41   margin: 0em 0.5em; 
     65  margin-bottom: 0.5em; 
    4266} 
    4367 
  • screenshotsplugin/0.11/tracscreenshots/htdocs/css/screenshots.css

    r4344 r4359  
    6161{ 
    6262  display: block; 
     63  border-color: #b00; 
     64  border-style: solid; 
    6365} 
    6466 
     
    6668{ 
    6769  display: block; 
    68   border-color: #b00; 
    69   border-style: solid; 
     70  margin: auto; 
    7071} 
    7172 
     
    7980{ 
    8081  display: block; 
    81   margin: 0em
     82  margin: 0em 2em
    8283  padding: 0em; 
    8384} 
     
    8687{ 
    8788  display: block; 
    88   margin: 0em; 
    89   margin-top: 0.5em; 
     89  margin: 0.5em 0em; 
    9090  padding: 0em; 
    9191} 
    9292 
    93 span.thumbnail-left a, span.thumbnail-right a, 
     93span.thumbnail-left a, span.thumbnail-right a 
    9494{ 
    9595  display: block; 
     96  margin: 0em; 
     97  padding: 0em; 
     98  border-color: #b00; 
     99  border-style: solid; 
    96100} 
    97101 
     
    99103{ 
    100104  display: block; 
    101   border-color: #b00; 
    102   border-style: solid; 
     105  margin: auto; 
    103106} 
    104107 
     
    111114span.thumbnail, span.thumbnail-left, span.thumbnail-right 
    112115{ 
    113   margin: 16px; 
    114   margin-top: 0em; 
    115   padding: 0em; 
    116116  font-size: 75%; 
    117117  text-align: center; 
  • screenshotsplugin/0.11/tracscreenshots/matrix_view.py

    r4355 r4359  
    4242        page = int(req.args.get('page') or -1) 
    4343 
     44        self.log.debug('index: %s' % (index)) 
     45        self.log.debug('page: %s' % (page)) 
     46 
    4447        # Count index or page depending on user input. 
    4548        count = len(data['screenshots']) 
     
    4750        if index != -1: 
    4851            page = (index / count_on_page) + 1 
     52        elif page != -1: 
     53            index = (page - 1) * count_on_page 
    4954        else: 
    50             index = (page - 1) * count_on_page 
     55            index = 0 
     56            page = 1 
    5157 
    5258        self.log.debug('index: %s' % (index)) 
     
    9399        for I in xrange(count): 
    94100            # Add screenshot. 
    95             if (index + I) < len(screenshots): 
     101            if ((index + I) < len(screenshots)) and ((index + I) > 0): 
    96102                row.append(screenshots[index + I]) 
    97103            else: 
  • screenshotsplugin/0.11/tracscreenshots/templates/screenshots-matrix-view.html

    r4355 r4359  
    99              <td> 
    1010                <py:choose> 
    11                   <div py:when="image.id != -1" class="image"> 
    12                     <a href="${href.screenshots(image.id)}" title="${image.id}"> 
    13                       <img src="${href.screenshots(image.id)}?width=${screenshots.width};height=${screenshots.height};format=raw" 
    14                         alt="${image.description}" width="${screenshots.width}" height="${screenshots.height}"/> 
     11                  <div py:when="image.id != -1" class="image" style="width: ${screenshots.width}px; height: ${screenshots.height}px"> 
     12                    <?python 
     13                      frame_aspect = float(screenshots['width']) / float(screenshots['height']) 
     14                      image_aspect = float(image['width']) / float(image['height']) 
     15                      if frame_aspect < image_aspect: 
     16                          image_width = screenshots['width'] 
     17                          image_height = int(screenshots['width'] / image_aspect + 0.5) 
     18                      else: 
     19                          image_width = int(screenshots['height'] * image_aspect + 0.5) 
     20                          image_height = screenshots['height'] 
     21                    ?> 
     22                    <a href="${href.screenshots(image.id)}" title="${image.id}" style="line-height: ${screenshots.height - 4}px"> 
     23                      <img src="${href.screenshots(image.id)}?width=${image_width};height=${image_height};format=raw" 
     24                        alt="${image.description}"/> 
    1525                    </a> 
    1626                  </div> 
  • screenshotsplugin/0.11/tracscreenshots/wiki.py

    r4344 r4359  
    151151                              'border' : '1', 
    152152                              'format' : 'raw', 
    153                               'width' : screenshot['width'], 
    154                               'height' : screenshot['height'], 
    155153                              'alt' : screenshot['description'], 
    156154                              'description' : self.default_description} 
     
    162160                    if match: 
    163161                        attributes[str(match.group(1))] = match.group(2) 
     162 
     163                # Zero width or height means keep original. 
     164                if attributes.has_key('width'): 
     165                    if attributes['width'] == 0: 
     166                        attributes['width'] = screenshot['width'] 
     167                if attributes.has_key('height'): 
     168                    if attributes['height'] == 0: 
     169                        attributes['height'] = screenshot['height'] 
     170 
     171                # If one dimension is missing compute second to keep aspect. 
     172                if not attributes.has_key('width') and \ 
     173                  attributes.has_key('height'): 
     174                    attributes['width'] = int(int(attributes['height']) * ( 
     175                      float(screenshot['width']) / float(screenshot['height'])) 
     176                      + 0.5) 
     177                if not attributes.has_key('height') and \ 
     178                  attributes.has_key('width'): 
     179                    attributes['height'] = int(int(attributes['width']) * ( 
     180                      float(screenshot['height']) / float(screenshot['width'])) 
     181                      + 0.5) 
     182 
     183                # If both dimensions are missing keep original. 
     184                if not attributes.has_key('width') and not \ 
     185                  attributes.has_key('height'): 
     186                    attributes['width'] = screenshot['width'] 
     187                    attributes['height'] = screenshot['height'] 
     188 
    164189                self.log.debug('attributes: %s' % (attributes,)) 
    165190 
     
    169194 
    170195                # Make copy of attributes for image tag. 
    171                 img_attributes = {'style' : 'border-width: %spx;' % ( 
    172                                     attributes['border'],)} 
     196                img_attributes = {} 
    173197                for attribute in attributes.keys(): 
    174198                    if attribute not in ('align', 'border', 'description', 
    175                       'format'): 
     199                      'format', 'width', 'height'): 
    176200                        img_attributes[attribute] = attributes[attribute] 
    177201 
     
    181205                # Build screenshot image and/or screenshot link. 
    182206                image = html.img(src = formatter.req.href.screenshots( 
    183                   screenshot['id'], width = attributes['width'], height = 
    184                   attributes['height'], format = 'raw'), **img_attributes) 
     207                  screenshot['id'], format = 'raw', width = attributes['width'], 
     208                  height = attributes['height']), **img_attributes) 
    185209                link = html.a(image, href = formatter.req.href.screenshots( 
    186210                  screenshot['id'], format = attributes['format']), title = 
    187                   screenshot['description']) 
     211                  screenshot['description'], style = 'border-width: %spx;' % ( 
     212                  attributes['border'],)) 
    188213                width_and_border = int(attributes['width']) + 2 * \ 
    189214                  int(attributes['border'])