Skip to content

Commit a35a94c

Browse files
committed
move settings in a frame, add status bar + code cleanup
1 parent e6fa73e commit a35a94c

File tree

1 file changed

+80
-71
lines changed

1 file changed

+80
-71
lines changed

dragonpy/core/gui_starter.py

+80-71
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,31 @@
1212

1313
from __future__ import absolute_import, division, print_function
1414
import subprocess
15-
import os
16-
import distutils
17-
from dragonlib.utils import six
18-
1915
import sys
20-
import time
2116
import logging
22-
import string
17+
18+
import os
19+
2320
import dragonpy
2421
from dragonpy.core import configs
2522

2623
if sys.version_info[0] == 2:
2724
# Python 2
28-
import Queue as queue
2925
import Tkinter as tk
30-
import tkFileDialog as filedialog
31-
import tkMessageBox as messagebox
32-
import ScrolledText as scrolledtext
33-
import tkFont as TkFont
26+
# import tkFileDialog as filedialog
27+
# import tkMessageBox as messagebox
28+
# import ScrolledText as scrolledtext
29+
# import tkFont as TkFont
3430
else:
3531
# Python 3
36-
import queue
3732
import tkinter as tk
38-
from tkinter import filedialog
39-
from tkinter import messagebox
40-
from tkinter import scrolledtext
41-
from tkinter import font as TkFont
42-
43-
33+
# from tkinter import filedialog
34+
# from tkinter import messagebox
35+
# from tkinter import scrolledtext
36+
# from tkinter import font as TkFont
4437

4538
log = logging.getLogger(__name__)
4639

47-
4840
VERBOSITY_DICT = {
4941
1: "hardcode DEBUG ;)",
5042
10: "DEBUG",
@@ -57,14 +49,14 @@
5749
}
5850
VERBOSITY_DEFAULT_VALUE = 100
5951

60-
VERBOSITY_DICT2={}
52+
VERBOSITY_DICT2 = {}
6153
VERBOSITY_STRINGS = []
62-
VERBOSITY_DEFAULT=None
54+
VERBOSITY_DEFAULT = None
6355

64-
for no,text in sorted(VERBOSITY_DICT.items()):
65-
text = "%3i: %s" % (no,text)
66-
if no==VERBOSITY_DEFAULT_VALUE:
67-
VERBOSITY_DEFAULT=text
56+
for no, text in sorted(VERBOSITY_DICT.items()):
57+
text = "%3i: %s" % (no, text)
58+
if no == VERBOSITY_DEFAULT_VALUE:
59+
VERBOSITY_DEFAULT = text
6860
VERBOSITY_STRINGS.append(text)
6961
VERBOSITY_DICT2[text] = no
7062

@@ -75,8 +67,26 @@
7567
assert VERBOSITY_DEFAULT is not None
7668
assert VERBOSITY_DICT2[VERBOSITY_DEFAULT] == VERBOSITY_DEFAULT_VALUE
7769

70+
7871
# sys.exit()
7972

73+
class SettingsFrame(tk.LabelFrame):
74+
def __init__(self, master, **kwargs):
75+
tk.LabelFrame.__init__(self, master, text="Settings")
76+
self.grid(**kwargs)
77+
78+
self.var_verbosity = tk.StringVar()
79+
self.var_verbosity.set(VERBOSITY_DEFAULT)
80+
w = tk.Label(self, text="Verbosity:")
81+
w.grid(row=0, column=1, sticky=tk.E)
82+
w = tk.OptionMenu(
83+
self, self.var_verbosity,
84+
*VERBOSITY_STRINGS
85+
)
86+
w.config(width=20)
87+
w.grid(row=0, column=2, sticky=tk.W)
88+
89+
8090
class RunButtonsFrame(tk.LabelFrame):
8191
def __init__(self, master, **kwargs):
8292
tk.LabelFrame.__init__(self, master, text="Run machines")
@@ -89,21 +99,41 @@ def __init__(self, master, **kwargs):
8999
for row, machine_name in enumerate(sorted(self.machine_dict)):
90100
print(row, machine_name)
91101
b = tk.Radiobutton(self, text=machine_name,
92-
variable=self.var_machine, value=machine_name)
102+
variable=self.var_machine, value=machine_name)
93103
b.grid(row=row, column=1, sticky=tk.W)
94104

95105
button_run = tk.Button(self,
96106
width=25,
97107
text="run machine",
98108
command=master.run_machine
99109
)
100-
button_run.grid(row=row+1, column=1)
110+
button_run.grid(row=len(self.machine_dict), column=1)
111+
112+
113+
class MultiStatusBar(tk.Frame):
114+
"""
115+
code from idlelib.MultiStatusBar.MultiStatusBar
116+
"""
117+
118+
def __init__(self, master, **kwargs):
119+
tk.Frame.__init__(self, master)
120+
self.grid(**kwargs)
121+
self.labels = {}
122+
123+
def set_label(self, name, text='', side=tk.LEFT):
124+
if name not in self.labels:
125+
label = tk.Label(self, bd=1, relief=tk.SUNKEN, anchor=tk.W)
126+
label.pack(side=side)
127+
self.labels[name] = label
128+
else:
129+
label = self.labels[name]
130+
label.config(text=text)
101131

