Skip to content

Commit 66431d2

Browse files
committed
Tried fixing Windows paths and added an 'Open Project' dialog.
1 parent 09c82ce commit 66431d2

File tree

3 files changed

+108
-15
lines changed

3 files changed

+108
-15
lines changed

command_line.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
def get_file(path):
6464
parts = path.split('/')
6565
independent_path = utils.path_join(CWD, *parts)
66+
if utils.is_windows() and os.path.isabs(independent_path):
67+
independent_path = u'//?/' + independent_path
6668
return independent_path
6769

6870
__version__ = "v0.0.0"
@@ -89,7 +91,7 @@ def get_file(path):
8991
logger.addHandler(handler)
9092

9193
def my_excepthook(type_, value, tback):
92-
output_err = u''.join(unicode(traceback.format_exception(type_, value, tback)))
94+
output_err = u''.join([unicode(x) for x in traceback.format_exception(type_, value, tback)])
9395
logger.error(u'{}'.format(output_err))
9496
sys.__excepthook__(type_, value, tback)
9597

@@ -427,9 +429,9 @@ def get_versions(self):
427429
f.write(v+os.linesep)
428430
f.close()
429431
except IOError:
430-
error = u''.join(unicode(traceback.format_exception(sys.exc_info()[0],
431-
sys.exc_info()[1],
432-
sys.exc_info()[2])))
432+
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
433+
sys.exc_info()[1],
434+
sys.exc_info()[2])])
433435
self.show_error(error)
434436
self.enable_ui_after_error()
435437
finally:
@@ -454,9 +456,9 @@ def download_file_with_error_handling(self):
454456
if os.path.exists(setting.save_file_path(version, location)):
455457
os.remove(setting.save_file_path(version, location))
456458

457-
error = u''.join(unicode(traceback.format_exception(sys.exc_info()[0],
458-
sys.exc_info()[1],
459-
sys.exc_info()[2])))
459+
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
460+
sys.exc_info()[1],
461+
sys.exc_info()[2])])
460462
self.show_error(error)
461463
self.enable_ui_after_error()
462464

@@ -796,11 +798,11 @@ def make_output_dirs(self):
796798
os.remove(nw_path)
797799

798800
except Exception:
799-
exc = unicode(traceback.format_exception(sys.exc_info()[0],
800-
sys.exc_info()[1],
801-
sys.exc_info()[2]))
802-
self.logger.error(exc)
803-
self.output_err += u''.join(exc)
801+
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
802+
sys.exc_info()[1],
803+
sys.exc_info()[2])])
804+
self.logger.error(error)
805+
self.output_err += error
804806
finally:
805807
shutil.rmtree(temp_dir, ignore_errors=True)
806808

@@ -1247,7 +1249,7 @@ def main():
12471249
logger.addHandler(handler)
12481250

12491251
def my_excepthook(type_, value, tback):
1250-
output_err = u''.join(unicode(traceback.format_exception(type_, value, tback)))
1252+
output_err = u''.join([unicode(x) for x in traceback.format_exception(type_, value, tback)])
12511253
logger.error(u'{}'.format(output_err))
12521254
sys.__excepthook__(type_, value, tback)
12531255

@@ -1258,9 +1260,13 @@ def my_excepthook(type_, value, tback):
12581260
if args.quiet:
12591261
command_base.quiet = True
12601262

1261-
command_base._project_dir = args.project_dir
1263+
if utils.is_windows() and os.path.isabs(args.project_dir):
1264+
command_base._project_dir = u'//?/' + args.project_dir
1265+
else:
1266+
command_base._project_dir = args.project_dir
1267+
12621268
command_base._output_dir = (args.output_dir or
1263-
utils.path_join(args.project_dir, 'output'))
1269+
utils.path_join(command_base._project_dir, 'output'))
12641270

12651271
if args.app_name is None:
12661272
args.app_name = command_base.project_name()

main.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,77 @@ def url_exists(path):
3030
return True
3131
return False
3232

