Skip to content

Commit 303e31e

Browse files
committed
Rewrote cli
1 parent ec97e67 commit 303e31e

File tree

10 files changed

+42
-19
lines changed

10 files changed

+42
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*.egg-info
88
build/
99
**/.doctrees
10+
# Only so that we don't upload builds to github
11+
dist/
1012

1113
# Coverage
1214
.coverage

cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
import sys
2+
sys.argv.append("Test")
3+
14
from editor.__main__ import main
25
main()

editor/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def testing(string):
1515
def inner():
16-
print(string)
16+
Logger.Log(string)
1717
return inner
1818

1919
class Application(QApplication):
@@ -68,7 +68,7 @@ def start(self):
6868
self.exec_()
6969

7070
def open(self):
71-
print("Choosing folder...")
71+
Logger.Log("Choosing folder...")
7272
# Get opened project
7373
subprocess.Popen(["py", "cli.py"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
7474
self.quit()

editor/cli.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
from .splash import start
1+
from .splash import start, disable_print
2+
from time import strftime
3+
import os
4+
import sys
25

36
def main():
7+
if len(sys.argv) < 2:
8+
raise ValueError("Please specify a file.")
9+
elif not os.path.isdir(sys.argv[1]):
10+
raise ValueError("Please specify a valid directory.")
11+
412
from .app import Application
5-
app = Application("Test")
13+
app = Application(sys.argv[1])
614
app.start()
715

16+
def gui():
17+
disable_print()
18+
os.environ["PYUNITY_DEBUG_MODE"] = "0"
19+
from pyunity import Logger
20+
directory = os.path.join(os.path.dirname(Logger.folder), "Editor", "Logs")
21+
os.makedirs(directory, exist_ok=True)
22+
Logger.SetStream(open(os.path.join(directory, strftime("%Y-%m-%d %H-%M-%S") + ".log"), "w+"))
23+
start(main)
24+
825
def run():
926
start(main)

editor/files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from PyQt5.QtCore import QTimer, Qt
22
from PyQt5.QtWidgets import QMessageBox
33
from PyQt5.QtGui import QFont
4-
from pyunity import Loader
4+
from pyunity import Loader, Logger
55
import os
66
import glob
77
import enum
@@ -27,14 +27,14 @@ def check(self):
2727
files2 = set(glob.glob(os.path.join(self.path, "**/*"), recursive=True))
2828
for file in self.files:
2929
if file not in files2:
30-
print("Removed " + file)
30+
Logger.Log("Removed " + file)
3131
self.changed.append((file, FileState.DELETED))
3232
elif self.times[file] < os.stat(file)[8]:
33-
print("Modified " + file)
33+
Logger.Log("Modified " + file)
3434
self.changed.append((file, FileState.MODIFIED))
3535
self.times[file] = os.stat(file)[8]
3636
for file in files2 - self.files:
37-
print("Created " + file)
37+
Logger.Log("Created " + file)
3838
self.changed.append((file, FileState.CREATED))
3939
self.times[file] = os.stat(file)[8]
4040
self.files = files2

editor/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def pause(self, on):
9090
self.timer.start(1000 // config.fps)
9191

9292
def save(self):
93-
print(self.original.ids)
93+
pyu.Logger.Log(self.original.ids)
9494
pyu.Loader.SaveScene(self.original, self.file_tracker.project)
9595

9696
def on_switch(self):

editor/splash.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
import sys
77
from PIL import ImageTk, Image
88

9-
_print = builtins.print
109
sys._stderr = sys.stderr
10+
sys._stdout = sys.stdout
1111

1212
def disable_print():
13-
def wrapper(*args, **kwargs):
14-
pass
15-
builtins.print = wrapper
13+
sys.stdout = os.devnull
1614
sys.stderr = os.devnull
1715

1816
def enable_print():
19-
builtins.print = _print
17+
sys.stdout = sys._stdout
2018
sys.stderr = sys._stderr
2119

2220
def splash():

editor/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ def new_sibling(self):
103103
def remove(self):
104104
items = self.tree_widget.selectedItems()
105105
if len(items) == 0:
106-
print("Nothing selected")
106+
pyu.Logger.Log("Nothing selected")
107107
return
108108

109109
for item in items:
110110
item.selectAll()
111111
items = self.tree_widget.selectedItems()
112112
self.items = []
113113
for item in items:
114-
print("Removing", item.gameObject.name)
114+
pyu.Logger.Log("Removing", item.gameObject.name)
115115
self.tree_widget.invisibleRootItem().removeChild(item)
116116
if self.loaded.Has(item.gameObject):
117117
self.loaded.Remove(item.gameObject)

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# gui_scripts
2-
31
from setuptools import setup, find_packages
4-
import os
52
import glob
63

74
with open("README.md", "r") as fh:
@@ -37,6 +34,9 @@
3734
packages= ["editor"] + ["editor." + package for package in find_packages(where="editor")],
3835
package_data={"editor": [file[7:] for file in data_files]},
3936
entry_points={
37+
# "gui_scripts": [
38+
# "pyunity-editor=editor.cli:gui"
39+
# ]
4040
"console_scripts": [
4141
"pyunity-editor=editor.cli:run"
4242
]

splash.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
sys.argv.append("Test")
3+
14
from editor.splash import start
25

36
def main():

0 commit comments

Comments
 (0)