|
2 | 2 | import logging |
3 | 3 | from typing import ClassVar |
4 | 4 |
|
| 5 | +from gevent.lock import RLock |
| 6 | + |
5 | 7 | from flask import send_file |
6 | 8 | from mxcubecore import HardwareRepository as HWR |
7 | 9 | from mxcubecore import queue_entry as qe |
@@ -54,6 +56,7 @@ def __init__(self, ho, role, app): |
54 | 56 | self._click_limit = int(HWR.beamline.config.click_centring_num_clicks or 3) |
55 | 57 | self._centring_point_id = None |
56 | 58 | self._error = False |
| 59 | + self._click_lock = RLock() |
57 | 60 |
|
58 | 61 | self._ho.connect("shapesChanged", self._emit_shapes_updated) |
59 | 62 | self._ho.connect("newGridResult", self._handle_grid_result) |
@@ -396,25 +399,26 @@ def abort_centring(self): |
396 | 399 | return {} |
397 | 400 |
|
398 | 401 | def click(self, x: float, y: float): |
399 | | - if self._error: |
400 | | - msg = "Error while centring, please try again" |
401 | | - raise RuntimeError(msg) |
402 | | - |
403 | | - if HWR.beamline.diffractometer.current_centring_procedure: |
404 | | - try: |
405 | | - HWR.beamline.diffractometer.image_clicked(x, y) |
406 | | - self.centring_click() |
407 | | - except Exception: |
408 | | - logging.getLogger("MX3.HWR").exception("") |
409 | | - return {"clicksLeft": -1} |
| 402 | + with self._click_lock: |
| 403 | + if self._error: |
| 404 | + msg = "Error while centring, please try again" |
| 405 | + raise RuntimeError(msg) |
410 | 406 |
|
411 | | - elif not self.centring_clicks_left(): |
412 | | - self.centring_reset_click_count() |
413 | | - HWR.beamline.diffractometer.start_centring_method( |
414 | | - HWR.beamline.diffractometer.CENTRING_METHOD_MANUAL |
415 | | - ) |
| 407 | + if HWR.beamline.diffractometer.current_centring_procedure: |
| 408 | + try: |
| 409 | + HWR.beamline.diffractometer.image_clicked(x, y) |
| 410 | + self.centring_click() |
| 411 | + except Exception: |
| 412 | + logging.getLogger("MX3.HWR").exception("") |
| 413 | + return {"clicksLeft": -1} |
| 414 | + |
| 415 | + elif not self.centring_clicks_left(): |
| 416 | + self.centring_reset_click_count() |
| 417 | + HWR.beamline.diffractometer.start_centring_method( |
| 418 | + HWR.beamline.diffractometer.CENTRING_METHOD_MANUAL |
| 419 | + ) |
416 | 420 |
|
417 | | - return {"clicksLeft": self.centring_clicks_left()} |
| 421 | + return {"clicksLeft": self.centring_clicks_left()} |
418 | 422 |
|
419 | 423 | def accept_centring(self): |
420 | 424 | HWR.beamline.diffractometer.accept_centring() |
|
0 commit comments