forked from ThomasTheSpaceFox/SBTCVM-Mark-2
-
Notifications
You must be signed in to change notification settings - Fork 5
/
MK2-TOOLS.py
executable file
·243 lines (229 loc) · 7.98 KB
/
MK2-TOOLS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python
import time
import os
import sys
import pygame
from pygame.locals import *
import VMSYSTEM.libvmconf as libvmconf
#import VMSYSTEM.libbaltcalc as libbaltcalc
import VMSYSTEM.libvmui as vmui
#SBTCVM MK2 Graphical Tools launcher
#needeed by btclock
mixrate=int(libvmconf.getconf("audio", "mixrate"))
try:
cmd=sys.argv[1]
except:
cmd=None
if cmd=="-h" or cmd=="--help" or cmd=="help":
print '''This is MK2-TOOLS.py, a command line tools launcher for SBTCVM Mark 2
commands:
MK2-RUN.py -h (--help) (help): this text
MK2-RUN.py -v (--version) : version information.
MK2-RUN.py -a (--about) : about MK2-RUN.py
MK2-RUN.py -l (--list) : list all tools and their toolnames.
MK2-RUN.py [toolname] : run tool
'''
elif cmd=="-v" or cmd=="--version":
print "SBTCVM MK2-TOOLS tool launcher v2.0.3"
elif cmd=="-l" or cmd=="--list":
print '''List of tools:
[Toolname] | [Tool description]
-----------------------------------------------
btclock : show a balanced ternary clock
pause : test VM pause menu
uicredits : scrolling credits window called by VM's file menu.
yndiag : test yndiag function
okdiag : test okdiag function
menu : test graphical menu function.
textinput : test text input function.
scrollbtn : test scroll buttons.
imgview [image] : fileview's image viewer
textview [file] : fileview's text viewer
codeview [file] : fileview's code viewer
guiasm [tasm file] : GUI wrapper for SBTCVM-asm2.py
namecrunch [string] : test namecrunch function
timecodetest : test ternary Timecode encode/decode'''
elif cmd=="-a" or cmd=="--about":
print '''#SBTCVM Mark 2 tool launcher
v2.0.3
Copyright (c) 2016-2018 Thomas Leathers and Contributors
SBTCVM Mark 2 tool launcher is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SBTCVM Mark 2 tool launcher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SBTCVM Mark 2 tool launcher. If not, see <http://www.gnu.org/licenses/>
'''
elif cmd==None:
print "tip: use MK2-TOOLS.py -h for help."
elif cmd=="namecrunch" or cmd=="timecodetest":
if cmd=="namecrunch":
import VMSYSTEM.libSBTCVM as libSBTCVM
try:
ncruncharg=sys.argv[2]
except IndexError:
ncruncharg="thisisatest"
print ncruncharg
print libSBTCVM.namecrunch(ncruncharg, "-tools-test.log")
if cmd=="timecodetest":
import VMSYSTEM.libSBTCVM as libSBTCVM
for BI in [19.682, 10.000, 0]:
print BI
BG=libSBTCVM.timeencode(BI)
print BG
BQ=libSBTCVM.timedecode(BG)
print BQ
elif cmd=="btclock" or cmd=="guiasm" or cmd=="pause" or cmd=="scrollbtn" or cmd=="uicredits" or cmd=="imgview" or cmd=="textview" or cmd=="codeview" or cmd=="textinput" or cmd=="menu" or cmd=="okdiag" or cmd=="yndiag":
#print "SBTCVM Graphical Tools launcher starting..."
pygame.display.init()
pygame.font.init()
if cmd=="uicredits":
pygame.display.set_caption("SBTCVM Credits", "SBTCVM Credits")
elif cmd=="imgview":
pygame.display.set_caption("imgview", "imgview")
elif cmd=="textview":
pygame.display.set_caption("textview", "textview")
elif cmd=="codeview":
pygame.display.set_caption("codeview", "codeview")
else:
pygame.display.set_caption("SBTCVM Mark 2 | Tools", "SBTCVM Mark 2 | Tools")
GLOBKIOSK=1
if cmd=="imgview":
windowicon=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'imgview64.png'))
pygame.display.set_icon(windowicon)
elif cmd=="textview":
windowicon=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'textview64.png'))
pygame.display.set_icon(windowicon)
elif cmd=="codeview":
windowicon=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'codeview64.png'))
pygame.display.set_icon(windowicon)
else:
windowicon=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'icon64.png'))
pygame.display.set_icon(windowicon)
#screen fonts
if cmd=="uicredits":
screensurf=pygame.display.set_mode((600, 370))
elif cmd=="guiasm":
screensurf=pygame.display.set_mode((800, 600))
elif cmd=="imgview":
screensurf=pygame.display.set_mode((800, 600), pygame.RESIZABLE)
elif cmd=="textview" or cmd=="codeview":
screensurf=pygame.display.set_mode((800, 600), pygame.RESIZABLE)
else:
screensurf=pygame.display.set_mode((800, 600))
#init VMUI library.
vmui.initui(screensurf, 1)
#uicredits is the special creditsscroll wrapper mode used by launcher.py
if cmd=="uicredits":
vmui.toolsscreen(4)
vmui.creditsscroll(topleft=1)
if cmd=="textinput":
vmui.toolsscreen(1)
textinpout=vmui.textinput(4, 210)
print "Input has returned:"
print textinpout
if cmd=="scrollbtn":
vmui.toolsscreen(1)
hscroll=vmui.makehscroll()
screensurf.blit(hscroll[0], (20, 20))
screensurf.blit(hscroll[1], (20, 60))
vscroll=vmui.makevscroll()
screensurf.blit(vscroll[0], (60, 20))
screensurf.blit(vscroll[1], (60, 60))
textinpout=vmui.textinput(4, 210)
print "Input has returned:"
print textinpout
if cmd=="okdiag":
vmui.toolsscreen(1)
#note: to center dialog in a pygame window use half the window width as xpos,
#and half the window height as ypos
screenw=800
screenh=600
xpos=(screenw // 2)
ypos=(screenh // 2)
diagtext='''This is a test.
of vmui.okdiag()
a function to create OK dialogs.'''
diagout=vmui.okdiag(diagtext, xpos, ypos)
print "ok dialog has returned:"
print diagout
diagout=vmui.okdiag("test", xpos, ypos)
print "ok dialog 2 has returned:"
print diagout
if cmd=="yndiag":
vmui.toolsscreen(1)
#note: to center dialog in a pygame window use half the window width as xpos,
#and half the window height as ypos
screenw=800
screenh=600
xpos=(screenw // 2)
ypos=(screenh // 2)
diagtext='''This is a test.
of vmui.yndiag()
a function to create Yes/No dialogs.'''
diagout=vmui.yndiag(diagtext, xpos, ypos)
print "yes/no dialog has returned:"
print diagout
diagout=vmui.yndiag("test", xpos, ypos)
print "yes/no dialog 2 has returned:"
print diagout
if cmd=="menu":
vmui.toolsscreen(1)
mi1=vmui.menuitem("Testing", "ITEM1", icon=windowicon)
mi2=vmui.menuitem("Testing2", "ITEM2")
mi3=vmui.menuitem("Testing3 (this item is not clickable)", "ITEM3", noclick=1)
mi0a=vmui.menuitem("This menu will ignore clicks outside menu. (reclick=2)", "ITEM4", noclick=1)
mi0b=vmui.menuitem("This menu will just return None for clicks outside menu (reclick=0)", "ITEM4", noclick=1)
menulist=[mi0a, mi1, mi2, mi3]
menulist2=[mi0b, mi1, mi2, mi3]
menuret=vmui.menuset(menulist, 4, 210, reclick=2)
vmui.toolsscreen(1)
print "menu has returned:"
print menuret
menuret2=vmui.menuset(menulist2, 20, 210, reclick=0)
print "menu2 has returned:"
print menuret2
if cmd=="imgview":
vmui.toolsscreen(1)
try:
vmui.imgview(sys.argv[2])
except IndexError:
print "MUST SPECIFY IMAGE FILENAME."
if cmd=="guiasm":
vmui.toolsscreen(1)
try:
vmui.guiasm(sys.argv[2])
except IndexError:
print "MUST SPECIFY TASM FILENAME."
if cmd=="textview":
vmui.toolsscreen(1)
try:
vmui.textview(sys.argv[2])
except IndexError:
print "MUST SPECIFY TEXT FILENAME."
if cmd=="codeview":
vmui.toolsscreen(1)
try:
vmui.codeview(sys.argv[2])
except IndexError:
print "MUST SPECIFY TEXT FILENAME."
if cmd=="btclock":
pygame.mixer.init(frequency=mixrate , size=-16)
import VMSYSTEM.libbttools as bttool
vmui.toolsscreen(1)
bttool.initui(screensurf, 1)
bttool.BTCLOCKDATE()
if cmd=="pause":
pygame.mixer.init(frequency=mixrate , size=-16)
print "launching SBTCVM VM pause menu."
#pause menu needs readouts area to be drawn.
vmui.toolsscreen(3)
pmenret=vmui.pausemenu()
if pmenret=="c":
print "Pause menu reports a continue VM"
else:
print 'Pause menu reports a Stop VM / Exit to Main Menu'