Coverage for khufu/images/imageWell.py : 30%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# encoding: utf-8
3"""
4*Class to generate a well of images*
6:Author:
7 David Young
8"""
9from __future__ import absolute_import
10from __future__ import division
11from builtins import range
12from builtins import object
13from past.utils import old_div
14import sys
15import os
16import math
17from ..__init__ import *
18from .imagingModal import imagingModal
20class imageWell(object):
21 """
22 *Framework for a bootstrap style well containing thumbnail images that can be clicked on to reveal a modal of more imformation*
24 **Key Arguments**
26 - ``log`` -- logger
27 - ``title`` -- Title of Image Well
28 - ``description`` -- Description of the content of the image well
29 - ``imageDisplay`` -- [ rounded | circle | polaroid | False ]
31 """
33 def __init__(
34 self,
35 log,
36 title="Title of Image Well",
37 description="Description of the content of the image well",
38 imageDisplay="rounded"
39 ):
40 self.log = log
41 self.description = description
42 self.title = title
43 self.description = description
44 self.imageDisplay = imageDisplay
45 self.imageColumns = []
46 self.imageSpan = 2
47 self.rowLength = 0
49 return None
51 def close(self):
52 del self
53 return None
55 def get(self):
56 """
57 *get the image well*
59 **Return**
61 - ``imageWellRow`` -- the html text
63 """
64 self.log.debug('starting the ``get`` method')
66 ## VARIABLES ##
67 numImages = len(self.imageColumns)
68 colPerRow = int(math.floor(old_div(12, self.imageSpan)))
69 numRows = int(math.ceil(old_div(float(numImages), float(colPerRow))))
71 # header text for the image well
72 self.title = pageHeader(
73 headline=self.title,
74 tagline=self.description
75 )
77 # determine the number of rows from the number and span of the images
78 # populate each of the rows and then append to ``theseRows``
79 theseRows = ""
80 for r in range(int(numRows)):
81 startC = r * colPerRow
82 endC = startC + colPerRow
83 columns = " ".join(self.imageColumns[startC:endC])
84 thisRow = grid_row(
85 responsive=True,
86 columns=columns,
87 htmlId=False,
88 htmlClass=False,
89 onPhone=True,
90 onTablet=True,
91 onDesktop=True
92 )
93 theseRows = """%(theseRows)s %(thisRow)s""" % locals()
95 # bunch all the image rows into one parent row
96 content = grid_row(
97 responsive=True,
98 columns=theseRows,
99 htmlId=False,
100 htmlClass=False,
101 onPhone=True,
102 onTablet=True,
103 onDesktop=True
104 )
106 # add header text and image rows to a well
107 imageWell = well(
108 wellText=self.title + content,
109 wellSize='large', # [ "default" | "large" | "small" ]
110 htmlId=False,
111 htmlClass="imagewell"
112 )
114 # wrapper the well in a parent row
115 imageWellRow = grid_row(
116 responsive=True,
117 columns=imageWell,
118 htmlId=False,
119 htmlClass="imagewell-row",
120 onPhone=True,
121 onTablet=True,
122 onDesktop=True
123 )
125 self.log.debug('completed the ``get`` method')
126 return """%(imageWellRow)s""" % locals()
128 def appendImage(
129 self,
130 imagePath,
131 imageTitle,
132 modalHeaderContent="",
133 modalFooterContent="",
134 modalFooterButtons=[]):
135 """
136 *append an image to the image well*
138 **Key Arguments**
140 - ``imagePath`` -- path to the image to add to the well
141 - ``imageTitle`` -- text to tag the image with
142 - ``modalHeaderContent`` -- the heading for the modal
143 - ``modalFooterContent`` -- the footer (usually buttons)
146 **Return**
148 - None
150 """
151 self.log.debug('starting the ``appendImage`` method')
153 # PACKAGE THE IMAGE UP WITH A MODAL TO VIEW A LARGER VERSION WITH
154 # DOWNLOAD OPTION
155 thisImage = imagingModal(
156 log=self.log,
157 imagePath=imagePath,
158 display=self.imageDisplay,
159 modalHeaderContent=modalHeaderContent,
160 modalFooterContent=modalFooterContent,
161 modalFooterButtons=modalFooterButtons,
162 stampWidth=180,
163 modalImageWidth=800,)
164 thisImage = thisImage.get()
166 # COLOR THE TITLE TEXT AND MAKE IT THE CORRECT SIZE
167 imageTitle = coloredText(
168 text=imageTitle,
169 color="lightgrey",
170 size=3, # 1-10
171 )
173 # POSITION THE TITLE TEXT CORRECTLY UNDER EACH IMAGE
174 imageTitle = row_adjustable(
175 span=12 - (self.imageSpan - 1),
176 offset=self.imageSpan - 1,
177 content=imageTitle,
178 htmlId=False,
179 htmlClass=False,
180 onPhone=True,
181 onTablet=True,
182 onDesktop=True
183 )
185 # PACKAGE THE IMAGE AND TITLE, ADD TO PARENT COLUMN AND APPEND TO MASTER
186 # IMAGE LIST
187 content = "%(thisImage)s%(imageTitle)s" % locals()
188 column = grid_column(
189 span=self.imageSpan, # 1-12
190 offset=0, # 1-12
191 content=content,
192 )
193 self.imageColumns.append(column)
195 self.log.debug('completed the ``appendImage`` method')
196 return None
198 # method-tmpx