Hide keyboard shortcuts

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*An image and modal -- click on the image to present the modal of the larger image with download options* 

5 

6:Author: 

7 David Young 

8""" 

9from __future__ import absolute_import 

10from builtins import object 

11import sys 

12import os 

13import numpy as np 

14from ..__init__ import * 

15from .. import modals 

16from .image import image 

17 

18 

19class imagingModal(object): 

20 """ 

21 *An image and modal -- click on the image to present the modal of the larger image with download options* 

22 

23 **Key Arguments** 

24 

25 - ``dbConn`` -- mysql database connection 

26 - ``log`` -- logger 

27 - ``display`` -- [ rounded | circle | polaroid | False ] 

28 - ``imagePath`` -- path to the image to be displayed 

29 - ``modalHeaderContent`` -- the heading for the modal 

30 - ``modalFooterContent`` -- the footer (usually buttons) 

31 - ``stampWidth`` -- 180 

32 - ``modalImageWidth`` -- 400 

33 - ``downloadLink`` -- False 

34 

35 """ 

36 

37 def __init__( 

38 self, 

39 log, 

40 dbConn=False, 

41 imagePath=False, 

42 display=False, 

43 modalHeaderContent="", 

44 modalFooterContent="", 

45 modalFooterButtons=[], 

46 stampWidth=180, 

47 modalImageWidth=400, 

48 downloadLink=False 

49 ): 

50 self.log = log 

51 self.dbConn = dbConn 

52 self.imagePath = imagePath 

53 self.display = display 

54 self.modalHeaderContent = modalHeaderContent 

55 self.modalFooterContent = modalFooterContent 

56 self.randomNum = np.random.randint(300000000) 

57 self.stampWidth = stampWidth 

58 self.modalImageWidth = modalImageWidth 

59 self.downloadLink = downloadLink 

60 self.modalFooterButtons = modalFooterButtons 

61 # x-self-arg-tmpx 

62 return None 

63 

64 def close(self): 

65 del self 

66 return None 

67 

68 def get(self): 

69 """ 

70 *get the object* 

71 

72 **Return** 

73 

74 - ``imageModal`` 

75 

76 """ 

77 self.log.debug('starting the ``get`` method') 

78 

79 # CREATE IMAGING MODAL AND ASSOCIATED IMAGE AND RETURN THEM 

80 thisImage = self._create_image(width=self.stampWidth) 

81 thisModal = self._create_modal() 

82 

83 self.log.debug('completed the ``get arse`` method') 

84 return thisImage + thisModal 

85 

86 def _create_image( 

87 self, 

88 width=False): 

89 """ 

90 *create the html for the image 

91 

92 - ``width`` -- image width* 

93 

94 **Return** 

95 

96 - ``thisImage`` -- the image created 

97 

98 """ 

99 self.log.debug('starting the ``create_image`` method') 

100 

101 # ADD PLACEHOLDER AS DEFAULT IMAGE 

102 if not self.imagePath: 

103 self.imagePath = 'holder.js/200x200/auto/industrial/text:placeholder' 

104 

105 # CREATE HTML CODE FOR THE IMAGE 

106 thisImage = image( 

107 src=self.imagePath, # [ industrial | gray | social ] 

108 href=False, 

109 display=self.display, # [ rounded | circle | polaroid | False ] 

110 pull=False, # [ "left" | "right" | "center" | False ] 

111 htmlClass=False, 

112 width=width, 

113 thumbnail=True 

114 ) 

115 

116 # LINK THE IMAGE TO THE ASSOCIATED MODAL WITH A RANDOM NUMBER TAG 

117 randNum = self.randomNum 

118 thisImage = a( 

119 content=thisImage, 

120 href="#modal%(randNum)s" % locals(), 

121 tableIndex=False, 

122 triggerStyle="modal", # [ False | "dropdown" | "tab" ] 

123 htmlClass=False, 

124 postInBackground=False, 

125 ) 

126 

127 self.log.debug('completed the ``create_image`` method') 

128 return thisImage 

129 

130 def _create_modal( 

131 self): 

132 """ 

133 *create modal* 

134 

135 **Return** 

136 

137 - ``imageModal`` -- the image modal 

138 

139 """ 

140 self.log.debug('starting the ``create_modal`` method') 

141 

142 # GRAB THE ASSOCIATED IMAGE AND PLACE IN A WRAPPER ROW 

143 thisImage = self._create_image(width=self.modalImageWidth) 

144 thisImage = row_adjustable( 

145 span=10, 

146 offset=1, 

147 content=thisImage, 

148 htmlId=False, 

149 htmlClass=False, 

150 onPhone=True, 

151 onTablet=True, 

152 onDesktop=True 

153 ) 

154 

155 # GENERATE THE DOWNLOAD BUTTON FOR THE MODAL FOOTER 

156 fileUrl = self.imagePath 

157 

158 from khufu import popover 

159 thisPopover = popover( 

160 tooltip=True, 

161 placement="bottom", # [ top | bottom | left | right ] 

162 trigger="hover", # [ False | click | hover | focus | manual ] 

163 title="download image", 

164 content=False, 

165 delay=20 

166 ) 

167 

168 if self.downloadLink: 

169 downloadLink = self.downloadLink 

170 downloadFileButton = button( 

171 buttonText="""<i class="icon-file-pdf"></i>""", 

172 # [ default | primary | info | success | warning | danger | inverse | link ] 

173 buttonStyle='primary', 

174 buttonSize='small', # [ large | default | small | mini ] 

175 htmlId=False, 

176 href=downloadLink, 

177 pull=False, # right, left, center 

178 submit=False, 

179 block=False, 

180 disable=False, 

181 dataToggle=False, # [ modal ] 

182 popover=thisPopover 

183 ) 

184 else: 

185 downloadFileButton = "" 

186 

187 buttonList = [downloadFileButton] 

188 buttonList.extend(self.modalFooterButtons) 

189 

190 thisButtonGroup = buttonGroup( 

191 buttonList=buttonList, 

192 format='default' # [ default | toolbar | vertical ] 

193 ) 

194 

195 # CREATE THE MODAL WITH THE CORRECT TRIGGER TAG 

196 randNum = self.randomNum 

197 imageModal = modals.modal( 

198 modalHeaderContent=self.modalHeaderContent, 

199 modalBodyContent=thisImage, 

200 modalFooterContent=self.modalFooterContent + thisButtonGroup, 

201 htmlId="modal%(randNum)s" % locals(), 

202 centerContent=True, 

203 htmlClass=False 

204 ) 

205 

206 self.log.debug('completed the ``create_modal`` method') 

207 return imageModal 

208 

209 # method-tmpx