-
Notifications
You must be signed in to change notification settings - Fork 4
/
Blank_App.py
259 lines (139 loc) · 5.37 KB
/
Blank_App.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
#!/usr/bin/env python3
#
# IP: HILICS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####----- Instructions -----#####
#
# This is a simple template to get started making your own simulation for HILICS
# To create your own App:
# 1. Create a copy of apps/BlankApp.py in the apps directory and name it appropriately
# 2. Rename the BlankApp class to match the new filename (must match exactly for import to work)
# 3. Create a copy of sims/BlankSim.py and name it appropriately
# 4. Rename the BlankSim class
# 5. Update the import statement below to reference your new Sim instead of BlankSim
# 6. Add your App to apps/appsList.txt (this will add it to the main display)
# If you have more than 6 apps, the rest will be shown in the drop-down menu
try:
import Tkinter as tk
from Tkinter import ttk
from Tkinter.font import Font
except ImportError:
import tkinter as tk
from tkinter import ttk
from tkinter.font import Font
##### Create a new sim using BlankSim as a template and update the import here
from sims.BlankSim import BlankSim
from widgets.Dial_Canvas import Dial_Canvas
from widgets.FloatNumpad import FloatNumpad
from widgets.Tank import Tank
import threading
import time
import math
class Blank_App(tk.Frame):
def __init__(self, master=None, default_bg=None, default_fg=None):
self.master = master
##### You can change the color scheme here
self.default_bg = default_bg
self.default_fg = default_fg
self.high_color = '#EC7600'
self.low_color = '#678CB1'
##### Update this line with your Sim class
self.sim = BlankSim()
self.val = 0.0
super().__init__(master)
self.pack()
##### create_widgets is the entry point for setting up the GUI
self.create_widgets()
##### worker_thread handles updating the simulation and any display items
self.running = True
self.thread = threading.Thread(target=self.worker_thread)
self.thread.setDaemon(True)
self.thread.start()
##### This function is called when the App is closing
def clean_up(self):
self.running = False
self.thread.join(1.0)
self.sim.close()
self.master.destroy()
def config_bg(self, wid):
if not self.default_bg is None:
wid['bg'] = self.default_bg
def config_fg(self, wid):
if not self.default_fg is None:
wid['fg'] = self.default_fg
def config_frame(self, frame):
frame['borderwidth'] = 1
frame['relief'] = tk.RIDGE
frame.pack_propagate(0)
frame.grid_propagate(0)
self.config_bg(frame)
def config_btn(self, btn):
btn['font'] = Font(root=self.master, family='Helvetica', size=18)
btn['width'] = 8
btn['height'] = 2
btn['activebackground'] = self.default_bg
btn['activeforeground'] = self.default_fg
btn['bd'] = 0
btn['highlightthickness'] = 1
btn['relief'] = 'ridge'
self.config_bg(btn)
self.config_fg(btn)
def config_label(self, lab):
self.config_bg(lab)
self.config_fg(lab)
##### worker_thread handles updating the simulation and any display items
def worker_thread(self):
while self.running:
try:
##### Update the simulation
self.sim.update()
##### Update display items here
##### Choose an appropriate sleep duration (smaller value for faster processes)
time.sleep(0.01)
except Exception as e:
print(e)
##### These setup methods create the frames for your App
#
# Frame1 is the primary display and is 800 pixels wide by 400 pixels tall (leaving 80 pixels for the bottom panel)
# You can split this frame into columns and rows like IO_Test
# Or you can create a canvas to fill the frame and do all your work in that (like GarageDoor)
#
# I recommend using a canvas
def setup_main_frame(self):
frame = tk.Frame(self, width=800, height=400)
self.config_frame(frame)
frame.grid(row = 0, column=0, columnspan=2, rowspan=1)
self.canvas = tk.Canvas(frame, width=800, height=400, bd=0, highlightthickness=0, relief='ridge')
self.config_bg(self.canvas)
self.canvas.pack()
##### The two bottom frames are for any config buttons and the Back button.
# You can also add images or labels
def setup_bottom_left_frame(self):
frame = tk.Frame(self, width=400, height=80)
self.config_frame(frame)
frame.grid(row = 1, column=0, columnspan=1, rowspan=1)
def setup_bottom_right_frame(self):
frame = tk.Frame(self, width=400, height=80)
self.config_frame(frame)
frame.grid(row = 1, column=1, columnspan=1, rowspan=1)
self.quit = tk.Button(frame, text='Back', command=self.clean_up)
self.config_btn(self.quit)
self.quit.place(relx=0.75, rely=0.5, anchor=tk.CENTER)
##### If you add any methods for setting up frames, call them here
def create_widgets(self):
self.master.minsize(width=800, height=480)
self.master.maxsize(width=800, height=480)
self.setup_main_frame()
self.setup_bottom_left_frame()
self.setup_bottom_right_frame()