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 pyqtgraph as pg
|
||||
import requests
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import Signal, Slot
|
||||
from qtpy.QtCore import QSize
|
||||
from qtpy.QtGui import QActionGroup, QIcon
|
||||
from qtpy.QtWidgets import QApplication, QMainWindow, QStyle
|
||||
|
||||
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.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.ui_loader import UILoader
|
||||
|
||||
MODULE_PATH = os.path.dirname(bec_widgets.__file__)
|
||||
|
||||
|
||||
class TomcatApp(QMainWindow):
|
||||
def __init__(self, parent=None):
|
||||
class TomcatApp(QMainWindow, BECWidget):
|
||||
select_slice = Signal()
|
||||
|
||||
def __init__(self, parent=None, client=None, gui_id=None):
|
||||
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")
|
||||
self.load_ui(ui_file_path)
|
||||
|
||||
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):
|
||||
loader = UILoader(self)
|
||||
self.ui = loader.loader(ui_file)
|
||||
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
|
||||
|
||||
@ -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)
|
||||
)
|
||||
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()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="BECImageWidget" name="bec_image_widget"/>
|
||||
<widget class="BECImageWidget" name="image_widget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -48,7 +48,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QRadioButton" name="radioButton">
|
||||
<widget class="QRadioButton" name="radio_dataset">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@ -62,7 +62,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QRadioButton" name="radioButton_2">
|
||||
<widget class="QRadioButton" name="radio_io">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@ -179,6 +179,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="slider_select">
|
||||
<property name="maximum">
|
||||
<number>500</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
@ -254,5 +257,22 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<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>
|
||||
|
Reference in New Issue
Block a user