-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableCard.py
More file actions
139 lines (111 loc) · 3.82 KB
/
Copy pathTableCard.py
File metadata and controls
139 lines (111 loc) · 3.82 KB
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
from typing import List
from DialogFlowPy import HorizontalAlignment
from DialogFlowPy.Button import Button
from DialogFlowPy.ColumnProperties import ColumnProperties
from DialogFlowPy.Image import Image
from DialogFlowPy.OpenUriAction import OpenUriAction
from DialogFlowPy.TableCardCell import TableCardCell
from DialogFlowPy.TableCardRow import TableCardRow
class TableCard(dict):
"""
{
"title": string,
"subtitle": string,
"image": {
object(Image)
},
"columnProperties": [
{
object(ColumnProperties)
}
],
"rows": [
{
object(Row)
}
],
"buttons": [
{
object(Button)
}
]
}
"""
def __init__(self, title: str, subtitle: str, image: Image, column_properties: List[ColumnProperties],
rows: List[TableCardRow], buttons: List[Button]):
super().__init__()
self['title'] = title
self['subtitle'] = subtitle
self['image'] = image
self['columnProperties'] = column_properties
self['rows'] = rows
self['buttons'] = buttons
@property
def title(self):
return self.get('title')
@title.setter
def title(self, title: str):
self['title'] = title
@property
def subtitle(self):
return self.get('subtitle')
@subtitle.setter
def subtitle(self, subtitle: str):
self['subtitle'] = subtitle
@property
def image(self):
return self.get('image')
@image.setter
def image(self, image: Image):
self['image'] = image
def add_image(self, image_uri: str, accessibility_text: str = '') -> Image:
self.image = Image(image_uri=image_uri, accessibility_text=accessibility_text)
return self.image
@property
def column_properties(self):
return self.get('columnProperties')
@column_properties.setter
def column_properties(self, column_properties: ColumnProperties):
self['columnProperties'] = column_properties
def add_column_properties(self, column_properties: ColumnProperties) -> List[ColumnProperties]:
for item in column_properties:
assert isinstance(item, ColumnProperties)
self['columnProperties'].append(item)
return self['columnProperties']
def add_column_property(self, header: str, horizontal_alignment: HorizontalAlignment) -> ColumnProperties:
column_property = ColumnProperties(header=header, horizontal_alignment=horizontal_alignment)
self['columnProperties'].append(column_property)
return column_property
@property
def rows(self):
return self.get('rows')
@rows.setter
def rows(self, rows_list: TableCardRow):
self.rows = rows_list
def add_rows(self, rows: TableCardRow) -> List[TableCardRow]:
for item in rows:
assert isinstance(item, TableCardRow)
self.rows.append(item)
return self.rows
def add_row(self, divider_after: bool = False, cells: TableCardCell = None) -> TableCardRow:
if cells is None:
cells = []
row = TableCardRow(divider_after=divider_after, table_card_cells=cells)
self.rows.append(row)
return row
@property
def buttons(self):
return self.get('buttons')
@buttons.setter
def buttons(self, buttons_list):
self['buttons'] = buttons_list
def add_buttons(self, buttons) -> List[Button]:
for item in buttons:
assert isinstance(item, Button)
self.buttons.append(item)
return self.buttons
def add_button(self, title: str, uri: str) -> Button:
assert isinstance(title, str)
assert isinstance(uri, str)
self.buttons.append(Button(title=title, open_uri_action=OpenUriAction(uri=uri)))
return self.buttons