From 14def4e8e90db0e4ced147aec8cc30cdfbb17cc3 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Thu, 9 Apr 2015 13:00:50 -0600 Subject: [PATCH] Fixed name/app name issues. They are now separate. --- command_line.py | 19 +++++++++++++++++-- files/linux-x64/place_holder.txt | 0 files/nw-versions.txt | 3 --- files/settings.cfg | 12 ++++++++++-- main.py | 31 ++++++++++++++++++++++++++++--- 5 files changed, 55 insertions(+), 10 deletions(-) delete mode 100644 files/linux-x64/place_holder.txt diff --git a/command_line.py b/command_line.py index 31b14b8..ef6b02a 100644 --- a/command_line.py +++ b/command_line.py @@ -71,6 +71,8 @@ class Setting(object): self.button_callback = kwargs.pop('button_callback', None) self.description = kwargs.pop('description', '') self.values = kwargs.pop('values', []) + self.filter = kwargs.pop('filter', '(?s).*') + self.filter_action = kwargs.pop('filter_action', 'None') self.set_extra_attributes_from_keyword_args(**kwargs) @@ -81,6 +83,12 @@ class Setting(object): self.get_file_information_from_url() + def filter_name(self, text): + action = unicode + if hasattr(unicode, self.filter_action): + action = getattr(unicode, self.filter_action) + return action(unicode(text)) + def get_file_information_from_url(self): if hasattr(self, 'url'): self.file_name = self.url.split('/')[-1] @@ -289,7 +297,7 @@ class CommandBase(object): def project_name(self): return (self._project_name or - os.path.basename(os.path.dirname(self.project_dir()))) + os.path.basename(os.path.abspath(self.project_dir()))) def get_setting(self, name): for setting_group in (self.settings['setting_groups'] + @@ -864,7 +872,14 @@ if __name__ == '__main__': command_base._output_dir = (args.output_dir or os.path.join(args.project_dir, 'output')) - command_base._project_name = args.name if not callable(args.name) else args.name() + if args.app_name is None: + args.app_name = command_base.project_name() + + if args.name is not None: + setting = command_base.get_setting('name') + args.name = setting.filter_name(args.name if not callable(args.name) else args.name()) + + command_base._project_name = args.app_name if not callable(args.app_name) else args.app_name() if not args.title: args.title = command_base.project_name() diff --git a/files/linux-x64/place_holder.txt b/files/linux-x64/place_holder.txt deleted file mode 100644 index e69de29..0000000 diff --git a/files/nw-versions.txt b/files/nw-versions.txt index cafd67a..9a7b27e 100644 --- a/files/nw-versions.txt +++ b/files/nw-versions.txt @@ -3,9 +3,6 @@ 0.12.0-alpha2 0.12.0-alpha1 0.12.0 -0.11.6 -0.11.5 -0.11.4 0.11.3 0.11.2 0.11.1 diff --git a/files/settings.cfg b/files/settings.cfg index 35d2ca4..930b62c 100644 --- a/files/settings.cfg +++ b/files/settings.cfg @@ -16,9 +16,17 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64' file_types='*.html *.php *.htm' description='Main html file relative to the project directory.' [[[name]]] - display_name='App Name' + display_name='Name' required=True type='string' + description='The name in the internal package.json. Must be alpha-numeric with no spaces.' + filter='[a-z0-9_\-\.]+' + filter_action='lower' + [[[app_name]]] + display_name='App Name' + required=False + type='string' + description='The name that your executable or app will have when exported.' [[[description]]] default_value='' type='string' @@ -308,7 +316,7 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64' [order] - application_setting_order="""['main', 'name', 'node-main', 'description', 'version', 'keywords', + application_setting_order="""['main', 'name', 'app_name', 'node-main', 'description', 'version', 'keywords', 'user-agent', 'chromium-args', 'node-remote', 'js-flags', 'inject-js-start', 'inject-js-end', 'additional_trust_anchors', 'snapshot', diff --git a/main.py b/main.py index d5e5b46..7c870dc 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,23 @@ from PySide.QtCore import QUrl, QFile, QIODevice, QCoreApplication from command_line import CWD, CommandBase +class Validator(QtGui.QRegExpValidator): + def __init__(self, regex, action, parent=None): + self.exp = regex + self.action = unicode + if hasattr(unicode, action): + self.action = getattr(unicode, action) + reg = QtCore.QRegExp(regex) + super(Validator, self).__init__(reg, parent) + + def validate(self, text, pos): + result = super(Validator, self).validate(text, pos) + return result + + def fixup(self, text): + return ''.join(re.findall(self.exp, self.action(unicode(text)))) + + class BackgroundThread(QtCore.QThread): def __init__(self, widget, method_name, parent=None): QtCore.QThread.__init__(self, parent) @@ -478,7 +495,7 @@ class MainWindow(QtGui.QWidget, CommandBase): return children def project_name(self): - return self.find_child_by_name('name').text() + return self.find_child_by_name('app_name').text() def browse_dir(self): self.update_json = False @@ -499,10 +516,17 @@ class MainWindow(QtGui.QWidget, CommandBase): if files: setting_input.setText(files[0].replace(self.project_dir() + os.path.sep, '')) - app_name_input = self.find_child_by_name('name') + app_name_input = self.find_child_by_name('app_name') + name_input = self.find_child_by_name('name') + name_setting = self.get_setting('name') title_input = self.find_child_by_name('title') + + if not name_input.text(): + name_input.setText(name_setting.filter_name(proj_name)) + if not app_name_input.text(): app_name_input.setText(proj_name) + if not title_input.text(): title_input.setText(proj_name) @@ -614,6 +638,7 @@ class MainWindow(QtGui.QWidget, CommandBase): setting = self.get_setting(name) text = QtGui.QLineEdit() + text.setValidator(Validator(setting.filter, setting.filter_action)) text.setObjectName(setting.name) text.textChanged.connect(self.call_with_object('setting_changed', @@ -833,7 +858,7 @@ class MainWindow(QtGui.QWidget, CommandBase): setting.type == 'string' or setting.type == 'folder'): val_str = self.convert_val_to_str(setting.value) - setting_field.setText(val_str) + setting_field.setText(setting.filter_name(val_str)) if setting.type == 'check': setting_field.setChecked(setting.value) if setting.type == 'list':