102132

103133
class GuiStarter(tk.Tk):
104134
def __init__(self, cli_file, machine_dict):
105135
tk.Tk.__init__(self)
106-
136+
107137
self.cli_file = os.path.abspath(cli_file)
108138
self.machine_dict = machine_dict
109139

@@ -112,29 +142,11 @@ def __init__(self, cli_file, machine_dict):
112142
))
113143
self.title("DragonPy v%s GUI starter" % dragonpy.__version__)
114144

115-
_row = 0
116-
117-
self.var_verbosity=tk.StringVar()
118-
self.var_verbosity.set(VERBOSITY_DEFAULT)
119-
w = tk.Label(self, text="Verbosity:")
120-
w.grid(row=_row, column=1, sticky=tk.E)
121-
w = tk.OptionMenu(
122-
self, self.var_verbosity,
123-
*VERBOSITY_STRINGS
124-
)
125-
w.config(width=20)
126-
w.grid(row=_row, column=2, sticky=tk.W)
127-
128-
_row += 1
129-
130-
w = tk.Label(
131-
self,
132-
text="CLI script:\n%r" % self.cli_file,
133-
justify=tk.LEFT
134-
)
135-
w.grid(row=_row, column=1, columnspan=2)
145+
self.columnconfigure(0, weight=1)
146+
self.rowconfigure(0, weight=1)
136147

137148
self.add_widgets()
149+
self.add_status_bar()
138150

139151
self.update()
140152

@@ -148,40 +160,36 @@ def add_widgets(self):
148160
"sticky": tk.NSEW, # stick to the cell boundary
149161
}
150162

151-
self.run_buttons = RunButtonsFrame(self, column=0, row=0, **defaults)
152-
# self.inputs = Inputs(self, column=0, row=1, **defaults)
153-
# self.actions = Buttons(self, column=1, row=0, rowspan=2, **defaults)
163+
self.frame_settings = SettingsFrame(self, column=0, row=0, **defaults)
164+
self.frame_buttons = RunButtonsFrame(self, column=1, row=0, **defaults)
165+
166+
def add_status_bar(self):
167+
self.status_bar = MultiStatusBar(self,
168+
column=0, row=2, columnspan=2,
169+
sticky=tk.NSEW,
170+
)
171+
self.status_bar.set_label("cli_file", self.cli_file)
172+
# self.status_bar.set_label('bar', "bar")
154173

155174
def run_machine(self):
156-
machine_name = self.run_buttons.var_machine.get()
175+
machine_name = self.frame_buttons.var_machine.get()
157176
print("run: %r" % machine_name)
158177

159-
verbosity = self.var_verbosity.get()
178+
verbosity = self.frame_settings.var_verbosity.get()
160179
verbosity_no = VERBOSITY_DICT2[verbosity]
161180
print("Verbosity: %i (%s)" % (verbosity_no, verbosity))
162181

163182
cmd_args = [
164183
sys.executable,
165184
self.cli_file,
166-
# # "--log_list",
167185
"--verbosity", "%s" % verbosity_no,
168186

169-
# # "--verbosity", "10", # DEBUG
170-
# # "--verbosity", "20", # INFO
171-
# # "--verbosity", "30", # WARNING
172-
# # "--verbosity", "40", # ERROR
173-
# # "--verbosity", "50", # CRITICAL/FATAL
174-
# # "--verbosity", "99", # nearly all off
175-
# "--verbosity", "100", # all off
176-
#
177-
# # "--log",
178-
# # "dragonpy.components.cpu6809,40",
179-
# # "dragonpy.Dragon32.MC6821_PIA,50",
180-
#
187+
# "--log_list",
188+
# "--log",
189+
# "dragonpy.components.cpu6809,40",
190+
# "dragonpy.Dragon32.MC6821_PIA,50",
191+
181192
"--machine", machine_name, "run",
182-
# # "--machine", "Vectrex", "run",
183-
# # "--max_ops", "1",
184-
# # "--trace",
185193
]
186194
print("Startup CLI with: %s" % " ".join(cmd_args[1:]))
187195
subprocess.Popen(cmd_args)
@@ -194,4 +202,5 @@ def start_gui(cli_file, machine_dict):
194202

195203
if __name__ == "__main__":
196204
from dragonpy.core.cli import main
197-
main(confirm_exit=False)
205+
206+
main(confirm_exit=False)

0 commit comments

Comments
 (0)