Skip to content

Commit 0c97cb7

Browse files
Robert0MartRobeMartinsgmmcosta15
authored
Refactor basic filament button logic (#297)
## Description - [x] refactor **BlocksScreen/lib/panels/widgets/basicFilamentPanel.py** - updated button logic (now using with filament map position) --------- Co-authored-by: Roberto Martins <roberto.martins@blockstec.com> Co-authored-by: Guilherme Costa <guilherme.costa@blockstec.com>
1 parent 4255931 commit 0c97cb7

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

‎BlocksScreen/lib/panels/widgets/basicFilamentPanel.py‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from functools import partial
44

5+
from devices.amu.models import FilamentPos, GateStatus
56
from lib.filament import Filament
67
from lib.panels.widgets.basePopup import BasePopup
78
from lib.panels.widgets.popupDialogWidget import Popup
@@ -55,6 +56,7 @@ def __init__(
5556
self.filament_buttons_list = []
5657
self.mmu_configured = False
5758
self.load_popup = load_popup
59+
self._mmu_state = None
5860
self._setupUi()
5961
self.filament_state = self.FilamentStates.UNKNOWN
6062

@@ -262,10 +264,25 @@ def on_mmu_state_changed(self, mmu_state):
262264
btn.clicked.connect(partial(self.open_pre_gate_popup, _filament_type))
263265
self.mmu_configured = True
264266

265-
if mmu_state.filament == "Loaded":
266-
self.filament_state = self.FilamentStates.LOADED
267-
else:
267+
self._mmu_state = mmu_state
268+
if mmu_state.filament_pos == FilamentPos.UNKNOWN:
269+
self.filament_state = self.FilamentStates.UNKNOWN
270+
elif mmu_state.filament_pos == FilamentPos.UNLOADED:
268271
self.filament_state = self.FilamentStates.UNLOADED
272+
else:
273+
self.filament_state = self.FilamentStates.LOADED
274+
275+
@property
276+
def _gate_has_filament(self) -> bool:
277+
_gate = self._mmu_state.current_gate_info if self._mmu_state else None
278+
return _gate is None or _gate.status != GateStatus.EMPTY
279+
280+
@property
281+
def _mmu_busy(self) -> bool:
282+
return self._mmu_state is not None and self._mmu_state.action not in (
283+
"",
284+
"Idle",
285+
)
269286

270287
@property
271288
def filament_state(self):
@@ -274,15 +291,13 @@ def filament_state(self):
274291
@filament_state.setter
275292
def filament_state(self, update: FilamentStates) -> None:
276293
self._filament_state = update
277-
if update is self.FilamentStates.LOADED:
278-
self.filament_page_unload_btn.setEnabled(True)
279-
self.filament_page_load_btn.setEnabled(False)
280-
elif update is self.FilamentStates.UNLOADED:
281-
self.filament_page_unload_btn.setEnabled(False)
282-
self.filament_page_load_btn.setEnabled(True)
283-
else:
284-
self.filament_page_load_btn.setEnabled(True)
285-
self.filament_page_unload_btn.setEnabled(True)
294+
_idle = not self._mmu_busy
295+
_loaded = update is self.FilamentStates.LOADED
296+
_unloaded = update is self.FilamentStates.UNLOADED
297+
self.filament_page_unload_btn.setEnabled(_idle and not _unloaded)
298+
self.filament_page_load_btn.setEnabled(
299+
_idle and not _loaded and self._gate_has_filament
300+
)
286301

287302
def change_page(self, index: int) -> None:
288303
"""Switch this stacked widget to the page at *index*."""

‎tests/widgets/conftest.py‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@
1313
if str(_project_root) not in sys.path:
1414
sys.path.insert(0, str(_project_root))
1515

16-
for _pkg in ("lib", "lib.panels", "lib.panels.widgets", "lib.utils"):
16+
for _pkg in (
17+
"lib",
18+
"lib.panels",
19+
"lib.panels.widgets",
20+
"lib.utils",
21+
"devices",
22+
"devices.amu",
23+
"devices.amu.models",
24+
):
1725
sys.modules.pop(_pkg, None)
1826

19-
_lib_mod = types.ModuleType("lib")
20-
_lib_mod.__path__ = [str(_project_root / "BlocksScreen" / "lib")]
21-
_lib_mod.__package__ = "lib"
22-
sys.modules["lib"] = _lib_mod
27+
for _name, _parts in (
28+
("lib", ("lib",)),
29+
("devices", ("devices",)),
30+
("devices.amu", ("devices", "amu")),
31+
):
32+
_m = types.ModuleType(_name)
33+
_m.__path__ = [str(_project_root.joinpath("BlocksScreen", *_parts))]
34+
_m.__package__ = _name
35+
sys.modules[_name] = _m
2336

2437
for _mod_name in ("events", "helper_methods"):
2538
_mod_path = _project_root / "BlocksScreen" / f"{_mod_name}.py"

0 commit comments

Comments
 (0)