[gen] Better rendering of buttons; added a new utility function for formatting elements like phone numbers.

This commit is contained in:
Gaetan Delannay 2014-05-16 12:58:53 +02:00
parent cf946e3222
commit 3b18619624
3 changed files with 19 additions and 9 deletions

View file

@ -1365,11 +1365,7 @@ class ToolMixin(BaseMixin):
def getButtonWidth(self, label): def getButtonWidth(self, label):
'''Determine button width, in pixels, corresponding to the button '''Determine button width, in pixels, corresponding to the button
p_label.''' p_label.'''
l = len(label) # Set a minimum width for small labels.
if l < 10: if len(label) < 15: return 'width:130px'
width = '130px' return 'padding-left: 26px; padding-right: 8px'
else:
# Consider 1 char = 6 pixels wide.
width = '%dpx' % (130 + ((l-10)*4))
return 'width:%s' % width
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -57,10 +57,10 @@ img { border: 0; vertical-align: middle }
.userStrip a:visited { color: #e7e7e7 } .userStrip a:visited { color: #e7e7e7 }
.breadcrumb { font-size: 11pt; padding-bottom: 6px } .breadcrumb { font-size: 11pt; padding-bottom: 6px }
.login { margin: 3px; color: black } .login { margin: 3px; color: black }
input.button { color: #666666; height: 20px; width: 130px; margin-bottom: 5px; input.button { color: #666666; height: 20px; margin-bottom: 5px;
cursor:pointer; font-size: 90%; padding-left: 10px; cursor:pointer; font-size: 90%; padding-left: 10px;
background-color: white; background-repeat: no-repeat; background-color: white; background-repeat: no-repeat;
background-position: 5% 25%; box-shadow: 2px 2px 2px #888888} background-position: 8px 25%; box-shadow: 2px 2px 2px #888888}
input.buttonSmall { width: 100px !important; font-size: 85%; height: 18px; input.buttonSmall { width: 100px !important; font-size: 85%; height: 18px;
margin-bottom: 3px} margin-bottom: 3px}
.fake { background-color: #e6e6e6 !important ; cursor:help !important } .fake { background-color: #e6e6e6 !important ; cursor:help !important }

View file

@ -269,6 +269,20 @@ def getStringDict(d):
res.append(value) res.append(value)
return '{%s}' % ','.join(res) return '{%s}' % ','.join(res)
def stretchText(s, pattern, char=' '):
'''Inserts occurrences of p_char within p_s according to p_pattern.
Example: stretchText("475123456", (3,2,2,2)) returns '475 12 34 56'.'''
res = ''
i = 0
for nb in pattern:
j = 0
while j < nb:
res += s[i+j]
j += 1
res += char
i += nb
return res
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
def formatNumber(n, sep=',', precision=2, tsep=' '): def formatNumber(n, sep=',', precision=2, tsep=' '):
'''Returns a string representation of number p_n, which can be a float '''Returns a string representation of number p_n, which can be a float