-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.py
2320 lines (1807 loc) · 80.7 KB
/
main.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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# My New Project... It *is* WSL related. Lets see what happens :)
# Dedicated to the unborn.
# Copyright Paul-E / Opticos Studios 2021-♾
#print("GO PYTHON!!!")
version = "1.7 MSIX"
lc_name = "Licenses1.txt"
import time
import re
# Here we go
import sys
#import pygame
import os
import subprocess
import random
import logging
import iset
import winreg
#import titlebar
import threading
import webbrowser
import ipaddress
# So this is like a strange descendant of GWSL. Lots of common code.
default_icon = "oiwcenteredsmall.png"#"icon3.png"
default_ico = "icon_centered.ico"
program_name = "OpenInWSL"
#args = sys.argv + ["--r"] + [r"C:\Users\PEF\AppData\Roaming\OpenInWSL\settings.json"]#[r"C:\Users\PEF\Desktop\GWSL-Source\assets\x11-icon.png"]
BUILD_MODE = "WIN32" # MSIX or WIN32
debug = False
frozen = 'not'
if getattr(sys, 'frozen', False):
# we are running in a bundle
frozen = 'ever so'
bundle_dir = sys._MEIPASS
else:
# we are running in a normal Python environment
bundle_dir = os.path.dirname(os.path.abspath(__file__))
# region Logging
if debug == True:
print("debug mode")
print('we are', frozen, 'frozen')
print('bundle dir is', bundle_dir)
print('sys.argv[0] is', sys.argv[0])
print('sys.executable is', sys.executable)
print('os.getcwd is', os.getcwd())
asset_dir = bundle_dir + "\\assets\\"
app_path = os.getenv('APPDATA') + f"\\{program_name}\\"
if os.path.isdir(app_path) == False:
# os.mkdir(app_path)
print(subprocess.getoutput('mkdir "' + app_path + '"'))
print("creating appdata directory")
class DuplicateFilter(logging.Filter):
def filter(self, record):
# add other fields if you need more granular comparison, depends on your app
current_log = (record.module, record.levelno, record.msg)
if current_log != getattr(self, "last_log", None):
self.last_log = current_log
return True
return False
logger = logging.Logger(f"{program_name} " + version, level=0)
# logger = logging.getLogger("GWSL " + version)
# Create handlers
f_handler = logging.FileHandler(app_path + 'main.log')
# f_handler.setLevel(10)
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
f_handler.setFormatter(f_format)
# Add handlers to the logger
logger.addHandler(f_handler)
logger.addFilter(DuplicateFilter())
# endregion
try:
iset.path = app_path + "settings.json"
if os.path.exists(app_path + "\\settings.json") == False:
iset.create(app_path + "\\settings.json")
print("creating settings")
else:
sett = iset.read()
if sett["conf_ver"] >= 2:
if debug == True:
print("Settings up to date")
else:
print("Updating settings")
old_iset = iset.read()
iset.create(app_path + "\\settings.json")
new_iset = iset.read()
# migrate user settings
new_iset["backend"] = old_iset["backend"]
new_iset["acrylic_enabled"] = old_iset["acrylic_enabled"]
new_iset["theme"] = old_iset["theme"]
new_iset["assocs"] = old_iset["assocs"]
try:
new_iset["hide_donation_reminder"] = old_iset["hide_donation_reminder"]
except:
pass
iset.set(new_iset)
# Get the script ready
import wsl_tools as tools
if os.path.exists(app_path + "GWSL_helper.sh") == False:
# print("Moving helper script")
print(subprocess.getoutput('copy "' + bundle_dir + "\\assets\GWSL_helper.sh" + '" "' + app_path + '"'))
else:
# make sure the script is up to date
scr = open(app_path + "GWSL_helper.sh", "r")
lines = scr.read()
if "v4" in lines:
if debug == True:
print("Script is up to date")
else:
print("Updating Script")
print(subprocess.getoutput('copy "' + bundle_dir + "\\assets\GWSL_helper.sh" + '" "' + app_path + '"'))
if os.path.exists(app_path + lc_name) == False:
print("Moving Licenses")
print(subprocess.getoutput('copy "' + bundle_dir + "\\assets\\" + lc_name + '" "' + app_path + '"'))
except Exception as e:
logger.exception("Exception occurred - Config generation")
sys.exit()
tools.script = app_path + "\\GWSL_helper.sh"
enable = """Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open in WSL]
"Icon"="ic_path"
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open in WSL\command]
@="app_path"
"""
disable = """Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open in WSL]
"Icon"="ic_path"
[-HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open in WSL\command]
@="app_path"
"""
#if app_mode != "MSIX":
try:
if os.path.exists(app_path + "context.ico") == False:
print("Moving Context Icon")
print(subprocess.getoutput('copy "' + bundle_dir + "\\assets\\" + "context.ico" + '" "' + app_path + '"'))
if BUILD_MODE == "MSIX":
if os.path.exists(app_path + "\\context_enable.reg") == False:
with open(app_path + "\\context_enable.reg", "w") as enabler:
ic_path = app_path.replace("""\\""", """\\\\""") + "context.ico"
apps_path = os.getenv('LOCALAPPDATA').replace("""\\""", """\\\\""") + """\\\\Microsoft\\\\WindowsApps\\\\oiw.exe %1"""
enable = enable.replace("ic_path", ic_path)
enable = enable.replace("app_path", apps_path)
enabler.write(enable)
enabler.close()
if os.path.exists(app_path + "\\context_disable.reg") == False:
with open(app_path + "\\context_disable.reg", "w") as disabler:
ic_path = app_path.replace("""\\""", """\\\\""") + "context.ico"
apps_path = os.getenv('LOCALAPPDATA').replace("""\\""", """\\\\""") + """\\\\Microsoft\\\\WindowsApps\\\\oiw.exe %1"""
disable = disable.replace("ic_path", ic_path)
disable = disable.replace("app_path", apps_path)
disabler.write(disable)
disabler.close()
else:
# WIN32
if os.path.exists(app_path + "\\context_enable_w32.reg") == False:
with open(app_path + "\\context_enable_w32.reg", "w") as enabler:
ic_path = app_path.replace("""\\""", """\\\\""") + "context.ico"
apps_path = app_path.replace("""\\""", """\\\\""") + "oiw.exe %1"
enable = enable.replace("ic_path", ic_path)
enable = enable.replace("app_path", apps_path)
enabler.write(enable)
enabler.close()
if os.path.exists(app_path + "\\context_disable_w32.reg") == False:
with open(app_path + "\\context_disable_w32.reg", "w") as disabler:
ic_path = app_path.replace("""\\""", """\\\\""") + "context.ico"
apps_path = app_path.replace("""\\""", """\\\\""") + "oiw.exe %1"
disable = disable.replace("ic_path", ic_path)
disable = disable.replace("app_path", apps_path)
disabler.write(disable)
disabler.close()
except:
logger.exception("Cannot Create .reg for context menu")
try:
import ctypes
import platform
if int(platform.release()) >= 8:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except Exception as e:
logger.exception("Exception occurred - Cannot set dpi aware")
# Tkinter Stuff
import tkinter as tk
from tkinter import *
from tkinter import ttk
root = None # tk.Tk() #this is intensive... import as needed?
# root.withdraw()
from PIL import Image, ImageTk
import PIL
import PIL.ImageTk
import win32gui
import win32con
import win32api
def get_light():
try:
registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
key = winreg.OpenKey(registry, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize')
key_value = winreg.QueryValueEx(key, 'AppsUseLightTheme')
k = int(key_value[0])
return k
except:
return 0
def get_system_light():
"""
Sets color of white based on Windows registry theme setting
:return:
"""
global light, white, accent
try:
registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
key = winreg.OpenKey(registry, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize')
key_value = winreg.QueryValueEx(key, 'SystemUsesLightTheme')
k = int(key_value[0])
light = False
white = [255, 255, 255]
if k == 1:
light = True
white = [0, 0, 0]
#for i in range(3):
# if accent[i] > 50:
# accent[i] -= 50
return white, light
except:
logger.exception("get l")
white = [255, 255, 255]
light = False
return white, light
default_font = asset_dir + "segoeui.ttf"
import OpticUI as ui
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "4.0.2"
import pygame
# print("whoops")
ui.asset_dir = asset_dir
import animator as anima
#from pygame.locals import *
t = time.perf_counter()
import pygame.gfxdraw
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
ui.init("dpi") # , tk, root)
from ctypes import wintypes, windll
if int(platform.release()) >= 8:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
from win32api import GetMonitorInfo, MonitorFromPoint
from pathlib import Path
sett = iset.read()
show_donate = not sett["hide_donation_reminder"]
def runs(distro, command, nolog=False):
#cmd = '"' + str(command) + '&"'
cmd = shlex.quote(str(command))
cmd = "wsl.exe ~ -d " + str(distro) + " . ~/.profile;nohup /bin/sh -c " + cmd + "&"
#print("runs yay")
if nolog == False:
logger.info(f"(runos) WSL SHELL $ {cmd}")
subprocess.Popen(cmd,
shell=True) # .readlines()
#print("runs. it would be", cmd)
return None
# return wsl_run(distro, command, "runs")
def get_ip(machine):
"""
Get IP of select WSL instance
:return:
"""
# print("get_ip")
cmd = "wsl.exe -d " + str(
machine) + ' ' + "/bin/sh -c " + '"' + """(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""" + '"'
# print(cmd)
result = os.popen(cmd).readlines()[0]
try:
result = result.rstrip()
except:
pass
if "nameserver" in result:
result = result[len("nameserver") + 1:]
try:
ipa = ipaddress.ip_address(result)
except:
cmd = "wsl.exe -d " + str(
machine) + ' ' + "/bin/sh -c " + '"' + """echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""" + '"'
result = os.popen(cmd).readlines()[0]
# result = "localhost"
# print("ipa", ipa, "ipd")
# result = runo3(machine, """echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""")
# print("ip", result, "done")
return result # [0][:-1]
def get_version(machine):
try:
machines = os.popen("wsl.exe -l -v").read() # lines()
machines = re.sub(r'[^a-z A-Z0-9_./\n-]', r'', machines).splitlines()
# machines = machines.splitlines()
machines2 = []
wsl_1 = True
for i in machines:
b = ''.join(i).split()
if 'VERSION' in b:
wsl_1 = False
if 'NAME' not in b and b != [] and b != None:
machines2.append(b)
if wsl_1 == True:
#print("assuming wsl 1")
return 1
for i in machines2:
if i[0] == machine:
return int(i[2])
return 1
except:
return 1
import psutil
def spawn_n_run(machine, command):
#start_t = time.perf_counter()
#fast = time.perf_counter() - start_time
#print("lets go")
ver = get_version(machine)
sett = iset.read()
backend = sett["backend"]
command = command.strip()
l_mode = ""
def start_gwsl():
cancel = False
try:
#print("checking for store version")
proc = subprocess.getoutput("gwsl.exe --r --startup")
if "not recognized" in proc:
raise FileNotFoundError
except:
#print("No Store Version")
if os.path.exists(os.getenv('APPDATA') + "\\GWSL\\gwsl.exe"):
#print("Traditional Version Installed")
try:
subprocess.Popen(os.getenv('APPDATA') + "\\GWSL\\gwsl.exe --r --startup", shell=True)
except:
logger.exception("Cannot start traditional GWSL")
else:
#print("No gwsl found")
logger.info("No GWSL installed. Install or get another xserver")
cancel = True
try:
gtk = ""
qt = ""
append = ""
if backend == "x" or backend == "gwsl":
#print("USING XSERVER")
if backend == "gwsl":
#print("gwsl integration enabled")
#print("For GWSL Integration. Make sure GWSL is running by doing a silent start?")
gwsl_running = False#chk_process.get_running("GWSL_service.exe")
"""
for p in psutil.process_iter(attrs=["name"]):
#print(p)
# if p.status() == "running":
try:
name = p.info['name'].lower()
if "gwsl_vcxsrv" in name:
gwsl_running = True
#print("GWSL is running")
break
except:
continue
"""
def windowEnumerationHandler(hwnd, top_windows):
nonlocal gwsl_running
if "SysTrayIconPy" in win32gui.GetWindowText(hwnd):
gwsl_running = True
top_windows = []
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
if gwsl_running == False:
print("Starting GWSL in silent")
gw = threading.Thread(target=start_gwsl)
gw.daemon=False
gw.start()
#if cancel == False:
test = 0
started = False
#print("finding")
while started == False:
for p in psutil.process_iter(["name"]):
try:
name = p.info['name'].lower()
if "gwsl_vcxsrv" in name:
started = True
print("found")
break
except:
continue
if started == False:
time.sleep(0.4)
test += 1
if test > 10:
break
#print("run")
#fast = time.perf_counter() - start_time
#print(2, fast)
else:
#print("basic x")
logger.info("Hey, I see you are not using GWSL but are using some other xserver. You should get GWSL :-)")
if ver == 1:
# print("check1")
runs(machine, "DISPLAY=:0 PULSE_SERVER=tcp:localhost " + command,
nolog=True)
else:
ip = get_ip(machine).strip()
#print("ready")
# print("check2")
runs(machine,
"DISPLAY=" + str(ip) + f":0 PULSE_SERVER=tcp:{ip} " + command,
nolog=True)
else:
#print("USING WSLG")
runs(machine, command,
nolog=True)
except Exception as e:
logger.exception("Exception occurred - cannot spawn process")
def w2l(file_path):
pass
def path_converter(path):
if "/" in path:
pt = path.split("/")
else:
pt = path.split("\\")
lin = "/mnt/" + pt[0][0].lower()
for f in pt[1:]:
lin += "/" + str(f.lower())
return lin
#home()
def open_help(context):
#print("helper", context)
webbrowser.open("https://opticos.github.io/openinwsl/help")
import win32mica
from win32mica import MICAMODE, ApplyMica
#mode = MICAMODE.DARK # Dark mode mica effect
#from ttkthemes import ThemedStyle
import sv_ttk
def dark_title_bar(window, dark):
#window.update()
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
set_window_attribute = ctypes.windll.dwmapi.DwmSetWindowAttribute
get_parent = ctypes.windll.user32.GetParent
hwnd = get_parent(window.winfo_id())
rendering_policy = DWMWA_USE_IMMERSIVE_DARK_MODE
value = 2 if dark else 0
value = ctypes.c_int(value)
set_window_attribute(hwnd, rendering_policy, ctypes.byref(value), ctypes.sizeof(value))
root = window
root.geometry(str(root.winfo_width()+1) + "x" + str(root.winfo_height()+1))
#Returns to original size
root.geometry(str(root.winfo_width()-1) + "x" + str(root.winfo_height()-1))
def style_dpi(root):
style = ttk.Style(root)
button_font_point = 9#int(ui.inch2pix(0.1) * (12 / 16))
style.configure('TButton', font=("", button_font_point))
radiobutton_font_point = 9#int(ui.inch2pix(0.099) * (12 / 16))
style.configure('TRadiobutton', font=("", radiobutton_font_point))
label_font_point = 9#int(ui.inch2pix(0.099) * (12 / 16))
style.configure('TLabel', font=("", label_font_point))
checkbutton_font_point = 9#int(ui.inch2pix(0.099) * (12 / 16))
style.configure('TCheckbutton', font=("", checkbutton_font_point))
#from ttkthemes import ThemedStyle
def home():
#ui.set_icons(asset_dir + "Paper/")
#k = get_light()
global root
if root:
root.withdraw()
boxRoot = tk.Toplevel(master=root) # , fg="red", bg="black")
boxRoot.withdraw()
else:
root = tk.Tk()
root.withdraw()
sett = iset.read()
if sett["theme"] == "dark":
en = "superhero"
elif sett["theme"] == "light":
en = "lumen"
#style = ThemedStyle(root)
#style.set_theme("equilux")
#root.style = style
#root.style = Style(theme=en)#darkly')
boxRoot = tk.Toplevel(master=root)
boxRoot.withdraw()
#get tkinter hwnd
hwnd = boxRoot.winfo_id()
if sett["theme"] == "dark":
sv_ttk.set_theme("dark")
mode = win32mica.MICAMODE.DARK
elif sett["theme"] == "light":
sv_ttk.set_theme("light")
mode = win32mica.MICAMODE.LIGHT
# Make style detect DPI
style_dpi(root)
#style = ThemedStyle(root)
#style.set_theme("yaru")
#boxRoot.configure(bg=style.lookup("TButton", "background"))
#root.tk.call("source", "azure.tcl")
#root.tk.call("set_theme", "dark")
#label = tk.Label(boxRoot, bg='#000000')
#boxRoot.lift()
#boxRoot.configure(bg="red")
#boxRoot.configure(bg="#000000")
#boxRoot.wm_attributes("-transparent", "#fafafa")
boxRoot.update()
HWND = windll.user32.GetParent(boxRoot.winfo_id())
if sett["theme"] == "dark":
ApplyMica(HWND, ColorMode=mode)
#style = Style(theme='superhero')#darkly')
#boxRoot.style = Style(theme='superhero')#darkly')
def quitter():
boxRoot.quit()
boxRoot.destroy()
boxRoot.running = False
# pygame.quit()
# sys.exit()
return None
boxRoot.title("Open In WSL")
boxRoot.iconname("Dialog")
WIDTH, HEIGHT = ui.inch2pix(5), ui.inch2pix(5.5)
boxRoot.minsize(WIDTH, HEIGHT)
boxRoot.running = True
boxRoot.protocol("WM_DELETE_WINDOW", quitter)
boxRoot.geometry('+%d+%d' % (screensize[0] / 2 - WIDTH / 2, screensize[1] / 2 - HEIGHT / 2 - ui.inch2pix(0.5)))
#boxRoot.configure(background='white')
#boxRoot.iconphoto(False, tk.PhotoImage(file=asset_dir + default_icon))
boxRoot.iconbitmap(asset_dir + default_ico)
# First the label
frame_0 = ttk.Frame(boxRoot)
frame_01 = ttk.Frame(frame_0)
logo = tk.Label(frame_01, text=f"Open In WSL",# font="SunValleyTitleLargeFont",
justify=LEFT)
logo.configure(font=("Segoe UI Semibold",13))
logo.grid(row=0, pady=0, sticky="WN")
explain = tk.Label(frame_01, text=f"Make Linux Apps Windows File Handlers ({version})", justify=LEFT)#, font="SunValleySubtitleFont")
explain.configure(font=("Segoe UI Semibold",10))
explain.grid(row=1, pady=0, sticky="wS")
frame_01.grid(row=0, column=1, padx=0, pady=("0.23i", "0.2i"), sticky="NW", rowspan=1) # , columnspan=3)
imager = Image.open(asset_dir + "oiw6.png")
# imager = imager.resize([48, 48])
im_size = ui.inch2pix(0.5)
img = PIL.ImageTk.PhotoImage(imager.resize([im_size, im_size]))#[75, 75]))
labelm = tk.Label(frame_0, image=img)
labelm.image = img
labelm.grid(row=0, column=0, padx="0.2i", pady=("0.15i", 0))
frame_0.columnconfigure(1, weight=1)
frame_0.grid(row=0, column=0, padx="0.1i", pady=0, sticky="NEW", rowspan=1) # , columnspan=3)
opt_label = ttk.Label(boxRoot, text=" Open In WSL Configuration ", font=("SunValleyBodyLargeFont", 9))
frame_1 = ttk.LabelFrame(boxRoot, style="Card.TFrame", padding="0.14i", labelwidget=opt_label)#text=" Open In WSL Configuration ", , font="SunValleyBodyStrongFont")
#opt_label = ttk.Label(frame_1, text="Open In WSL Configuration:")
#opt_label.grid(row=0, padx=0, pady=10, sticky="w")
gui_frame = ttk.Frame(frame_1)
backend = tk.StringVar()
sett = iset.read()
backend.set(sett["backend"])
def set_back():
sett = iset.read()
sett["backend"] = backend.get()
iset.set(sett)
x_lab = ttk.Label(gui_frame, text="Graphical Backend: ")
x_lab.grid(column=0, row=0, pady="0.1i", sticky="w")
gwsl_radio = ttk.Radiobutton(gui_frame, text="GWSL", value='gwsl', variable=backend, command=set_back)#, style=style)
gwsl_radio.grid(row=0, column=1, sticky="w", ipadx="0.05i")
wslg_radio = ttk.Radiobutton(gui_frame, text="wslg", value='wslg', variable=backend, command=set_back)
wslg_radio.grid(row=0, column=2, sticky="w", ipadx="0.05i")
xserver_radio = ttk.Radiobutton(gui_frame, text="Other XServer", value='x', variable=backend, command=set_back)
xserver_radio.grid(row=0, column=3, sticky="w", ipadx="0.05i")
gui_frame.grid(row=1, sticky="w", padx=0)
acrylic_frame = ttk.Frame(frame_1)
acrylic = tk.StringVar()
sett = iset.read()
if sett["acrylic_enabled"] == True:
en = 1
else:
en = 0
acrylic.set(en)
def set_acrylic():
sett = iset.read()
sett["acrylic_enabled"] = int(acrylic.get()) == 1
iset.set(sett)
x_lab = ttk.Label(acrylic_frame, text="Popup Transparency: ")
x_lab.grid(column=0, row=0, pady="0.1i", sticky="w")
gwsl_radio = ttk.Radiobutton(acrylic_frame, text="On", value=1, variable=acrylic, command=set_acrylic)
gwsl_radio.grid(row=0, column=1, sticky="w", ipadx="0.05i")
wslg_radio = ttk.Radiobutton(acrylic_frame, text="Off", value=0, variable=acrylic, command=set_acrylic)
wslg_radio.grid(row=0, column=2, sticky="w", ipadx="0.05i")
acrylic_frame.grid(row=2, sticky="w", padx=0)
dark_frame = ttk.Frame(frame_1)
darkmode = tk.StringVar()
sett = iset.read()
if sett["theme"] == "dark":
en = "dark"
elif sett["theme"] == "light":
en = "light"
else:
en = "dark"
darkmode.set(en)
def set_theme():
sett = iset.read()
sett["theme"] = darkmode.get()
iset.set(sett)
color = darkmode.get()
HWND = windll.user32.GetParent(boxRoot.winfo_id())
#tk.messagebox.showinfo(master=boxRoot, title="Theme Changed", message="Restart Open In WSL to apply changes")
if darkmode.get() == "dark":
sv_ttk.use_dark_theme()
dark_title_bar(boxRoot, True)
mode = win32mica.MICAMODE.DARK
ApplyMica(HWND, ColorMode=mode)
elif darkmode.get() == "light":
sv_ttk.use_light_theme()
dark_title_bar(boxRoot, False)
mode = win32mica.MICAMODE.LIGHT
#ApplyMica(HWND, ColorMode=mode)
win32mica.Disable(HWND)
style_dpi(root)
x_lab = ttk.Label(dark_frame, text="App Theme: ")
x_lab.grid(column=0, row=0, pady="0.1i", sticky="w")
dark_radio = ttk.Radiobutton(dark_frame, text="Dark", value='dark', variable=darkmode, command=set_theme)
dark_radio.grid(row=0, column=1, sticky="w", ipadx="0.05i")
light_radio = ttk.Radiobutton(dark_frame, text="Light", value='light', variable=darkmode, command=set_theme)
light_radio.grid(row=0, column=2, sticky="w", ipadx="0.05i")
#auto_radio = ttk.Radiobutton(dark_frame, text="Auto", value='auto', variable=darkmode, command=set_theme)
#auto_radio.grid(row=0, column=3, sticky="w", ipadx=5)
dark_frame.grid(row=3, sticky="w", padx=0)
def manage():
#print("opening association manager")
manage_assoc(parent=boxRoot)
frame_buttons = ttk.Frame(boxRoot) #style="Card.TFrame"
manage_button = ttk.Button(frame_buttons, text="Manage File Associations", style="secondary.TButton", command=manage)
manage_button.grid(row=0, column=0, padx=0, ipadx="0.05i", sticky="w", pady=0)
########
frame_22 = ttk.Frame(frame_buttons)
def config():
old_pat = os.getcwd()
os.chdir(app_path)
#os.popen("notepad service.log")
os.popen("settings.json")
os.chdir(old_pat)
def get_gwsl():
webbrowser.open("ms-windows-store://pdp/?productid=9nl6kd1h33v3")
manage_button = ttk.Button(frame_buttons, text="Get GWSL XServer", style="primary.Link.TButton", command=get_gwsl)
#manage_button.grid(row=0, padx=0, pady=5, ipadx=5, sticky="W", column=0)
def optic_web():
webbrowser.open("https://sites.google.com/bartimee.com/opticos-studios/home")
#manage_button = ttk.Button(frame_22, text="Opticos Website", style="primary.Link.TButton", command=optic_web)
manage_button.grid(row=0, padx=0, ipadx="0.2i", sticky="E", column=2)
def logs():
old_pat = os.getcwd()
os.chdir(app_path)
os.popen("notepad main.log")
os.chdir(old_pat)
#manage_button = ttk.Button(frame_22, text="Logs", style="primary.Outline.TButton", command=logs)
#manage_button.grid(row=2, padx=5, pady=5, ipadx=0, sticky="e", column=0)
def license():
old_pat = os.getcwd()
os.chdir(app_path)
#os.popen("notepad service.log")
os.popen("notepad Licenses1.txt")
os.chdir(old_pat)
#manage_button = ttk.Button(frame_22, text="Licenses", style="primary.Outline.TButton", command=license)
#manage_button.grid(row=1, padx=5, pady=5, ipadx=0, sticky="e", column=0)
frame_22.columnconfigure(0, weight=1)
frame_22.columnconfigure(1, weight=1)
frame_22.columnconfigure(2, weight=1)
#frame_22.grid(row=1, sticky="SEW", columnspan=1, pady=("0.1i", "0.05i"))#, padx="0.14i")
frame_1.columnconfigure(0, weight=1)
def context():
try:
w32 = ""
if BUILD_MODE == "WIN32":
w32 = "_w32"
if contexter.get() == 1:
print("Enabling")
#print(subprocess.getoutput(f"regedit /s {app_path}/context_enable{w32}.reg"))
print(subprocess.getoutput(f"reg import {app_path}/context_enable{w32}.reg"))
else:
print("Disabling")
#print(subprocess.getoutput(f"regedit /s {app_path}/context_disable{w32}.reg"))
print(subprocess.getoutput(f"reg import {app_path}/context_disable{w32}.reg"))
except:
logger.exception("cannot toggle context option")
contexter = tk.IntVar()
contexter.set(1)
registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
try:
key = winreg.OpenKey(registry, r'SOFTWARE\Classes\*\shell\Open in WSL\command')
key_value = winreg.QueryValueEx(key, None)
k = key_value[0]
except:
contexter.set(0)
#contexter.set(1)
cont_button = ttk.Checkbutton(frame_1, text='Show "Open In WSL" in Explorer Context Menu', command=context, variable=contexter)
cont_button.grid(row=4, padx=0, pady="0.1i", ipadx="0.05i", sticky="w")
# Donation disabling system (11/30/22)
def hide_donate():
if donater.get() == 1:
show_donate = False
sett = iset.read()
sett["hide_donation_reminder"] = True
iset.set(sett)
donate.grid_forget()
else:
show_donate = True
sett = iset.read()
sett["hide_donation_reminder"] = False
iset.set(sett)
donate.grid(row=3, padx="0.2i", ipadx="0.05i", sticky="wES", pady="0.1i", ipady="0.05i")
donater = tk.IntVar()
donater.set(1)
try:
sett = iset.read()
print(sett["hide_donation_reminder"])
donater.set(1 if sett["hide_donation_reminder"] else 0)
except:
donater.set(0)
ad_button = ttk.Checkbutton(frame_1, text='Disable Donation Reminders', command=hide_donate,
variable=donater)
ad_button.grid(row=5, padx=0, pady="0.1i", ipadx="0.05i", sticky="wNS")
"""
autolaunch = tk.IntVar()
sett = iset.read()
if sett["start_gwsl"] == True:
ent = 1
else:
ent = 0
def launch_gwsl():
sett = iset.read()
sett["start_gwsl"] = autolaunch.get() == 1
iset.set(sett)
autolaunch.set(ent)
cont_button = ttk.Checkbutton(frame_1, text='Auto-Launch GWSL (Sometimes Slower)', command=launch_gwsl, variable=autolaunch)
cont_button.grid(row=5, padx=0, pady=10, ipadx=5, sticky="w")
"""
#frame_1.columnconfigure(1, weight=1)
frame_1.grid(row=1, column=0, padx="0.2i", pady="0.1i", sticky="EW") # , columnspan=3)
frame_buttons.columnconfigure(0, weight=2)
frame_buttons.grid(row=2, column=0, padx="0.2i", pady=("0.1i","0.1i"), sticky="EW")
def donate():
webbrowser.open_new("https://opticos.github.io/openinwsl/#donate")
donate = ttk.Button(boxRoot, text="Please Consider Donating 💖", style="Accent.TButton", command=donate) # old for bootstrapstyle="success.TButton"
if show_donate:
donate.grid(row=3, padx="0.2i", ipadx="0.05i", sticky="wES", pady="0.1i", ipady="0.05i")
#frame_2.columnconfigure(1, weight=1)
#frame_2.grid(row=2, column=0, padx=20, pady=20, sticky="NWE")#, columnspan=4)
#frame_2.grid_columnconfigure(1, weight=1)
frame_3 = ttk.Frame(boxRoot)#, borderwidth=3, relief="ridge")
cancel = ttk.Button(frame_3, text="Website", style="secondary.TButton", command=optic_web)
cancel.grid(row=0, column=0, sticky="we", padx=(0,"0.05i"), ipadx="0.05i", pady=("0.1i", 0))
manage_button = ttk.Button(frame_3, text="Configure", style="primary.Outline.TButton", command=config)
manage_button.grid(row=0, padx="0.05i", ipadx="0.05i", sticky="we", column=1, pady=("0.1i", 0))
manage_button = ttk.Button(frame_3, text="License", style="primary.Outline.TButton", command=license)
manage_button.grid(row=0, padx="0.05i", ipadx=0, sticky="we", column=2, pady=("0.1i", 0))
manage_button = ttk.Button(frame_3, text="Logs", style="primary.Outline.TButton", command=logs)
manage_button.grid(row=0, padx="0.05i", ipadx=0, sticky="We", column=3, pady=("0.1i", 0))
def helper():
open_help("home")
help = ttk.Button(frame_3, text="Help", command=helper)
help.grid(row=0, column=4, sticky="wE", padx=("0.05i", 0), ipadx="0.05i", pady=("0.1i", 0))
#apply = ttk.Button(frame_3, text="Save Configuration", style="success.TButton")
#apply.grid(row=0, column=2, sticky="WE", padx=5, ipadx=5)
frame_3.columnconfigure(0, weight=1)
frame_3.columnconfigure(1, weight=1)
frame_3.columnconfigure(2, weight=1)
frame_3.columnconfigure(3, weight=1)
frame_3.columnconfigure(4, weight=1)
frame_3.rowconfigure(1, weight=2)
frame_3.rowconfigure(2, weight=3)
frame_3.grid(row=4, column=0, padx="0.2i", sticky="WENS", ipady="0.1i", pady=(0, 0))
#HWN = root.winfo_id()
#titlebar.ChangeMenuBarColor(HWN)
#boxRoot.overrideredirect(True)
#lbl = tk.Label(boxRoot, text="Create a Start Menu Shortcut:", justify=CENTER) # , font=("Helvetica", 16))
#lbl.grid(row=0, padx=10, pady=10, sticky="EW")
#boxRoot.grid_rowconfigure(0, weight=0)