Skip to content

Commit 3cecd83

Browse files
committed
WIP: starter GUI
1 parent e5de8b6 commit 3cecd83

File tree

4 files changed

+198
-6
lines changed

4 files changed

+198
-6
lines changed

DragonPy_CLI.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
print("-"*79)
2828
print()
2929

30-
from dragonpy.core.cli import cli
31-
cli()
30+
from dragonpy.core.cli import main
31+
main()

dragonpy/core/cli.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import atexit
1717
import locale
1818
import logging
19-
import unittest
20-
from dragonpy.tests import run_tests
19+
import sys
2120

2221
try:
2322
# https://pypi.python.org/pypi/click/
@@ -35,6 +34,8 @@
3534
from basic_editor.editor import run_basic_editor
3635

3736
import dragonpy
37+
from dragonpy.core.gui_starter import start_gui
38+
from dragonpy.tests import run_tests
3839
from dragonpy.CoCo.config import CoCo2bCfg
3940
from dragonpy.CoCo.machine import run_CoCo2b
4041
from dragonpy.Dragon32.config import Dragon32Cfg
@@ -204,5 +205,17 @@ def tests(verbosity, failfast):
204205
run_tests(verbosity, failfast)
205206

206207

208+
def main():
209+
if len(sys.argv)==1:
210+
def confirm():
211+
# don't close the terminal window directly
212+
# important for windows users ;)
213+
click.prompt("Please press [ENTER] to exit", default="", show_default=False)
214+
atexit.register(confirm)
215+
216+
start_gui(__file__, machine_dict)
217+
else:
218+
cli()
219+
207220
if __name__ == "__main__":
208-
cli()
221+
main()

