-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
215 lines (181 loc) · 6.54 KB
/
gui.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import db
xml_output=''
random_id = 1 # used to generate id's for labels, buttons etc
XPAD = 10
test_definition_file = '' # name of the test definition file
def get_xml_header(title):
temp = """<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="main">
<property name="can_focus">False</property>
<signal name="delete-event" handler="onDeleteWindow" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">20</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">""" + title + """</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">10</property>
<property name="column_spacing">5</property>
<property name="row_homogeneous">True</property>"""
return temp
def get_xml_footer():
temp = """
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>"""
return temp
# returns the xml corresponding to a row of a test
def get_row_xml(fields):
global random_id
global test_definition_file
temp = ''
i = 0
for row in fields:
t = row.split(';')
id = db.validate(t[0])
name = t[0]
test_type = t[1]
unit = t[2]
reference_range = t[3]
# input field
items = ''
if test_type == 'A': # text area
object_class = 'GtkTextView'
elif test_type[0] == 'T' and len(test_type)>1 and test_type[1] == '[': # combo box
object_class = 'GtkComboBoxText'
items = """
<property name="entry_text_column">0</property>
<property name="id_column">1</property>
<items>"""
its = test_type[2:-1].split(',') # get items to be inserted to the combo box
for item in its:
items = items + """
<item translatable="yes">""" + item.strip() + """</item>"""
items = items + """
</items>"""
elif len(test_type)>1 and test_type[1] == '(': # calculation field, just ignore it
continue
else: # text field
object_class = 'GtkEntry'
temp = temp + """
<child>
<object class=\"""" + object_class + """\" id=\"""" + id + """\">
<property name="visible">True</property>
<property name="can_focus">True</property>
""" + items + """
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">""" + str(i) + """</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>"""
# test name
# label was moved here so that calculation field labels are not added
temp = temp + get_label(name, i, 0)
# unit
if unit != '':
temp = temp + get_label(unit, i, 2)
# reference range
if reference_range != '':
temp = temp + get_label(reference_range, i, 3)
i = i + 1
# done button
temp = temp + """
<child>
<object class="GtkButton" id="button""" + str(random_id) + """\">
<property name="label" translatable="yes">Done</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="done" swapped="no"/>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">""" + str(i) + """</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>"""
# label to hold the name of the test definition file
temp = temp + """<child>
<object class="GtkLabel" id="test_filename">
<property name="can_focus">False</property>
<property name="visible">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes">""" + test_definition_file + """</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">""" + str(i) + """</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
"""
random_id = random_id + 1
return str(temp)
def get_label(value, row, column):
global random_id
temp = """
<child>
<object class="GtkLabel" id="label""" + str(random_id) + """\">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">""" + str(XPAD) + """</property>
<property name="label" translatable="yes">""" + value + """</property>
</object>
<packing>
<property name="left_attach">""" + str(column) + """</property>
<property name="top_attach">""" + str(row) + """</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>"""
random_id = random_id + 1
return temp
# returns the xml of glade, when the list of fields is passed
def get_glade(data, filename): # filename is the test definition file name
global test_definition_file
test_definition_file = filename
xml_output = get_xml_header(data[0])
xml_output = xml_output + get_row_xml(data[1:])
xml_output = xml_output + get_xml_footer()
return xml_output
def main():
pass
if __name__ == '__main__':
main()