Skip to content

Commit 6050c3c

Browse files
Added A Simple CLI. Takes One Argument dir_or_file_path Which Is Path To The File Or Directory.
1 parent fca4956 commit 6050c3c

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

main.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@
7979

8080

8181
class App(wx.Frame):
82-
def __init__(self, parent, title):
82+
def __init__(self, parent, title, dir_or_file_path):
8383

8484
self.title = title
85+
self.dirname = os.getcwd()
8586
self.filename = ""
8687
self.file_ext = ".py"
87-
self.dirname = os.getcwd()
8888

8989
wx.Frame.__init__(self, parent, title=self.title, size=(800, 600))
9090

@@ -93,7 +93,37 @@ def __init__(self, parent, title):
9393
self.load_settings_widgets()
9494
self.editor_keyup()
9595

96-
self.open_project()
96+
print(dir_or_file_path)
97+
98+
if dir_or_file_path != "":
99+
path_to_open = path.abspath(
100+
path.join(path.abspath(os.getcwd()), dir_or_file_path))
101+
if path.isdir(path_to_open):
102+
self.dirname = path.abspath(path_to_open)
103+
items_in_project = os.listdir(path.abspath(self.dirname))
104+
self.dirTree.DeleteAllItems()
105+
self.updateDirTree()
106+
for item in items_in_project:
107+
if (item == "main.py"
108+
or item == "index.py") and not path.isdir(item):
109+
self.editor.SetValue(
110+
open(path.join(self.dirname, item), "r").read())
111+
self.filename = item
112+
self.file_ext = path.splitext(self.filename)
113+
elif path.isfile(path.join(os.getcwd(), dir_or_file_path)):
114+
self.dirname = path.dirname(path.abspath(path_to_open))
115+
self.dirTree.DeleteAllItems()
116+
self.updateDirTree()
117+
self.filename = path.basename(path.abspath(path_to_open))
118+
self.file_ext = path.splitext(self.filename)
119+
self.editor.SetValue(
120+
open(path.join(self.dirname, self.filename), "r").read())
121+
# print(path.abspath(path.join(path.abspath(os.getcwd()), dir_or_file_path)))
122+
elif dir_or_file_path == "":
123+
self.dirname = os.getcwd()
124+
self.filename = ""
125+
self.file_ext = ".py"
126+
self.open_project()
97127

98128
self.Show()
99129
self.Maximize()
@@ -179,6 +209,7 @@ def create_status_and_menu_bar(self):
179209

180210
def open_settings(self, event):
181211
self.settings_win.Show()
212+
self.load_settings_widgets()
182213

183214
def view_python_shell(self, event):
184215
shellWin = wx.Frame(self, title="Python Shell", size=(800, 600))
@@ -423,6 +454,7 @@ def open_project(self, event=None):
423454
self.editor.SetValue(
424455
open(path.join(self.dirname, item), "r").read())
425456
self.filename = item
457+
self.file_ext = ".py"
426458
dlg.Destroy()
427459

428460
def save_file(self, event):
@@ -465,6 +497,18 @@ def saveas_file(self, event):
465497
dlg.Destroy()
466498

467499

468-
root = wx.App()
469-
App(None, title="PyCode - Code Editor")
470-
root.MainLoop()
500+
import click
501+
502+
503+
@click.command()
504+
@click.argument("dir_or_file_path")
505+
@click.version_option("0.0.1")
506+
def pycode(dir_or_file_path=""):
507+
print(path.abspath(dir_or_file_path))
508+
root = wx.App()
509+
App(None, title="PyCode - Code Editor", dir_or_file_path=dir_or_file_path)
510+
root.MainLoop()
511+
512+
513+
if __name__ == "__main__":
514+
pycode()

0 commit comments

Comments
 (0)