dragonpy/core/gui_starter.py

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env python
2+
# encoding:utf8
3+
4+
"""
5+
DragonPy - Dragon 32 emulator in Python
6+
=======================================
7+
8+
:created: 2015 by Jens Diemer - www.jensdiemer.de
9+
:copyleft: 2015 by the DragonPy team, see AUTHORS for more details.
10+
:license: GNU GPL v3 or above, see LICENSE for more details.
11+
"""
12+
13+
from __future__ import absolute_import, division, print_function
14+
import subprocess
15+
import os
16+
import distutils
17+
from dragonlib.utils import six
18+
19+
import sys
20+
import time
21+
import logging
22+
import string
23+
import dragonpy
24+
from dragonpy.core import configs
25+
26+
try:
27+
# Python 3
28+
import queue
29+
import tkinter
30+
from tkinter import filedialog
31+
from tkinter import messagebox
32+
from tkinter import scrolledtext
33+
from tkinter import font as TkFont
34+
except ImportError:
35+
# Python 2
36+
import Queue as queue
37+
import Tkinter as tkinter
38+
import tkFileDialog as filedialog
39+
import tkMessageBox as messagebox
40+
import ScrolledText as scrolledtext
41+
import tkFont as TkFont
42+
43+
log = logging.getLogger(__name__)
44+
45+
46+
VERBOSITY_DICT = {
47+
1: "hardcode DEBUG ;)",
48+
10: "DEBUG",
49+
20: "INFO",
50+
30: "WARNING",
51+
40: "ERROR",
52+
50: "CRITICAL/FATAL",
53+
99: "nearly all off",
54+
100: "all off",
55+
}
56+
VERBOSITY_DEFAULT_VALUE = 100
57+
58+
VERBOSITY_DICT2={}
59+
VERBOSITY_STRINGS = []
60+
VERBOSITY_DEFAULT=None
61+
62+
for no,text in sorted(VERBOSITY_DICT.items()):
63+
text = "%3i: %s" % (no,text)
64+
if no==VERBOSITY_DEFAULT_VALUE:
65+
VERBOSITY_DEFAULT=text
66+
VERBOSITY_STRINGS.append(text)
67+
VERBOSITY_DICT2[text] = no
68+
69+
# print(VERBOSITY_STRINGS)
70+
# print(VERBOSITY_DICT2)
71+
# print(VERBOSITY_DEFAULT_VALUE, VERBOSITY_DEFAULT)
72+
73+
assert VERBOSITY_DEFAULT is not None
74+
assert VERBOSITY_DICT2[VERBOSITY_DEFAULT] == VERBOSITY_DEFAULT_VALUE
75+
76+
# sys.exit()
77+
78+
79+
80+
class GuiStarter(object):
81+
def __init__(self, cli_file, machine_dict):
82+
self.cli_file = os.path.abspath(cli_file)
83+
self.machine_dict = machine_dict
84+
85+
self.root = tkinter.Tk(className="STARTER")
86+
self.root.geometry("+%d+%d" % (
87+
self.root.winfo_screenwidth() * 0.1, self.root.winfo_screenheight() * 0.1
88+
))
89+
self.root.title("DragonPy v%s GUI starter" % dragonpy.__version__)
90+
91+
_row = -1
92+
93+
self.var_machine = tkinter.StringVar()
94+
self.var_machine.set(configs.DRAGON64)
95+
for machine_name, data in self.machine_dict.items():
96+
b = tkinter.Radiobutton(self.root, text=machine_name,
97+
variable=self.var_machine, value=machine_name)
98+
_row += 1
99+
b.grid(row=_row, column=1, columnspan=2, sticky=tkinter.W)
100+
101+
_row += 1
102+
103+
self.var_verbosity=tkinter.StringVar()
104+
self.var_verbosity.set(VERBOSITY_DEFAULT)
105+
w = tkinter.Label(self.root, text="Verbosity:")
106+
w.grid(row=_row, column=1, sticky=tkinter.E)
107+
w = tkinter.OptionMenu(
108+
self.root, self.var_verbosity,
109+
*VERBOSITY_STRINGS
110+
)
111+
w.config(width=20)
112+
w.grid(row=_row, column=2, sticky=tkinter.W)
113+
114+
_row += 1
115+
116+
button_run = tkinter.Button(self.root,
117+
width=25,
118+
text="run",
119+
command=self.run_machine
120+
)
121+
button_run.grid(row=_row, column=1, columnspan=2)
122+
123+
_row += 1
124+
125+
w = tkinter.Label(
126+
self.root,
127+
text="CLI script:\n%r" % self.cli_file,
128+
justify=tkinter.LEFT
129+
)
130+
w.grid(row=_row, column=1, columnspan=2)
131+
132+
self.root.update()
133+
134+
def run_machine(self):
135+
machine_name = self.var_machine.get()
136+
print("run: %r" % machine_name)
137+
138+
verbosity = self.var_verbosity.get()
139+
verbosity_no = VERBOSITY_DICT2[verbosity]
140+
print("Verbosity: %i (%s)" % (verbosity_no, verbosity))
141+
142+
cmd_args = [
143+
sys.executable,
144+
self.cli_file,
145+
# # "--log_list",
146+
"--verbosity", "%s" % verbosity_no,
147+
148+
# # "--verbosity", "10", # DEBUG
149+
# # "--verbosity", "20", # INFO
150+
# # "--verbosity", "30", # WARNING
151+
# # "--verbosity", "40", # ERROR
152+
# # "--verbosity", "50", # CRITICAL/FATAL
153+
# # "--verbosity", "99", # nearly all off
154+
# "--verbosity", "100", # all off
155+
#
156+
# # "--log",
157+
# # "dragonpy.components.cpu6809,40",
158+
# # "dragonpy.Dragon32.MC6821_PIA,50",
159+
#
160+
"--machine", machine_name, "run",
161+
# # "--machine", "Vectrex", "run",
162+
# # "--max_ops", "1",
163+
# # "--trace",
164+
]
165+
print("Startup CLI with: %s" % " ".join(cmd_args[1:]))
166+
subprocess.Popen(cmd_args)
167+
168+
def mainloop(self):
169+
""" for standalone usage """
170+
self.root.mainloop()
171+
172+
def start_gui(cli_file, machine_dict):
173+
gui = GuiStarter(cli_file, machine_dict)
174+
gui.mainloop()
175+
176+
177+
if __name__ == "__main__":
178+
from dragonpy.core.cli import main
179+
main()

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def rmtree(path):
192192
long_description=long_description,
193193
url="https://github.com/jedie/DragonPy",
194194
entry_points={
195-
"console_scripts": ["DragonPy = dragonpy.core.cli:cli"],
195+
"console_scripts": ["DragonPy = dragonpy.core.cli:main"],
196196
},
197197
license="GPL v3+",
198198
classifiers=[

0 commit comments

Comments
 (0)