Skip to content

Commit f98ef3b

Browse files
author
James Boulton
committed
Add text replace functionality to the TextBoxControl
1 parent b64916b commit f98ef3b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

dashio/iotcontrol/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class TextFormat(Enum):
256256
DTLONG = "DTLONG"
257257
INTVL = "INTVL"
258258
LOG = "LOG"
259+
SUBS = "SUBS"
259260

260261

261262
class TextAlignment(Enum):

dashio/iotcontrol/textbox.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(
5151
keyboard_type: Keyboard,
5252
close_keyboard_on_send: bool,
5353
caption_mode: CaptionMode,
54+
replace: dict[str: str] | None,
5455
control_position: ControlPosition | None
5556
) -> None:
5657
super().__init__(control_id, title, control_position, title_position)
@@ -62,6 +63,12 @@ def __init__(
6263
self.cfg["kbdType"] = keyboard_type.value
6364
self.cfg["closeKbdOnSend"] = close_keyboard_on_send
6465
self.cfg["captionMode"] = caption_mode.value
66+
if replace is not None:
67+
for key, val in replace.items():
68+
for c in '\t\n':
69+
if (c in key) or (c in val):
70+
raise ValueError("Bad characters '\t\n' in replace dictionary.")
71+
self.cfg["replace"] = replace
6572

6673
@classmethod
6774
def from_dict(cls, cfg_dict: dict):
@@ -88,6 +95,7 @@ def from_dict(cls, cfg_dict: dict):
8895
_get_keyboard_type(cfg_dict["kbdType"]),
8996
cfg_dict["closeKbdOnSend"],
9097
_get_caption_mode(cfg_dict["captionMode"]),
98+
cfg_dict["replace"],
9199
ControlPosition(cfg_dict["xPositionRatio"], cfg_dict["yPositionRatio"], cfg_dict["widthRatio"], cfg_dict["heightRatio"])
92100
)
93101
tmp_cls.parent_id = cfg_dict["parentID"]
@@ -111,6 +119,7 @@ def __init__(
111119
keyboard_type=Keyboard.ALL,
112120
close_keyboard_on_send=True,
113121
caption_mode=CaptionMode.MSG,
122+
replace=None,
114123
control_position=None,
115124
column_no=1
116125
):
@@ -143,6 +152,8 @@ def __init__(
143152
caption_mode: CaptionMode, optional default MSG
144153
CaptionMode.MSG is for when the caption receives messages to be displayed.
145154
CaptionMode.SENT is when the caption shows the last message the user has entered.
155+
replace: { str: str }
156+
Dictionary of replacement text key value replacements to be performed by the Text box in the App.
146157
column_no : int, optional default is 1. Must be 1..3
147158
The Dash App reports its screen size in columns. column_no allows you to specify which column no to load into.
148159
Each control can store three configs that define how the device looks for Dash apps installed on single column
@@ -162,6 +173,7 @@ def __init__(
162173
keyboard_type,
163174
close_keyboard_on_send,
164175
caption_mode,
176+
replace,
165177
control_position
166178
)
167179
)
@@ -198,6 +210,7 @@ def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
198210
_get_keyboard_type(cfg_dict["kbdType"]),
199211
cfg_dict["closeKbdOnSend"],
200212
_get_caption_mode(cfg_dict["captionMode"]),
213+
cfg_dict.get("replace"),
201214
ControlPosition(cfg_dict["xPositionRatio"], cfg_dict["yPositionRatio"], cfg_dict["widthRatio"], cfg_dict["heightRatio"]),
202215
column_no
203216
)

utilities/c64_encode

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ def main():
4545
args = _parse_commandline_arguments()
4646
json_filename = args.file
4747
c64_filename = os.path.splitext(json_filename)[0] + ".c64"
48+
cfg64 = ""
4849

4950
if args.out_file:
5051
c64_filename = args.out_file
5152

5253
try:
5354
with open(json_filename, mode="r", encoding='utf-8') as fp:
5455
json_cfg = fp.read()
56+
config_dict = json.loads(json_cfg)
57+
cfg64 = dashio.encode_cfg64(config_dict)
5558

5659
except FileNotFoundError:
5760
print("File not found")
5861

59-
config_dict = json.loads(json_cfg)
60-
cfg64 = dashio.encode_cfg64(config_dict)
6162
cfg_file = open(c64_filename, "w", encoding='utf-8')
6263

6364
out_format = args.format.upper()

0 commit comments

Comments
 (0)