A table class to create table cells with an image. Example: cell = SimpleTableImage('images/image_1.jpg')
| 89 | |
| 90 | |
| 91 | class SimpleTableImage: |
| 92 | """A table class to create table cells with an image. |
| 93 | |
| 94 | Example: |
| 95 | cell = SimpleTableImage('images/image_1.jpg') |
| 96 | """ |
| 97 | |
| 98 | def __init__(self, image_file, width=None, height=None): |
| 99 | """Table cell constructor. |
| 100 | |
| 101 | Keyword arguments: |
| 102 | image_file -- relative filepath to image file to display. |
| 103 | width -- (optional) width of the image in pixels |
| 104 | height -- (optional) height of the image in pixels |
| 105 | """ |
| 106 | self.image_file = image_file |
| 107 | if width: |
| 108 | self.width = round(width) |
| 109 | else: |
| 110 | self.width = width |
| 111 | if height: |
| 112 | self.height = round(height) |
| 113 | else: |
| 114 | self.height = height |
| 115 | |
| 116 | def __str__(self): |
| 117 | """Return the HTML code for the table cell with the image.""" |
| 118 | safe_filename = quote(self.image_file) |
| 119 | output = '<a href="%s" target="_blank">' % (safe_filename) |
| 120 | output += '<img src="%s"' % (safe_filename) |
| 121 | if self.height: |
| 122 | output += ' height="%s"' % (self.height) |
| 123 | if self.width: |
| 124 | output += ' width="%s"' % (self.width) |
| 125 | output += "></a>" |
| 126 | |
| 127 | return output |
| 128 | |
| 129 | |
| 130 | class SimpleTableRow: |
no outgoing calls
no test coverage detected