forked from stevenang/randomness_testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
277 lines (223 loc) · 10.7 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from tkinter import Button
from tkinter import Canvas
from tkinter import Checkbutton
from tkinter import DISABLED
from tkinter import Entry
from tkinter import Frame
from tkinter import IntVar
from tkinter import Label
from tkinter import LabelFrame
from tkinter import OptionMenu
from tkinter import Scrollbar
from tkinter import StringVar
class CustomButton:
def __init__(self, master, title, x_coor, y_coor, width, action=None):
button = Button(master, text=title, command=action)
button.config(font=("Calibri", 10))
button.place(x=x_coor, y=y_coor, width=width, height=25)
class Input:
def __init__(self, master, title, x_coor, y_coor, has_button=False, action=None, state='disabled', button_xcoor=1050, button_width=180):
# Setup Labels
label = Label(master, text=title)
label.config(font=("Calibri", 12))
label.place(x=x_coor, y=y_coor, height=25)
self.__data = StringVar()
self.__data_entry = Entry(master, textvariable=self.__data)
self.__data_entry.place(x=150, y=y_coor, width=900, height=25)
if has_button:
self.__data_entry.config(state='disabled')
button_title = 'Select ' + title
button = Button(master, text=button_title, command=action)
button.config(font=("Calibri", 10))
button.place(x=button_xcoor, y=y_coor, width=180, height=25)
def set_data(self, value):
self.__data.set(value)
def get_data(self):
return self.__data.get()
def change_state(self, state):
self.__data_entry.config(state=state)
class LabelTag:
def __init__(self, master, title, x_coor, y_coor, width, font_size=18, border=0, relief='flat'):
label = Label(master, text=title, borderwidth=border, relief=relief)
label.config(font=("Calibri", font_size))
label.place(x=x_coor, y=y_coor, width=width, height=25)
class Options:
def __init__(self, master, title, data, x_coor, y_coor, width):
self.__selected = StringVar()
label = Label(master, text=title)
label.config(font=("Calibri", 12))
self.__selected.set(data[0])
label.place(x=x_coor, y=y_coor, height=25, width=100)
self.__option = OptionMenu(master, self.__selected, *data)
self.__option.place(x=150, y=y_coor, height=25, width=width)
def set_selected(self, data):
self.__selected.set(data)
def get_selected(self):
return self.__selected.get()
def update_data(self, data):
self.__option.option_clear()
self.__option.option_add(data, '')
self.__option.update()
class TestItem:
def __init__(self, master, title, x_coor, y_coor, serial=False, p_value_x_coor=365, p_value_width=500, result_x_coor=870, result_width=350, font_size=12, two_columns=False):
self.__chb_var = IntVar()
self.__p_value = StringVar()
self.__result = StringVar()
self.__p_value_02 = StringVar()
self.__result_02 = StringVar()
checkbox = Checkbutton(master, text=title, variable=self.__chb_var)
checkbox.config(font=("Calibri", font_size))
checkbox.place(x=x_coor, y=y_coor)
p_value_entry = Entry(master, textvariable=self.__p_value)
p_value_entry.config(state=DISABLED)
p_value_entry.place(x=p_value_x_coor, y=y_coor, width=p_value_width, height=25)
result_entry = Entry(master, textvariable=self.__result)
result_entry.config(state=DISABLED)
result_entry.place(x=result_x_coor, y=y_coor, width=result_width, height=25)
if serial and two_columns:
p_value_entry_02 = Entry(master, textvariable=self.__p_value_02)
p_value_entry_02.config(state=DISABLED)
p_value_entry_02.place(x=875, y=y_coor, width=235, height=25)
result_entry_02 = Entry(master, textvariable=self.__result_02)
result_entry_02.config(state=DISABLED)
result_entry_02.place(x=1115, y=y_coor, width=110, height=25)
elif serial and not two_columns:
p_value_entry_02 = Entry(master, textvariable=self.__p_value_02)
p_value_entry_02.config(state=DISABLED)
p_value_entry_02.place(x=365, y=y_coor+25, width=500, height=25)
result_entry_02 = Entry(master, textvariable=self.__result_02)
result_entry_02.config(state=DISABLED)
result_entry_02.place(x=870, y=y_coor+25, width=350, height=25)
def get_check_box_value(self):
return self.__chb_var.get()
def set_check_box_value(self, value):
self.__chb_var.set(value)
def set_p_value(self, value):
self.__p_value.set(value)
def set_result_value(self, value):
self.__result.set(value)
def set_p_value_02(self, value):
self.__p_value_02.set(value)
def set_result_value_02(self, value):
self.__result_02.set(value)
def set_values(self, values):
self.__p_value.set(values[0])
self.__result.set(self.__get_result_string(values[1]))
def set_p_2_values(self, values):
self.__p_value_02(values[0])
self.__result_02(self.__get_result_string(values[1]))
def reset(self):
self.set_check_box_value(0)
self.set_p_value('')
self.set_result_value('')
self.set_p_value_02('')
self.set_result_value_02('')
def __get_result_string(self, result):
if result == True:
return 'Random'
else:
return 'Non-Random'
class RandomExcursionTestItem:
def __init__(self, master, title, x_coor, y_coor, data, variant=False, font_size=11):
self.__chb_var = IntVar()
self.__state = StringVar()
self.__count = StringVar()
self.__xObs = StringVar()
self.__p_value = StringVar()
self.__result = StringVar()
self.__results = []
self.__variant = variant
checkbox = Checkbutton(master, text=title, variable=self.__chb_var)
checkbox.config(font=("Calibri", font_size))
checkbox.place(x=x_coor, y=y_coor)
state_label = LabelTag(master, 'State', (x_coor + 60), (y_coor + 30), width=100, font_size=font_size, border=2, relief='groove')
if variant:
self.__state.set('-1.0')
else:
self.__state.set('+1')
state_option = OptionMenu(master, self.__state, *data)
state_option.place(x=(x_coor + 60), y=(y_coor + 60), height=25, width=100)
if not variant:
xObs_label = LabelTag(master, 'CHI-SQUARED', (x_coor + 165), (y_coor + 30), width=350, font_size=font_size, border=2,
relief='groove')
xObs_Entry = Entry(master, textvariable=self.__xObs)
xObs_Entry.place(x=(x_coor + 165), y=(y_coor + 60), width=350, height=25)
else:
count_label = LabelTag(master, 'Count', (x_coor + 165), (y_coor + 30), width=350, font_size=font_size,
border=2, relief='groove')
count_Entry = Entry(master, textvariable=self.__count)
count_Entry.place(x=(x_coor + 165), y=(y_coor + 60), width=350, height=25)
pass
p_value_label = LabelTag(master, 'P-Value', (x_coor + 520), (y_coor + 30), width=350, font_size=font_size, border=2,
relief='groove')
p_value_Entry = Entry(master, textvariable=self.__p_value)
p_value_Entry.place(x=(x_coor + 520), y=(y_coor + 60), width=350, height=25)
conclusion_label = LabelTag(master, 'Conclusion', (x_coor + 875), (y_coor + 30), width=150, font_size=font_size, border=2,
relief='groove')
conclusion_Entry = Entry(master, textvariable=self.__result)
conclusion_Entry.place(x=(x_coor + 875), y=(y_coor + 60), width=150, height=25)
update_button = Button(master, text='Update', command=self.update)
update_button.config(font=("Calibri", 10))
update_button.place(x=(x_coor+1030), y=(y_coor + 60), width=180, height=25)
def get_check_box_value(self):
return self.__chb_var.get()
def set_check_box_value(self, value):
self.__chb_var.set(value)
def set_results(self, results):
self.__results = results
self.update()
def update(self):
match = False
for result in self.__results:
if result[0] == self.__state.get():
if self.__variant:
self.__count.set(result[2])
else:
self.__xObs.set(result[2])
self.__p_value.set(result[3])
self.__result.set(self.get_result_string(result[4]))
match = True
if not match:
if self.__variant:
self.__count.set('')
else:
self.__xObs.set('')
self.__p_value.set('')
self.__result.set('')
def get_result_string(self, result):
if result == True:
return 'Random'
else:
return 'Non-Random'
def reset(self):
self.__chb_var.set('0')
if self.__variant:
self.__state.set('-1.0')
self.__count.set('')
else:
self.__state.set('+1')
self.__xObs.set('')
self.__p_value.set('')
self.__result.set('')
class ScrollLabelFrame(LabelFrame):
def __init__(self, parent, label):
super().__init__(master=parent, text=label, padx=5, pady=5)
self._canvas = Canvas(self, background="#ffffff")
self.inner_frame = Frame(self._canvas, background="#ffffff")
self._scroll_bar = Scrollbar(self, orient="vertical", command=self._canvas.yview)
self._canvas.configure(yscrollcommand=self._scroll_bar.set)
self._scroll_bar.pack(side="right", fill="y")
self._canvas.pack(side="left", fill="both", expand=True)
self._canvas_window = self._canvas.create_window((4,4), window=self.inner_frame, anchor="nw", #add view port frame to canvas
tags="self.inner_frame")
self.inner_frame.bind("<Configure>", self.onFrameConfigure) # bind an event whenever the size of the viewPort frame changes.
self._canvas.bind("<Configure>", self.onCanvasConfigure) # bind an event whenever the size of the viewPort frame changes.
self.onFrameConfigure(None)
def onFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self._canvas.configure(scrollregion=self._canvas.bbox(
"all")) # whenever the size of the frame changes, alter the scroll region respectively.
def onCanvasConfigure(self, event):
'''Reset the canvas window to encompass inner frame when required'''
canvas_width = event.width
self._canvas.itemconfig(self._canvas_window, width=canvas_width)