mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
WIP Tomcat demo UI connection with slider and status
This commit is contained in:
@ -1,31 +1,76 @@
|
|||||||
import os
|
import os
|
||||||
|
import pyqtgraph as pg
|
||||||
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from PySide6.QtCore import Signal, Slot
|
||||||
from qtpy.QtCore import QSize
|
from qtpy.QtCore import QSize
|
||||||
from qtpy.QtGui import QActionGroup, QIcon
|
from qtpy.QtGui import QActionGroup, QIcon
|
||||||
from qtpy.QtWidgets import QApplication, QMainWindow, QStyle
|
from qtpy.QtWidgets import QApplication, QMainWindow, QStyle
|
||||||
|
|
||||||
import bec_widgets
|
import bec_widgets
|
||||||
|
from bec_lib.client import BECClient
|
||||||
|
from bec_lib.service_config import ServiceConfig
|
||||||
from bec_widgets.examples.general_app.web_links import BECWebLinksMixin
|
from bec_widgets.examples.general_app.web_links import BECWebLinksMixin
|
||||||
|
from bec_widgets.qt_utils.error_popups import SafeSlot
|
||||||
|
from bec_widgets.utils.bec_dispatcher import QtRedisConnector
|
||||||
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
from bec_widgets.utils.colors import apply_theme
|
from bec_widgets.utils.colors import apply_theme
|
||||||
from bec_widgets.utils.ui_loader import UILoader
|
from bec_widgets.utils.ui_loader import UILoader
|
||||||
|
|
||||||
MODULE_PATH = os.path.dirname(bec_widgets.__file__)
|
MODULE_PATH = os.path.dirname(bec_widgets.__file__)
|
||||||
|
|
||||||
|
|
||||||
class TomcatApp(QMainWindow):
|
class TomcatApp(QMainWindow, BECWidget):
|
||||||
def __init__(self, parent=None):
|
select_slice = Signal()
|
||||||
|
|
||||||
|
def __init__(self, parent=None, client=None, gui_id=None):
|
||||||
super(TomcatApp, self).__init__(parent)
|
super(TomcatApp, self).__init__(parent)
|
||||||
|
BECWidget.__init__(self, client=client, gui_id=gui_id)
|
||||||
ui_file_path = os.path.join(os.path.dirname(__file__), "tomcat_app.ui")
|
ui_file_path = os.path.join(os.path.dirname(__file__), "tomcat_app.ui")
|
||||||
self.load_ui(ui_file_path)
|
self.load_ui(ui_file_path)
|
||||||
|
|
||||||
self.resize(1280, 720)
|
self.resize(1280, 720)
|
||||||
|
self.get_bec_shortcuts()
|
||||||
|
|
||||||
|
self.bec_dispatcher.connect_slot(self.test_connection, "GPU Fastapi message")
|
||||||
|
self.bec_dispatcher.connect_slot(self.status_update, "GPU Fastapi message")
|
||||||
|
|
||||||
|
self.ui.slider_select.valueChanged.connect(self.select_slice_from_slider)
|
||||||
|
self.proxy_slider = pg.SignalProxy(self.select_slice, rateLimit=2, slot=self.send_slice)
|
||||||
|
|
||||||
def load_ui(self, ui_file):
|
def load_ui(self, ui_file):
|
||||||
loader = UILoader(self)
|
loader = UILoader(self)
|
||||||
self.ui = loader.loader(ui_file)
|
self.ui = loader.loader(ui_file)
|
||||||
self.setCentralWidget(self.ui)
|
self.setCentralWidget(self.ui)
|
||||||
|
|
||||||
|
def status_update(self, msg):
|
||||||
|
status = msg["data"]["GPU SVC Status"]
|
||||||
|
|
||||||
|
if status == "Running":
|
||||||
|
self.ui.radio_io.setChecked(True)
|
||||||
|
else:
|
||||||
|
self.ui.radio_io.setChecked(False)
|
||||||
|
|
||||||
|
# @SafeSlot(dict, dict)
|
||||||
|
def test_connection(self, msg):
|
||||||
|
print("Test Connection")
|
||||||
|
print(msg)
|
||||||
|
# print(metadata)
|
||||||
|
|
||||||
|
def select_slice_from_slider(self, value):
|
||||||
|
print(value)
|
||||||
|
self.select_slice.emit()
|
||||||
|
|
||||||
|
@Slot()
|
||||||
|
def send_slice(self):
|
||||||
|
value = self.ui.slider_select.value()
|
||||||
|
requests.post(
|
||||||
|
"http://ra-gpu-006:8000/api/v1/reco/single_slice",
|
||||||
|
json={"slice": value, "rot_center": 0},
|
||||||
|
)
|
||||||
|
print(f"Sending slice {value}")
|
||||||
|
|
||||||
|
|
||||||
def main(): # pragma: no cover
|
def main(): # pragma: no cover
|
||||||
|
|
||||||
@ -35,7 +80,12 @@ def main(): # pragma: no cover
|
|||||||
os.path.join(MODULE_PATH, "assets", "app_icons", "BEC-General-App.png"), size=QSize(48, 48)
|
os.path.join(MODULE_PATH, "assets", "app_icons", "BEC-General-App.png"), size=QSize(48, 48)
|
||||||
)
|
)
|
||||||
app.setWindowIcon(icon)
|
app.setWindowIcon(icon)
|
||||||
main_window = TomcatApp()
|
|
||||||
|
config = ServiceConfig(redis={"host": "ra-gpu-006", "port": 6379})
|
||||||
|
|
||||||
|
client = BECClient(config=config, connector_cls=QtRedisConnector)
|
||||||
|
|
||||||
|
main_window = TomcatApp(client=client)
|
||||||
main_window.show()
|
main_window.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="BECImageWidget" name="bec_image_widget"/>
|
<widget class="BECImageWidget" name="image_widget"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -48,7 +48,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QRadioButton" name="radioButton">
|
<widget class="QRadioButton" name="radio_dataset">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -62,7 +62,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QRadioButton" name="radioButton_2">
|
<widget class="QRadioButton" name="radio_io">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -179,6 +179,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSlider" name="slider_select">
|
<widget class="QSlider" name="slider_select">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>500</number>
|
||||||
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -254,5 +257,22 @@
|
|||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>slider_select</sender>
|
||||||
|
<signal>valueChanged(int)</signal>
|
||||||
|
<receiver>label_4</receiver>
|
||||||
|
<slot>setNum(int)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>61</x>
|
||||||
|
<y>396</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>73</x>
|
||||||
|
<y>425</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
Reference in New Issue
Block a user