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 ()
0 commit comments