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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

#!/usr/local/bin/python 

# encoding: utf-8 

""" 

_dryxTBS_dropdowns 

================================= 

:Summary: 

    Dropdown menus partial for the dryxTwitterBootstrap module 

 

:Author: 

    David Young 

 

:Date Created: 

    March 15, 2013 

 

:dryx syntax: 

    - ``xxx`` = come back here and do some more work 

    - ``_someObject`` = a 'private' object that should only be changed for debugging 

 

:Notes: 

    - If you have any questions requiring this script please email me: d.r.young@qub.ac.uk 

""" 

 

 

################################################################### 

# CLASSES                                                         # 

################################################################### 

 

################################################################### 

# PUBLIC FUNCTIONS                                                # 

################################################################### 

# xxx-replace 

## LAST MODIFIED : December 17, 2012 

## CREATED : December 17, 2012 

## AUTHOR : DRYX 

def get_dropdown_menu_for(dbConn, log, menuName, title, linkList): 

  """Generate a dropdown menu with the provided list of links. 

 

  **Key Arguments:** 

    - ``dbConn`` -- mysql database connection 

    - ``log`` -- logger 

    - ``menuName`` -- the name of the menu 

    - ``title`` -- the title of the menu 

    - ``linkList`` -- a list of links that the menu should display 

 

  **Return:** 

    - ``menu`` -- the dropdown menu 

  """ 

  ################ > IMPORTS ################ 

  import ordereddict as c # REMOVE WHEN PYTHON 2.7 INSTALLED ON PSDB 

  #import collections as c 

 

  ################ > VARIABLE SETTINGS ###### 

  gh = lambda x: get_html_block(x) 

 

  ################ >ACTION(S) ################ 

  ## BUTTONS 

  buttonDict = {} 

  i=0 

  for item in linkList: 

    key = ('%05i' % i) 

    buttonDict[key] = dict( 

                            tag="div", 

                            htmlClass=menuName+'MenuButton', 

                            blockContent=item 

                          ) 

    i += 1 

 

  blockDict = {} 

  blockDict[menuName+'Hover'] = gh( 

                                    dict ( 

                                          tag="div", 

                                          htmlClass='dropDownMenu', 

                                          htmlId=menuName+'Hover', 

                                          blockContent = title 

                                    ) 

                                  ) 

 

  obuttonDict = c.OrderedDict(sorted(buttonDict.items())) 

 

  blockContent = blockDict[menuName+'Hover'] 

  for k, v in obuttonDict.iteritems(): 

    blockContent += gh(v) 

 

  blockDict[menuName+'SubItems'] = gh( 

                                        dict ( 

                                              tag="div", 

                                              htmlClass='dropDownMenu', 

                                              htmlId=menuName+'SubItems', 

                                              blockContent=blockContent 

                                        ) 

                                      ) 

 

  blockDict[menuName+'Menu'] = gh( 

                                    dict ( 

                                          tag="div", 

                                          htmlClass='dropDownMenu', 

                                          blockContent=blockContent, 

                                          htmlId=menuName+'Menu' 

                                    ) 

                                  ) 

 

  return blockDict[menuName+'Menu'] 

 

# xxx-replace 

## LAST MODIFIED : December 12, 2012 

## CREATED : December 12, 2012 

## AUTHOR : DRYX 

def get_option_list(optionList): 

  """Create a dropdown option list 

 

    **Key Arguments:** 

        - ``optionList`` -- list of items to appear in option list 

        - ``attributeDict`` -- dictionary of the following keywords: 

        - ``htmlClass`` -- the html element class 

        - ``htmlId`` -- the html element id 

        - ``blockContent`` -- actual content to be placed in html code block 

        - ``jsEvents`` -- inline javascript events 

        - ``extraAttr`` -- extra inline css attributes and/or handles 

        - ``name`` -- an extra hook (much like "id") 

        - ``type`` -- HTML input types = color, date, datetime, datetime-local, email, month, number, range, search, tel, time, url, week 

        - ``placeholder`` -- text to be displayed by default in the input box 

        - ``required`` -- make input required (boolean) 

        - ``autofocus`` -- make this the auofocus element of the form (i.e. place cursor here) 

        - ``maxlength`` -- maximum character length for the form 

 

    **Returns:** 

        - ``block`` -- the HTML code block 

  """ 

  ################ > IMPORTS ################ 

 

  ################ > VARIABLE SETTINGS ###### 

  block = "" 

 

  ################ >ACTION(S) ################ 

  for option in optionList: 

    htmlId = option.replace(' ','') 

    block += get_html_block( 

                              dict( 

                                tag="option", 

                                htmlId=htmlId, 

                                value=option, 

                                blockContent=option 

                              ) 

                            ) 

  return block 

 

 

