Skip to content

Commit

Permalink
Hotstrings 0.3.1: Fixed import script
Browse files Browse the repository at this point in the history
  • Loading branch information
ewerybody committed Apr 15, 2023
1 parent 82bec81 commit c93e9ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions HotStrings/a2_menu_item_import_hotstrings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# a2 menu item script "import_hotstrings"
import a2core
import a2mod
from a2qt import QtWidgets

def main(a2: a2core.A2Obj, mod):
print('Import Hotstrings ... %s' % __name__)
log = a2core.get_logger(__name__)


def main(a2: a2core.A2Obj, mod: a2mod.Mod):
file_path, _ = QtWidgets.QFileDialog.getOpenFileName(
None, 'Import Hotstrings Data', a2.paths.a2, '(*.ahk *.json)'
)
if not file_path:
return

log.info('Importing Hotstrings from ...\n %s', file_path)

import os
import a2util
import hotstrings_io
Expand All @@ -23,7 +27,7 @@ def main(a2: a2core.A2Obj, mod):
elif ext == '.json':
hs_input = a2util.json_read(file_path)
else:
raise NotImplementedError('Unknown file type "%s"!' % ext)
raise NotImplementedError(f'Unknown file type "{ext}"!')

hotstrings_io.scopes_to_groups(hs_input)

Expand All @@ -34,14 +38,14 @@ def main(a2: a2core.A2Obj, mod):
for name, group in hs_input.get(Args.groups, {}).items():
if not Args.hotstrings in group:
continue
if not len(group[Args.hotstrings]):
if not group[Args.hotstrings]:
continue
name = f'Imported {base} - {name}'
name = a2util.get_next_free_number(name, current_names)
group[Args.enabled] = False
current_groups[name] = group
current_names.append(name)

mod.set_user_cfg({'name': hotstrings_io.Args.hotstrings}, current_cfg)
mod.set_user_cfg({Args.hotstrings: current_cfg})
a2.win.load_runtime_and_ui()
a2.win.check_element(Args.hotstrings)
4 changes: 2 additions & 2 deletions HotStrings/a2module.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"typ": "nfo",
"url": "https://github.com/ewerybody/a2.modules/tree/master/HotStrings#hotstrings",
"version": "0.3"
"version": "0.3.1"
},
{
"label": "Import Hotstrings",
Expand All @@ -30,4 +30,4 @@
"name": "hotstrings",
"typ": "a2_local_element"
}
]
]

0 comments on commit c93e9ef

Please sign in to comment.