From 4f74202b0959e90935f4f1a97d07ba894f272e6a Mon Sep 17 00:00:00 2001 From: ewerybody Date: Mon, 18 Jun 2018 14:35:25 +0200 Subject: [PATCH 1/3] added menu button help into hotkey dialog --- ui/a2core.py | 16 ++++++------- ui/a2widget/a2hotkey/keyboard_dialog/base.py | 9 ++++++++ ui/a2widget/a2hotkey/keyboard_dialog/base.ui | 23 ++++++++++++++++++- .../a2hotkey/keyboard_dialog/base_ui.py | 9 +++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/ui/a2core.py b/ui/a2core.py index f31b432c..cd3e15ee 100644 --- a/ui/a2core.py +++ b/ui/a2core.py @@ -110,14 +110,14 @@ def __init__(self, a2_urls_ahk): variables_dict = a2ahk.get_variables(a2_urls_ahk) self.a2 = variables_dict.get('a2_url', 'https://github.com/ewerybody/a2') self.help = variables_dict.get('a2_help', (self.a2 + '#a2-')) - self.wiki = self.a2 + '/wiki' - self.helpEditCtrl = self.wiki + '/EditCtrls' - self.helpHotkey = self.wiki + '/Edit-Hotkey-Control' - self.helpCheckbox = self.wiki + '/Edit-Checkbox-Control' - self.help_scopes = self.wiki + '/Edit-Scopes' - self.help_string = self.wiki + '/Edit-String' - self.help_number = self.wiki + '/Edit-Number' - self.help_path = self.wiki + '/Edit-Path' + self.wiki = self.a2 + '/wiki/' + self.helpEditCtrl = self.wiki + 'EditCtrls' + self.helpHotkey = self.wiki + 'Edit-Hotkey-Control' + self.helpCheckbox = self.wiki + 'Edit-Checkbox-Control' + self.help_scopes = self.wiki + 'Edit-Scopes' + self.help_string = self.wiki + 'Edit-String' + self.help_number = self.wiki + 'Edit-Number' + self.help_path = self.wiki + 'Edit-Path' self.help_report_issue = self.a2 + '/issues/new' self.security = variables_dict.get('a2_security', '') diff --git a/ui/a2widget/a2hotkey/keyboard_dialog/base.py b/ui/a2widget/a2hotkey/keyboard_dialog/base.py index 10df5669..a1d6ce5e 100644 --- a/ui/a2widget/a2hotkey/keyboard_dialog/base.py +++ b/ui/a2widget/a2hotkey/keyboard_dialog/base.py @@ -22,6 +22,7 @@ DB_KEY_NUMPAD = 'hotkey_dialog_show_numpad' _HERE = os.path.dirname(__file__) _IGNORE_BUTTONS = ['a2cancel_button', 'a2ok_button'] +HOTKEY_HELP_PAGE = 'Hotkey-Setup' class KeyboardDialogBase(QtGui.QDialog): @@ -110,6 +111,7 @@ def _setup_ui(self): self.ui.a2ok_button.clicked.connect(self.ok) self.ui.a2cancel_button.clicked.connect(self.close) + self.ui.option_button.menu_called.connect(self.build_option_menu) self.refresh_style() @@ -289,6 +291,10 @@ def refresh_style(self): self.cursor_block_widget.setStyleSheet(cursor_block_css) self.numpad_block_widget.setStyleSheet(cursor_block_css) + def build_option_menu(self, menu): + icons = a2ctrl.Icons.inst() + menu.addAction(icons.help, 'Help on Hotket Setup', self.goto_help) + def _log_size(self): """ Eventually I want to put the dialog under the cursor. But for that we need to @@ -316,6 +322,9 @@ def _log_size(self): except AttributeError: pass + def goto_help(self): + a2util.surf_to(self.a2.urls.wiki + HOTKEY_HELP_PAGE) + class CursorBlockWidget(QtGui.QWidget): def __init__(self, parent): diff --git a/ui/a2widget/a2hotkey/keyboard_dialog/base.ui b/ui/a2widget/a2hotkey/keyboard_dialog/base.ui index 584c69b5..3f112db7 100644 --- a/ui/a2widget/a2hotkey/keyboard_dialog/base.ui +++ b/ui/a2widget/a2hotkey/keyboard_dialog/base.ui @@ -26,7 +26,21 @@ 10 - + + + + + + true + + + + + + + ... + + @@ -279,6 +293,13 @@ + + + A2MoreButton + QToolButton +
a2widget
+
+
diff --git a/ui/a2widget/a2hotkey/keyboard_dialog/base_ui.py b/ui/a2widget/a2hotkey/keyboard_dialog/base_ui.py index 80229644..b6778b9a 100644 --- a/ui/a2widget/a2hotkey/keyboard_dialog/base_ui.py +++ b/ui/a2widget/a2hotkey/keyboard_dialog/base_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'C:\Users\eric\io\code\a2\ui\a2widget\a2hotkey\keyboard_dialog\base.ui' # -# Created: Thu Jun 7 20:06:23 2018 +# Created: Mon Jun 18 14:12:20 2018 # by: pyside-uic 0.2.15 running on PySide 1.2.1 # # WARNING! All changes made in this file will be lost! @@ -20,8 +20,13 @@ def setupUi(self, Keyboard): self.top_layout.setContentsMargins(-1, 10, -1, 10) self.top_layout.setObjectName("top_layout") self.key_field = QtGui.QLineEdit(Keyboard) + self.key_field.setText("") + self.key_field.setReadOnly(True) self.key_field.setObjectName("key_field") self.top_layout.addWidget(self.key_field) + self.option_button = A2MoreButton(Keyboard) + self.option_button.setObjectName("option_button") + self.top_layout.addWidget(self.option_button) self.label_2 = QtGui.QLabel(Keyboard) self.label_2.setObjectName("label_2") self.top_layout.addWidget(self.label_2) @@ -186,5 +191,7 @@ def setupUi(self, Keyboard): def retranslateUi(self, Keyboard): Keyboard.setWindowTitle(QtGui.QApplication.translate("Keyboard", "Hotkey Dialog", None, QtGui.QApplication.UnicodeUTF8)) + self.option_button.setText(QtGui.QApplication.translate("Keyboard", "...", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("Keyboard", "Show:", None, QtGui.QApplication.UnicodeUTF8)) +from a2widget import A2MoreButton From 822491331f69600bf608f58ad737fc614b1d356c Mon Sep 17 00:00:00 2001 From: ewerybody Date: Mon, 18 Jun 2018 14:58:40 +0200 Subject: [PATCH 2/3] added 'common' module for hotkeys stuff --- ui/a2widget/a2hotkey/__init__.py | 1 + ui/a2widget/a2hotkey/edit_func_widget.py | 3 ++- ui/a2widget/a2hotkey/hotkey_common.py | 9 +++++++++ ui/a2widget/a2hotkey/hotkey_widget.py | 8 ++------ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 ui/a2widget/a2hotkey/hotkey_common.py diff --git a/ui/a2widget/a2hotkey/__init__.py b/ui/a2widget/a2hotkey/__init__.py index a78b1da2..6983bae5 100644 --- a/ui/a2widget/a2hotkey/__init__.py +++ b/ui/a2widget/a2hotkey/__init__.py @@ -1 +1,2 @@ from .hotkey_widget import A2Hotkey +from .hotkey_common import Vars diff --git a/ui/a2widget/a2hotkey/edit_func_widget.py b/ui/a2widget/a2hotkey/edit_func_widget.py index 4099aeb8..45a36039 100644 --- a/ui/a2widget/a2hotkey/edit_func_widget.py +++ b/ui/a2widget/a2hotkey/edit_func_widget.py @@ -3,9 +3,10 @@ import a2util from PySide import QtGui, QtCore from a2widget.a2hotkey import edit_func_widget_ui +from a2widget.a2hotkey.hotkey_common import Vars -FUNCTIONS = ['functionCode', 'functionURL', 'functionSend'] +FUNCTIONS = [Vars.function_code, Vars.function_url, Vars.function_send] SEND_MODES = ['sendraw', 'sendinput', 'sendplay', 'sendevent', 'send'] MOD_KEYS = ['! - Alt', '^ - Control', '+ - Shift', '# - Win'] diff --git a/ui/a2widget/a2hotkey/hotkey_common.py b/ui/a2widget/a2hotkey/hotkey_common.py new file mode 100644 index 00000000..8c403a9d --- /dev/null +++ b/ui/a2widget/a2hotkey/hotkey_common.py @@ -0,0 +1,9 @@ +class Vars(object): + scope = 'scope' + scope_mode = 'scopeMode' + scope_change = 'scopeChange' + + function_mode = 'functionMode' + function_code = 'functionCode' + function_url = 'functionURL' + function_send = 'functionSend' diff --git a/ui/a2widget/a2hotkey/hotkey_widget.py b/ui/a2widget/a2hotkey/hotkey_widget.py index b4560b43..118d5dad 100644 --- a/ui/a2widget/a2hotkey/hotkey_widget.py +++ b/ui/a2widget/a2hotkey/hotkey_widget.py @@ -4,6 +4,8 @@ import a2ctrl from a2widget.a2hotkey.simple_dialog import HotkeyDialog1 from a2widget.a2hotkey.dialogs import HotKeyBoard +from a2widget.a2hotkey.hotkey_common import Vars + SCOPE_TOOLTIP_GLOBAL = 'Hotkey scope is set "global" so it works anywhere.' SCOPE_TOOLTIP_INCLUDE = 'Hotkey scope is set to work only in specific windows.' @@ -12,12 +14,6 @@ SCOPE_GLOBAL_NOCHANGE = 'Global - unchangable' -class Vars(object): - scope = 'scope' - scope_mode = 'scopeMode' - scope_change = 'scopeChange' - - class A2Hotkey(QtGui.QWidget): hotkey_changed = QtCore.Signal(str) scope_changed = QtCore.Signal(list, int) From 2c183e9607eb24be8aea11cc7023a06401319be7 Mon Sep 17 00:00:00 2001 From: ewerybody Date: Mon, 18 Jun 2018 14:59:31 +0200 Subject: [PATCH 3/3] hotkeys are now blank by default fixes #124 --- ui/a2element/common.py | 6 +++++- ui/a2element/hotkey.py | 15 +++++---------- ui/a2widget/a2hotkey/keyboard_dialog/base.py | 14 ++++++++++++++ ui/a2widget/demo/hotkey_demo.py | 1 - 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ui/a2element/common.py b/ui/a2element/common.py index 7a5a2e62..d1c81a2e 100644 --- a/ui/a2element/common.py +++ b/ui/a2element/common.py @@ -62,7 +62,11 @@ def set_user_value(self, this, name=None): Name is None by by default so you can just set the default value by ... well: passing the value. Voila! """ - self.mod.set_user_cfg(self.cfg, this, name) + try: + self.mod.set_user_cfg(self.cfg, this, name) + except AttributeError: + # cannot set config if no module given + pass def change(self, specific=None): """ diff --git a/ui/a2element/hotkey.py b/ui/a2element/hotkey.py index 144e5979..80e45d47 100644 --- a/ui/a2element/hotkey.py +++ b/ui/a2element/hotkey.py @@ -23,12 +23,11 @@ import a2core from a2element import DrawCtrl, EditCtrl from a2widget import A2MoreButton -from a2widget.a2hotkey import A2Hotkey +from a2widget.a2hotkey import A2Hotkey, Vars from functools import partial log = a2core.get_logger(__name__) -DEFAULT_HOTKEY = 'Win+F' class Draw(DrawCtrl): @@ -148,11 +147,6 @@ def __init__(self, cfg, main, parent_cfg): self.ui = edit_widget_ui.Ui_edit() self.ui.setupUi(self.mainWidget) - for key, value in [('key', DEFAULT_HOTKEY), - ('functionMode', 0)]: - if key not in self.cfg: - self.cfg[key] = value - self.helpUrl = self.a2.urls.helpHotkey self.ui.hotkey_button.set_config(self.cfg) @@ -193,10 +187,11 @@ def element_icon(): def get_settings(_module_key, cfg, db_dict, user_cfg): key = a2ctrl.get_cfg_value(cfg, user_cfg, 'key', str) - scope = a2ctrl.get_cfg_value(cfg, user_cfg, 'scope', list) - scope_mode = a2ctrl.get_cfg_value(cfg, user_cfg, 'scopeMode', int) + scope = a2ctrl.get_cfg_value(cfg, user_cfg, Vars.scope, list) + scope_mode = a2ctrl.get_cfg_value(cfg, user_cfg, Vars.scope_mode, int) function = cfg.get( - ['functionCode', 'functionURL', 'functionSend'][cfg['functionMode']], + [Vars.function_code, Vars.function_url, Vars.function_send] + [cfg.get(Vars.function_mode, 0)], '') db_dict.setdefault('hotkeys', {}) diff --git a/ui/a2widget/a2hotkey/keyboard_dialog/base.py b/ui/a2widget/a2hotkey/keyboard_dialog/base.py index a1d6ce5e..a53aeaae 100644 --- a/ui/a2widget/a2hotkey/keyboard_dialog/base.py +++ b/ui/a2widget/a2hotkey/keyboard_dialog/base.py @@ -293,6 +293,8 @@ def refresh_style(self): def build_option_menu(self, menu): icons = a2ctrl.Icons.inst() + if self.key: + menu.addAction(icons.clear, 'Clear Hotkey', self.clear_hotkey) menu.addAction(icons.help, 'Help on Hotket Setup', self.goto_help) def _log_size(self): @@ -322,6 +324,18 @@ def _log_size(self): except AttributeError: pass + def clear_hotkey(self): + self.key = '' + + for modifier in self.checked_modifier: + self.modifier[modifier].setChecked(False) + self.checked_modifier = [] + + if self.checked_key: + self.key_dict[self.checked_key].setChecked(False) + self.checked_key = '' + self.update_hotkey_label() + def goto_help(self): a2util.surf_to(self.a2.urls.wiki + HOTKEY_HELP_PAGE) diff --git a/ui/a2widget/demo/hotkey_demo.py b/ui/a2widget/demo/hotkey_demo.py index 06f64640..d3d6e2f5 100644 --- a/ui/a2widget/demo/hotkey_demo.py +++ b/ui/a2widget/demo/hotkey_demo.py @@ -19,7 +19,6 @@ "functionMode": 0, "functionSend": "", "functionURL": "", - "key": "Ctrl+Alt+R", "keyChange": True, "multiple": True }