From 0b678e828f423b362910179b9f1d2a7f1e20e51b Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sun, 15 Sep 2019 22:06:46 -0500 Subject: [PATCH] Add support for shortcuts --- .gitignore | 1 + CHANGELOG | 4 +++ VERSION | 2 +- source/conf.py.example | 76 +++++++++++++++++++++++++++++++++++++++--- source/easymacro.py | 9 ++--- source/zaz.py | 5 +++ 6 files changed, 86 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 58bd977..05f63a9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ conf.py files/ docs/ +source/source/ # Virtualenv .env/ diff --git a/CHANGELOG b/CHANGELOG index 2e67c8b..024eb63 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v 0.5.0 [15-sep-2019] +--------------------- + - Add support for shortcuts + v 0.4.0 [14-sep-2019] --------------------- - Add support for locales diff --git a/VERSION b/VERSION index 1d0ba9e..8f0916f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +0.5.0 diff --git a/source/conf.py.example b/source/conf.py.example index 7c03a49..865d99f 100644 --- a/source/conf.py.example +++ b/source/conf.py.example @@ -36,13 +36,20 @@ ID = 'org.myextension.test' # ~ If you extension will be multilanguage set: True # ~ This feature used gettext, set pythonpath and easymacro in True +# ~ Yu can used PoEdit for edit PO files and generate MO files. +# ~ https://poedit.net/ USE_LOCALES = True DOMAIN = 'base' PATH_LOCALES = 'locales' +# ~ locate pygettext.py +PATH_PYGETTEXT = '/usr/lib/python3.7/Tools/i18n/pygettext.py' +PATH_MSGMERGE = 'msgmerge' + +# ~ Show in extension manager PUBLISHER = { - 'en': {'text': 'El Mau', 'link': 'https://elmau.net'}, - 'es': {'text': 'El Mau', 'link': 'https://elmau.net'}, + 'en': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, + 'es': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, } # ~ Name in this folder for copy @@ -102,6 +109,12 @@ CONTEXT = { # ~ For icons con name: NAME_16.bmp, used only NAME # ~ PARENT = '' # ~ MENU_MAIN = {} +# ~ Shortcut: Key + "Modifier Keys" +# ~ Important: Not used any shortcuts used for LibreOffice +# ~ SHIFT is mapped to Shift on all platforms. +# ~ MOD1 is mapped to Ctrl on Windows/Linux, while it is mapped to Cmd on Mac. +# ~ MOD2 is mapped to Alt on all platforms. +# ~ For example: Shift+Ctrl+Alt+M -> M_SHIFT_MOD1_MOD2 PARENT = 'OfficeMenuBar' MENU_MAIN = { 'en': 'My Extension', @@ -114,9 +127,11 @@ MENUS = ( 'context': 'calc,writer', 'icon': 'icon', 'toolbar': True, + 'shortcut': '', }, ) + # ~ Functions, only for TYPE_EXTENSION = 3 FUNCTIONS = { 'test': { @@ -150,8 +165,9 @@ DIRS = { 'images': 'images', 'registration': 'registration', 'files': 'files', - 'pythonpath': True, + 'office': 'Office', 'locales': PATH_LOCALES, + 'pythonpath': True, } @@ -167,6 +183,7 @@ FILES = { 'rdb': f'X{NAME}.rdb', 'update': f'{NAME.lower()}.update.xml', 'addin': 'CalcAddIn.xcu', + 'shortcut': 'Accelerators.xcu', 'easymacro': True, } @@ -418,7 +435,8 @@ if TYPE_EXTENSION == 3: FILE_MANIFEST = f""" - {NODE_ADDONS} + + {NODE_ADDONS} """ @@ -559,6 +577,55 @@ FILE_ADDIN = f""" """ +NODE_SHORTCUT = """ {0} + {0} + {0}service:{2}?{3} + {0} + {0} +""" + + +NODE_SHORTCUTS = '' +if TYPE_EXTENSION == 1: + node_global = [] + node_module = {} + for m in MENUS: + if not m['shortcut']: + continue + if m['context']: + for c in m['context'].split(','): + if not c in node_module: + node_module[c] = [] + node = NODE_SHORTCUT.format(' ', m['shortcut'], ID, m['argument']) + node_module[c].append(node) + continue + node = NODE_SHORTCUT.format('', m['shortcut'], ID, m['argument']) + node_global.append(node) + if node_global: + NODE_SHORTCUTS = ' \n' + NODE_SHORTCUTS += '\n'.join(node_global) + NODE_SHORTCUTS += ' ' + if node_module: + NODE_SHORTCUTS += ' \n' + for c, n in node_module.items(): + NODE_SHORTCUTS += ' \n'.format(CONTEXT[c]) + NODE_SHORTCUTS += '\n'.join(n) + NODE_SHORTCUTS += ' \n' + NODE_SHORTCUTS += ' ' + +FILE_SHORTCUTS = f""" + + +{NODE_SHORTCUTS} + + +""" + + DATA = { 'py': FILE_PY, 'manifest': FILE_MANIFEST, @@ -567,6 +634,7 @@ DATA = { 'update': FILE_UPDATE, 'idl': FILE_IDL, 'addin': FILE_ADDIN, + 'shortcut': FILE_SHORTCUTS, } diff --git a/source/easymacro.py b/source/easymacro.py index 622248c..e6ca331 100644 --- a/source/easymacro.py +++ b/source/easymacro.py @@ -68,12 +68,9 @@ MSG_LANG = { FILE_NAME_DEBUG = 'zaz-debug.log' LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' LOG_DATE = '%d/%m/%Y %H:%M:%S' -LEVEL_ERROR = logging.getLevelName(logging.ERROR) -LEVEL_DEBUG = logging.getLevelName(logging.DEBUG) -LEVEL_INFO = logging.getLevelName(logging.INFO) -logging.addLevelName(logging.ERROR, f'\033[1;41m{LEVEL_ERROR}\033[1;0m') -logging.addLevelName(logging.DEBUG, f'\x1b[33m{LEVEL_DEBUG}\033[1;0m') -logging.addLevelName(logging.INFO, f'\x1b[32m{LEVEL_INFO}\033[1;0m') +logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m') +logging.addLevelName(logging.DEBUG, '\x1b[33mDEBUG\033[1;0m') +logging.addLevelName(logging.INFO, '\x1b[32mINFO\033[1;0m') logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE) log = logging.getLogger(__name__) diff --git a/source/zaz.py b/source/zaz.py index ebbc1ff..8d977d4 100644 --- a/source/zaz.py +++ b/source/zaz.py @@ -114,6 +114,8 @@ def _create_new_directories(): _mkdir(path) path = _join(path_source, DIRS['registration']) _mkdir(path) + path = _join(path_source, DIRS['office']) + _mkdir(path) if FILES['easymacro'] or DIRS['pythonpath']: path = _join(path_source, 'pythonpath') @@ -223,6 +225,9 @@ def _update_files(): path = _join(path_source, DIRS['meta'], FILES['manifest']) _save(path, DATA['manifest']) + path = _join(path_source, DIRS['office'], FILES['shortcut']) + _save(path, DATA['shortcut']) + path = _join(path_source, FILES['addons']) _save(path, DATA['addons'])