Skip to content

Commit 7b8548d

Browse files
authored
Handle missing Genesis facility/transfer providers (#128)
1 parent 36fb64c commit 7b8548d

7 files changed

Lines changed: 224 additions & 51 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ptychozoon = ["ptychozoon"]
4848
[tool.uv.sources]
4949
#ptychi = { path = "../pty-chi", editable = true }
5050
#ptychopinn = { path = "../PtychoPINN", editable = true }
51-
ptychopinn = { git = "https://github.com/hoidn/PtychoPINN", branch = "main" }
51+
#ptychopinn = { git = "https://github.com/hoidn/PtychoPINN", branch = "main" }
5252

5353
#[[tool.uv.index]]
5454
#name = "pytorch-cu132"

src/ptychodus/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def main() -> int:
101101

102102
from ptychodus.view import ViewCore
103103

104-
view = ViewCore()
104+
view = ViewCore(is_developer_mode_enabled=model.is_developer_mode_enabled)
105105

106106
from ptychodus.controller import ControllerCore
107107

src/ptychodus/api/plugins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def register_plugin(self, strategy: T, *, display_name: str, simple_name: str =
118118

119119
def get_current_plugin(self) -> Plugin[T]:
120120
"""Return the currently selected plugin."""
121+
if not self._registered_plugins:
122+
raise LookupError('No plugins registered')
121123
return self._registered_plugins[self._current_index]
122124

123125
def set_current_plugin(self, name: str) -> None:

src/ptychodus/controller/core.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ def __init__(
9292
view.product_view,
9393
self._file_dialog_factory,
9494
)
95-
self._product_visualization_controller = ProductVisualizationController(
96-
model.analysis_core.residual_analyzer,
97-
model.analysis_core.residual_real_space_visualization_engine,
98-
model.analysis_core.residual_reciprocal_space_visualization_engine,
99-
self._product_controller,
100-
view.product_visualization_view,
101-
self._status_bar,
102-
self._file_dialog_factory,
103-
)
95+
if is_developer_mode_enabled:
96+
self._product_visualization_controller = ProductVisualizationController(
97+
model.analysis_core.residual_analyzer,
98+
model.analysis_core.residual_real_space_visualization_engine,
99+
model.analysis_core.residual_reciprocal_space_visualization_engine,
100+
self._product_controller,
101+
view.product_visualization_view,
102+
self._status_bar,
103+
self._file_dialog_factory,
104+
)
104105
self._probe_positions_controller = ProbePositionsController(
105106
model.product_core.probe_positions_repository,
106107
model.product_core.probe_positions_api,
@@ -209,7 +210,7 @@ def __init__(
209210
view.genesis_action: model.genesis_core.is_supported,
210211
}
211212

212-
self._swap_central_widgets(view.patterns_action)
213+
self._swap_central_widgets(view.patterns_action, animated=False)
213214
view.patterns_action.setChecked(True)
214215
view.navigation.action_group.triggered.connect(
215216
lambda action: self._swap_central_widgets(action)
@@ -222,19 +223,20 @@ def show_main_window(self, window_title: str) -> None:
222223
self.view.setWindowTitle(window_title)
223224
self.view.show()
224225

225-
def _swap_central_widgets(self, action: QAction | None) -> None:
226+
def _swap_central_widgets(self, action: QAction | None, *, animated: bool = True) -> None:
226227
if action is None:
227228
raise ValueError('QAction is None!')
228229

229230
self.view.navigation.set_current_index(action.data())
230-
self._update_subview_visibility(action)
231+
self._update_subview_visibility(action, animated=animated)
231232

232-
def _update_subview_visibility(self, action: QAction) -> None:
233+
def _update_subview_visibility(self, action: QAction, *, animated: bool = True) -> None:
233234
for group in self.view.navigation.subview_groups:
234235
expanded = action is group.parent_action or action in group.child_actions
235236
for child in group.child_actions:
236237
allowed = self._action_permitted.get(child, True)
237-
child.setVisible(expanded and allowed)
238+
group.container.set_child_button_visible(child, allowed)
239+
group.container.set_expanded(expanded, animated=animated)
238240
group.top_separator.setVisible(expanded)
239241
group.bottom_separator.setVisible(expanded)
240242

src/ptychodus/model/genesis/core.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,38 +102,59 @@ def supported_transfer_clients(self) -> Sequence[str]:
102102
return [plugin.display_name for plugin in self._transfer_client_chooser]
103103

104104
def refresh_projects(self) -> None:
105+
if not self._facility_chooser:
106+
logger.debug('refresh_projects: no facility adapter registered; skipping')
107+
return
105108
facility_adapter = self._facility_chooser.get_current_plugin().strategy
106109
facility_adapter.refresh_projects()
107110

108111
def supported_projects(self) -> Sequence[str]:
112+
if not self._facility_chooser:
113+
return []
109114
facility_adapter = self._facility_chooser.get_current_plugin().strategy
110115
return facility_adapter.project_names()
111116

112117
def map_project_name_to_id(self, name: str) -> str:
118+
if not self._facility_chooser:
119+
return name
113120
facility_adapter = self._facility_chooser.get_current_plugin().strategy
114121
return facility_adapter.map_project_name_to_id(name)
115122

116123
def map_project_id_to_name(self, project_id: str) -> str:
124+
if not self._facility_chooser:
125+
return project_id
117126
facility_adapter = self._facility_chooser.get_current_plugin().strategy
118127
return facility_adapter.map_project_id_to_name(project_id)
119128

120129
def refresh_compute_resources(self) -> None:
130+
if not self._facility_chooser:
131+
logger.debug('refresh_compute_resources: no facility adapter registered; skipping')
132+
return
121133
facility_adapter = self._facility_chooser.get_current_plugin().strategy
122134
facility_adapter.refresh_compute_resources()
123135

124136
def supported_compute_resources(self) -> Sequence[str]:
137+
if not self._facility_chooser:
138+
return []
125139
facility_adapter = self._facility_chooser.get_current_plugin().strategy
126140
return facility_adapter.compute_resource_names()
127141

128142
def map_compute_resource_name_to_id(self, name: str) -> str:
143+
if not self._facility_chooser:
144+
return name
129145
facility_adapter = self._facility_chooser.get_current_plugin().strategy
130146
return facility_adapter.map_compute_resource_name_to_id(name)
131147

132148
def map_compute_resource_id_to_name(self, resource_id: str) -> str:
149+
if not self._facility_chooser:
150+
return resource_id
133151
facility_adapter = self._facility_chooser.get_current_plugin().strategy
134152
return facility_adapter.map_compute_resource_id_to_name(resource_id)
135153

136154
def apply_facility_defaults(self) -> None:
155+
if not self._facility_chooser:
156+
logger.debug('apply_facility_defaults: no facility adapter registered; skipping')
157+
return
137158
adapter = self._facility_chooser.get_current_plugin().strategy
138159
globus_collection = adapter.get_default_globus_collection()
139160

@@ -163,10 +184,13 @@ def __init__(
163184
for name, provider in create_globus_transfer_providers().items():
164185
self._transfer_client_chooser.register_plugin(provider, display_name=name)
165186

166-
self._facility_chooser.synchronize_with_parameter(self.settings.facility)
167-
self._transfer_client_chooser.synchronize_with_parameter(
168-
self.settings.globus_transfer_provider
169-
)
187+
if self._facility_chooser:
188+
self._facility_chooser.synchronize_with_parameter(self.settings.facility)
189+
190+
if self._transfer_client_chooser:
191+
self._transfer_client_chooser.synchronize_with_parameter(
192+
self.settings.globus_transfer_provider
193+
)
170194

171195
status_q: queue.Queue[GenesisStatus] = queue.Queue()
172196
self.status_repository = GenesisStatusRepository(status_q)

0 commit comments

Comments
 (0)