-
Notifications
You must be signed in to change notification settings - Fork 5
/
ignite.py
193 lines (141 loc) · 5.1 KB
/
ignite.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
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
# -*- coding: utf-8 -*-
from . import core as html5
################################################################
# NOTE: This part of the html5 library is superseded by flare. #
# It is not improved anymore, and just remains here for #
# existing projects. #
# #
# Visit https://github.com/mausbrand/flare for details. #
################################################################
@html5.tag
class Label(html5.Label):
_parserTagName = "ignite-label"
def __init__(self, *args, **kwargs):
super(Label, self).__init__(style="label ignt-label", *args, **kwargs)
@html5.tag
class Input(html5.Input):
_parserTagName = "ignite-input"
def __init__(self, *args, **kwargs):
super(Input, self).__init__(style="input ignt-input", *args, **kwargs)
@html5.tag
class Switch(html5.Div):
_parserTagName = "ignite-switch"
def __init__(self, *args, **kwargs):
super(Switch, self).__init__(style="switch ignt-switch", *args, **kwargs)
self.input = html5.Input(style="switch-input")
self.appendChild(self.input)
self.input["type"] = "checkbox"
switchLabel = html5.Label(forElem=self.input)
switchLabel.addClass("switch-label")
self.appendChild(switchLabel)
def _setChecked(self, value):
self.input["checked"] = bool(value)
def _getChecked(self):
return self.input["checked"]
@html5.tag
class Check(html5.Input):
_parserTagName = "ignite-check"
def __init__(self, *args, **kwargs):
super(Check, self).__init__(style="check ignt-check", *args, **kwargs)
checkInput = html5.Input()
checkInput.addClass("check-input")
checkInput["type"] = "checkbox"
self.appendChild(checkInput)
checkLabel = html5.Label(forElem=checkInput)
checkLabel.addClass("check-label")
self.appendChild(checkLabel)
@html5.tag
class Radio(html5.Div):
_parserTagName = "ignite-radio"
def __init__(self, *args, **kwargs):
super(Radio, self).__init__(style="radio ignt-radio", *args, **kwargs)
radioInput = html5.Input()
radioInput.addClass("radio-input")
radioInput["type"] = "radio"
self.appendChild(radioInput)
radioLabel = html5.Label(forElem=radioInput)
radioLabel.addClass("radio-label")
self.appendChild(radioLabel)
@html5.tag
class Select(html5.Select):
_parserTagName = "ignite-select"
def __init__(self, *args, **kwargs):
super(Select, self).__init__(style="select ignt-select", *args, **kwargs)
defaultOpt = html5.Option()
defaultOpt["selected"] = True
defaultOpt["disabled"] = True
defaultOpt.element.innerHTML = ""
self.appendChild(defaultOpt)
@html5.tag
class Textarea(html5.Textarea):
_parserTagName = "ignite-textarea"
def __init__(self, *args, **kwargs):
super(Textarea, self).__init__(style="textarea ignt-textarea", *args, **kwargs)
@html5.tag
class Progress(html5.Progress):
_parserTagName = "ignite-progress"
def __init__(self, *args, **kwargs):
super(Progress, self).__init__(style="progress ignt-progress", *args, **kwargs)
@html5.tag
class Item(html5.Div):
_parserTagName = "ignite-item"
def __init__(self, title=None, descr=None, className=None, *args, **kwargs):
super(Item, self).__init__(style="item ignt-item", *args, **kwargs)
if className:
self.addClass(className)
self.fromHTML("""
<div class="item-image ignt-item-image" [name]="itemImage">
</div>
<div class="item-content ignt-item-content" [name]="itemContent">
<div class="item-headline ignt-item-headline" [name]="itemHeadline">
</div>
</div>
""")
if title:
self.itemHeadline.appendChild(html5.TextNode(title))
if descr:
self.itemSubline = html5.Div()
self.addClass("item-subline ignt-item-subline")
self.itemSubline.appendChild(html5.TextNode(descr))
self.appendChild(self.itemSubline)
@html5.tag
class Table(html5.Table):
_parserTagName = "ignite-table"
def __init__(self, *args, **kwargs):
super(Table, self).__init__(*args, **kwargs)
self.head.addClass("ignt-table-head")
self.body.addClass("ignt-table-body")
def prepareRow(self, row):
assert row >= 0, "Cannot create rows with negative index"
for child in self.body._children:
row -= child["rowspan"]
if row < 0:
return
while row >= 0:
tableRow = html5.Tr()
tableRow.addClass("ignt-table-body-row")
self.body.appendChild(tableRow)
row -= 1
def prepareCol(self, row, col):
assert col >= 0, "Cannot create cols with negative index"
self.prepareRow(row)
for rowChild in self.body._children:
row -= rowChild["rowspan"]
if row < 0:
for colChild in rowChild._children:
col -= colChild["colspan"]
if col < 0:
return
while col >= 0:
tableCell = html5.Td()
tableCell.addClass("ignt-table-body-cell")
rowChild.appendChild(tableCell)
col -= 1
return
def fastGrid( self, rows, cols, createHidden=False ):
colsstr = "".join(['<td class="ignt-table-body-cell"></td>' for i in range(0, cols)])
tblstr = '<tbody [name]="body" class="ignt-table-body" >'
for r in range(0, rows):
tblstr += '<tr class="ignt-table-body-row %s">%s</tr>' %("is-hidden" if createHidden else "",colsstr)
tblstr +="</tbody>"
self.fromHTML(tblstr)