Skip to content

Commit

Permalink
Merge pull request #13 from BCDA-APS/connect-to-qserver
Browse files Browse the repository at this point in the history
Connect to qserver
  • Loading branch information
olliviergassant authored Jul 8, 2024
2 parents 849fb08 + 6d616ca commit 23e367f
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,4 @@ logs/
.ruff_cache/*

test_experiment/
queueUI/qserverconnect.ipynb
59 changes: 59 additions & 0 deletions queueUI/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
~MainWindow
"""

from bluesky_queueserver_api.zmq import REManagerAPI
from PyQt5 import QtWidgets

from . import APP_TITLE, utils
from .user_settings import settings

UI_FILE = utils.getUiFileName(__file__)

# Connect to the QServer
# def queueserver_api():
# try:
# #Where is the TOML file located?
# config = load_config()["queueserver"]
# except KeyError:
# raise InvalidConfiguration("Could not load queueserver info from iconfig.toml file.")
# ctrl_addr = f"tcp://{config['control_host']}:{config['control_port']}"
# info_addr = f"tcp://{config['info_host']}:{config['info_port']}"
# api = REManagerAPI(zmq_control_addr=ctrl_addr, zmq_info_addr=info_addr)
# return api


class MainWindow(QtWidgets.QMainWindow):
"""
Expand All @@ -32,6 +45,52 @@ def __init__(self):
settings.restoreWindowGeometry(self, "mainwindow_geometry")
print("Settings are saved in:", settings.fileName())

self.RM = REManagerAPI()

self.run_engine_state_change()
self.REOpenButton.clicked.connect(self.openRunEngine)
self.RECloseButton.clicked.connect(self.closeRunEngine)

# RE Function:

def openRunEngine(self):
"""Open RE"""
self.RM.environment_open()
self.RM.wait_for_idle()
self.run_engine_state_change()

def closeRunEngine(self):
"""Close RE"""
self.RM.environment_close()
self.RM.wait_for_idle()
self.run_engine_state_change()

def run_engine_state(self, status, status_string):
"""Set RE State"""
self.setStatus(f"RE Environment is {status_string}.", timeout=0)
if status is True:
self.RECloseButton.setEnabled(True)
self.REOpenButton.setEnabled(False)
else:
self.RECloseButton.setEnabled(False)
self.REOpenButton.setEnabled(True)

self.setStatus(f"RE Environment is now {status_string}", timeout=0)

def run_engine_state_change(self):
"""Check RE state"""
if self.RM.status().get("worker_environment_exists"):
status_string = "open"
self.run_engine_state(True, status_string)
else:
status_string = "closed"
self.run_engine_state(False, status_string)

def destroyRunEngine(self):
"""Destroys the RunEngine."""
# TODO: Remove this function.
self.RM.environment_destroy()

@property
def status(self):
"""Returns the current message in the mainwindow status bar.
Expand Down
227 changes: 224 additions & 3 deletions queueUI/resources/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>719</width>
<height>364</height>
<width>1171</width>
<height>525</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -53,6 +53,227 @@
<property name="toolTip">
<string extracomment="Select"/>
</property>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>1151</width>
<height>181</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>3</number>
</property>
<property name="midLineWidth">
<number>5</number>
</property>
<widget class="QFrame" name="hostServerConnection">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>201</width>
<height>151</height>
</rect>
</property>
<widget class="QPushButton" name="connectButton">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>181</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
<widget class="QPushButton" name="disconnectButton">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>181</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Disconnect</string>
</property>
</widget>
<widget class="QLabel" name="hostServeConnectionLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>171</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Host Server Connection</string>
</property>
</widget>
</widget>
<widget class="QFrame" name="environmentControl">
<property name="geometry">
<rect>
<x>250</x>
<y>10</y>
<width>201</width>
<height>161</height>
</rect>
</property>
<widget class="QPushButton" name="REOpenButton">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>181</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Open</string>
</property>
</widget>
<widget class="QPushButton" name="RECloseButton">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>181</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
<widget class="QPushButton" name="REDestroyButton">
<property name="geometry">
<rect>
<x>10</x>
<y>110</y>
<width>181</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Destroy</string>
</property>
</widget>
<widget class="QLabel" name="REControlLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>181</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Run Engine (RE) Control</string>
</property>
</widget>
</widget>
<widget class="QFrame" name="queueControl">
<property name="geometry">
<rect>
<x>750</x>
<y>10</y>
<width>391</width>
<height>161</height>
</rect>
</property>
<widget class="QLabel" name="queueControlLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>141</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Queue Control</string>
</property>
</widget>
<widget class="QPushButton" name="queuePlayButton">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>121</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Play</string>
</property>
</widget>
<widget class="QPushButton" name="queueResumeButton">
<property name="geometry">
<rect>
<x>260</x>
<y>30</y>
<width>121</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Resume</string>
</property>
</widget>
<widget class="QPushButton" name="queuePauseButton">
<property name="geometry">
<rect>
<x>140</x>
<y>30</y>
<width>111</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Pause</string>
</property>
</widget>
<widget class="QPushButton" name="queueStopButton">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>121</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
<widget class="QPushButton" name="queueAbortButton">
<property name="geometry">
<rect>
<x>140</x>
<y>80</y>
<width>111</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Abort</string>
</property>
</widget>
</widget>
</widget>
</widget>
</item>
</layout>
Expand All @@ -65,7 +286,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>719</width>
<width>1171</width>
<height>24</height>
</rect>
</property>
Expand Down

0 comments on commit 23e367f

Please sign in to comment.