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

#!/usr/bin/python 

# encoding: utf-8 

""" 

_dryxTBS_buttons 

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

:Summary: 

    Buttons partial for the dryxTwitterBootstrap module 

 

:Author: 

    David Young 

 

:Date Created: 

    April 25, 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 : March 12, 2013 

## CREATED : March 12, 2013 

## AUTHOR : DRYX 

def get_button(size="large", 

                block=False, 

                color="blue", 

                text="button", 

                htmlId=False, 

                htmlClass=False, 

                extraAttr=False, 

                disabled=False): 

    """The button method (bases on the twitter bootstrap buttons) 

 

    **Key Arguments:** 

        - ``size`` - button size - mini, small, default, large 

        - ``block`` - block button? 

        - ``color`` - color 

        - ``text`` - button text 

        - ``htmlId`` -- the name of the button 

        - ``htmlClass`` -- the class of the button 

        - ``disabled`` -- disable the button if true (flatten & unclickable) 

 

    **Return:** 

        - ``button`` 

    """ 

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

    ## STANDARD LIB ## 

    ## THIRD PARTY ## 

    ## LOCAL APPLICATION ## 

 

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

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

    if block: 

        block = "btn-block" 

    else: 

        block = "" 

    if htmlId: 

        htmlId = """id="%s" """ % (htmlId,) 

    else: 

        htmlId = "" 

    if not htmlClass: htmlClass = "" 

    if not extraAttr: 

        extraAttr = "" 

    if disabled: 

        disabled = "disabled" 

    else: 

        disabled = "" 

 

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

 

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

    button = """ 

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

        %s 

        </button>""" % (size, block, color, htmlClass, disabled, htmlId, extraAttr, text) 

 

    return button 

 

# xxx-replace 

## LAST MODIFIED : March 12, 2013 

## CREATED : March 12, 2013 

## AUTHOR : DRYX 

# def get_linked_button(size="large", 

#                 block=False, 

#                 color="blue", 

#                 text="button", 

#                 href="#", 

#                 htmlId=False, 

#                 htmlClass=False, 

#                 extraAttr=False, 

#                 disabled=False): 

#     """The button method (bases on the twitter bootstrap buttons) 

 

#     **Key Arguments:** 

#         - ``size`` - button size - mini, small, default, large 

#         - ``block`` - block button? 

#         - ``color`` - color 

#         - ``text`` - button text 

#         - ``href`` - the link 

#         - ``htmlId`` -- the name of the button 

#         - ``htmlClass`` -- the class of the button 

 

#     **Return:** 

#         - ``link_button`` 

#     """ 

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

#     ## STANDARD LIB ## 

#     ## THIRD PARTY ## 

#     ## LOCAL APPLICATION ## 

 

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

#     size = "btn-%s" % (size,) 

#     if block: 

#         block = "btn-block" 

#     else: 

#         block = "" 

#     if htmlId: 

#         htmlId = """id="%s" """ % (htmlId,) 

#     else: 

#         htmlId = "" 

#     if not htmlClass: htmlClass = "" 

#     if not extraAttr: 

#         extraAttr = "" 

#     if disabled: 

#         disabled = "disabled" 

#     else: 

#         disabled = "" 

 

#     color = "btn-%s" % (color,) 

 

 

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

#     link_button = """ 

#         <a href="%s" class="btn %s %s %s %s %s" %s %s>%s</a>""" % (href, size, block, color, htmlClass, disabled, htmlId, extraAttr, text) 

 

#     return link_button 

 

 

## LAST MODIFIED : April 25, 2013 

## CREATED : April 25, 2013 

## AUTHOR : DRYX 

def button( 

        buttonText="", 

        buttonStyle="default", 

        buttonSize="default", 

        href=False, 

        submit=False, 

        block=False, 

        disable=False): 

    """Generate a button - TBS style 

 

    **Key Arguments:** 

        - ``buttonText`` -- the text to display on the button 

        - ``buttonStyle`` -- the style of the button required [ default | primary | info | success | warning | danger | inverse | link ] 

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

        - ``href`` -- link the button to another location? 

        - ``submit`` -- set to true if a form button [ true | false ] 

        - ``block`` -- create block level buttons—those that span the full width of a parent [ True | False ] 

        - ``disable`` -- this class is only for aesthetic; you must use custom JavaScript to disable links here 

 

    **Return:** 

        - ``button`` -- the button 

    """ 

    if buttonStyle == "default": 

        buttonStyle = "" 

    else: 

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

 

    if buttonSize == "default": 

        buttonSize = "" 

    else: 

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

 

    if block is True: 

        block = "btn-block" 

    else: 

        block = "" 

 

    if disable is True: 

        disable = "disable" 

    else: 

        disable = "" 

 

    if submit is True: 

        submit = """type="submit" """ 

    else: 

        submit = "" 

 

    if href: 

        elementOpen = """a href="%s" """ % (href,) 

        elementClose = """a""" 

    else: 

        elementOpen = """button type="button" """ 

        elementClose = """button""" 

 

    button = """ 

        <%s class="btn %s %s %s %s" id="  " %s > 

            %s 

        </%s>""" % (elementOpen, buttonStyle, buttonSize, block, disable, submit, buttonText, elementClose) 

 

    return button 

 

 

## LAST MODIFIED : April 29, 2013 

## CREATED : April 29, 2013 

## AUTHOR : DRYX 

def buttonGroup( 

        buttonList="", 

        format="default"): 

    """Generate a buttonGroup - TBS style 

 

    **Key Arguments:** 

        - ``buttonList`` -- a list of buttons 

        - ``format`` -- format of the button [ default | toolbar | vertical ] 

 

    **Return:** 

        - ``buttonGroup`` -- the buttonGroup 

    """ 

    thisButtonList = "" 

    for button in buttonList: 

        thisButtonList += button 

 

    if format is "vertical": 

        vertical = "btn-group-vertical" 

    else: 

        vertical = "" 

 

    buttonGroup = """ 

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

            %s 

        </div>""" % (vertical, buttonList,) 

 

    if format == "toolbar": 

        buttonGroup = """ 

        <div class="btn-toolbar"> 

            %s 

        </div>""" % (buttonGroup,) 

 

    return buttonGroup 

 

 

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

# PRIVATE (HELPER) FUNCTIONS                                      # 

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

 

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

# TEMPLATE FUNCTIONS                                              # 

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