Skip to content

Commit a3bed3d

Browse files
committed
Add macro editing functionality and dependency on 'sh' library
1 parent 94b01f4 commit a3bed3d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

not1mm/__main__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020
import queue
2121
import socket
22+
import sh
2223
import sys
2324
import uuid
2425

@@ -3381,6 +3382,29 @@ def edited_macro(self) -> None:
33813382
)
33823383
self.edit_macro_dialog.close()
33833384

3385+
if self.radioButton_run.isChecked():
3386+
rm = "R"
3387+
else:
3388+
rm = "S"
3389+
3390+
_, _, new_label = self.edit_macro_dialog.macro_label.text().partition(":")
3391+
fkey, _, old_label = self.edit_macro_dialog.old_label.partition(":")
3392+
3393+
new_label = new_label.strip()
3394+
old_label = old_label.strip()
3395+
3396+
old_string = self.edit_macro_dialog.old_macro
3397+
new_string = f"{self.edit_macro_dialog.the_macro.text()}"
3398+
3399+
sed_string = f"s/{rm}|{fkey}|{old_label}|{old_string}/{rm}|{fkey}|{new_label}|{new_string}/g"
3400+
3401+
macro_file = str(self.get_macro_filename())
3402+
3403+
try:
3404+
sh.sed("-i", sed_string, macro_file)
3405+
except sh.ErrorReturnCode_2:
3406+
...
3407+
33843408
def process_macro(self, macro: str) -> str:
33853409
"""
33863410
Process CW macro substitutions for contest.

not1mm/lib/edit_macro.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ def __init__(self, function_key, app_data_path):
1414
self.macro_label.setText(function_key.text())
1515
self.the_macro.setText(function_key.toolTip())
1616

17+
self.old_macro = function_key.toolTip()
18+
self.old_label = function_key.text()
19+
1720
def store(self):
1821
"""dialog magic"""

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies = [
2525
"rapidfuzz",
2626
"appdata",
2727
"adif_io",
28+
"sh>=2.2.2",
2829
]
2930
classifiers = [
3031
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)