79
79
80
80
81
81
class App (wx .Frame ):
82
- def __init__ (self , parent , title ):
82
+ def __init__ (self , parent , title , dir_or_file_path ):
83
83
84
84
self .title = title
85
+ self .dirname = os .getcwd ()
85
86
self .filename = ""
86
87
self .file_ext = ".py"
87
- self .dirname = os .getcwd ()
88
88
89
89
wx .Frame .__init__ (self , parent , title = self .title , size = (800 , 600 ))
90
90
@@ -93,7 +93,37 @@ def __init__(self, parent, title):
93
93
self .load_settings_widgets ()
94
94
self .editor_keyup ()
95
95
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 ()
97
127
98
128
self .Show ()
99
129
self .Maximize ()
@@ -179,6 +209,7 @@ def create_status_and_menu_bar(self):
179
209
180
210
def open_settings (self , event ):
181
211
self .settings_win .Show ()
212
+ self .load_settings_widgets ()
182
213
183
214
def view_python_shell (self , event ):
184
215
shellWin = wx .Frame (self , title = "Python Shell" , size = (800 , 600 ))
@@ -423,6 +454,7 @@ def open_project(self, event=None):
423
454
self .editor .SetValue (
424
455
open (path .join (self .dirname , item ), "r" ).read ())
425
456
self .filename = item
457
+ self .file_ext = ".py"
426
458
dlg .Destroy ()
427
459
428
460
def save_file (self , event ):
@@ -465,6 +497,18 @@ def saveas_file(self, event):
465
497
dlg .Destroy ()
466
498
467
499
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