Skip to content

Commit 4566632

Browse files
macevhiczMHendricks
authored andcommitted
Allow passing a fully formed workbox name
1 parent 7d16873 commit 4566632

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

preditor/gui/workbox_mixin.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,28 @@
1515
class WorkboxName(str):
1616
"""The joined name of a workbox `group/workbox` with access to its parts.
1717
18+
You may pass the group, workbox, or the fully formed workbox name:
19+
examples:
20+
workboxName = WorkboxName("Group01", "Workbox05")
21+
workboxName = WorkboxName("Group01/Workbox05")
1822
This subclass provides properties for the group and workbox values separately.
1923
"""
2024

21-
def __new__(cls, group, workbox):
22-
txt = "/".join((group, workbox))
25+
def __new__(cls, name, sub_name=None):
26+
if sub_name is not None:
27+
txt = "/".join((name, sub_name))
28+
else:
29+
txt = name
30+
try:
31+
name, sub_name = txt.split("/")
32+
except ValueError:
33+
msg = "A fully formed name, or a group and name, must be passed in."
34+
raise ValueError(msg) from None
35+
2336
ret = super().__new__(cls, txt)
2437
# Preserve the imitable nature of str's by using properties without setters.
25-
ret._group = group
26-
ret._workbox = workbox
38+
ret._group = name
39+
ret._workbox = sub_name
2740
return ret
2841

2942
@property

0 commit comments

Comments
 (0)