Progress
dcmspec.progress
Progress tracking classes for monitoring long-running operations in dcmspec.
Progress
Represent the progress of a long-running operation.
PARAMETER | DESCRIPTION |
---|---|
percent
|
The progress percentage (0-100).
TYPE:
|
status
|
A machine-readable status code (see ProgressStatus enum). Clients are responsible for mapping this code to a user-facing string or UI element.
TYPE:
|
step
|
The current step number in a multi-step process (1-based).
TYPE:
|
total_steps
|
The total number of steps in the process.
TYPE:
|
Source code in src/dcmspec/progress.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
percent
property
Get the progress percentage.
status
property
Get the progress status.
step
property
Get the current step number.
total_steps
property
Get the total number of steps.
__init__(percent, status=None, step=None, total_steps=None)
Initialize the progress private attributes.
This class is immutable: the percent value is set at initialization and should not be changed. To report new progress, create a new Progress instance.
PARAMETER | DESCRIPTION |
---|---|
percent
|
The progress percentage (0-100).
TYPE:
|
status
|
A status code indicating the current operation.
TYPE:
|
step
|
The current step number in a multi-step process (1-based).
TYPE:
|
total_steps
|
The total number of steps in the process.
TYPE:
|
Source code in src/dcmspec/progress.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
__setattr__(name, value)
Prevent modification of attributes after initialization.
Source code in src/dcmspec/progress.py
59 60 61 62 63 |
|
ProgressObserver
Observer for monitoring progress updates.
Source code in src/dcmspec/progress.py
221 222 223 224 225 226 227 228 229 230 231 232 |
|
__call__(progress)
Handle progress updates.
PARAMETER | DESCRIPTION |
---|---|
progress
|
The current progress state.
TYPE:
|
Source code in src/dcmspec/progress.py
224 225 226 227 228 229 230 231 232 |
|
ProgressStatus
Bases: Enum
Enumeration of progress statuses.
This enum defines the various states that a long-running operation can be in.
Name | Value | Description |
---|---|---|
DOWNLOADING | auto() | Generic download (e.g., a document) |
DOWNLOADING_IOD | auto() | Downloading the IOD specification document (Part 3) |
PARSING_TABLE | auto() | Parsing a DICOM table |
PARSING_IOD_MODULE_LIST | auto() | Parsing the list of modules in the IOD |
PARSING_IOD_MODULES | auto() | Parsing the IOD modules |
SAVING_MODEL | auto() | Saving a specification model to disk |
SAVING_IOD_MODEL | auto() | Saving the IOD model to disk |
Example
In your application, you can use ProgressStatus to present progress information to users:
from dcmspec.progress import ProgressStatus
def progress_observer(progress):
if progress.status == ProgressStatus.DOWNLOADING_IOD:
print(f"Downloading IOD... {progress.percent}%")
Source code in src/dcmspec/progress.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
adapt_progress_observer(observer)
Wrap a progress observer or callback so it can accept either a Progress object or an int percent.
This function provides backward compatibility for legacy progress callbacks that expect
an integer percent value. If the observer is a plain function that takes a single argument
(typed as int
or untyped), it will be wrapped so that it receives progress.percent
instead of the Progress object. A DeprecationWarning is issued when this legacy usage occurs.
Only plain functions are wrapped; class instances or callables are left unchanged to avoid interfering with class-based observers that expect a Progress object.
PARAMETER | DESCRIPTION |
---|---|
observer
|
The progress observer or callback.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[Callable[[Progress], None]]
|
callable or None: An observer that always accepts a Progress object, or a wrapper that calls the |
Optional[Callable[[Progress], None]]
|
original callback with progress.percent if it expects an int. |
Example
Legacy callback (int)
def my_callback(percent): print(f"Progress: {percent}%")
New-style callback (Progress)
def my_observer(progress): print(f"Progress: {progress.percent}%")
Source code in src/dcmspec/progress.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
add_progress_step(step, total_steps, status=None)
Define a decorator to enrich progress events with step, total_steps, and optionally status.
Source code in src/dcmspec/progress.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
calculate_percent(downloaded, total)
Calculate percent complete, rounded, or -1 if total is unknown/invalid.
Source code in src/dcmspec/progress.py
137 138 139 140 141 |
|
handle_legacy_callback(progress_observer=None, progress_callback=None)
Resolve and return a progress_observer, handling legacy progress_callback and warning if both are provided.
If both are provided, only progress_observer is used and a warning is issued. If only progress_callback is provided, it is adapted to a progress_observer.
Source code in src/dcmspec/progress.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
offset_progress_steps(step_offset, total_steps)
Define a decorator to offset progress steps by a fixed amount.
Source code in src/dcmspec/progress.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|