Add support for shortcuts

This commit is contained in:
Mauricio Baeza 2019-09-15 22:06:46 -05:00
parent 563ac48a6b
commit 0b678e828f
6 changed files with 86 additions and 11 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ conf.py
files/
docs/
source/source/
# Virtualenv
.env/

View File

@ -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

View File

@ -1 +1 @@
0.4.0
0.5.0

View File

@ -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"""<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
<manifest:file-entry manifest:full-path="{FILES['py']}" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>{NODE_ADDONS}
<manifest:file-entry manifest:full-path="{FILES['py']}" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
<manifest:file-entry manifest:full-path="Office/Accelerators.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>{NODE_ADDONS}
</manifest:manifest>
"""
@ -559,6 +577,55 @@ FILE_ADDIN = f"""<?xml version="1.0" encoding="UTF-8"?>
</oor:component-data>"""
NODE_SHORTCUT = """ {0}<node oor:name="{1}" oor:op="fuse">
{0}<prop oor:name="Command">
{0}<value xml:lang="en-US">service:{2}?{3}</value>
{0}</prop>
{0}</node>
"""
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 = ' <node oor:name="Global">\n'
NODE_SHORTCUTS += '\n'.join(node_global)
NODE_SHORTCUTS += ' </node>'
if node_module:
NODE_SHORTCUTS += ' <node oor:name="Modules">\n'
for c, n in node_module.items():
NODE_SHORTCUTS += ' <node oor:name="{}">\n'.format(CONTEXT[c])
NODE_SHORTCUTS += '\n'.join(n)
NODE_SHORTCUTS += ' </node>\n'
NODE_SHORTCUTS += ' </node>'
FILE_SHORTCUTS = f"""<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data
xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="Accelerators"
oor:package="org.openoffice.Office">
<node oor:name="PrimaryKeys">
{NODE_SHORTCUTS}
</node>
</oor:component-data>
"""
DATA = {
'py': FILE_PY,
'manifest': FILE_MANIFEST,
@ -567,6 +634,7 @@ DATA = {
'update': FILE_UPDATE,
'idl': FILE_IDL,
'addin': FILE_ADDIN,
'shortcut': FILE_SHORTCUTS,
}

View File

@ -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__)

View File

@ -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'])