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

#!/usr/bin/python 

# -*- coding: utf-8 -*- 

 

""" _dryxLabelsAndBadges 

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

:Summary: 

    Partial for dryxTwitterBootstrap 

 

:Author: 

    David Young 

 

:Date Created: 

    20130508 

 

: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 code please email me: d.r.young@qub.ac.uk """ 

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

# CLASSES                                                         # 

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

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

# PUBLIC FUNCTIONS                                                # 

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

## LAST MODIFIED : 20130508 

## CREATED : 20130508 

## AUTHOR : DRYX 

 

def label(text='', level='default'): 

    """ Generate a label - TBS style 

 

    **Key Arguments:** 

        - ``text`` -- the text content 

        - ``level`` -- the level colour of the label [ "default" | "success" | "warning" | "important" | "info" | "inverse" ] 

 

    **Return:** 

        - ``label`` -- the label """ 

 

    if level == 'default': 

        level = '' 

    else: 

        level = 'label-%s' % (level, ) 

    label = """ 

        <span class="label %s" id="  "> 

            %s 

        </span>""" % (level, text) 

    return label 

 

 

def badge(text='', level='default'): 

    """ Generate a badge - TBS style 

 

    **Key Arguments:** 

        - ``text`` -- the text content 

        - ``level`` -- the level colour of the badge [ "default" | "success" | "warning" | "important" | "info" | "inverse" ] 

 

    **Return:** 

        - ``badge`` -- the badge """ 

 

    if level == 'default': 

        level = '' 

    else: 

        level = 'badge-%s' % (level, ) 

    badge = """ 

        <span class="badge %s" id="  "> 

            %s 

        </span>""" % (level, text) 

    return badge 

 

 

## LAST MODIFIED : 20130508 

## CREATED : 20130508 

## AUTHOR : DRYX 

 

def alert(alertText='', 

    alertHeading="", 

    extraPadding=False, 

    alertLevel="warning"): 

    """ Generate a alert - TBS style 

 

    **Key Arguments:** 

        - ``alertText`` -- the text to be displayed in the alert 

        - ``extraPadding`` -- for longer messages, increase the padding on the top and bottom of the alert wrapper 

        - ``alertLevel`` -- the level of the alert [ "warning" | "error" | "success" | "info" ] 

 

    **Return:** 

        - ``alert`` -- the alert """ 

 

    falseList = [extraPadding,] 

    for i in range(len(falseList)): 

            if not falseList[i]: 

                falseList[i] = "" 

    [extraPadding,]  = falseList 

 

    if alertLevel == "warning": 

        alertLevel = "" 

    else: 

        alertHeading = "alert-%s" % (alertLevel,) 

 

    if extraPadding: 

        extraPadding = "alert-block" 

        alertHeading = "<h4>%s</h4>" % (alertHeading,) 

    else: 

        alertHeading = "<strong>%s</strong>" % (alertHeading,) 

 

 

    alert = \ 

        """ 

        <div class="alert %s %s"> 

          <button type="button" class="close" data-dismiss="alert">&times;</button> 

          %s %s 

        </div>""" \ 

        % (extraPadding, alertLevel, alertHeading, alertText, ) 

    return alert 

 

 

## LAST MODIFIED : 20130508 

## CREATED : 20130508 

## AUTHOR : DRYX 

def progressBar( 

        barStyle="plain", 

        precentageWidth="10", 

        barLevel="info"): 

    """Generate a progress bar - TBS style 

 

    **Key Arguments:** 

        - ``barStyle`` -- style of the progress bar [ "plain" | "stripped" | "stripped-active" ] 

        - ``precentageWidth`` -- the current progress of the bar 

        - ``barLevel`` -- the level color of the bar [ "info" | "warning" | "success" | "error" ] 

 

    **Return:** 

        - ``progressBar`` -- the progressBar 

    """ 

    barLevel = "progress-%s" % (barLevel,) 

 

    if barStyle == "stripped": 

        barStyle == "progess-stripped" 

    elif barStyle == "stripped-active": 

        barStyle == "progess-stripped active" 

    else: 

        barStyle = "" 

 

    progressBar = """ 

        <div class="progress %s %s"> 

          <div class="bar" style="width: %s%%;"></div> 

        </div>""" % (barLevel, barStyle, precentageWidth,) 

 

    return progressBar 

 

 

## LAST MODIFIED : 20130508 

## CREATED : 20130508 

## AUTHOR : DRYX 

def stackedProgressBar( 

        barStyle="plain", 

        infoWidth="10", 

        successWidth="10", 

        warningWidth="10", 

        errorWidth="10" 

        ): 

    """Generate a progress bar - TBS style 

 

    **Key Arguments:** 

        - ``barStyle`` -- style of the progress bar [ "plain" | "stripped" | "stripped-active" ] 

        - ``infoWidth`` -- the precentage width of the info level bar 

        - ``successWidth`` -- the precentage width of the success level bar 

        - ``warningWidth`` -- the precentage width of the warning level bar 

        - ``errorWidth`` -- the precentage width of the error level bar 

 

    **Return:** 

        - ``progressBar`` -- the progressBar 

    """ 

    barLevel = "progress-%s" % (barLevel,) 

 

    if barStyle == "stripped": 

        barStyle == "progess-stripped" 

    elif barStyle == "stripped-active": 

        barStyle == "progess-stripped active" 

    else: 

        barStyle = "" 

 

    stackedProgressBar = """ 

        <div class="progress %s %s"> 

          <div class="bar bar-info" style="width: %s%%;"></div> 

          <div class="bar bar-success" style="width: %s%%;"></div> 

          <div class="bar bar-warning" style="width: %s%%;"></div> 

          <div class="bar bar-error" style="width: %s%%;"></div> 

        </div>""" % (barLevel, barStyle, infoWidth, successWidth, warningWidth, errorWidth) 

 

    return stackedProgressBar 

 

 

 

 

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

# PRIVATE (HELPER) FUNCTIONS                                      # 

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

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

# TEMPLATE FUNCTIONS                                              # 

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