## LAST MODIFIED : March 8, 2013 

## CREATED : March 8, 2013 

## AUTHOR : DRYX 

def dropdown( 

        buttonSize="default", 

        color="grey", 

        menuTitle="#", 

        splitButton=False, 

        linkList=[], 

        separatedLinkList=False, 

        pull=False, 

        direction="down", 

        onPhone=True, 

        onTablet=True, 

        onDesktop=True): 

    """get a toggleable, contextual menu for displaying lists of links. Made interactive with the dropdown JavaScript plugin. You need to wrap the dropdown's trigger and the dropdown menu within .dropdown, or another element that declares position: relative; 

 

    - ``buttonSize`` -- size of button [ mini | small | default | large ] 

    - ``buttonColor`` -- [ default | sucess | error | warning | info ] 

    - ``menuTitle`` -- the title of the menu 

    - ``splitButton`` -- split the button into a separate action button and a dropdown 

    - ``linkList`` -- a list of (linked) items items that the menu should display 

    - ``separatedLinkList`` -- a list of (linked) items items that the menu should display below divider 

    - ``pull`` -- [ false | right | left ] (e.g Add ``right`` to a ``.dropdown-menu`` to right align the dropdown menu.) 

    - ``direction`` -- drop [ down | up ] 

    - ``onPhone`` -- does this container get displayed on a phone sized screen 

    - ``onTablet`` -- does this container get displayed on a tablet sized screen 

    - ``onDesktop`` -- does this container get displayed on a desktop sized screen 

 

      **Return:** 

        - ``dropdown`` -- the dropdown menu 

    """ 

    # Twitter Bootstrap notes 

    # ------------------------ 

    # Add .pull-right to a .dropdown-menu to right align the dropdown menu. 

    # Add .disabled to a <li> in the dropdown to disable the link. 

    # Add .dropdown-submenu to any li in an existing dropdown menu for automatic styling. 

    thisLinkList = "" 

    for link in linkList: 

        thisLinkList += """%s""" % (link, ) 

 

    thisSeparatedLinkList = "" 

    if separatedLinkList: 

        thisSeparatedLinkList = """<li class="divider"></li>""" 

        for link in separatedLinkList: 

            thisSeparatedLinkList += """%s""" % (link, ) 

 

    thisLinkList = thisLinkList + thisSeparatedLinkList 

 

    if buttonSize == "default": 

        buttonSize = "" 

    else: 

        buttonSize = "btn-%s" % (buttonSize,) 

 

    if direction == "up": 

        direction = "dropup" 

    else: 

        direction = "" 

 

    if splitButton: 

        dropdownButton = """ 

            <button class="btn %s %s">%s</button> 

            <button class="btn %s %s dropdown-toggle" data-toggle="dropdown"> 

                <span class="caret"></span> 

            </button>""" % (buttonSize, buttonColor, menuTitle, buttonSize, buttonColor) 

    else: 

        dropdownButton = """ 

            <a class="btn %s %s dropdown-toggle" data-toggle="dropdown" href="#"> 

              %s 

              <span class="caret"></span> 

            </a>""" % (buttonSize, buttonColor, menuTitle,) 

 

    if pull: 

        pull = """pull-%s""" % (pull,) 

    else: 

        pull = "" 

 

    if onPhone: 

        onPhone = "" 

    else: 

        onPhone = "hidden-phone" 

    if onTablet: 

        onTablet = "" 

    else: 

        onTablet = "hidden-tablet" 

    if onDesktop: 

        onDesktop = "" 

    else: 

        onDesktop = "hidden-desktop" 

 

    dropdown = """ 

        <div class="btn-group %s %s %s %s" id="" %s> 

            %s 

            <ul class="dropdown-menu"> 

                <!-- dropdown menu links --> 

                %s 

          </ul> 

        </div>""" % (pull, onPhone, onTablet, onDesktop, direction, dropdownButton, thisLinkList) 

 

    return dropdown 

 

################################################################### 

# PRIVATE (HELPER) FUNCTIONS                                      # 

################################################################### 

 

if __name__ == '__main__': 

    main() 

 

 

################################################################### 

# TEMPLATE FUNCTIONS                                              # 

###################################################################