Skip to content

Commit d8f0169

Browse files
authored
feat: Add asterisk to mandatory parameters (#50)
* Default parameters asterisk * Documentation for mandatory parameters.
1 parent 3c030b1 commit d8f0169

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

docs/source/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Glossary
2626
Releases
2727
---------------------
2828

29+
v1.5.0
30+
=====================
31+
- Added an asterisk (*) to mandatory parameters.
32+
2933
v1.4.10
3034
=====================
3135
- Fixed string casting sometimes being cast to a list type.

docs/source/guide/defining.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ We will click on the "New" button located in the same row as the ``name`` label
115115
:width: 15cm
116116

117117

118+
119+
Mandatory & optional parameters
120+
-----------------------------------
121+
When a parameter has a default value assigned to it, it is considered an optional parameter.
122+
Parameters without a default value are considered mandatory. Mandatory parameters are marked
123+
with the asterisk (``*``) symbol.
124+
125+
.. image:: ./images/mandatory_parameter_asterisk.png
126+
:width: 15cm
127+
128+
118129
Defining strings
119130
=====================
120131
Clicking on "New -> str", as seen on the previous picture, will open up a new definition frame (page),
14.8 KB
Loading

tkclasswiz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
SOFTWARE.
2828
"""
2929

30-
__version__ = "1.4.10"
30+
__version__ = "1.5.0"
3131

3232

3333
from .object_frame import *

tkclasswiz/messagebox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def show_error(cls, title: str, message: str, **kwargs):
5757
@classmethod
5858
def show_info(cls, title: str, message: str, **kwargs):
5959
cls._process_kwargs(kwargs)
60-
mb.showinfo(title, message, **kwargs)
60+
mb.showinfo(title, message, **kwargs)

tkclasswiz/object_frame/frame_struct.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,23 @@ def _create_fields(self, annotations: dict[str, type], additional_values: dict,
151151
dpi_5h = dpi_5 // 2
152152

153153
labels: list[ttk.Label] = []
154+
155+
# Get parameters with default values.
156+
# This is used for adding an asterisk to parameters without a default (mandatory parameters).
157+
signature = inspect.signature(self.class_)
158+
param_defaults = set([k for k, v in signature.parameters.items() if v.default is not v.empty])
159+
154160
for (k, v) in annotations.items():
155161
# Init widgets
156162
entry_types = convert_types(v)
157163
frame_annotated = ttk.Frame(frame)
158164
frame_annotated.pack(fill=tk.BOTH, expand=True, pady=dpi_5)
159-
label = ttk.Label(frame_annotated, text=k)
165+
166+
text = k
167+
if k not in param_defaults: # Parameter is mandatory
168+
text = f'* {text}'
169+
170+
label = ttk.Label(frame_annotated, text=text)
160171
labels.append(label)
161172
label.pack(side="left")
162173

0 commit comments

Comments
 (0)