forked from onp/gmcr-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_03_irreversibles.py
145 lines (107 loc) · 4.95 KB
/
frame_03_irreversibles.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
# Copyright: (c) Oskar Petersons 2013
"""Frame allowing control over option reversibility.
Loaded by the a_Main_Window module, and implements all of its required
interfaces.
"""
from tkinter import Tk, N, S, E, W, VERTICAL
from tkinter import ttk
from frame_00_frameTemplate import FrameTemplate
from data_01_conflictModel import ConflictModel
from widgets_f03_01_irreversibleToggles import IrreversibleSetter
NSEW = (N, S, E, W)
class IrrevInpFrame(FrameTemplate):
"""Frame allowing control over option reversibility."""
# Label used for button to select frame in the main program.
buttonLabel = 'Irreversible Moves'
# Image used on button to select frame, when frame is active.
activeIcon = 'icons/Irreversible_Moves_ON.gif'
# Image used on button to select frame, when frame is inactive.
inactiveIcon = 'icons/Irreversible_Moves_OFF.gif'
# Help text to be displayed when screen is active.
helpText = ("Specify the reversibility of moves by clicking the arrow "
"until it correctly shows the direction(s) in which a move "
"may be made.")
# ######################## INITIALIZATION ################################
def __init__(self, master, conflict, *args):
"""Initialize the Frame. Does not build widgets."""
FrameTemplate.__init__(self, master, conflict, self.buttonLabel,
self.activeIcon, self.inactiveIcon,
self.helpText)
self.lastBuildDMs = None
# ############################ METHODS ###################################
def hasRequiredData(self):
"""Check that minimum data required to render the frame exists."""
if len(self.conflict.decisionMakers) < 1:
return False
if len(self.conflict.options) < 1:
return False
else:
return True
def dataChanged(self):
"""Check if data has changed since the last build of the Frame."""
if self.lastBuildDMs != self.conflict.decisionMakers.export_rep():
return True
else:
return False
def buildFrame(self):
"""Contruct frame widgets and initialize data."""
if self.built:
return
# Ensure all required parts of the conflict model are properly set-up.
self.lastBuildDMs = self.conflict.decisionMakers.export_rep()
# infoFrame: frame and label definitions (with master 'self.infoFrame')
self.infoLabel = ttk.Label(self.infoFrame, text='')
# helpFrame: frame and label definitions (with master 'self.helpFrame')
self.helpLabel = ttk.Label(self.helpFrame, textvariable=self.helpVar,
wraplength=150)
# Define frame-specific input widgets (with 'self' as master)
self.irrevEntry = IrreversibleSetter(self, self.conflict)
# ######## preliminary gridding and option configuration
# configuring the input frame
self.grid(column=0, row=0, rowspan=5, sticky=NSEW)
self.grid_remove()
self.columnconfigure(0, weight=1)
# configuring infoFrame & infoFrame widgets
self.infoFrame.grid(column=2, row=0, sticky=NSEW, padx=3, pady=3)
self.infoFrame.grid_remove()
self.infoLabel.grid(column=0, row=1, sticky=NSEW)
# configuring helpFrame & helpFrame widgets
self.helpFrame.grid(column=2, row=1, sticky=NSEW, padx=3, pady=3)
self.helpFrame.grid_remove()
self.helpLabel.grid(column=0, row=0, sticky=NSEW)
# configuring frame-specific options
self.irrevEntry.grid(column=0, row=0, sticky=NSEW)
self.rowconfigure(0, weight=1)
# bindings
# None
self.built = True
def refresh(self, *args):
"""Refresh data in all active display widgets."""
self.irrevEntry.refreshDisplay()
def enter(self, *args):
"""Re-grid the screen into the master. Perform required updates."""
if self.dataChanged():
self.clearFrame()
FrameTemplate.enter(self)
# #############################################################################
# ############### TESTING ###########
# #############################################################################
# Code in this section is only run when this module is run by itself. It serves
# as a test of module funcitonality.
def main():
"""Run screen in test window."""
root = Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
cFrame = ttk.Frame(root)
cFrame.columnconfigure(0, weight=1)
cFrame.rowconfigure(1, weight=1)
cFrame.grid(column=0, row=0, sticky=NSEW)
hSep = ttk.Separator(cFrame, orient=VERTICAL)
hSep.grid(column=1, row=0, rowspan=10, sticky=NSEW)
testConflict = ConflictModel('Prisoners.gmcr')
testFrame = IrrevInpFrame(cFrame, testConflict)
testFrame.enter()
root.mainloop()
if __name__ == '__main__':
main()