forked from ThomasTheSpaceFox/SBTCVM-Mark-2
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlauncher.py
executable file
·910 lines (853 loc) · 29.8 KB
/
launcher.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
#!/usr/bin/env python
import pygame.event
import pygame.key
import pygame.display
import pygame.image
import pygame.mixer
import pygame
import time
import copy
import sys
import os
import subprocess
from pygame.locals import *
import VMSYSTEM.libvmui as vmui
import VMSYSTEM.libvmconf as libvmconf
import VMSYSTEM.libthemeconf as libthemeconf
import VMSYSTEM.liblaunchutils2 as launchutils
import VMSYSTEM.libfilevirtual as libfilevirtual
import traceback
print "SBTCVM Desktop v3.0"
pygame.display.init()
pygame.font.init()
simplefontC = pygame.font.SysFont(None, 28)
simplefontB = pygame.font.SysFont(None, 19)
tilefont = pygame.font.SysFont(None, 19)
catfont = pygame.font.SysFont(None, 19)
pygame.event.set_allowed([QUIT, MOUSEBUTTONDOWN, KEYDOWN])
pygame.display.set_caption(("SBTCVM Desktop"), ("SBTCVM Desktop"))
windowicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'icon.png'))
pygame.display.set_icon(windowicon)
screensurf=pygame.display.set_mode((800, 600), pygame.RESIZABLE)
screenx=800
screeny=600
vmui.initui(screensurf, 1)
diagabt="""SBTCVM Desktop v3.0
Part of the SBTCVM Project
Copyright (c) 2016-2018 Thomas Leathers and Contributors
See README.md for more information."""
#image data:
#bghud=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'launchhud.png')).convert_alpha()
#bghud=pygame.Surface((screenx, screeny), SRCALPHA)
bg=(libthemeconf.bgmake(None)).convert()
sbtcvmbadge=pygame.image.load(os.path.join("VMSYSTEM", "GFX", 'SBTCVMbadge.png')).convert()
bgoverlay=pygame.image.load(os.path.join("VMSYSTEM", "GFX", 'helpbgover.png')).convert_alpha()
gtticn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'gtt.png')).convert_alpha()
introicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'intro.png')).convert_alpha()
DUMMY=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'dummy.png')).convert_alpha()
helpicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'help.png')).convert_alpha()
fvicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'fileview.png')).convert_alpha()
filemanicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'fileman.png')).convert_alpha()
settingsicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'settings.png')).convert_alpha()
themeicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'theme.png')).convert_alpha()
calcicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'calc.png')).convert_alpha()
#creditsicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'credits.png')).convert()
romicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'ROM.png')).convert_alpha()
#miniscribble=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'miniscribble.png')).convert()
taskmanicn=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'taskman.png')).convert_alpha()
consoleicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'console.png')).convert_alpha()
sysshellicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'sysshell.png')).convert_alpha()
genericcaticon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'genericcat.png')).convert_alpha()
#fvfilemenu=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'fvfilemenu.png')).convert()
fmicon=pygame.image.load(os.path.join("VMSYSTEM", "GFX", 'filemenuicon.png')).convert_alpha()
fvfilemenu=vmui.makemenubtn("FILE", icon=fmicon).convert()
fvcatmenu=vmui.makemenubtn("CATEGORY", width=80).convert()
fvsystemmenu=vmui.makemenubtn("SYSTEM", width=60).convert()
#fvcatmenu=pygame.image.load(os.path.join("VMSYSTEM", "GFX", "launch", 'catmenu.png')).convert()
def errorreport(widtitle, area, err):
global scupdate
launchutils.consolewrite(">>ERROR in: \"" + widtitle + "\" terminating")
launchutils.consolewrite(">>Area: " + area)
print(traceback.format_exc())
errdiagtxt=("Error In: \"" + widtitle + "\" terminating... \n Area: " + area + " \n see Standard output for traceback. \n\"" + str(err) + "\"")
vmui.okdiag(errdiagtxt, (screenx // 2), (screeny // 2))
for errline in vmui.listline(str(err)):
launchutils.consolewrite(errline)
scupdate=1
#"fake" program class passed to shell for system shell.
systemshellhelp="""SBTCVM Desktop - System Shell.
help : this text
dir : list current directory
ls : list current directory
cd [directory] : change to specified directory
cd.. : macro for moving up one directory.
shtest : test shell
tasks : list tasks
taskman : start task manager
console : start console"""
class sysshellque:
def __init__(self):
self.title="SYSTEM"
#all system-level class objects have a taskid of -1.
self.taskid=-1
self.qstart=None
self.pathlist=['.']
self.pathstr='.'
self.title="SYSTEM - " + self.pathstr
def QSTART(self):
self.qstartX=self.qstart
self.qstart=None
return self.qstartX
def que(self, signal):
if signal[0]==102:
return ["System Shell ready. Type help for help."]
if signal[0]==101:
return
if signal[0]==100:
self.cmd=((signal[1]).split(" "))[0].lower()
if self.cmd=="taskman":
self.qstart="taskman"
return ["Launching Taskman"]
if self.cmd=="console":
self.qstart="console"
return ["Launching Console"]
if self.cmd=="shtest":
return ["Shell working."]
if self.cmd=="help":
return vmui.listline(systemshellhelp)
#directory navigation
if self.cmd=="dir" or self.cmd=="ls":
return libfilevirtual.dirlist(self.pathlist)
if self.cmd=="cd..":
self.pathlist=libfilevirtual.dir_cdup(self.pathlist)
self.pathstr=os.path.join(*self.pathlist)
self.title="SYSTEM - " + self.pathstr
if self.cmd=="cd":
try:
self.dirstr=((signal[1]).split(" "))[1]
except IndexError:
return ["Error: please specify path!"]
self.tmplist=libfilevirtual.dir_cd(self.pathlist, self.dirstr)
if self.tmplist==None:
return ["Error: Path Not Found"]
else:
self.pathlist=self.tmplist
self.pathstr=os.path.join(*self.pathlist)
self.title="SYSTEM - " + self.pathstr
#task listing
if self.cmd=="tasks":
self.retlist=[]
for self.task in activewids:
self.retlist.extend([("Name: " + self.task.title + " | Order: " + str(self.task.wo) + " | taskid: " + str(self.task.taskid))])
return self.retlist
ShellSystem=sysshellque()
class launchtile:
def __init__(self, label, icon, ltype, lref=None, lref2=None):
self.label=label
self.tileh=90
self.tilew=90
self.iconw=60
self.iconh=60
self.textren2=None
self.textren=tilefont.render(self.label, True, libthemeconf.tiletext)
if self.textren.get_width()>self.tilew:
self.label1, self.label2 = self.label[:len(self.label)//2], self.label[len(self.label)//2:]
self.textren=tilefont.render(self.label1, True, libthemeconf.tiletext)
self.textren2=tilefont.render(self.label2, True, libthemeconf.tiletext)
self.icon=icon
self.ltype=ltype
self.lref=lref
self.lref2=lref2
self.tilebox=pygame.Rect(0, 0, self.tileh, self.tilew)
self.tilesurf=pygame.Surface((self.tilew, self.tileh), SRCALPHA).convert_alpha()
self.tilesurf.fill(libthemeconf.tilecolor)
self.textx=((self.tileh // 2) - (self.textren.get_width() // 2))
self.iconx=((self.tileh // 2) - (self.icon.get_width() // 2))
self.icony=3
self.texty=(self.icony+self.iconh+3)
self.tilesurf.blit(self.icon, (self.iconx, self.icony))
if self.textren2!=None:
self.textx2=((self.tileh // 2) - (self.textren2.get_width() // 2))
self.tilesurf.blit(self.textren2, (self.textx2, self.texty + 8))
self.tilesurf.blit(self.textren, (self.textx, self.texty - 10))
else:
self.tilesurf.blit(self.textren, (self.textx, self.texty))
if ltype==5:
self.plusrect1=pygame.Rect(6, 2, 4, 12)
self.plusrect2=pygame.Rect(2, 6, 12, 4)
pygame.draw.rect(self.tilesurf, libthemeconf.tiletext, self.plusrect1, 0)
pygame.draw.rect(self.tilesurf, libthemeconf.tiletext, self.plusrect2, 0)
def render(self, xpos, ypos, surf=bg):
self.tilebox=surf.blit(self.tilesurf, (xpos, ypos))
def act(self):
if self.ltype==4:
return "taskman"
if self.lref!=None:
if self.ltype==0:
if self.lref2!=None:
subprocess.Popen(["python", self.lref, self.lref2])
else:
subprocess.Popen(["python", self.lref])
if self.ltype==3:
if self.lref2!=None:
return (self.lref, self.lref2)
else:
return (self.lref, None)
if self.ltype==5:
return (self.lref, None, None)
if self.ltype==1:
subprocess.Popen(["python", "MK2-RUN.py", "-k", self.lref])
if self.ltype==2:
subprocess.Popen(["python", "MK2-RUN.py", self.lref])
if self.ltype==6:
return (self.lref, self.lref2)
#create launchtile objects
helpt=launchtile("Help", helpicn, 0, lref="helpview.py")
filet=launchtile("FileView", fvicn, 0, lref="fileview2.py")
settingt=launchtile("Settings", settingsicn, 0, lref="settings.py")
themet=launchtile("Theme", themeicn, 0, lref="theme.py")
calct=launchtile("Calc", calcicn, 0, lref="calc.py")
#creditt=launchtile("Credits", creditsicn, 3, lref="credits")
introt=launchtile("intro", introicn, 1, lref="intro.streg")
gttt=launchtile("GTT", gtticn, 2, lref="gtt.streg")
starryt=launchtile("Starry", romicon, 2, lref="starry.streg")
rayburstt=launchtile("Ray Burst", romicon, 2, lref="rayburst.streg")
dazzlet=launchtile("Dazzle", romicon, 1, lref="dazzle.streg")
pixelpatt=launchtile("Pixel Patterns", romicon, 2, lref="pixelpat.streg")
#launch tools
#widtest=launchtile("Test tool", DUMMY, 3, lref="TEST")
#widscribble=launchtile("Scribble", miniscribble, 3, lref="scribble")
#widcred=launchtile("credits", DUMMY, 3, lref="credits")
TASKMAN=launchtile("Task Manager", taskmanicn, 4)
LAUNCHCON=launchtile("Console", consoleicon, 3, lref="LaunchConsole")
LAUNCHSHELL=launchtile("System Shell", sysshellicon, 3, lref="shell", lref2=ShellSystem)
LAUNCHFILE=launchtile("File Manager", filemanicon, 3, lref="fileman")
#prevent rect problems with desk category
DESKFILE=launchtile("File Manager", filemanicon, 3, lref="fileman")
DESKHELP=launchtile("Help", helpicn, 0, lref="helpview.py")
#testwid=launchutils.testwid(screensurf, 40, 40)
activewids=[]
#category lists
maincat=[filet, calct, settingt, themet, helpt]
gamescat=[gttt]
welcomecat=[introt]
democat=[introt, starryt, rayburstt, dazzlet, pixelpatt]
ltoolcat=[TASKMAN, LAUNCHCON, LAUNCHSHELL, LAUNCHFILE]
plugincat=[]
myvmcat=[]
mytromscat=[]
otherromscat=[]
for vmuserfile in libfilevirtual.diriterate(["VMUSER"]):
if (vmuserfile.lower()).endswith(".trom"):
mytromscat.extend([launchtile((vmuserfile.rsplit('.', 1)[0]), romicon, 2, lref=os.path.join("VMUSER", vmuserfile))])
for romfile in libfilevirtual.diriterate(["ROMS"]):
if (romfile.lower()).endswith(".trom"):
otherromscat.extend([launchtile((romfile.rsplit('.', 1)[0]), romicon, 2, lref=os.path.join("ROMS", romfile))])
for plug in launchutils.pluglist:
PLUGTILE=launchtile(plug.label, plug.icon, 5, lref=plug.classref)
plugincat.extend([PLUGTILE])
if 0 in plug.catid:
maincat.extend([PLUGTILE])
if 1 in plug.catid:
gamescat.extend([PLUGTILE])
if 2 in plug.catid:
welcomecat.extend([PLUGTILE])
if 3 in plug.catid:
democat.extend([PLUGTILE])
if 4 in plug.catid:
ltoolcat.extend([PLUGTILE])
plugcatt=launchtile("Plugins", genericcaticon, 6, lref="Plugins", lref2=plugincat)
maincatt=launchtile("Main", genericcaticon, 6, lref="main", lref2=maincat)
welcomet=launchtile("Welcome", genericcaticon, 6, lref="Welcome", lref2=welcomecat)
maincat.extend([welcomet])
maincat.extend([plugcatt])
myvmt=launchtile("My VM", genericcaticon, 6, lref="My VM", lref2=myvmcat)
mytromst=launchtile("My TROMs", genericcaticon, 6, lref="My TROMs", lref2=mytromscat)
myvmcat.extend([mytromst])
moreromst=launchtile("More TROMs", genericcaticon, 6, lref="More TROMs", lref2=otherromscat)
demot=launchtile("VM Apps", genericcaticon, 6, lref="VM Applications", lref2=democat)
democat.extend([moreromst])
gamest=launchtile("Games", genericcaticon, 6, lref="Games", lref2=gamescat)
ltoolt=launchtile("Desk Apps", genericcaticon, 6, lref="Desk Applications", lref2=ltoolcat)
#note: these should be unique class instances, (create duplicates if needed)
deskcat=[DESKFILE, DESKHELP, maincatt, demot, gamest, ltoolt, myvmt]
#category definitions
tilelist=deskcat
catid=0
catname="Main"
#categoru menu
cmitem0=vmui.menuitem("Main", "MAIN")
cmitem1=vmui.menuitem("Games", "GAMES")
cmitem2=vmui.menuitem("Welcome", "WELCOME")
cmitem3=vmui.menuitem("Demos", "DEMOS")
cmitem4=vmui.menuitem("Mini Tools", "LTOOL")
cmitem5=vmui.menuitem("Plugins", "PLUG")
catmenu=[cmitem0, cmitem1, cmitem2, cmitem3, cmitem4, cmitem5]
#widitem0=vmui.menuitem("main",
#file menu
fmhelp=vmui.menuitem("Help", "HELP")
fmabout=vmui.menuitem("About Desktop", "ABOUT")
fmabout2=vmui.menuitem("readme", "ABOUT2")
fmtask=vmui.menuitem("Task Manager", "TASKMAN")
fmcon=vmui.menuitem("Console", "CON")
fmbg=vmui.menuitem("Background", "SETBG")
fmquit=vmui.menuitem("Quit", "QUIT")
filemenu=[fmhelp, fmabout, fmabout2, fmbg, fmquit]
#system menu
sysyssh=vmui.menuitem("Shell", "SYSSHELL")
sytask=vmui.menuitem("Task Manager", "TASKMAN")
sycon=vmui.menuitem("Console", "CON")
syfile=vmui.menuitem("Fileman", "FILEMAN")
syscshot=vmui.menuitem("Screenshot", "SCSHOT")
systemmenu=[sysyssh, syfile, sytask, sycon, syscshot]
versnumgfx=simplefontB.render("v2.0.3", True, libthemeconf.hudtext)
bg.blit(bgoverlay, ((screenx - 250), (screeny - 250)))
pygame.key.set_repeat(250, 50)
movewid=0
widtomove=None
scupdate=1
qflg=0
resizeflg=0
uptcat=1
redrawhud=1
taskidcnt=0
fullredraw=0
#wids hidden from task switcher bar
hiddenwids=list()
uptlist=list()
hudtasksw=launchutils.hudswitch(screensurf, 0, 114, 0, [activewids, hiddenwids])
hudtasksw.taskid=taskidcnt
hudtaskswid=taskidcnt
activewids.extend([hudtasksw])
hiddenwids.extend([taskidcnt])
taskidcnt += 1
catsellist=list()
engtimer=pygame.time.Clock()
#keep track of taskman taskids. (to prevent sneaky programs from messing with things...)
taskmanlist=list()
launchutils.consolewrite(">>SBTCVM Desktop v3.0")
while qflg==0:
#pygame window resize logic
if resizeflg==1:
resizeflg=2
elif resizeflg==2:
if resw<300:
resw=300
if resh<300:
resh=300
screensurf=pygame.display.set_mode((resw, resh), pygame.RESIZABLE)
bg=(libthemeconf.bgmake(None)).convert()
bg=pygame.transform.scale(bg, (resw, resh))
scupdate=1
resizeflg=0
screeny=resh
screenx=resw
bg.blit(bgoverlay, ((screenx - 250), (screeny - 250)))
hudtasksw.resizet(0, 0)
redrawhud=1
elif fullredraw==1:
fullredraw=0
bg=(libthemeconf.bgmake(None)).convert()
bg=pygame.transform.scale(bg, (screenx, screeny))
bg.blit(bgoverlay, ((screenx - 250), (screeny - 250)))
redrawhud=1
#hud rendering. (draws onto bg)
if redrawhud==1:
redrawhud=0
hudrect=pygame.Rect(0, 0, screenx, 44)
pygame.draw.rect(bg, libthemeconf.hudbg, hudrect, 0)
bg.blit(sbtcvmbadge, ((screenx-120), 0))
bg.blit(versnumgfx, ((screenx - versnumgfx.get_width() - 10), 30))
#
filemx=bg.blit(fvfilemenu, (3, 3))
#sysmx=bg.blit(fvsystemmenu, (133, 3))
sysmx=bg.blit(fvsystemmenu, (48, 3))
uptcat=1
#category button redraw (avoid full hud redraw on cat change
if uptcat==1:
uptcat=0
#catmx=bg.blit(fvcatmenu, (48, 3))
#menulabel=catfont.render(catname, True, libthemeconf.btntext)
#bg.blit(menulabel, ((48+40-(menulabel.get_width() // 2)), 5))
tilex=10
tiley=60
tilejumpx=100
tilejumpy=95
#tile render
for tile in tilelist:
tile.render(tilex, tiley, surf=bg)
if tilex+tilejumpx+90<screenx:
tilex += tilejumpx
else:
tilex=10
tiley += tilejumpy
#display drawing
if scupdate==1:
scupdate=0
screensurf.blit(bg, (0, 0))
#minitool render
activewids.sort(key=lambda x: x.wo, reverse=True)
for wid in activewids:
try:
wid.render()
uptlist.extend([wid.framerect])
except Exception as err:
errorreport(wid.title, "Render", err)
activewids.remove(wid)
pygame.display.update()
else:
#passive minitool renderer to keep minitools updated.
uptlist=list()
activewids.sort(key=lambda x: x.wo, reverse=True)
for wid in activewids:
try:
#render should return either none or a list of updated areas.
widrectret=wid.render()
if widrectret==None:
uptlist.extend([wid.framerect])
else:
uptlist=uptlist + widrectret
except Exception as err:
errorreport(wid.title, "Render", err)
activewids.remove(wid)
pygame.display.update(uptlist)
#window movement
if movewid==1:
prevpos=movepos
movepos=pygame.mouse.get_pos()
xoff =(prevpos[0] - movepos[0])
yoff =(prevpos[1] - movepos[1])
try:
widtomove.movet(xoff, yoff)
except Exception as err:
errorreport(wid.title, "Window Move", err)
activewids.remove(widtomove)
movewid=0
scupdate=1
#time.sleep(0.04)
elif movewid==2:
prevpos=movepos
movepos=pygame.mouse.get_pos()
xoff =(prevpos[0] - movepos[0])
yoff =(prevpos[1] - movepos[1])
try:
widtomove.resizet(xoff, yoff)
except AttributeError:
pass
except Exception as err:
errorreport(wid.title, "Window Move", err)
activewids.remove(widtomove)
movewid=0
scupdate=1
# time.sleep(0.04)
#else:
# time.sleep(0.04)
engtimer.tick(30)
#ShellSystem processor
shsysret=ShellSystem.QSTART()
if shsysret=="taskman":
try:
widx=launchutils.taskman(screensurf, 0, 40, 80, argument=activewids)
widx.taskid=taskidcnt
taskidcnt +=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
taskmanlist.extend([widx.taskid])
except Exception as err:
errorreport("Taskman", "Init (TASKMAN)", err)
if shsysret=="console":
try:
widx=launchutils.launchconsole(screensurf, 0, 40, 80)
widx.taskid=taskidcnt
taskidcnt +=1
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("Console", "Init (Console)", err)
#minitool sig processor
for wid in activewids:
noerror=1
try:
widret=wid.sig()
except Exception as err:
errorreport(wid.title, "Signal Query", err)
activewids.remove(wid)
noerror=0
if noerror==1:
if widret!=None:
if widret[0]==0:
widadd=widret[1]
for widd in activewids:
widd.wo += 1
widadd.movet(-40, -80)
widadd.wo=0
widadd.taskid=taskidcnt
taskidcnt +=1
activewids.extend([widadd])
elif widret[0]==1:
if widret[1]==0:
wid.close()
activewids.remove(wid)
scupdate=1
elif widret[0]=="TASKSWITCH" and wid.taskid==hudtaskswid:
wid.sigret=None
if widret[1]==0:
for widq in activewids:
widq.wo += 1
for widd in activewids:
if widd.taskid==widret[2]:
#launchutils.consolewrite("Taskswitcher: bring task: \"" + widd.title + "\" Of TaskID: \"" + str(widd.taskid) + "\" To Front")
widd.wo=0
scupdate=1
elif widret[0]=="CATSEL" and wid.taskid in catsellist:
wid.sigret=None
actret=widret[1]
if actret!=None:
if actret=="taskman":
#widis=launchutils.widlookup("taskman")
try:
widx=launchutils.taskman(screensurf, 0, 40, 80, argument=activewids)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
taskmanlist.extend([widx.taskid])
except Exception as err:
errorreport("Taskman", "Init (TASKMAN)", err)
elif widret[2]==6:
#widis=launchutils.widlookup("taskman")
try:
widx=launchutils.catsel(screensurf, 0, 40, 80, argument=[actret[0], actret[1]])
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
catsellist.extend([widx.taskid])
except Exception as err:
errorreport("Catsel", "Init (CATSEL)", err)
elif len(actret)==3:
widis=actret[0]
try:
widx=widis(screensurf, 0, 40, 80, argument=None)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("<INIT ERROR, SEE TRACEBACK>", "Init (plugin)", err)
else:
widis=launchutils.widlookup(actret[0])
try:
widx=widis(screensurf, 0, 40, 80, argument=actret[1])
widx.taskid=taskidcnt
taskidcnt +=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
scupdate=1
activewids.extend([widx])
#activewids.sort(key=lambda x: x.wo, reverse=True)
except Exception as err:
errorreport("<INIT ERROR, SEE TRACEBACK>", "Init (internal)", err)
elif widret[0]=="TASKMAN" and wid.taskid in taskmanlist:
#reset taskman's return variable.
wid.sigret=None
if widret[1]==0:
for widd in activewids:
if widd.taskid==widret[2]:
if widret[2] not in hiddenwids:
activewids.remove(widd)
widd.close()
scupdate=1
launchutils.consolewrite("Taskman: Close task: \"" + widd.title + "\" Of TaskID: \"" + str(widd.taskid) + "\"")
else:
launchutils.consolewrite("Taskman: ERROR: CANNOT Close task: \"" + widd.title + "\"")
launchutils.consolewrite("Of TaskID: \"" + str(widd.taskid) + "\"")
launchutils.consolewrite("It is a protected task used by the system!")
if widret[1]==1:
if widret[2] not in hiddenwids:
for widq in activewids:
widq.wo += 1
for widd in activewids:
if widd.taskid==widret[2]:
launchutils.consolewrite("Taskman: bring task: \"" + widd.title + "\" Of TaskID: \"" + str(widd.taskid) + "\" To Front")
widd.wo=0
widd.x=40
widd.y=80
widd.movet(0, 0)
scupdate=1
else:
for widd in activewids:
if widd.taskid==widret[2]:
launchutils.consolewrite("Taskman: ERROR: CANNOT bring task: \"" + widd.title + "\"")
launchutils.consolewrite("Of TaskID: \"" + str(widret[2]) + "\" To Front")
launchutils.consolewrite("It is a protected task used by the system!")
break
elif widret[0]=="TASKMAN":
launchutils.consolewrite(">>WARNING: Unauthorized use of TASKMAN signals was blocked.")
launchutils.consolewrite(">>Task name: \"" + wid.title + "\" TaskID: \"" + str(wid.taskid) + "\"")
#event handler
for event in pygame.event.get():
if event.type == QUIT:
qflg=1
for wid in activewids:
try:
wid.hostquit()
except Exception as err:
errorreport(wid.title, "Host Quit", err)
break
#free up these keys for applications...
#if event.type == KEYDOWN and event.key == K_F1:
# subprocess.Popen(["python", "helpview.py", "launcher.xml"])
#elif event.type == KEYDOWN and event.key == K_F8:
# pygame.image.save(screensurf, (os.path.join('CAP', 'SCREENSHOT-launcher.png')))
# break
#minitool keyboard event processors.
elif event.type == KEYDOWN:
for wid in activewids:
if wid.wo==0:
try:
wid.keydown(event)
except Exception as err:
errorreport(wid.title, "Keydown", err)
activewids.remove(wid)
break
if event.type == KEYUP:
for wid in activewids:
if wid.wo==0:
try:
wid.keyup(event)
except Exception as err:
errorreport(wid.title, "Keyup", err)
activewids.remove(wid)
break
#screen resize code activation
if event.type==VIDEORESIZE:
resizeflg=1
resw=event.w
resh=event.h
time.sleep(0.1)
break
#mousebuttonup code
if event.type==MOUSEBUTTONUP:
if movewid==1:
movewid=0
elif movewid==2:
movewid=0
else:
for wid in activewids:
if wid.wo==0:
#if wid.widbox.collidepoint(event.pos)==1:
try:
wid.clickup(event)
except Exception as err:
errorreport(wid.title, "Clickup", err)
activewids.remove(wid)
break
if event.type==MOUSEBUTTONDOWN:
#minitool click processing
notile=0
#first=1
activewids.sort(key=lambda x: x.wo, reverse=False)
for wid in activewids:
#if wid.wo==0 and first==1:
# print "fun"
#first=0
if wid.framerect.collidepoint(event.pos)==1:
notile=1
if not wid.widbox.collidepoint(event.pos)==1:
if wid.closerect.collidepoint(event.pos)==1 and event.button==1:
try:
wid.close()
except Exception as err:
errorreport(wid.title, "Close", err)
activewids.remove(wid)
scupdate=1
break
elif event.pos[1]>(wid.y + wid.widbox.h):
movewid=2
movepos=event.pos
widtomove=wid
if wid.wo!=0:
wid.wo=0
activewids.remove(wid)
for widd in activewids:
widd.wo += 1
activewids.extend([wid])
break
else:
movewid=1
movepos=event.pos
widtomove=wid
if wid.wo!=0:
wid.wo=0
activewids.remove(wid)
for widd in activewids:
widd.wo += 1
activewids.extend([wid])
break
#activewids.insert(0, wid)
#activewids.sort(key=lambda x: x.wo, reverse=True)
else:
try:
wid.click(event)
except Exception as err:
errorreport(wid.title, "Click", err)
activewids.remove(wid)
break
if wid.wo!=0:
wid.wo=0
scupdate=1
activewids.remove(wid)
for widd in activewids:
widd.wo += 1
activewids.extend([wid])
break
#tile click processing
if notile==0:
for tile in tilelist:
if tile.tilebox.collidepoint(event.pos)==1 and event.button==1:
actret=tile.act()
if actret!=None:
if actret=="taskman":
#widis=launchutils.widlookup("taskman")
try:
widx=launchutils.taskman(screensurf, 0, 40, 80, argument=activewids)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
taskmanlist.extend([widx.taskid])
except Exception as err:
errorreport("Taskman", "Init (TASKMAN)", err)
elif tile.ltype==6:
#widis=launchutils.widlookup("taskman")
try:
widx=launchutils.catsel(screensurf, 0, 40, 80, argument=[actret[0], actret[1]])
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
catsellist.extend([widx.taskid])
except Exception as err:
errorreport("Catsel", "Init (CATSEL)", err)
elif len(actret)==3:
widis=actret[0]
try:
widx=widis(screensurf, 0, 40, 80, argument=None)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("<INIT ERROR, SEE TRACEBACK>", "Init (plugin)", err)
else:
widis=launchutils.widlookup(actret[0])
try:
widx=widis(screensurf, 0, 40, 80, argument=actret[1])
widx.taskid=taskidcnt
taskidcnt +=1
#ctivewids=activewids + [widx]
for wid in activewids:
wid.wo += 1
scupdate=1
activewids.extend([widx])
#activewids.sort(key=lambda x: x.wo, reverse=True)
except Exception as err:
errorreport("<INIT ERROR, SEE TRACEBACK>", "Init (internal)", err)
#file menu
if filemx.collidepoint(event.pos)==1 and event.button==1:
menuret=vmui.menuset(filemenu, 3, 43, reclick=0, fontsize=26)
if menuret=="HELP":
subprocess.Popen(["python", "helpview.py", "launcher.xml"])
if menuret=="ABOUT2":
subprocess.Popen(["python", "MK2-TOOLS.py", "textview", "README.md"])
if menuret=="ABOUT":
vmui.aboutdiag(diagabt, (screenx // 2), (screeny // 2))
if menuret=="SETBG":
vmui.settheme(3, 43)
scupdate=1
bg=(libthemeconf.bgmake(None)).convert()
bg=pygame.transform.scale(bg, (screenx, screeny))
bg.blit(bgoverlay, ((screenx - 250), (screeny - 250)))
redrawhud=1
if menuret=="QUIT":
qflg=1
for wid in activewids:
try:
wid.hostquit()
except Exception as err:
errorreport(wid.title, "Host Quit", err)
break
#system menu
if sysmx.collidepoint(event.pos)==1 and event.button==1:
menuret=vmui.menuset(systemmenu, 48, 43, reclick=0, fontsize=26)
if menuret=="TASKMAN":
try:
#widis=launchutils.widlookup("taskman")
widx=launchutils.taskman(screensurf, 0, 40, 80, argument=activewids)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
taskmanlist.extend([widx.taskid])
except Exception as err:
errorreport("Taskman", "Init (TASKMAN)", err)
if menuret=="CON":
try:
widx=launchutils.launchconsole(screensurf, 0, 40, 80)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("Console", "Init (Console)", err)
if menuret=="SYSSHELL":
try:
widx=launchutils.shell(screensurf, 0, 40, 80, argument=ShellSystem)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("Console", "Init (Shell)", err)
if menuret=="FILEMAN":
try:
widx=launchutils.fileman(screensurf, 0, 40, 80)
widx.taskid=taskidcnt
taskidcnt +=1
scupdate=1
for wid in activewids:
wid.wo += 1
activewids.extend([widx])
except Exception as err:
errorreport("Console", "Init (Fileman)", err)
if menuret=="SCSHOT":
pygame.image.save(screensurf, (os.path.join('CAP', 'SCREENSHOT-launcher.png')))