Skip to content

Commit

Permalink
Merge pull request #158 from ewerybody/master
Browse files Browse the repository at this point in the history
getting stuff from master
  • Loading branch information
ewerybody authored Jun 19, 2018
2 parents c6a4c60 + 7d5e26b commit 5627a81
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 28 deletions.
16 changes: 8 additions & 8 deletions ui/a2core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')

Expand Down
6 changes: 5 additions & 1 deletion ui/a2element/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
15 changes: 5 additions & 10 deletions ui/a2element/hotkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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', {})
Expand Down
1 change: 1 addition & 0 deletions ui/a2widget/a2hotkey/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .hotkey_widget import A2Hotkey
from .hotkey_common import Vars
3 changes: 2 additions & 1 deletion ui/a2widget/a2hotkey/edit_func_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
9 changes: 9 additions & 0 deletions ui/a2widget/a2hotkey/hotkey_common.py
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 2 additions & 6 deletions ui/a2widget/a2hotkey/hotkey_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions ui/a2widget/a2hotkey/keyboard_dialog/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -289,6 +291,12 @@ 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()
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):
"""
Eventually I want to put the dialog under the cursor. But for that we need to
Expand Down Expand Up @@ -316,6 +324,21 @@ 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)


class CursorBlockWidget(QtGui.QWidget):
def __init__(self, parent):
Expand Down
23 changes: 22 additions & 1 deletion ui/a2widget/a2hotkey/keyboard_dialog/base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@
<number>10</number>
</property>
<item>
<widget class="QLineEdit" name="key_field"/>
<widget class="QLineEdit" name="key_field">
<property name="text">
<string notr="true"/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="A2MoreButton" name="option_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
Expand Down Expand Up @@ -279,6 +293,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>A2MoreButton</class>
<extends>QToolButton</extends>
<header>a2widget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
6 changes: 6 additions & 0 deletions ui/a2widget/a2hotkey/keyboard_dialog/base_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def setupUi(self, Keyboard):
self.top_layout.setContentsMargins(-1, 10, -1, 10)
self.top_layout.setObjectName("top_layout")
self.key_field = QtWidgets.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 = QtWidgets.QLabel(Keyboard)
self.label_2.setObjectName("label_2")
self.top_layout.addWidget(self.label_2)
Expand Down Expand Up @@ -187,3 +192,4 @@ def retranslateUi(self, Keyboard):
Keyboard.setWindowTitle(QtWidgets.QApplication.translate("Keyboard", "Hotkey Dialog", None, -1))
self.label_2.setText(QtWidgets.QApplication.translate("Keyboard", "Show:", None, -1))

from a2widget import A2MoreButton
1 change: 0 additions & 1 deletion ui/a2widget/demo/hotkey_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"functionMode": 0,
"functionSend": "",
"functionURL": "",
"key": "Ctrl+Alt+R",
"keyChange": True,
"multiple": True
}
Expand Down

0 comments on commit 5627a81

Please sign in to comment.