33+
class ExistingProjectDialog(QtGui.QDialog):
34+
def __init__(self, recent_projects, directory_callback, parent=None):
35+
super(ExistingProjectDialog, self).__init__(parent)
36+
self.setWindowTitle('Open Project Folder')
37+
self.setMinimumWidth(500)
38+
self.parent().menuBar().hide()
39+
40+
group_box = QtGui.QGroupBox('Existing Projects')
41+
gbox_layout = QtGui.QVBoxLayout()
42+
self.project_list = QtGui.QListWidget()
43+
44+
gbox_layout.addWidget(self.project_list)
45+
group_box.setLayout(gbox_layout)
46+
47+
self.callback = directory_callback
48+
49+
self.projects = recent_projects
50+
51+
for i in xrange(len(recent_projects)):
52+
project = recent_projects[i]
53+
text = u'{} - {}'.format(os.path.basename(project), project)
54+
self.project_list.addItem(text)
55+
56+
self.project_list.itemClicked.connect(self.project_clicked)
57+
58+
self.cancel = QtGui.QPushButton('Cancel')
59+
self.open = QtGui.QPushButton('Open Selected')
60+
self.browse = QtGui.QPushButton('Browse...')
61+
62+
self.open.setEnabled(False)
63+
self.open.clicked.connect(self.open_clicked)
64+
65+
self.browse.clicked.connect(self.browse_clicked)
66+
67+
buttons = QtGui.QWidget()
68+
69+
button_layout = QtGui.QHBoxLayout()
70+
button_layout.addWidget(self.cancel)
71+
button_layout.addWidget(QtGui.QWidget())
72+
button_layout.addWidget(self.browse)
73+
button_layout.addWidget(self.open)
74+
75+
buttons.setLayout(button_layout)
76+
77+
layout = QtGui.QVBoxLayout()
78+
layout.addWidget(group_box)
79+
layout.addWidget(buttons)
80+
81+
self.setLayout(layout)
82+
self.cancel.clicked.connect(self.cancelled)
83+
84+
def browse_clicked(self):
85+
86+
directory = QtGui.QFileDialog.getExistingDirectory(self, 'Find Project Directory',
87+
self.parent().project_dir() or self.parent().last_project_dir)
88+
89+
if directory:
90+
self.callback(directory)
91+
self.close()
92+
93+
def open_clicked(self):
94+
pos = self.project_list.currentRow()
95+
self.callback(self.projects[pos])
96+
self.close()
97+
98+
def project_clicked(self, item):
99+
self.open.setEnabled(True)
100+
101+
def cancelled(self):
102+
self.close()
103+
33104
class Validator(QtGui.QRegExpValidator):
34105
def __init__(self, regex, action, parent=None):
35106
self.exp = regex
@@ -124,6 +195,15 @@ def __init__(self, width, height, app, parent=None):
124195
super(MainWindow, self).__init__(parent)
125196
CommandBase.__init__(self)
126197

198+
recent_projects = self.load_recent_projects()
199+
200+
existing_dialog = ExistingProjectDialog(recent_projects, self.load_project, parent=self)
201+
existing_dialog.show()
202+
203+
drect = QtGui.QApplication.desktop().availableGeometry(self)
204+
center = drect.center()
205+
self.move(center.x() - self.width() * 0.5, center.y() - self.height()*0.5)
206+
127207
self.icon_style = 'width:48px;height:48px;background-color:white;border-radius:5px;border:1px solid rgb(50,50,50);'
128208

129209
self.last_project_dir = self.load_last_project_path()

utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ def get_data_path(dir_path):
3939
parts = dir_path.split('/')
4040
dirs = AppDirs('Web2Executable', 'Web2Executable')
4141
data_path = path_join(dirs.user_data_dir, *parts)
42+
43+
if is_windows() and os.path.isabs(data_path):
44+
data_path = u'//?/' + data_path
45+
4246
if not os.path.exists(data_path):
4347
os.makedirs(data_path)
48+
4449
return data_path
4550

4651
def get_data_file_path(file_path):
4752
parts = file_path.split('/')
4853
data_path = get_data_path('/'.join(parts[:-1]))
54+
if is_windows() and os.path.isabs(data_path):
55+
data_path = u'//?/' + data_path
4956
return path_join(data_path, parts[-1])
5057

5158
def log(*args):

0 commit comments

Comments
 (0)