Skip to content

Commit 596adc8

Browse files
Moved function get_viewport_info to SampleView component
1 parent e733cfc commit 596adc8

File tree

4 files changed

+47
-60
lines changed

4 files changed

+47
-60
lines changed

mxcubeweb/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626

2727
from mxcubeweb.core.adapter.adapter_manager import HardwareObjectAdapterManager
28-
from mxcubeweb.core.components.beamline import Beamline
2928
from mxcubeweb.core.components.chat import Chat
3029
from mxcubeweb.core.components.component_base import import_component
3130
from mxcubeweb.core.components.harvester import Harvester
@@ -167,7 +166,6 @@ def init(
167166
)
168167
MXCUBEApplication.chat = Chat(MXCUBEApplication, {})
169168
MXCUBEApplication.sample_changer = SampleChanger(MXCUBEApplication, {})
170-
MXCUBEApplication.beamline = Beamline(MXCUBEApplication, {})
171169
MXCUBEApplication.sample_view = SampleView(MXCUBEApplication, {})
172170
MXCUBEApplication.workflow = Workflow(MXCUBEApplication, {})
173171
MXCUBEApplication.harvester = Harvester(MXCUBEApplication, {})

mxcubeweb/core/components/beamline.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

mxcubeweb/core/components/sampleview.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def init_signals(self):
225225

226226
def set_image_size(self, width, height):
227227
HWR.beamline.sample_view.camera.restart_streaming((width, height))
228-
return self.app.beamline.get_viewport_info()
228+
return self.get_viewport_info()
229229

230230
def move_to_centred_position(self, point_id):
231231
point = HWR.beamline.sample_view.get_shape(point_id)
@@ -447,3 +447,48 @@ def set_centring_method(self, method):
447447
HWR.beamline.queue_manager.centring_method = CENTRING_METHOD.MANUAL
448448

449449
logging.getLogger("user_level_log").info(msg)
450+
451+
def get_viewport_info(self):
452+
"""
453+
Get information about current "view port" video dimension, beam position,
454+
pixels per mm, returns a dictionary with the format:
455+
456+
data = {"pixelsPerMm": pixelsPerMm,
457+
"imageWidth": width,
458+
"imageHeight": height,
459+
"format": fmt,
460+
"sourceIsScalable": source_is_scalable,
461+
"scale": scale,
462+
"videoSizes": video_sizes,
463+
"position": position,
464+
"shape": shape,
465+
"size_x": sx, "size_y": sy}
466+
467+
:returns: Dictionary with view port data, with format described above
468+
:rtype: dict
469+
"""
470+
fmt, source_is_scalable = "MJPEG", False
471+
472+
if self.app.CONFIG.app.VIDEO_FORMAT == "MPEG1":
473+
fmt, source_is_scalable = "MPEG1", True
474+
video_sizes = HWR.beamline.sample_view.camera.get_available_stream_sizes()
475+
(width, height, scale) = HWR.beamline.sample_view.camera.get_stream_size()
476+
else:
477+
scale = 1
478+
width = HWR.beamline.sample_view.camera.get_width()
479+
height = HWR.beamline.sample_view.camera.get_height()
480+
video_sizes = [(width, height)]
481+
482+
pixels_per_mm = HWR.beamline.diffractometer.get_pixels_per_mm()
483+
484+
return {
485+
"pixelsPerMm": pixels_per_mm,
486+
"imageWidth": width,
487+
"imageHeight": height,
488+
"format": fmt,
489+
"sourceIsScalable": source_is_scalable,
490+
"scale": scale,
491+
"videoSizes": video_sizes,
492+
"videoHash": HWR.beamline.sample_view.camera.stream_hash,
493+
"videoURL": self.app.CONFIG.app.VIDEO_STREAM_URL,
494+
}

mxcubeweb/routes/samplecentring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_image_data():
8989
:statuscode: 200: no error
9090
:statuscode: 409: error
9191
"""
92-
data = app.beamline.get_viewport_info()
92+
data = app.sample_view.get_viewport_info()
9393

9494
resp = jsonify(data)
9595
resp.status_code = 200

0 commit comments

Comments
 (0)