Tried fixing Windows paths and added an 'Open Project' dialog.
This commit is contained in:
parent
09c82cef04
commit
66431d2d14
3 changed files with 108 additions and 15 deletions
|
|
@ -63,6 +63,8 @@ else:
|
|||
def get_file(path):
|
||||
parts = path.split('/')
|
||||
independent_path = utils.path_join(CWD, *parts)
|
||||
if utils.is_windows() and os.path.isabs(independent_path):
|
||||
independent_path = u'//?/' + independent_path
|
||||
return independent_path
|
||||
|
||||
__version__ = "v0.0.0"
|
||||
|
|
@ -89,7 +91,7 @@ handler = lh.RotatingFileHandler(LOG_FILENAME, maxBytes=100000, backupCount=2)
|
|||
logger.addHandler(handler)
|
||||
|
||||
def my_excepthook(type_, value, tback):
|
||||
output_err = u''.join(unicode(traceback.format_exception(type_, value, tback)))
|
||||
output_err = u''.join([unicode(x) for x in traceback.format_exception(type_, value, tback)])
|
||||
logger.error(u'{}'.format(output_err))
|
||||
sys.__excepthook__(type_, value, tback)
|
||||
|
||||
|
|
@ -427,9 +429,9 @@ class CommandBase(object):
|
|||
f.write(v+os.linesep)
|
||||
f.close()
|
||||
except IOError:
|
||||
error = u''.join(unicode(traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2])))
|
||||
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2])])
|
||||
self.show_error(error)
|
||||
self.enable_ui_after_error()
|
||||
finally:
|
||||
|
|
@ -454,9 +456,9 @@ class CommandBase(object):
|
|||
if os.path.exists(setting.save_file_path(version, location)):
|
||||
os.remove(setting.save_file_path(version, location))
|
||||
|
||||
error = u''.join(unicode(traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2])))
|
||||
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2])])
|
||||
self.show_error(error)
|
||||
self.enable_ui_after_error()
|
||||
|
||||
|
|
@ -796,11 +798,11 @@ class CommandBase(object):
|
|||
os.remove(nw_path)
|
||||
|
||||
except Exception:
|
||||
exc = unicode(traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2]))
|
||||
self.logger.error(exc)
|
||||
self.output_err += u''.join(exc)
|
||||
error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
|
||||
sys.exc_info()[1],
|
||||
sys.exc_info()[2])])
|
||||
self.logger.error(error)
|
||||
self.output_err += error
|
||||
finally:
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
|
||||
|
|
@ -1247,7 +1249,7 @@ def main():
|
|||
logger.addHandler(handler)
|
||||
|
||||
def my_excepthook(type_, value, tback):
|
||||
output_err = u''.join(unicode(traceback.format_exception(type_, value, tback)))
|
||||
output_err = u''.join([unicode(x) for x in traceback.format_exception(type_, value, tback)])
|
||||
logger.error(u'{}'.format(output_err))
|
||||
sys.__excepthook__(type_, value, tback)
|
||||
|
||||
|
|
@ -1258,9 +1260,13 @@ def main():
|
|||
if args.quiet:
|
||||
command_base.quiet = True
|
||||
|
||||
command_base._project_dir = args.project_dir
|
||||
if utils.is_windows() and os.path.isabs(args.project_dir):
|
||||
command_base._project_dir = u'//?/' + args.project_dir
|
||||
else:
|
||||
command_base._project_dir = args.project_dir
|
||||
|
||||
command_base._output_dir = (args.output_dir or
|
||||
utils.path_join(args.project_dir, 'output'))
|
||||
utils.path_join(command_base._project_dir, 'output'))
|
||||
|
||||
if args.app_name is None:
|
||||
args.app_name = command_base.project_name()
|
||||
|
|
|
|||
80
main.py
80
main.py
|
|
@ -30,6 +30,77 @@ def url_exists(path):
|
|||
return True
|
||||
return False
|
||||
|
||||
class ExistingProjectDialog(QtGui.QDialog):
|
||||
def __init__(self, recent_projects, directory_callback, parent=None):
|
||||
super(ExistingProjectDialog, self).__init__(parent)
|
||||
self.setWindowTitle('Open Project Folder')
|
||||
self.setMinimumWidth(500)
|
||||
self.parent().menuBar().hide()
|
||||
|
||||
group_box = QtGui.QGroupBox('Existing Projects')
|
||||
gbox_layout = QtGui.QVBoxLayout()
|
||||
self.project_list = QtGui.QListWidget()
|
||||
|
||||
gbox_layout.addWidget(self.project_list)
|
||||
group_box.setLayout(gbox_layout)
|
||||
|
||||
self.callback = directory_callback
|
||||
|
||||
self.projects = recent_projects
|
||||
|
||||
for i in xrange(len(recent_projects)):
|
||||
project = recent_projects[i]
|
||||
text = u'{} - {}'.format(os.path.basename(project), project)
|
||||
self.project_list.addItem(text)
|
||||
|
||||
self.project_list.itemClicked.connect(self.project_clicked)
|
||||
|
||||
self.cancel = QtGui.QPushButton('Cancel')
|
||||
self.open = QtGui.QPushButton('Open Selected')
|
||||
self.browse = QtGui.QPushButton('Browse...')
|
||||
|
||||
self.open.setEnabled(False)
|
||||
self.open.clicked.connect(self.open_clicked)
|
||||
|
||||
self.browse.clicked.connect(self.browse_clicked)
|
||||
|
||||
buttons = QtGui.QWidget()
|
||||
|
||||
button_layout = QtGui.QHBoxLayout()
|
||||
button_layout.addWidget(self.cancel)
|
||||
button_layout.addWidget(QtGui.QWidget())
|
||||
button_layout.addWidget(self.browse)
|
||||
button_layout.addWidget(self.open)
|
||||
|
||||
buttons.setLayout(button_layout)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(group_box)
|
||||
layout.addWidget(buttons)
|
||||
|
||||
self.setLayout(layout)
|
||||
self.cancel.clicked.connect(self.cancelled)
|
||||
|
||||
def browse_clicked(self):
|
||||
|
||||
directory = QtGui.QFileDialog.getExistingDirectory(self, 'Find Project Directory',
|
||||
self.parent().project_dir() or self.parent().last_project_dir)
|
||||
|
||||
if directory:
|
||||
self.callback(directory)
|
||||
self.close()
|
||||
|
||||
def open_clicked(self):
|
||||
pos = self.project_list.currentRow()
|
||||
self.callback(self.projects[pos])
|
||||
self.close()
|
||||
|
||||
def project_clicked(self, item):
|
||||
self.open.setEnabled(True)
|
||||
|
||||
def cancelled(self):
|
||||
self.close()
|
||||
|
||||
class Validator(QtGui.QRegExpValidator):
|
||||
def __init__(self, regex, action, parent=None):
|
||||
self.exp = regex
|
||||
|
|
@ -124,6 +195,15 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
|||
super(MainWindow, self).__init__(parent)
|
||||
CommandBase.__init__(self)
|
||||
|
||||
recent_projects = self.load_recent_projects()
|
||||
|
||||
existing_dialog = ExistingProjectDialog(recent_projects, self.load_project, parent=self)
|
||||
existing_dialog.show()
|
||||
|
||||
drect = QtGui.QApplication.desktop().availableGeometry(self)
|
||||
center = drect.center()
|
||||
self.move(center.x() - self.width() * 0.5, center.y() - self.height()*0.5)
|
||||
|
||||
self.icon_style = 'width:48px;height:48px;background-color:white;border-radius:5px;border:1px solid rgb(50,50,50);'
|
||||
|
||||
self.last_project_dir = self.load_last_project_path()
|
||||
|
|
|
|||
7
utils.py
7
utils.py
|
|
@ -39,13 +39,20 @@ def get_data_path(dir_path):
|
|||
parts = dir_path.split('/')
|
||||
dirs = AppDirs('Web2Executable', 'Web2Executable')
|
||||
data_path = path_join(dirs.user_data_dir, *parts)
|
||||
|
||||
if is_windows() and os.path.isabs(data_path):
|
||||
data_path = u'//?/' + data_path
|
||||
|
||||
if not os.path.exists(data_path):
|
||||
os.makedirs(data_path)
|
||||
|
||||
return data_path
|
||||
|
||||
def get_data_file_path(file_path):
|
||||
parts = file_path.split('/')
|
||||
data_path = get_data_path('/'.join(parts[:-1]))
|
||||
if is_windows() and os.path.isabs(data_path):
|
||||
data_path = u'//?/' + data_path
|
||||
return path_join(data_path, parts[-1])
|
||||
|
||||
def log(*args):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue