2025-01-19 18:27:26 +08:00
|
|
|
import logging
|
2025-02-11 23:24:49 +08:00
|
|
|
import platform
|
2025-01-06 11:21:04 +08:00
|
|
|
import sys
|
2025-03-03 22:22:06 +08:00
|
|
|
import time
|
2025-02-18 23:31:44 +08:00
|
|
|
import traceback
|
2025-01-20 17:21:53 +08:00
|
|
|
from enum import Enum, auto
|
2025-01-20 19:28:03 +08:00
|
|
|
from pathlib import Path
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-03-03 22:22:06 +08:00
|
|
|
import zmq
|
2025-04-12 18:02:29 +08:00
|
|
|
from PyQt6 import QtWidgets, QtGui
|
|
|
|
|
from PyQt6.QtCore import QByteArray, pyqtSlot
|
2025-02-20 14:06:23 +08:00
|
|
|
from PyQt6.QtWidgets import QMainWindow, QApplication, QFrame, QMessageBox, QFileDialog, QLineEdit
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-05-11 17:35:37 +08:00
|
|
|
from flandre import P
|
|
|
|
|
from flandre import C
|
2025-04-12 00:03:28 +08:00
|
|
|
from flandre.nodes.Node import Node
|
2025-04-12 18:02:29 +08:00
|
|
|
from flandre.pyqt.Main import Ui_MainWindow
|
|
|
|
|
from flandre.pyqt.ZMQReceiver import ZMQReceiver
|
|
|
|
|
from flandre.utils.Msg import KillMsg, Msg, ImageArgMsg, SeqIdMinMax, MoveAxisMsg, PlaybackSeqListMsg, SetBaseMsg, \
|
2025-02-18 23:31:44 +08:00
|
|
|
SetSeqMetaMsg, SetPlayMode, DeviceConnectedMsg, DeviceEnabledMsg, DeviceOnlineMsg, SetDeviceEnabledMsg, \
|
2025-02-14 11:29:55 +08:00
|
|
|
SetDeviceConnectedMsg, DeviceConfigListMsg, SetDeviceConfigMsg, SetRecordMsg, RobotRtsiMsg, RecordFrameMsg, \
|
2025-03-23 22:33:55 +08:00
|
|
|
SeqIdList, SetWindowVisibleMsg, SetSidMsg, ImagingConfigNameListMsg, DeviceZero, DeviceSwitchMsg, \
|
2025-04-17 20:28:07 +08:00
|
|
|
SetDeviceSwitchMsg, SeqMetaMsg, RefreshDeviceMsg, MaxMsg
|
2025-04-12 00:03:28 +08:00
|
|
|
from flandre.utils.RfMeta import RfSequenceMeta
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-02-14 11:29:55 +08:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-01-20 17:21:53 +08:00
|
|
|
class LinkStatus(Enum):
|
|
|
|
|
RED = auto()
|
|
|
|
|
YELLOW = auto()
|
|
|
|
|
GREEN = auto()
|
2025-03-23 22:33:55 +08:00
|
|
|
ORANGE = auto()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_style_sheet(name, color):
|
|
|
|
|
return f"""
|
|
|
|
|
#{name}{{
|
|
|
|
|
background: {color};
|
|
|
|
|
border-radius: 7px;
|
|
|
|
|
}}
|
|
|
|
|
""".strip()
|
2025-01-20 17:21:53 +08:00
|
|
|
|
|
|
|
|
|
2025-01-20 19:28:03 +08:00
|
|
|
def humanbytes(B):
|
|
|
|
|
"""Return the given bytes as a human friendly KB, MB, GB, or TB string."""
|
|
|
|
|
B = float(B)
|
|
|
|
|
KB = float(1024)
|
|
|
|
|
MB = float(KB ** 2) # 1,048,576
|
|
|
|
|
GB = float(KB ** 3) # 1,073,741,824
|
|
|
|
|
TB = float(KB ** 4) # 1,099,511,627,776
|
|
|
|
|
|
|
|
|
|
if B < KB:
|
|
|
|
|
return '{0} {1}'.format(B, 'Bytes' if 0 == B > 1 else 'Byte')
|
|
|
|
|
elif KB <= B < MB:
|
|
|
|
|
return '{0:.2f} KB'.format(B / KB)
|
|
|
|
|
elif MB <= B < GB:
|
|
|
|
|
return '{0:.2f} MB'.format(B / MB)
|
|
|
|
|
elif GB <= B < TB:
|
|
|
|
|
return '{0:.2f} GB'.format(B / GB)
|
|
|
|
|
elif TB <= B:
|
|
|
|
|
return '{0:.2f} TB'.format(B / TB)
|
|
|
|
|
|
|
|
|
|
|
2025-01-06 11:21:04 +08:00
|
|
|
class Adv(QMainWindow, Ui_MainWindow):
|
|
|
|
|
def __init__(self, p: Node, parent=None):
|
|
|
|
|
super(Adv, self).__init__(parent)
|
|
|
|
|
self.p = p
|
|
|
|
|
self.setupUi(self)
|
2025-04-12 15:39:56 +08:00
|
|
|
|
|
|
|
|
# set default folder
|
2025-05-11 17:46:45 +08:00
|
|
|
self.l_base.setText(C.record_folder.__str__())
|
2025-04-12 15:39:56 +08:00
|
|
|
|
2025-03-23 22:33:55 +08:00
|
|
|
self.device_switch_state: LinkStatus = LinkStatus.RED
|
|
|
|
|
icon = QtGui.QIcon()
|
2025-05-11 17:35:37 +08:00
|
|
|
icon.addPixmap(QtGui.QPixmap(str(P.ASSETS / 'switch_button.png')))
|
2025-03-23 22:33:55 +08:00
|
|
|
self.b_probe_head_switch.setIcon(icon)
|
|
|
|
|
self.b_us_switch.setIcon(icon)
|
|
|
|
|
self.b_cobot_switch.setIcon(icon)
|
|
|
|
|
icon = QtGui.QIcon()
|
2025-05-11 17:35:37 +08:00
|
|
|
icon.addPixmap(QtGui.QPixmap(str(P.ASSETS / 'refresh_button.png')))
|
2025-03-23 22:33:55 +08:00
|
|
|
self.b_us_refresh.setIcon(icon)
|
2025-01-06 11:21:04 +08:00
|
|
|
zmq_receiver = ZMQReceiver(self)
|
|
|
|
|
zmq_receiver.zmq_event.connect(self.on_zmq_event)
|
|
|
|
|
zmq_receiver.start()
|
2025-01-20 13:03:02 +08:00
|
|
|
self.s_t_start.valueChanged.connect(self.on_t_start)
|
|
|
|
|
self.s_t_end.valueChanged.connect(self.on_t_end)
|
|
|
|
|
self.arg = ImageArgMsg('ui', t_start=0, t_end=1499)
|
2025-04-15 21:18:04 +08:00
|
|
|
self.playback_seq_meta: RfSequenceMeta | None = None
|
|
|
|
|
self.live_seq_meta: RfSequenceMeta | None = None
|
2025-01-19 18:27:26 +08:00
|
|
|
self.record = False
|
|
|
|
|
self.device_connected = False
|
|
|
|
|
self.device_enabled = False
|
2025-02-19 00:05:14 +08:00
|
|
|
self.l_base.textChanged.connect(lambda e:
|
|
|
|
|
self.l_base.setStyleSheet("")
|
|
|
|
|
if Path(e).exists() else
|
|
|
|
|
self.l_base.setStyleSheet("background-color: pink;"))
|
2025-01-19 18:27:26 +08:00
|
|
|
|
2025-01-20 19:28:03 +08:00
|
|
|
self.record_size_cnt = 0
|
|
|
|
|
self.record_frame_cnt = 0
|
2025-02-11 23:24:49 +08:00
|
|
|
self.update_device_buttons()
|
2025-01-20 19:28:03 +08:00
|
|
|
|
2025-02-14 11:29:55 +08:00
|
|
|
self.seq_id_list = []
|
|
|
|
|
|
|
|
|
|
self.b_select_base.clicked.connect(self.on_select_base)
|
|
|
|
|
|
2025-02-18 23:31:44 +08:00
|
|
|
self.cb_bscan.stateChanged.connect(self.on_cb_bscan)
|
2025-03-03 22:22:06 +08:00
|
|
|
self.b_probe_single.clicked.connect(self.on_probe('single'))
|
|
|
|
|
self.b_probe_orig.clicked.connect(self.on_probe('orig'))
|
|
|
|
|
self.b_probe_start.clicked.connect(self.on_probe('start'))
|
|
|
|
|
self.b_probe_stop.clicked.connect(self.on_probe('stop'))
|
|
|
|
|
self.b_device_zero.clicked.connect(lambda: self.p.send(DeviceZero()))
|
2025-03-23 22:33:55 +08:00
|
|
|
|
|
|
|
|
self.mi_req_socket = zmq.Context().socket(zmq.REQ)
|
2025-04-12 14:36:23 +08:00
|
|
|
self.mi_req_socket.connect(C.mi_rep_socket)
|
2025-03-23 22:33:55 +08:00
|
|
|
|
2025-04-19 21:05:29 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_us_switch_clicked(self):
|
2025-03-23 22:33:55 +08:00
|
|
|
match self.device_switch_state:
|
|
|
|
|
case LinkStatus.RED:
|
|
|
|
|
self.p.send(SetDeviceSwitchMsg(True))
|
|
|
|
|
self.p.send(DeviceSwitchMsg('YELLOW'))
|
|
|
|
|
case LinkStatus.GREEN | LinkStatus.YELLOW | LinkStatus.ORANGE:
|
|
|
|
|
self.p.send(SetDeviceSwitchMsg(False))
|
|
|
|
|
|
2025-04-19 21:05:29 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_us_refresh_clicked(self):
|
2025-03-23 22:33:55 +08:00
|
|
|
match self.device_switch_state:
|
|
|
|
|
case LinkStatus.GREEN | LinkStatus.YELLOW | LinkStatus.ORANGE:
|
|
|
|
|
self.p.send(RefreshDeviceMsg())
|
|
|
|
|
self.set_device_enable(LinkStatus.RED)
|
|
|
|
|
self.set_device_connection(LinkStatus.RED)
|
|
|
|
|
self.update_device_buttons()
|
|
|
|
|
|
|
|
|
|
def on_device_switch_state(self):
|
|
|
|
|
match self.device_switch_state:
|
|
|
|
|
case LinkStatus.RED:
|
|
|
|
|
self.g_device.setEnabled(False)
|
|
|
|
|
self.g_us.setStyleSheet(get_style_sheet('g_us', 'pink'))
|
|
|
|
|
self.set_device_enable(LinkStatus.RED)
|
|
|
|
|
self.set_device_connection(LinkStatus.RED)
|
|
|
|
|
self.update_device_buttons()
|
|
|
|
|
case LinkStatus.YELLOW:
|
|
|
|
|
self.g_device.setEnabled(False)
|
|
|
|
|
self.g_us.setStyleSheet(get_style_sheet('g_us', 'yellow'))
|
|
|
|
|
case LinkStatus.GREEN:
|
|
|
|
|
self.g_device.setEnabled(True)
|
|
|
|
|
self.g_us.setStyleSheet(get_style_sheet('g_us', 'LightGreen'))
|
|
|
|
|
case LinkStatus.ORANGE:
|
|
|
|
|
self.g_device.setEnabled(False)
|
|
|
|
|
self.g_us.setStyleSheet(get_style_sheet('g_us', 'orange'))
|
2025-03-03 22:22:06 +08:00
|
|
|
|
|
|
|
|
def on_probe(self, arg):
|
|
|
|
|
def f():
|
|
|
|
|
ctx = zmq.Context()
|
|
|
|
|
p = ctx.socket(zmq.PUSH)
|
|
|
|
|
p.connect('tcp://q1hyb.as:23456')
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
p.send_string(arg)
|
|
|
|
|
p.disconnect('tcp://q1hyb.as:23456')
|
|
|
|
|
|
|
|
|
|
return f
|
|
|
|
|
|
2025-04-13 20:17:05 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_new_imaging_config_clicked(self):
|
|
|
|
|
filename, okPressed = QtWidgets.QInputDialog.getText(None,
|
|
|
|
|
"Set New Imaging Config Name",
|
|
|
|
|
"Config Name:",
|
|
|
|
|
QLineEdit.EchoMode.Normal,
|
2025-04-19 17:50:09 +08:00
|
|
|
self.c_imaging_config.currentText())
|
2025-04-13 20:17:05 +08:00
|
|
|
if okPressed and filename != '':
|
|
|
|
|
(C.imaging_config_folder / f'{filename}.json').write_text(self.arg.json())
|
|
|
|
|
idx = self.c_imaging_config.findText(filename)
|
|
|
|
|
if idx == -1:
|
|
|
|
|
self.c_imaging_config.addItem(filename)
|
|
|
|
|
idx = self.c_imaging_config.findText(filename)
|
|
|
|
|
self.c_imaging_config.setCurrentIndex(idx)
|
|
|
|
|
else:
|
|
|
|
|
self.c_imaging_config.setCurrentIndex(idx)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_c_imaging_config_currentIndexChanged(self, i):
|
2025-02-20 14:06:23 +08:00
|
|
|
name = self.c_imaging_config.itemText(i)
|
2025-04-12 00:34:24 +08:00
|
|
|
self.p.send(ImageArgMsg.from_path(C.imaging_config_folder / f'{name}.json'))
|
2025-02-20 14:06:23 +08:00
|
|
|
|
2025-02-14 11:29:55 +08:00
|
|
|
def on_select_base(self):
|
|
|
|
|
base = QFileDialog.getExistingDirectory(self, 'Select Base Folder', DS.__str__())
|
|
|
|
|
self.l_base.setText(Path(base).__str__())
|
|
|
|
|
|
2025-04-15 21:18:04 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_test1_clicked(self):
|
|
|
|
|
logger.info(f'test1 {self.arg}')
|
|
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_base_clicked(self):
|
2025-02-18 23:31:44 +08:00
|
|
|
if Path(self.l_base.text()):
|
2025-01-20 19:28:03 +08:00
|
|
|
self.p.send(SetBaseMsg(self.l_base.text()))
|
2025-03-23 22:33:55 +08:00
|
|
|
self.g_cap.setEnabled(True)
|
2025-01-20 19:28:03 +08:00
|
|
|
|
2025-01-20 17:21:53 +08:00
|
|
|
def set_device_connection(self, status: LinkStatus):
|
|
|
|
|
match status:
|
|
|
|
|
case LinkStatus.RED:
|
2025-01-20 17:37:18 +08:00
|
|
|
self.device_connected = False
|
2025-02-18 23:31:44 +08:00
|
|
|
self.c_live_seq_name.setEnabled(False)
|
2025-01-20 17:21:53 +08:00
|
|
|
self.lb_device_connection.setText('Disconnected')
|
|
|
|
|
self.lb_device_connection.setStyleSheet('background-color: pink;')
|
|
|
|
|
case LinkStatus.YELLOW:
|
|
|
|
|
self.lb_device_connection.setText('Waiting')
|
|
|
|
|
self.lb_device_connection.setStyleSheet('background-color: yellow;')
|
|
|
|
|
case LinkStatus.GREEN:
|
2025-01-20 17:37:18 +08:00
|
|
|
self.device_connected = True
|
2025-02-18 23:31:44 +08:00
|
|
|
self.c_live_seq_name.setEnabled(True)
|
2025-01-20 17:21:53 +08:00
|
|
|
self.lb_device_connection.setText('Connected')
|
|
|
|
|
self.lb_device_connection.setStyleSheet('background-color: LightGreen;')
|
|
|
|
|
|
|
|
|
|
def set_device_enable(self, status: LinkStatus):
|
|
|
|
|
match status:
|
|
|
|
|
case LinkStatus.RED:
|
2025-01-20 17:37:18 +08:00
|
|
|
self.device_enabled = False
|
2025-01-20 17:21:53 +08:00
|
|
|
self.lb_device_enable.setText('Disabled')
|
|
|
|
|
self.lb_device_enable.setStyleSheet('background-color: pink;')
|
|
|
|
|
case LinkStatus.YELLOW:
|
|
|
|
|
self.lb_device_enable.setText('Waiting')
|
|
|
|
|
self.lb_device_enable.setStyleSheet('background-color: yellow;')
|
|
|
|
|
case LinkStatus.GREEN:
|
2025-01-20 17:37:18 +08:00
|
|
|
self.device_enabled = True
|
2025-01-20 17:21:53 +08:00
|
|
|
self.lb_device_enable.setText('Enabled')
|
|
|
|
|
self.lb_device_enable.setStyleSheet('background-color: LightGreen;')
|
|
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(bool)
|
|
|
|
|
def on_g_live_clicked(self, b):
|
2025-03-23 22:33:55 +08:00
|
|
|
if b:
|
|
|
|
|
self.g_playback.setChecked(False)
|
|
|
|
|
self.p.send(SetPlayMode('live'))
|
2025-04-15 21:18:04 +08:00
|
|
|
if self.live_seq_meta is not None:
|
|
|
|
|
self.update_max(max(self.live_seq_meta.shape))
|
2025-04-12 18:02:29 +08:00
|
|
|
logger.info(f'set playmode live')
|
2025-03-23 22:33:55 +08:00
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(bool)
|
|
|
|
|
def on_g_playback_clicked(self, b):
|
2025-03-23 22:33:55 +08:00
|
|
|
if b:
|
|
|
|
|
self.g_live.setChecked(False)
|
|
|
|
|
self.p.send(SetPlayMode('playback'))
|
2025-04-15 21:18:04 +08:00
|
|
|
if self.playback_seq_meta is not None:
|
|
|
|
|
self.update_max(max(self.playback_seq_meta.shape))
|
2025-04-12 18:02:29 +08:00
|
|
|
logger.info(f'set playmode playback')
|
2025-01-19 18:27:26 +08:00
|
|
|
|
2025-01-20 17:21:53 +08:00
|
|
|
def on_device_disable(self):
|
|
|
|
|
self.p.send(SetDeviceEnabledMsg(False))
|
|
|
|
|
self.b_device_enable.setEnabled(False)
|
|
|
|
|
self.set_device_enable(LinkStatus.YELLOW)
|
|
|
|
|
|
|
|
|
|
def on_device_enable(self):
|
|
|
|
|
self.p.send(SetDeviceEnabledMsg(True))
|
|
|
|
|
self.b_device_enable.setEnabled(False)
|
|
|
|
|
self.set_device_enable(LinkStatus.YELLOW)
|
|
|
|
|
|
|
|
|
|
def on_device_disconnect(self):
|
|
|
|
|
self.p.send(SetDeviceConnectedMsg(False))
|
|
|
|
|
self.b_device_connection.setEnabled(False)
|
|
|
|
|
self.set_device_connection(LinkStatus.YELLOW)
|
|
|
|
|
|
|
|
|
|
def on_device_connect(self):
|
2025-03-23 22:33:55 +08:00
|
|
|
logger.info('btn pre')
|
2025-01-20 17:21:53 +08:00
|
|
|
self.p.send(SetDeviceConnectedMsg(True))
|
|
|
|
|
self.b_device_connection.setEnabled(False)
|
|
|
|
|
self.set_device_connection(LinkStatus.YELLOW)
|
|
|
|
|
|
|
|
|
|
def update_device_buttons(self):
|
|
|
|
|
if self.device_connected and self.device_enabled:
|
|
|
|
|
self.b_device_connection.setText('Disconnect')
|
|
|
|
|
self.b_device_connection.setEnabled(False)
|
|
|
|
|
self.b_device_enable.setText('Disable')
|
|
|
|
|
self.b_device_enable.setEnabled(True)
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_connection.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_enable.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
self.b_device_enable.clicked.connect(self.on_device_disable)
|
|
|
|
|
if self.device_connected and not self.device_enabled:
|
|
|
|
|
self.b_device_connection.setText('Disconnect')
|
|
|
|
|
self.b_device_connection.setEnabled(True)
|
|
|
|
|
self.b_device_enable.setText('Enable')
|
|
|
|
|
self.b_device_enable.setEnabled(True)
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_connection.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_enable.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
self.b_device_enable.clicked.connect(self.on_device_enable)
|
|
|
|
|
self.b_device_connection.clicked.connect(self.on_device_disconnect)
|
|
|
|
|
if not self.device_connected and self.device_enabled:
|
|
|
|
|
raise Exception("wtf?")
|
|
|
|
|
if not self.device_connected and not self.device_enabled:
|
|
|
|
|
self.b_device_connection.setText('Connect')
|
|
|
|
|
self.b_device_connection.setEnabled(True)
|
|
|
|
|
self.b_device_enable.setText('Enable')
|
|
|
|
|
self.b_device_enable.setEnabled(False)
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_connection.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
try:
|
|
|
|
|
self.b_device_enable.clicked.disconnect()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
self.b_device_connection.clicked.connect(self.on_device_connect)
|
|
|
|
|
|
2025-04-19 17:50:09 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_record_clicked(self):
|
2025-01-19 18:27:26 +08:00
|
|
|
if self.record:
|
2025-01-20 19:28:03 +08:00
|
|
|
self.l_record_commit.setEnabled(True)
|
2025-01-19 18:49:41 +08:00
|
|
|
self.p.send(SetRecordMsg(False))
|
2025-01-19 18:27:26 +08:00
|
|
|
self.record = False
|
|
|
|
|
self.b_record.setStyleSheet('')
|
|
|
|
|
else:
|
2025-01-19 18:49:41 +08:00
|
|
|
if self.l_record_commit.text() != '':
|
2025-04-19 17:50:09 +08:00
|
|
|
self.l_record_commit.setEnabled(False)
|
2025-01-20 19:28:03 +08:00
|
|
|
self.record_size_cnt = 0
|
|
|
|
|
self.record_frame_cnt = 0
|
|
|
|
|
self.p.send(SetRecordMsg(True, self.l_record_commit.text(), self.l_base.text()))
|
2025-01-19 18:49:41 +08:00
|
|
|
self.record = True
|
|
|
|
|
self.b_record.setStyleSheet('background-color: red;')
|
2025-01-20 19:28:03 +08:00
|
|
|
else:
|
|
|
|
|
QMessageBox.warning(None, 'hint', 'Commit is empty!!')
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-04-17 20:28:07 +08:00
|
|
|
def update_max_2(self, m):
|
2025-04-15 21:18:04 +08:00
|
|
|
self.s_t_start.setMaximum(m)
|
|
|
|
|
self.s_t_end.setMaximum(m)
|
2025-04-17 20:28:07 +08:00
|
|
|
|
2025-04-15 21:18:04 +08:00
|
|
|
self.sp_crop_center.setMaximum(m)
|
|
|
|
|
self.sp_crop_width.setMaximum(m)
|
2025-04-17 20:28:07 +08:00
|
|
|
|
|
|
|
|
def update_max(self, m):
|
|
|
|
|
self.s_f_rows.setMaximum(m)
|
2025-04-15 21:18:04 +08:00
|
|
|
self.sp_f_rows.setMaximum(m)
|
|
|
|
|
|
2025-04-17 20:28:07 +08:00
|
|
|
self.s_dct_center.setMaximum(m)
|
|
|
|
|
self.s_dct_bandwidth.setMaximum(m)
|
|
|
|
|
|
|
|
|
|
self.sp_dct_center.setMaximum(m)
|
|
|
|
|
self.sp_dct_bandwidth.setMaximum(m)
|
2025-05-11 17:35:37 +08:00
|
|
|
|
2025-01-06 11:21:04 +08:00
|
|
|
def on_zmq_event(self, msg: QByteArray):
|
2025-02-18 23:31:44 +08:00
|
|
|
try:
|
|
|
|
|
msg = Msg.decode_msg(msg.data())
|
|
|
|
|
if isinstance(msg, KillMsg):
|
|
|
|
|
if msg.name == '':
|
|
|
|
|
self.close()
|
|
|
|
|
elif isinstance(msg, ImageArgMsg):
|
2025-02-20 14:06:23 +08:00
|
|
|
self.arg = msg
|
|
|
|
|
self.arg.sender = 'ui'
|
2025-04-14 01:34:05 +08:00
|
|
|
|
2025-02-19 00:05:14 +08:00
|
|
|
self.s_t_start.setValue(msg.t_start)
|
2025-02-18 23:31:44 +08:00
|
|
|
self.s_t_end.setValue(msg.t_end)
|
2025-04-13 20:17:05 +08:00
|
|
|
self.s_f_rows.setValue(msg.f_rows)
|
|
|
|
|
self.s_v2.setValue(msg.v2)
|
|
|
|
|
self.s_dct_center.setValue(msg.dct_center)
|
|
|
|
|
self.s_dct_bandwidth.setValue(msg.dct_bandwidth)
|
2025-04-14 01:34:05 +08:00
|
|
|
self.s_beta.setValue(msg.beta)
|
|
|
|
|
|
|
|
|
|
self.sp_crop_center.setValue(msg.t_start)
|
|
|
|
|
self.sp_crop_width.setValue(msg.t_end)
|
|
|
|
|
self.sp_f_rows.setValue(msg.f_rows)
|
2025-04-15 21:18:04 +08:00
|
|
|
|
2025-04-14 01:34:05 +08:00
|
|
|
self.sp_v2.setValue(msg.v2)
|
|
|
|
|
self.sp_dct_center.setValue(msg.dct_center)
|
|
|
|
|
self.sp_dct_bandwidth.setValue(msg.dct_bandwidth)
|
|
|
|
|
self.sp_beta.setValue(msg.beta)
|
|
|
|
|
|
2025-04-16 23:31:52 +08:00
|
|
|
self.s_g1.setValue(msg.g1)
|
|
|
|
|
self.s_g2.setValue(msg.g2)
|
|
|
|
|
self.s_g3.setValue(msg.g3)
|
|
|
|
|
self.s_g4.setValue(msg.g4)
|
|
|
|
|
self.s_g5.setValue(msg.g5)
|
|
|
|
|
self.s_g6.setValue(msg.g6)
|
|
|
|
|
self.s_g7.setValue(msg.g7)
|
|
|
|
|
self.s_g8.setValue(msg.g8)
|
|
|
|
|
|
|
|
|
|
self.sp_g1.setValue(msg.g1)
|
|
|
|
|
self.sp_g2.setValue(msg.g2)
|
|
|
|
|
self.sp_g3.setValue(msg.g3)
|
|
|
|
|
self.sp_g4.setValue(msg.g4)
|
|
|
|
|
self.sp_g5.setValue(msg.g5)
|
|
|
|
|
self.sp_g6.setValue(msg.g6)
|
|
|
|
|
self.sp_g7.setValue(msg.g7)
|
|
|
|
|
self.sp_g8.setValue(msg.g8)
|
|
|
|
|
|
2025-04-14 01:34:05 +08:00
|
|
|
|
|
|
|
|
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, MoveAxisMsg):
|
|
|
|
|
match msg.axis:
|
|
|
|
|
case 'S':
|
|
|
|
|
pass
|
|
|
|
|
# self.s_sid.setValue(msg.value)
|
|
|
|
|
# self.l_seq_current.setText(str(self.seq_id_list[msg.value]))
|
|
|
|
|
elif isinstance(msg, SetSidMsg):
|
|
|
|
|
self.s_sid.setValue(msg.value)
|
2025-02-19 00:05:14 +08:00
|
|
|
self.sp_sid.setValue(msg.value)
|
2025-02-18 23:31:44 +08:00
|
|
|
self.l_seq_current.setText(str(self.seq_id_list[msg.value]))
|
|
|
|
|
elif isinstance(msg, SeqIdList):
|
|
|
|
|
self.seq_id_list = msg.li
|
|
|
|
|
self.s_sid.setMaximum(msg.li.__len__() - 1)
|
|
|
|
|
self.sp_sid.setMaximum(msg.li.__len__() - 1)
|
|
|
|
|
self.l_seq_min.setText(str(min(msg.li)))
|
|
|
|
|
self.l_seq_max.setText(str(max(msg.li)))
|
2025-04-12 18:02:29 +08:00
|
|
|
elif isinstance(msg, PlaybackSeqListMsg):
|
2025-02-18 23:31:44 +08:00
|
|
|
self.c_playback_seq_name.clear()
|
|
|
|
|
for name in msg.value:
|
|
|
|
|
self.c_playback_seq_name.addItem(name)
|
|
|
|
|
if msg.value.__len__() > 0:
|
2025-04-12 18:02:29 +08:00
|
|
|
self.p.send(SetSeqMetaMsg('playback', self.c_playback_seq_name.currentText()))
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, SetSeqMetaMsg):
|
2025-04-15 21:18:04 +08:00
|
|
|
if msg.target == 'playback':
|
|
|
|
|
self.playback_seq_meta = RfSequenceMeta.from_name(msg.name)
|
|
|
|
|
self.update_max(max(self.playback_seq_meta.shape))
|
|
|
|
|
elif isinstance(msg, SeqMetaMsg):
|
|
|
|
|
if msg.target == 'live':
|
|
|
|
|
self.l_live_seq_name.setText(msg.name)
|
|
|
|
|
self.b_live_seq_apply.setEnabled(True)
|
|
|
|
|
self.live_seq_meta = RfSequenceMeta.from_name(msg.name)
|
|
|
|
|
self.update_max(max(self.live_seq_meta.shape))
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, DeviceConnectedMsg):
|
|
|
|
|
if msg.value:
|
|
|
|
|
self.set_device_connection(LinkStatus.GREEN)
|
|
|
|
|
else:
|
|
|
|
|
self.set_device_connection(LinkStatus.RED)
|
|
|
|
|
self.update_device_buttons()
|
|
|
|
|
elif isinstance(msg, DeviceEnabledMsg):
|
|
|
|
|
if msg.value:
|
|
|
|
|
self.set_device_enable(LinkStatus.GREEN)
|
|
|
|
|
else:
|
|
|
|
|
self.set_device_enable(LinkStatus.RED)
|
|
|
|
|
self.update_device_buttons()
|
2025-04-15 21:18:04 +08:00
|
|
|
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, DeviceConfigListMsg):
|
|
|
|
|
for name, txt in msg.arr:
|
|
|
|
|
self.c_live_seq_name.addItem(name, txt)
|
|
|
|
|
elif isinstance(msg, RobotRtsiMsg):
|
2025-03-03 22:22:06 +08:00
|
|
|
self.ln_x.display(f"{msg.pos[0] / 100:.2f}")
|
|
|
|
|
self.ln_y.display(f"{msg.pos[1] / 100:.2f}")
|
|
|
|
|
self.ln_z.display(f"{msg.pos[2] / 100:.2f}")
|
|
|
|
|
self.ln_rx.display(f"{msg.pos[3] / 1000:.3f}")
|
|
|
|
|
self.ln_ry.display(f"{msg.pos[4] / 1000:.3f}")
|
|
|
|
|
self.ln_rz.display(f"{msg.pos[5] / 1000:.3f}")
|
|
|
|
|
|
|
|
|
|
self.ln_fx.display(f"{msg.force[0] / 10:.1f}")
|
|
|
|
|
self.ln_fy.display(f"{msg.force[1] / 10:.1f}")
|
|
|
|
|
self.ln_fz.display(f"{msg.force[2] / 10:.1f}")
|
|
|
|
|
self.ln_frx.display(f"{msg.force[3] / 100:.2f}")
|
|
|
|
|
self.ln_fry.display(f"{msg.force[4] / 100:.2f}")
|
|
|
|
|
self.ln_frz.display(f"{msg.force[5] / 100:.2f}")
|
2025-04-17 20:28:07 +08:00
|
|
|
elif isinstance(msg, MaxMsg):
|
|
|
|
|
self.update_max_2(msg.value)
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, RecordFrameMsg):
|
|
|
|
|
|
|
|
|
|
self.record_frame_cnt += 1
|
|
|
|
|
self.record_size_cnt += msg.size
|
|
|
|
|
self.l_record_size.setText(humanbytes(self.record_size_cnt))
|
|
|
|
|
self.l_record_frames.setText(str(self.record_frame_cnt))
|
|
|
|
|
self.l_record_max_sid.setText(str(msg.current_sid))
|
|
|
|
|
elif isinstance(msg, SetWindowVisibleMsg):
|
|
|
|
|
if msg.name == 'bscan' and msg.sender != 'ui':
|
|
|
|
|
self.cb_bscan.setChecked(msg.value)
|
2025-02-20 14:06:23 +08:00
|
|
|
elif isinstance(msg, ImagingConfigNameListMsg):
|
2025-04-12 15:39:56 +08:00
|
|
|
# print(msg, flush=True) todo fix
|
2025-02-20 14:06:23 +08:00
|
|
|
self.c_imaging_config.clear()
|
|
|
|
|
for name in msg.value:
|
|
|
|
|
self.c_imaging_config.addItem(name)
|
2025-03-23 22:33:55 +08:00
|
|
|
elif isinstance(msg, DeviceSwitchMsg):
|
|
|
|
|
self.device_switch_state = LinkStatus[msg.value]
|
|
|
|
|
self.on_device_switch_state()
|
2025-02-18 23:31:44 +08:00
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(e)
|
|
|
|
|
traceback.print_exception(e)
|
2025-01-20 15:23:27 +08:00
|
|
|
|
|
|
|
|
def closeEvent(self, event):
|
|
|
|
|
self.p.send(KillMsg(''))
|
|
|
|
|
# event.accept()
|
|
|
|
|
# event.ignore()
|
2025-01-20 17:21:53 +08:00
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-02-18 23:31:44 +08:00
|
|
|
def on_cb_bscan(self, v):
|
|
|
|
|
if self.cb_bscan.sender() is None:
|
|
|
|
|
self.p.send(SetWindowVisibleMsg('ui', 'bscan', v == 2))
|
|
|
|
|
|
2025-04-14 01:34:05 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_sp_crop_center_valueChanged(self, v):
|
|
|
|
|
if self.sp_crop_center.sender() is None:
|
|
|
|
|
self.arg.t_start = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_sp_crop_width_valueChanged(self, v):
|
|
|
|
|
if self.sp_crop_width.sender() is None:
|
|
|
|
|
self.arg.t_end = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_sp_v2_valueChanged(self, v):
|
|
|
|
|
if self.sp_v2.sender() is None:
|
|
|
|
|
self.arg.v2 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-23 17:03:38 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_sp_f_rows_valueChanged(self, v):
|
|
|
|
|
if self.sp_f_rows.sender() is None:
|
|
|
|
|
self.arg.f_rows = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-13 23:22:29 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_beta_valueChanged(self, v):
|
|
|
|
|
if self.s_beta.sender() is None:
|
|
|
|
|
self.arg.beta = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-13 20:17:05 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_dct_center_valueChanged(self, v):
|
|
|
|
|
if self.s_dct_center.sender() is None:
|
|
|
|
|
self.arg.dct_center = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_dct_bandwidth_valueChanged(self, v):
|
|
|
|
|
if self.s_dct_bandwidth.sender() is None:
|
|
|
|
|
self.arg.dct_bandwidth = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_v2_valueChanged(self, v):
|
|
|
|
|
if self.s_v2.sender() is None:
|
|
|
|
|
self.arg.v2 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-16 23:31:52 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_tgc_valueChanged(self, v):
|
|
|
|
|
if self.s_tgc.sender() is None:
|
|
|
|
|
self.arg.tgc = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g1_valueChanged(self, v):
|
|
|
|
|
if self.s_g1.sender() is None:
|
|
|
|
|
self.arg.g1 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g2_valueChanged(self, v):
|
|
|
|
|
if self.s_g2.sender() is None:
|
|
|
|
|
self.arg.g2 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g3_valueChanged(self, v):
|
|
|
|
|
if self.s_g3.sender() is None:
|
|
|
|
|
self.arg.g3 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g4_valueChanged(self, v):
|
|
|
|
|
if self.s_g4.sender() is None:
|
|
|
|
|
self.arg.g4 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g5_valueChanged(self, v):
|
|
|
|
|
if self.s_g5.sender() is None:
|
|
|
|
|
self.arg.g5 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g6_valueChanged(self, v):
|
|
|
|
|
if self.s_g6.sender() is None:
|
|
|
|
|
self.arg.g6 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g7_valueChanged(self, v):
|
|
|
|
|
if self.s_g7.sender() is None:
|
|
|
|
|
self.arg.g7 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_g8_valueChanged(self, v):
|
|
|
|
|
if self.s_g8.sender() is None:
|
|
|
|
|
self.arg.g8 = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-01-20 13:03:02 +08:00
|
|
|
def on_t_start(self, v):
|
|
|
|
|
if self.s_t_end.sender() is None:
|
|
|
|
|
self.arg.t_start = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-01-20 13:03:02 +08:00
|
|
|
def on_t_end(self, v):
|
|
|
|
|
if self.s_t_end.sender() is None:
|
|
|
|
|
self.arg.t_end = v
|
2025-01-19 18:27:26 +08:00
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-13 20:17:05 +08:00
|
|
|
@pyqtSlot(int)
|
|
|
|
|
def on_s_f_rows_valueChanged(self, v):
|
|
|
|
|
if self.s_f_rows.sender() is None:
|
|
|
|
|
self.arg.f_rows = v
|
|
|
|
|
self.p.send(self.arg)
|
|
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-04-20 17:10:40 +08:00
|
|
|
def on_c_playback_seq_name_currentIndexChanged(self, v):
|
2025-01-20 17:37:18 +08:00
|
|
|
if self.c_playback_seq_name.sender() is None or isinstance(self.c_playback_seq_name.sender(), QFrame):
|
2025-02-19 00:05:14 +08:00
|
|
|
self.p.send(SetSeqMetaMsg('playback', self.c_playback_seq_name.itemText(v)))
|
2025-01-19 18:27:26 +08:00
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-04-20 17:10:40 +08:00
|
|
|
def on_s_sid_valueChanged(self, v):
|
2025-01-19 18:27:26 +08:00
|
|
|
if self.s_sid.sender() is None:
|
2025-02-18 23:31:44 +08:00
|
|
|
self.p.send(SetSidMsg(v))
|
2025-02-19 00:05:14 +08:00
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
@pyqtSlot(int)
|
2025-04-20 17:10:40 +08:00
|
|
|
def on_sp_sid_valueChanged(self, v):
|
2025-02-19 00:05:14 +08:00
|
|
|
if self.sp_sid.sender() is None:
|
|
|
|
|
self.p.send(SetSidMsg(v))
|
2025-01-19 18:27:26 +08:00
|
|
|
|
2025-04-12 18:02:29 +08:00
|
|
|
# @pyqtSlot(int)
|
2025-04-15 21:18:04 +08:00
|
|
|
@pyqtSlot()
|
|
|
|
|
def on_b_live_seq_apply_clicked(self):
|
2025-03-23 22:33:55 +08:00
|
|
|
v = self.c_live_seq_name.currentIndex()
|
|
|
|
|
name = self.c_live_seq_name.currentText()
|
|
|
|
|
if name != 'Empty':
|
|
|
|
|
self.b_live_seq_apply.setEnabled(False)
|
|
|
|
|
self.p.send(SetDeviceConfigMsg(name, self.c_live_seq_name.itemData(v)))
|
2025-01-06 11:21:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainUI(Node):
|
2025-01-19 18:27:26 +08:00
|
|
|
topics = [ImageArgMsg, SeqIdMinMax, MoveAxisMsg,
|
2025-02-20 14:06:23 +08:00
|
|
|
ImagingConfigNameListMsg,
|
2025-04-12 18:02:29 +08:00
|
|
|
PlaybackSeqListMsg, SetSeqMetaMsg, SeqIdList, SetWindowVisibleMsg, SetSidMsg,
|
2025-01-20 15:23:27 +08:00
|
|
|
DeviceConnectedMsg, DeviceEnabledMsg, DeviceOnlineMsg, DeviceConfigListMsg,
|
2025-03-23 22:33:55 +08:00
|
|
|
RobotRtsiMsg, DeviceSwitchMsg,
|
2025-04-17 20:28:07 +08:00
|
|
|
RecordFrameMsg, SeqMetaMsg, MaxMsg]
|
2025-01-06 11:21:04 +08:00
|
|
|
|
2025-01-19 18:27:26 +08:00
|
|
|
def __init__(self, level=logging.INFO):
|
|
|
|
|
super().__init__(level=level)
|
2025-01-06 11:21:04 +08:00
|
|
|
|
|
|
|
|
def loop(self):
|
2025-02-18 23:31:44 +08:00
|
|
|
try:
|
|
|
|
|
app = QApplication(sys.argv)
|
2025-02-19 00:05:14 +08:00
|
|
|
app.setDesktopFileName('TestTest')
|
2025-02-18 23:31:44 +08:00
|
|
|
if platform.system() == 'Windows':
|
|
|
|
|
app.setStyle('windowsvista')
|
|
|
|
|
MainWindow = Adv(self)
|
2025-02-19 00:05:14 +08:00
|
|
|
# icon = QtGui.QIcon()
|
|
|
|
|
# icon.addPixmap(QtGui.QPixmap("remilia3.png"),
|
|
|
|
|
# QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
|
|
|
|
# MainWindow.setApp(icon)
|
2025-02-18 23:31:44 +08:00
|
|
|
# MainWindow.move(int(px), int(py))
|
|
|
|
|
# MainWindow.resize(int(sx), int(sy))
|
|
|
|
|
MainWindow.show()
|
|
|
|
|
app.exec()
|
|
|
|
|
except Exception as e:
|
2025-04-12 14:36:23 +08:00
|
|
|
traceback.print_exception(e)
|