Application State¶
Observable application runtime state.
Provides a singleton for managing mutable application state with Qt signals for reactive updates. Use this for state that changes during runtime and needs to be observed by multiple components.
from src.shared_services.state.app_state import AppState
# Get singleton
state = AppState.instance()
# Connect to state changes
state.software_changed.connect(self.on_software_changed)
# Update state (emits signal automatically)
state.set_active_software("PlantDesign")
For theme state, use StylesheetManager instead.
API Reference¶
src.shared_services.state.app_state
¶
Observable application runtime state.
Provides a singleton for managing mutable application state with Qt signals for reactive updates. Use this for state that changes during runtime and needs to be observed by multiple components.
Usage
from src.shared_services.state.app_state import AppState
Get singleton¶
state = AppState.instance()
Connect to state changes¶
state.software_changed.connect(self.on_software_changed)
Update state (emits signal automatically)¶
state.set_active_software("PlantDesign")
Note
For theme state, use StylesheetManager instead: from src.shared_services.rendering.stylesheets.api import StylesheetManager
AppState
¶
Bases: QObject
Singleton managing observable application runtime state.
This class manages mutable state that needs to be shared across the application with change notifications via Qt signals.
Signals
software_changed: Emitted when active software changes. Args: software_name (str), is_active (bool) library_mode_changed: Emitted when library editing mode changes. Args: in_edit_view (bool), in_project_usage (bool) network_status_changed: Emitted when network connectivity changes. Args: connected (bool)
Example
Basic usage::
state = AppState.instance()
# Connect to changes
state.software_changed.connect(self.handle_software_change)
# Set active software
state.set_active_software("PlantDesign")
# Check state
if state.is_software_active:
print(f"Running: {state.active_software}")
Source code in src\shared_services\state\app_state.py
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 64 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
active_software
property
¶
Get the name of the currently active software module.
has_network_override
property
¶
Check if network state override is active.
is_library_edit_mode
property
¶
Check if the library system is in edit view.
is_library_in_project_usage
property
¶
Check if the library system is being used within a project.
is_network_connected
property
¶
Check if the network is currently connected.
is_software_active
property
¶
Check if any software module is currently active.
network_override_value
property
¶
Get the current network override value (None if not overridden).
__init__()
¶
Initialize the application state.
Source code in src\shared_services\state\app_state.py
clear_active_software()
¶
clear_network_override()
¶
Clear network override and restore normal connectivity checking.
After calling this, network state will be determined by actual connectivity checks again.
Source code in src\shared_services\state\app_state.py
instance()
classmethod
¶
reset_instance()
classmethod
¶
Reset the singleton instance.
Useful for testing to ensure clean state between tests.
set_active_software(name)
¶
Set the active software module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the software module (e.g., "PlantDesign"). Empty string clears the active software. |
required |
Emits
software_changed: With (name, is_active) arguments.
Source code in src\shared_services\state\app_state.py
set_library_edit_mode(in_edit_view)
¶
Set the library editing mode state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_edit_view
|
bool
|
True if editing a library, False otherwise. |
required |
Emits
library_mode_changed: With (in_edit_view) argument when state changes.
Source code in src\shared_services\state\app_state.py
set_library_in_project_usage(active)
¶
Set whether the library system is in project usage mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active
|
bool
|
True if library is used within a project context. |
required |
Emits
library_project_usage_changed: With (active) argument when state changes.
Source code in src\shared_services\state\app_state.py
set_network_connected(connected)
¶
Set the network connectivity state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connected
|
bool
|
True if network is connected, False otherwise. |
required |
Emits
network_status_changed: With (connected) argument when state changes.
Source code in src\shared_services\state\app_state.py
set_network_override(connected)
¶
Override network connectivity state for testing.
When set, the actual network check is bypassed and this value is used instead. Call clear_network_override() to restore normal behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connected
|
bool
|
The mock connectivity state (False = simulate offline). |
required |
Example
Simulate offline mode for testing¶
state = AppState.instance() state.set_network_override(False)
... test offline behavior ...¶
state.clear_network_override() # Restore normal behavior