/
Button.py
65 lines (54 loc) · 1.92 KB
/
Button.py
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
# CTK: Cherokee Toolkit
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2009 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
from Widget import Widget
from util import props_to_str
class Button (Widget):
"""
Widget for the BUTTON HTML element. All arguments are optional.
Arguments:
caption: text that should appear in the button. By default,
"Submit".
props: dictionary with properties for HTML element, such as
{'class': 'test', 'display': 'none'}
Examples:
button1 = CTK.Button()
button2 = CTK.Box('Validate', {'class': 'blue_button'})
"""
def __init__ (self, caption="Submit", props={}):
Widget.__init__ (self)
self.props = props.copy()
if 'class' in props:
self.props['class'] += " button"
else:
self.props['class'] = "button"
self.id = props.pop('id', "button_%d"%(self.uniq_id))
self.caption = caption
# Public interface
#
def Render (self):
id = self.id
caption = self.caption
props = props_to_str (self.props)
html = '<button id="%(id)s" %(props)s>%(caption)s</button>' %(locals())
render = Widget.Render (self)
render.html += html
return render