-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui_GetSet.py
More file actions
284 lines (213 loc) · 7.88 KB
/
Gui_GetSet.py
File metadata and controls
284 lines (213 loc) · 7.88 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
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
278
279
280
281
282
283
284
class Gui_GetSet():
"""
Main class for creating class specific functions. MainLabelCreate, CharLabelCreate and ChemLabelCreate inherit these functions.
Functions:
"""
def __init__(self):
"""
INIT Method
"""
pass
def tabchange(self, tabobject, index):
"""
Set the current index of a tab object.
Parameters:
- tabobject: The tab object.
- index (int): The index to set for the tab.
Returns:
None
"""
tabobject.setCurrentIndex(index)
def set_label(self, labelobject, labeltext):
"""
Sets the text of a label object.
Parameters:
- labelobject: The label object.
- labeltext (str): The text to set for the label.
Returns:
None
"""
labelobject.setText(labeltext)
def get_lineedit(self, lineeditobject, upper = True):
"""
Gets the text of a line edit object. Optionally updates the text to be uppercase.
Parameters:
- lineeditobject: The line edit object.
- upper (bool): If True, converts the text to uppercase.
Returns:
str: The text of the line edit object.
"""
lineedittext = lineeditobject.text()
if upper:
lineedittext= lineedittext.upper()
lineeditobject.setText(lineedittext)
return lineedittext
def set_lineedit(self, lineeditobject, input):
"""
Sets the text of a line edit object.
Parameters:
- lineeditobject: The line edit object.
- input (str): The text to set for the line edit.
Returns:
None
"""
lineeditobject.setText(input)
def upper_lineedit(self, lineeditobject):
"""
Sets the text of a line edit object to uppercase.
Parameters:
- lineeditobject: The line edit object.
Returns:
None
"""
lineedittext = lineeditobject.text()
lineedittext= lineedittext.upper()
lineeditobject.setText(lineedittext)
def get_date(self, dateobject):
"""
Gets a date from a date time object and splits it into Year, Month, Day.
Parameters:
- dateobject: The date time object.
Returns:
Tuple[int, int, int]: Year, Month, Day
"""
date = dateobject.date().toPython()
year = date.strftime("%Y")
month = date.strftime("%m")
day = date.strftime("%d")
return int(year),int(month),int(day)
def set_date(self, dateobject, dateinput):
"""
Sets the date value in the specific date field.
Parameters:
- dateobject: The date object.
- dateinput: The date to set.
Returns:
None
"""
dateobject.setDate(dateinput)
def encrypt_year(self, encryptyear, startingyear):
"""
Translates a year to an alphanumeric character.
Parameters:
- encryptyear (int): The year to be translated.
- startingyear (int): The starting year for translation.
Returns:
str: The translated alphanumeric character representing the year.
"""
shortyear = chr(int(encryptyear)-startingyear+65)
return shortyear
def decrypt_year(self, decryptyear, startingyear):
"""
Translates alphanumeric characters to a year.
Parameters:
- decryptyear (str): The alphanumeric character representing the year.
- startingyear (int): The starting year for the translation.
Returns:
int: The translated year.
Raises:
TypeError: If the input is not in the correct format.
"""
if isinstance(decryptyear, str) and len(decryptyear) == 1 and decryptyear.isalpha():
year = int(ord(decryptyear.upper())) + startingyear - 65
return year
else:
raise TypeError("Input must be a letter.")
def encrypt_month(self, encryptmonth):
"""
Translates a month to an alphanumeric character.
Parameters:
- encryptmonth (int): The month to be translated.
Returns:
str: The translated alphanumeric character representing the month.
"""
shortmonth = chr(int(encryptmonth)-1+65)
return shortmonth
def decrypt_month(self, decryptmonth):
"""
Translates alphanumeric characters to a month.
Parameters:
- decryptmonth (str): The alphanumeric character representing the month.
Returns:
int: The translated month.
Raises:
TypeError: If the input is not in the correct format.
"""
if isinstance(decryptmonth, str) and len(decryptmonth) == 1 and decryptmonth.isalpha():
month = int(ord(decryptmonth.upper())) + 1 - 65
return month
else:
raise TypeError("Input must be a letter.")
def encrypt_day(self, encryptday):
"""
Translates a day to an alphanumeric character.
Parameters:
- encryptday (int): The day to be translated.
Returns:
str or int: The translated alphanumeric character or integer representing the day.
"""
if int(encryptday) <= 26:
shortday = chr(int(encryptday)-1+65)
else:
shortday = int(encryptday) - 26
return shortday
def decrypt_day(self, decryptday):
"""
Translates alphanumeric characters to a day.
Parameters:
- decryptday (str or int): The alphanumeric character or integer representing the day.
Returns:
int: The translated day.
Raises:
TypeError: If the input is not in the correct format.
"""
try:
if int(decryptday) <= 5:
day = int(decryptday) + 26
else:
raise TypeError("Wrong format for the day.")
except:
if isinstance(decryptday, str) and len(decryptday) == 1 and decryptday.isalpha():
day = int(ord(decryptday.upper())) + 1 - 65
else:
raise TypeError("Wrong format for the day.")
return day
def getstate_checkbox(self, checkboxobject):
"""
Get the state of a checkbox.
Parameters:
- checkboxobject: The checkbox object.
Returns:
bool: True if the checkbox is checked, False otherwise.
"""
if checkboxobject.isChecked():
return True
else:
return False
def checkbox_visibilitychange(self, checkboxobject, visibleobject, inverse = False):
"""
Set the visibility of an object according to the state of a checkbox object.
Parameters:
- checkboxobject: The checkbox object.
- visibleobject: The object whose visibility is controlled by the checkbox.
- inverse (bool): If True, the visibility is set inversely to the checkbox state.
Returns:
bool: The new visibility state of the object.
Note:
If inverse is True, the object's visibility will be set to False when the checkbox is checked,
and vice versa.
"""
if inverse:
if checkboxobject.isChecked():
visibleobject.setVisible(False)
return False
else:
visibleobject.setVisible(True)
return True
else:
if checkboxobject.isChecked():
visibleobject.setVisible(True)
return True
else:
visibleobject.setVisible(False)
return False