-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ dist | |
venv/ | ||
test.py | ||
.DS_Store | ||
tmp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.black] | ||
line-length = 88 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
from dataclasses import dataclass, field | ||
from sssekai.__main__ import create_parser | ||
from typing import Any, List | ||
from argparse import ArgumentParser | ||
from logging import basicConfig | ||
|
||
try: | ||
from gooey import Gooey, GooeyParser | ||
except ImportError as e: | ||
print("Please install sssekai[gui] to use the GUI") | ||
raise e | ||
|
||
|
||
# https://github.com/chriskiehl/Gooey/issues/826#issuecomment-1240180894 | ||
def __Gooey_120_patch_TaskBar(): | ||
from rewx import widgets | ||
from rewx.widgets import set_basic_props, dirname | ||
from rewx.dispatch import update | ||
import wx | ||
import sys | ||
|
||
@update.register(wx.Frame) | ||
def frame(element, instance: wx.Frame): | ||
props = element["props"] | ||
set_basic_props(instance, props) | ||
if "title" in props: | ||
instance.SetTitle(props["title"]) | ||
if "show" in props: | ||
instance.Show(props["show"]) | ||
if "icon_uri" in props: | ||
pass # No icons for now | ||
if "on_close" in props: | ||
instance.Bind(wx.EVT_CLOSE, props["on_close"]) | ||
|
||
return instance | ||
|
||
widgets.frame = frame | ||
|
||
|
||
def __Gooey_120_patch_wxTimer(): | ||
from gooey.gui.util.time import get_current_time, Timing | ||
|
||
def __patch(self: Timing): | ||
self.startTime = get_current_time() | ||
self.estimatedRemaining = None | ||
self.wxTimer.Start(milliseconds=1) | ||
|
||
Timing.start = __patch | ||
|
||
|
||
def __Gooey_120_patch_tqdm(): | ||
from subprocess import Popen | ||
from gooey.gui import events | ||
from gooey.gui.processor import ProcessController, pub | ||
|
||
def __patch(self, process: Popen): | ||
""" | ||
Reads the stdout of `process` and forwards lines and progress | ||
to any interested subscribers | ||
""" | ||
while True: | ||
line = [] | ||
while ch := process.stdout.read(1): | ||
if ch in (b"\r", b"\n"): | ||
line.append(b"\n") | ||
break | ||
line.append(ch) | ||
if not line: | ||
break | ||
line = b"".join(line) | ||
_progress = line.find(b"%") | ||
if _progress in range(0, 4): | ||
_progress = int(line[:_progress].strip()) | ||
else: | ||
_progress = None | ||
pub.send_message(events.PROGRESS_UPDATE, progress=_progress) | ||
if _progress is None or self.hide_progress_msg is False: | ||
pub.send_message(events.CONSOLE_UPDATE, msg=line.decode(self.encoding)) | ||
pub.send_message(events.EXECUTION_COMPLETE) | ||
|
||
ProcessController._forward_stdout = __patch | ||
pass | ||
|
||
|
||
from sssekai.unity import sssekai_set_unity_version | ||
|
||
|
||
class GooeyParser(GooeyParser): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
# It's guaranteed that with file input/outputs | ||
# that we have | ||
# infile, outfile, indir, outdir as names | ||
# Map them to File Widgets | ||
def add_argument(self, name, *args, **kwargs): | ||
WIDGET_MAP = { | ||
"infile": "FileChooser", | ||
"outfile": "FileSaver", | ||
"indir": "DirChooser", | ||
"outdir": "DirChooser", | ||
# Special cases | ||
# AppHash | ||
"--apk_src": "FileChooser", | ||
"--ab_src": "FileChooser", | ||
# AbCache | ||
"--db": "FileChooser", | ||
"--download_dir": "DirChooser", | ||
"--dump_master_data": "DirChooser", | ||
"--dump_user_data": "DirChooser", | ||
} | ||
kwargs |= {"widget": WIDGET_MAP.get(name, None)} | ||
return super().add_argument(name, *args, **kwargs) | ||
|
||
|
||
@Gooey(show_preview_warning=False) | ||
def __main__(): | ||
__Gooey_120_patch_TaskBar() | ||
__Gooey_120_patch_wxTimer() | ||
__Gooey_120_patch_tqdm() | ||
# ooh ooh aah aah monkey patching | ||
parser = create_parser(GooeyParser) | ||
args = parser.parse_args() | ||
basicConfig( | ||
level="DEBUG", | ||
format="[%(levelname).4s] %(name)s %(message)s", | ||
) | ||
# override unity version | ||
sssekai_set_unity_version(args.unity_version) | ||
if "func" in args: | ||
args.func(args) | ||
pass | ||
|
||
|
||
if __name__ in {"__main__", "__gui__"}: | ||
__main__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters