Skip to content

Commit

Permalink
WIP: starter GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Aug 18, 2015
1 parent e5de8b6 commit 3cecd83
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DragonPy_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
print("-"*79)
print()

from dragonpy.core.cli import cli
cli()
from dragonpy.core.cli import main
main()
19 changes: 16 additions & 3 deletions dragonpy/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import atexit
import locale
import logging
import unittest
from dragonpy.tests import run_tests
import sys

try:
# https://pypi.python.org/pypi/click/
Expand All @@ -35,6 +34,8 @@
from basic_editor.editor import run_basic_editor

import dragonpy
from dragonpy.core.gui_starter import start_gui
from dragonpy.tests import run_tests
from dragonpy.CoCo.config import CoCo2bCfg
from dragonpy.CoCo.machine import run_CoCo2b
from dragonpy.Dragon32.config import Dragon32Cfg
Expand Down Expand Up @@ -204,5 +205,17 @@ def tests(verbosity, failfast):
run_tests(verbosity, failfast)


def main():
if len(sys.argv)==1:
def confirm():
# don't close the terminal window directly
# important for windows users ;)
click.prompt("Please press [ENTER] to exit", default="", show_default=False)
atexit.register(confirm)

start_gui(__file__, machine_dict)
else:
cli()

if __name__ == "__main__":
cli()
main()
179 changes: 179 additions & 0 deletions dragonpy/core/gui_starter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/usr/bin/env python
# encoding:utf8

"""
DragonPy - Dragon 32 emulator in Python
=======================================
:created: 2015 by Jens Diemer - www.jensdiemer.de
:copyleft: 2015 by the DragonPy team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""

from __future__ import absolute_import, division, print_function
import subprocess
import os
import distutils
from dragonlib.utils import six

import sys
import time
import logging
import string
import dragonpy
from dragonpy.core import configs

try:
# Python 3
import queue
import tkinter
from tkinter import filedialog
from tkinter import messagebox
from tkinter import scrolledtext
from tkinter import font as TkFont
except ImportError:
# Python 2
import Queue as queue
import Tkinter as tkinter
import tkFileDialog as filedialog
import tkMessageBox as messagebox
import ScrolledText as scrolledtext
import tkFont as TkFont

log = logging.getLogger(__name__)


VERBOSITY_DICT = {
1: "hardcode DEBUG ;)",
10: "DEBUG",
20: "INFO",
30: "WARNING",
40: "ERROR",
50: "CRITICAL/FATAL",
99: "nearly all off",
100: "all off",
}
VERBOSITY_DEFAULT_VALUE = 100

VERBOSITY_DICT2={}
VERBOSITY_STRINGS = []
VERBOSITY_DEFAULT=None

for no,text in sorted(VERBOSITY_DICT.items()):
text = "%3i: %s" % (no,text)
if no==VERBOSITY_DEFAULT_VALUE:
VERBOSITY_DEFAULT=text
VERBOSITY_STRINGS.append(text)
VERBOSITY_DICT2[text] = no

# print(VERBOSITY_STRINGS)
# print(VERBOSITY_DICT2)
# print(VERBOSITY_DEFAULT_VALUE, VERBOSITY_DEFAULT)

assert VERBOSITY_DEFAULT is not None
assert VERBOSITY_DICT2[VERBOSITY_DEFAULT] == VERBOSITY_DEFAULT_VALUE

# sys.exit()



class GuiStarter(object):
def __init__(self, cli_file, machine_dict):
self.cli_file = os.path.abspath(cli_file)
self.machine_dict = machine_dict

self.root = tkinter.Tk(className="STARTER")
self.root.geometry("+%d+%d" % (
self.root.winfo_screenwidth() * 0.1, self.root.winfo_screenheight() * 0.1
))
self.root.title("DragonPy v%s GUI starter" % dragonpy.__version__)

_row = -1

self.var_machine = tkinter.StringVar()
self.var_machine.set(configs.DRAGON64)
for machine_name, data in self.machine_dict.items():
b = tkinter.Radiobutton(self.root, text=machine_name,
variable=self.var_machine, value=machine_name)
_row += 1
b.grid(row=_row, column=1, columnspan=2, sticky=tkinter.W)

_row += 1

self.var_verbosity=tkinter.StringVar()
self.var_verbosity.set(VERBOSITY_DEFAULT)
w = tkinter.Label(self.root, text="Verbosity:")
w.grid(row=_row, column=1, sticky=tkinter.E)
w = tkinter.OptionMenu(
self.root, self.var_verbosity,
*VERBOSITY_STRINGS
)
w.config(width=20)
w.grid(row=_row, column=2, sticky=tkinter.W)

_row += 1

button_run = tkinter.Button(self.root,
width=25,
text="run",
command=self.run_machine
)
button_run.grid(row=_row, column=1, columnspan=2)

_row += 1

w = tkinter.Label(
self.root,
text="CLI script:\n%r" % self.cli_file,
justify=tkinter.LEFT
)
w.grid(row=_row, column=1, columnspan=2)

self.root.update()

def run_machine(self):
machine_name = self.var_machine.get()
print("run: %r" % machine_name)

verbosity = self.var_verbosity.get()
verbosity_no = VERBOSITY_DICT2[verbosity]
print("Verbosity: %i (%s)" % (verbosity_no, verbosity))

cmd_args = [
sys.executable,
self.cli_file,
# # "--log_list",
"--verbosity", "%s" % verbosity_no,

# # "--verbosity", "10", # DEBUG
# # "--verbosity", "20", # INFO
# # "--verbosity", "30", # WARNING
# # "--verbosity", "40", # ERROR
# # "--verbosity", "50", # CRITICAL/FATAL
# # "--verbosity", "99", # nearly all off
# "--verbosity", "100", # all off
#
# # "--log",
# # "dragonpy.components.cpu6809,40",
# # "dragonpy.Dragon32.MC6821_PIA,50",
#
"--machine", machine_name, "run",
# # "--machine", "Vectrex", "run",
# # "--max_ops", "1",
# # "--trace",
]
print("Startup CLI with: %s" % " ".join(cmd_args[1:]))
subprocess.Popen(cmd_args)

def mainloop(self):
""" for standalone usage """
self.root.mainloop()

def start_gui(cli_file, machine_dict):
gui = GuiStarter(cli_file, machine_dict)
gui.mainloop()


if __name__ == "__main__":
from dragonpy.core.cli import main
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def rmtree(path):
long_description=long_description,
url="https://github.com/jedie/DragonPy",
entry_points={
"console_scripts": ["DragonPy = dragonpy.core.cli:cli"],
"console_scripts": ["DragonPy = dragonpy.core.cli:main"],
},
license="GPL v3+",
classifiers=[
Expand Down

0 comments on commit 3cecd83

Please sign in to comment.