Skip to content

Commit fa13250

Browse files
authored
Merge pull request #14 from PovertyAction/ux-improvements
Ux improvements
2 parents 0f2ef5f + 77909e6 commit fa13250

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

tkinter_script.py

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def file_select():
125125

126126
root.after(2000, next_steps(identified_pii, dataset, datap_functions_conn, datap_messages_conn, tkinter_functions_conn, tkinter_messages_conn))
127127

128+
def about():
129+
import webbrowser
130+
webbrowser.open('https://github.com/PovertyAction/PII_detection/blob/master/README.md#pii_detection')
131+
132+
def contact():
133+
import webbrowser
134+
webbrowser.open('https://github.com/PovertyAction/PII_detection/issues')
135+
128136
def next_steps(identified_pii, dataset, datap_functions_conn, datap_messages_conn, tkinter_functions_conn, tkinter_messages_conn):
129137
### Date Detection ###
130138
tkinter_display('in next steps')
@@ -144,6 +152,16 @@ def next_steps(identified_pii, dataset, datap_functions_conn, datap_messages_con
144152
### Exit Gracefully ###
145153
# Consider adding option to restart script.
146154
tkinter_display('Processing complete.')
155+
Button(root, text="Run Again", command=restart_program).pack()
156+
157+
158+
def restart_program():
159+
"""Restarts the current program.
160+
Note: this function does not return. Any cleanup action (like
161+
saving data) must be done before calling this function."""
162+
import os
163+
python = sys.executable
164+
os.execl(python, python, * sys.argv)
147165

148166

149167
if __name__ == '__main__':
@@ -156,11 +174,31 @@ def next_steps(identified_pii, dataset, datap_functions_conn, datap_messages_con
156174
my_gui = GUI(root) # runs code in class GUI
157175

158176
# Styles
159-
root.configure(background='light gray')
177+
menubar = tkinter.Menu(root)#.pack()
178+
179+
# create a pulldown menu, and add it to the menu bar
180+
filemenu = Menu(menubar, tearoff=0)
181+
filemenu.add_command(label="Restart", command=restart_program)
182+
#filemenu.add_command(label="Save", command=hello)
183+
filemenu.add_separator()
184+
filemenu.add_command(label="Exit", command=root.quit)
185+
menubar.add_cascade(label="File", menu=filemenu)
186+
187+
# create more pulldown menus
188+
helpmenu = Menu(menubar, tearoff=0)
189+
helpmenu.add_command(label="About", command=about)
190+
helpmenu.add_command(label="File Issue on GitHub", command=contact)
191+
menubar.add_cascade(label="Help", menu=helpmenu)
192+
193+
root.configure(background='light gray', menu=menubar)
160194
root.style = ttk.Style()
161195
# root.style.theme_use("clam") # ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')
162196
root.style.configure('my.TButton', font=("Calibri", 11, 'bold'), background='white')
163197
root.style.configure('my.TLabel', background='white')
198+
root.style.configure('my.TCheckbutton', background='white')
199+
root.style.configure('my.TMenubutton', background='white')
200+
201+
root.resizable(False, False) # prevents window from being resized
164202

165203
# Display
166204

@@ -191,36 +229,38 @@ def onFrameConfigure(canvas):
191229
ttk.Label(frame, text=app_title, wraplength=536, justify=LEFT, font=("Calibri", 13, 'bold'), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(30, 10))
192230
ttk.Label(frame, text=intro_text, wraplength=546, justify=LEFT, font=("Calibri", 11), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 12))
193231
ttk.Label(frame, text=intro_text_p2, wraplength=546, justify=LEFT, font=("Calibri", 11), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 30))
232+
233+
ttk.Label(frame, text="Start Application:", wraplength=546, justify=LEFT, font=("Calibri", 12, 'bold'), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 10))
194234
ttk.Button(frame, text="Select Dataset", command=file_select, style='my.TButton').pack(anchor='nw', padx=(30, 30), pady=(0, 30))
195235

236+
ttk.Label(frame, text="Options:", justify=LEFT, font=("Calibri", 12, 'bold'), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 10))
237+
238+
# Dropdown
239+
240+
ttk.Label(frame, text="Select Detection Sensitivity:", justify=LEFT, font=("Calibri", 11), style='my.TLabel').pack(anchor='nw', padx=(30,0))
241+
242+
sensitivity = StringVar(frame)
243+
w = ttk.OptionMenu(frame, sensitivity, "Medium (Default)", "Maximum", "High", "Medium (Default)", "Low", "Minimum", style='my.TMenubutton').pack(anchor='nw', padx=(30,0))
244+
# A combobox may be a better choice
245+
196246
# Checkbox
197247

198-
# checkTemp = IntVar() #IntVar only necessary if I need app to change upon being checked
248+
# checkTemp = IntVar() #IntVar only necessary if need app to change upon being checked
199249
# checkTemp.set(0)
200250
# checkCmd.get() == 0 # tests if unchecked, = 1 if checked
201251

202252
checkTemp = 0
253+
checkBox1 = ttk.Checkbutton(frame, variable=checkTemp, onvalue=1, offvalue=0, text="Output Session Log", style='my.TCheckbutton').pack(anchor='nw', padx=(30, 0), pady=(10,0), fill=X)
203254

204-
checkBox1 = Checkbutton(frame, variable=checkTemp, onvalue=1, offvalue=0, text="Output Log").pack(anchor = 'nw', padx=(30, 30))
205-
206-
# Dropdown
207-
208-
sensitivity = StringVar(frame)
209-
sensitivity.set("Medium (Default)") # default value
210-
211-
w = OptionMenu(frame, sensitivity, "Maximum", "High", "Medium (Default)", "Low", "Minimum").pack(anchor = 'nw', padx=(30,30))
255+
ttk.Label(frame, text="Status:", justify=LEFT, font=("Calibri", 12, 'bold'), style='my.TLabel').pack(anchor='nw', padx=(30,0), pady=(30, 0))
256+
first_message = "Awaiting dataset selection."
257+
first_message = datetime.now().strftime("%H:%M:%S") + ' ' + first_message
258+
ttk.Label(frame, text=first_message, wraplength=546, justify=LEFT, font=("Calibri Italic", 11), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 12))
212259

213260
# Listener
214261

215262
root.mainloop() # constantly looping event listener
216263

217-
try:
218-
if len(messages_pipe) != 0:
219-
ttk.Label(frame, text=messages_pipe.get(), wraplength=546, justify=LEFT, font=("Calibri", 11), style='my.TLabel').pack(anchor='nw', padx=(30, 30), pady=(0, 30))
220-
except NameError:
221-
pass
222-
223-
224264
# Extra code
225265

226266
# ### Implement this for improvements to formatting

0 commit comments

Comments
 (0)