12
12
13
13
from __future__ import absolute_import , division , print_function
14
14
import subprocess
15
- import os
16
- import distutils
17
- from dragonlib .utils import six
18
-
19
15
import sys
20
- import time
21
16
import logging
22
- import string
17
+
18
+ import os
19
+
23
20
import dragonpy
24
21
from dragonpy .core import configs
25
22
26
23
if sys .version_info [0 ] == 2 :
27
24
# Python 2
28
- import Queue as queue
29
25
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
34
30
else :
35
31
# Python 3
36
- import queue
37
32
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
44
37
45
38
log = logging .getLogger (__name__ )
46
39
47
-
48
40
VERBOSITY_DICT = {
49
41
1 : "hardcode DEBUG ;)" ,
50
42
10 : "DEBUG" ,
57
49
}
58
50
VERBOSITY_DEFAULT_VALUE = 100
59
51
60
- VERBOSITY_DICT2 = {}
52
+ VERBOSITY_DICT2 = {}
61
53
VERBOSITY_STRINGS = []
62
- VERBOSITY_DEFAULT = None
54
+ VERBOSITY_DEFAULT = None
63
55
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
68
60
VERBOSITY_STRINGS .append (text )
69
61
VERBOSITY_DICT2 [text ] = no
70
62
75
67
assert VERBOSITY_DEFAULT is not None
76
68
assert VERBOSITY_DICT2 [VERBOSITY_DEFAULT ] == VERBOSITY_DEFAULT_VALUE
77
69
70
+
78
71
# sys.exit()
79
72
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
+
80
90
class RunButtonsFrame (tk .LabelFrame ):
81
91
def __init__ (self , master , ** kwargs ):
82
92
tk .LabelFrame .__init__ (self , master , text = "Run machines" )
@@ -89,21 +99,41 @@ def __init__(self, master, **kwargs):
89
99
for row , machine_name in enumerate (sorted (self .machine_dict )):
90
100
print (row , machine_name )
91
101
b = tk .Radiobutton (self , text = machine_name ,
92
- variable = self .var_machine , value = machine_name )
102
+ variable = self .var_machine , value = machine_name )
93
103
b .grid (row = row , column = 1 , sticky = tk .W )
94
104
95
105
button_run = tk .Button (self ,
96
106
width = 25 ,
97
107
text = "run machine" ,
98
108
command = master .run_machine
99
109
)
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 )
101
131
102
132
103
133
class GuiStarter (tk .Tk ):
104
134
def __init__ (self , cli_file , machine_dict ):
105
135
tk .Tk .__init__ (self )
106
-
136
+
107
137
self .cli_file = os .path .abspath (cli_file )
108
138
self .machine_dict = machine_dict
109
139
@@ -112,29 +142,11 @@ def __init__(self, cli_file, machine_dict):
112
142
))
113
143
self .title ("DragonPy v%s GUI starter" % dragonpy .__version__ )
114
144
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 )
136
147
137
148
self .add_widgets ()
149
+ self .add_status_bar ()
138
150
139
151
self .update ()
140
152
@@ -148,40 +160,36 @@ def add_widgets(self):
148
160
"sticky" : tk .NSEW , # stick to the cell boundary
149
161
}
150
162
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")
154
173
155
174
def run_machine (self ):
156
- machine_name = self .run_buttons .var_machine .get ()
175
+ machine_name = self .frame_buttons .var_machine .get ()
157
176
print ("run: %r" % machine_name )
158
177
159
- verbosity = self .var_verbosity .get ()
178
+ verbosity = self .frame_settings . var_verbosity .get ()
160
179
verbosity_no = VERBOSITY_DICT2 [verbosity ]
161
180
print ("Verbosity: %i (%s)" % (verbosity_no , verbosity ))
162
181
163
182
cmd_args = [
164
183
sys .executable ,
165
184
self .cli_file ,
166
- # # "--log_list",
167
185
"--verbosity" , "%s" % verbosity_no ,
168
186
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
+
181
192
"--machine" , machine_name , "run" ,
182
- # # "--machine", "Vectrex", "run",
183
- # # "--max_ops", "1",
184
- # # "--trace",
185
193
]
186
194
print ("Startup CLI with: %s" % " " .join (cmd_args [1 :]))
187
195
subprocess .Popen (cmd_args )
@@ -194,4 +202,5 @@ def start_gui(cli_file, machine_dict):
194
202
195
203
if __name__ == "__main__" :
196
204
from dragonpy .core .cli import main
197
- main (confirm_exit = False )
205
+
206
+ main (confirm_exit = False )
0 commit comments