-
Notifications
You must be signed in to change notification settings - Fork 7
/
Tabs.py
executable file
·319 lines (234 loc) · 11.7 KB
/
Tabs.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
'''
NRGsuite: PyMOL molecular tools interface
Copyright (C) 2011 Gaudreault, F., Morency, LP. & Najmanovich, R.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys
if sys.version_info[0] < 3:
from Tkinter import *
import Queue
else:
from tkinter import *
import queue as Queue
import General
class Tab(object):
# 100 ms
TKINTER_UPDATE_INTERVAL = 100
def __init__(self, top, PyMOL, FrameButton, FrameName, Vars, Prefs):
self.PyMOL = PyMOL
self.Prefs = Prefs
self.top = top
self.Tab = FrameButton
self.FrameName = FrameName
self.font_Text = self.top.font_Text
self.font_Title = self.top.font_Title
self.font_Title_H = self.top.font_Title_H
self.Color_Black = self.top.Color_Black
self.Color_Blue = self.top.Color_Blue
self.Color_White = self.top.Color_White
self.Color_Red = self.top.Color_Red
self.DisplayMessage = self.top.DisplayMessage
self.StateList = []
self.Validator = []
self.Vars = Vars
self.Def_Vars()
self.Init_Vars()
self.fFrame = self.Frame()
self.Trace()
''' ==================================================================================
FUNCTION Def_Vars: Define extra variables for the tab
================================================================================== '''
def Def_Vars(self):
return
''' ==================================================================================
FUNCTION Init_Vars: Sets the default values of the variables
================================================================================== '''
def Init_Vars(self):
return
''' ==================================================================================
FUNCTION Show: Displays the frame onto the middle main frame
================================================================================== '''
def Show(self):
self.Load_Message()
self.fFrame.pack(fill=BOTH, expand=True)
''' ==================================================================================
FUNCTION After_Show: Actions related after showing the frame
================================================================================== '''
def After_Show(self):
return
''' ==================================================================================
FUNCTION Del_Trace: Deletes observer callbacks
================================================================================= '''
def Del_Trace(self):
return
''' ==================================================================================
FUNCTION Before_Kill_Frame: Actions related before killing a frame
================================================================================= '''
def Before_Kill_Frame(self):
return True
''' ==================================================================================
FUNCTION Kill_Frame: Kills the main frame window
================================================================================= '''
def Kill_Frame(self):
self.fFrame.pack_forget()
return True
''' ==================================================================================
FUNCTION Frame: Generate the frame in the the middle frame section of FlexAID root
================================================================================== '''
def Frame(self):
return
''' ==================================================================================
FUNCTION Trace: Adds a callback to StringVars
================================================================================= '''
def Trace(self):
return
''' ==================================================================================
FUNCTION Load_Session: Actions related to when a new session is loaded
================================================================================= '''
def Load_Session(self):
return
''' ==================================================================================
FUNCTION Check_Integrity: Compares the checksum of the physical files in the session
================================================================================= '''
def Check_Integrity(self):
return
''' ==================================================================================
FUNCTION Load_Message: Welcome message (frame-specific)
================================================================================= '''
def Load_Message(self):
return
''' ==================================================================================
FUNCTION Validator_Fail: Triggers visual events upon validation failure
================================================================================= '''
''' ==================================================================================
FUNCTION Validator_Fail: Runs actions when tab fails to validate
================================================================================= '''
def Validator_Fail(self):
return
''' ==================================================================================
FUNCTION Validate_Field: Validates an Entry Field in the FlexAID interface
================================================================================== '''
def Validate_Field(self, *args, **kwargs):
input = kwargs.pop('input')
var = kwargs.pop('var')
min = kwargs.pop('min')
max = kwargs.pop('max')
ndec = kwargs.pop('ndec')
tag = kwargs.pop('tag')
_type = kwargs.pop('_type')
rv = -1
if _type == float:
if type(min) != float:
try:
min = float(min.get())
except:
min = 0
if type(max) != float:
try:
max = float(max.get())
except:
max = 0
rv = General.validate_Float(var.get(), min, max, ndec)
elif _type == int:
if type(min) != int:
try:
min = int(min.get())
except ValueError:
min = 0
if type(max) != int:
try:
max = int(max.get())
except ValueError:
max = 100
rv = General.validate_Integer(var.get(), min, max)
# Return-value testing
if rv == 0:
input.config(bg=self.Color_White)
return True
elif rv == -1:
return True
else:
if rv == 1:
self.DisplayMessage("Value has erroneus format for field " + tag, 1)
elif rv == 2:
self.DisplayMessage("The number of decimals cannot exceed (" + str(ndec) + ") for field " + tag, 1)
elif rv == 3:
self.DisplayMessage("Value must be within the range[" + str(min) + "," + str(max) + "] for field " + tag, 1)
input.config(bg=self.Color_Red)
return False
return True
''' ==================================================================================
FUNCTION Validate_Fields: Validate all fields of a frame before switching
================================================================================== '''
def Validate_Fields(self):
for Validator in self.Validator:
if not Validator[1] and \
Validator[2] != None and \
Validator[2]['state'] == 'normal' and \
Validator[2]['bg'] == self.Color_Red:
return Validator[0]
return 0
''' ==================================================================================
FUNCTION Disable_Frame: Disables all controls on main frame
================================================================================= '''
def Disable_Frame(self, *args):
del self.StateList[:]
General.saveState(self.fFrame, self.StateList)
General.setState(self.fFrame)
for arg in args:
General.setState(arg,'normal')
''' ==================================================================================
FUNCTION Enable_Frame: Enables all controls on main frame
================================================================================= '''
def Enable_Frame(self):
General.backState(self.fFrame, self.StateList)
''' ==================================================================================
FUNCTION Start_Update: Starts updating Tkinter with tasks in the queue
================================================================================== '''
def Start_Update(self):
self.queue = Queue.Queue()
self.QueueParse = True
self.Update_Tkinter()
''' ==================================================================================
FUNCTION Condition_Update: Tests tab specific conditions to trigger stopping
================================================================================== '''
def Condition_Update(self):
if self.QueueParse:
return True
else:
return False
''' ==================================================================================
FUNCTION End_Update: Stops updating Tkinter interface using the queue
================================================================================== '''
def End_Update(self):
self.QueueParse = False
''' ==================================================================================
FUNCTION After_Update: Executes tasks when done updating Tkinter
================================================================================== '''
def After_Update(self):
# override this method in base class
return
''' ==================================================================================
FUNCTION Update_Tkinter: update the tkinter interface (tasks queued from the worker)
================================================================================== '''
def Update_Tkinter(self):
# Check every 100 ms if there is something new in the queue.
while self.queue.qsize():
try:
func = self.queue.get()
func()
except Queue.Empty:
pass
if self.Condition_Update():
self.top.root.after(self.TKINTER_UPDATE_INTERVAL, self.Update_Tkinter)
else:
self.After_Update()