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-03-23 22:33:55 +08:00
|
|
|
from PyQt6 import QtCore, QtWidgets, QtGui
|
2025-01-06 11:21:04 +08:00
|
|
|
from PyQt6.QtCore import QByteArray
|
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
|
|
|
|
|
|
|
|
from Main import Ui_MainWindow
|
2025-01-19 19:05:56 +08:00
|
|
|
from ZMQReceiver import ZMQReceiver
|
2025-03-23 22:33:55 +08:00
|
|
|
from config import DS, SOFTWARE_CONFIG, IMAGING_CONFIG, ASSETS, MI_REP_SOCKET_PORT
|
2025-01-19 19:05:56 +08:00
|
|
|
from nodes.Node import Node
|
2025-02-19 00:05:14 +08:00
|
|
|
from utils.Msg import KillMsg, Msg, ImageArgMsg, SeqIdMinMax, MoveAxisMsg, SeqListMsg, 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, \
|
|
|
|
|
SetDeviceSwitchMsg, SeqMetaMsg, RefreshDeviceMsg
|
2025-02-11 23:24:49 +08:00
|
|
|
from 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-03-23 22:33:55 +08:00
|
|
|
self.device_switch_state: LinkStatus = LinkStatus.RED
|
|
|
|
|
icon = QtGui.QIcon()
|
|
|
|
|
icon.addPixmap(QtGui.QPixmap(str(ASSETS / 'switch_button.png')))
|
|
|
|
|
self.b_probe_head_switch.setIcon(icon)
|
|
|
|
|
self.b_us_switch.setIcon(icon)
|
|
|
|
|
self.b_cobot_switch.setIcon(icon)
|
|
|
|
|
icon = QtGui.QIcon()
|
|
|
|
|
icon.addPixmap(QtGui.QPixmap(str(ASSETS / 'refresh_button.png')))
|
|
|
|
|
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)
|
2025-02-14 11:29:55 +08:00
|
|
|
self.c_playback_seq_name.currentIndexChanged.connect(self.on_select_plyayback_seq_name)
|
2025-02-19 00:05:14 +08:00
|
|
|
self.s_sid.valueChanged.connect(self.on_s_sid)
|
|
|
|
|
self.sp_sid.valueChanged.connect(self.on_sp_sid)
|
2025-01-20 13:03:02 +08:00
|
|
|
self.arg = ImageArgMsg('ui', t_start=0, t_end=1499)
|
2025-02-18 23:31:44 +08:00
|
|
|
self.b_base.clicked.connect(self.on_base_open)
|
2025-01-19 18:27:26 +08:00
|
|
|
self.seq_meta: RfSequenceMeta | None = None
|
2025-03-23 22:33:55 +08:00
|
|
|
# self.b_play_live.clicked.connect(self.on_play_live)
|
|
|
|
|
# self.b_play_playback.clicked.connect(self.on_play_playback)
|
|
|
|
|
self.g_playback.clicked.connect(self.on_play_playback)
|
|
|
|
|
self.g_live.clicked.connect(self.on_play_live)
|
|
|
|
|
|
2025-01-19 18:27:26 +08:00
|
|
|
self.b_record.clicked.connect(self.on_record)
|
|
|
|
|
self.record = False
|
|
|
|
|
self.device_connected = False
|
|
|
|
|
self.device_enabled = False
|
2025-01-20 17:21:53 +08:00
|
|
|
# self.b_device_enabled.clicked.connect(lambda: self.p.send(SetDeviceEnabledMsg(not self.device_enabled)))
|
|
|
|
|
# self.b_device_connected.clicked.connect(lambda: self.p.send(SetDeviceConnectedMsg(not self.device_connected)))
|
2025-03-23 22:33:55 +08:00
|
|
|
# self.c_live_seq_name.currentIndexChanged.connect(self.on_seq_meta)
|
|
|
|
|
self.b_live_seq_apply.clicked.connect(self.on_seq_meta)
|
2025-02-18 23:31:44 +08:00
|
|
|
self.l_base.setText(SOFTWARE_CONFIG.base_dir.__str__())
|
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.b1, self.b2 = False, False
|
|
|
|
|
self.b3, self.b4 = False, False
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
# self.cb_bscan.checkStateChanged.connect(lambda e: print(e == 2, flush=True))
|
|
|
|
|
# self.cb_bscan.checkStateChanged.connect(lambda e: print(e.name, flush=True))
|
|
|
|
|
|
2025-02-20 14:06:23 +08:00
|
|
|
self.b_new_imaging_config.clicked.connect(self.on_new_imaging_config)
|
|
|
|
|
self.c_imaging_config.currentIndexChanged.connect(self.on_imaging_config)
|
|
|
|
|
|
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.b_us_switch.clicked.connect(self.on_deivce_switch)
|
|
|
|
|
self.b_us_refresh.clicked.connect(self.on_deivce_refresh)
|
|
|
|
|
|
|
|
|
|
self.mi_req_socket = zmq.Context().socket(zmq.REQ)
|
|
|
|
|
self.mi_req_socket.connect(f"tcp://127.0.0.1:{MI_REP_SOCKET_PORT}")
|
|
|
|
|
|
|
|
|
|
def on_deivce_switch(self):
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
def on_deivce_refresh(self):
|
|
|
|
|
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-02-20 14:06:23 +08:00
|
|
|
def on_imaging_config(self, i):
|
|
|
|
|
name = self.c_imaging_config.itemText(i)
|
|
|
|
|
self.p.send(ImageArgMsg.from_path(IMAGING_CONFIG / f'{name}.json'))
|
|
|
|
|
|
|
|
|
|
def on_new_imaging_config(self):
|
|
|
|
|
text, okPressed = QtWidgets.QInputDialog.getText(None,
|
|
|
|
|
"Set New Imaging Config Name",
|
|
|
|
|
"Config Name:",
|
|
|
|
|
QLineEdit.EchoMode.Normal,
|
|
|
|
|
"")
|
|
|
|
|
if okPressed and text != '':
|
|
|
|
|
(IMAGING_CONFIG / f'{text}.json').write_text(self.arg.json())
|
|
|
|
|
|
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-03-23 22:33:55 +08:00
|
|
|
# def update_b_play_live_enabled(self):
|
|
|
|
|
# self.b_play_live.setEnabled(all([self.b1, self.b2]))
|
2025-01-20 19:28:03 +08:00
|
|
|
|
2025-02-18 23:31:44 +08:00
|
|
|
def on_base_open(self):
|
|
|
|
|
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)
|
|
|
|
|
# self.b1 = True
|
|
|
|
|
# self.update_b_play_live_enabled()
|
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-01-20 19:28:03 +08:00
|
|
|
def update_c_playback_seq_name_enable(self):
|
|
|
|
|
self.c_playback_seq_name.setEnabled(all([self.b3, self.b4]))
|
|
|
|
|
|
2025-03-23 22:33:55 +08:00
|
|
|
def on_play_live(self, b):
|
|
|
|
|
if b:
|
|
|
|
|
self.g_playback.setChecked(False)
|
|
|
|
|
# self.s_sid.setEnabled(False)
|
|
|
|
|
# self.b_play_live.setStyleSheet('background-color: red;')
|
|
|
|
|
# self.b_play_playback.setStyleSheet('')
|
|
|
|
|
# self.b_record.setEnabled(True)
|
|
|
|
|
# self.l_record_commit.setEnabled(True)
|
|
|
|
|
# self.p.send(SetSeqMetaMsg('live', self.c_live_seq_name.itemText(self.c_live_seq_name.currentIndex())))
|
|
|
|
|
self.p.send(SetPlayMode('live'))
|
|
|
|
|
self.b3 = False
|
|
|
|
|
self.update_c_playback_seq_name_enable()
|
|
|
|
|
|
|
|
|
|
def on_play_playback(self, b):
|
|
|
|
|
if b:
|
|
|
|
|
self.g_live.setChecked(False)
|
|
|
|
|
# self.s_sid.setEnabled(True)
|
|
|
|
|
# self.b_play_live.setStyleSheet('')
|
|
|
|
|
# self.b_play_playback.setStyleSheet('background-color: red;')
|
|
|
|
|
# self.b_record.setEnabled(False)
|
|
|
|
|
# self.l_record_commit.setEnabled(False)
|
|
|
|
|
self.p.send(
|
|
|
|
|
SetSeqMetaMsg('playback', self.c_playback_seq_name.itemText(self.c_playback_seq_name.currentIndex())))
|
|
|
|
|
self.p.send(SetPlayMode('playback'))
|
|
|
|
|
logger.debug(f'set playmode playback')
|
|
|
|
|
self.b3 = True
|
|
|
|
|
self.update_c_playback_seq_name_enable()
|
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-01-19 18:27:26 +08:00
|
|
|
def on_record(self):
|
|
|
|
|
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-20 19:28:03 +08:00
|
|
|
self.l_record_commit.setEnabled(False)
|
2025-01-19 18:49:41 +08:00
|
|
|
if self.l_record_commit.text() != '':
|
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
|
|
|
|
|
|
|
|
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-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)
|
|
|
|
|
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)))
|
|
|
|
|
elif isinstance(msg, SeqListMsg):
|
|
|
|
|
self.b4 = True
|
|
|
|
|
self.update_c_playback_seq_name_enable()
|
|
|
|
|
self.c_playback_seq_name.clear()
|
|
|
|
|
for name in msg.value:
|
|
|
|
|
self.c_playback_seq_name.addItem(name)
|
|
|
|
|
if msg.value.__len__() > 0:
|
2025-02-19 00:05:14 +08:00
|
|
|
self.p.send(SetSeqMetaMsg('playback', self.c_playback_seq_name.itemText(
|
|
|
|
|
self.c_playback_seq_name.currentIndex())))
|
2025-03-23 22:33:55 +08:00
|
|
|
# self.b_play_playback.setEnabled(True)
|
2025-02-18 23:31:44 +08:00
|
|
|
elif isinstance(msg, SetSeqMetaMsg):
|
|
|
|
|
self.seq_meta = RfSequenceMeta.from_name(msg.name)
|
2025-02-19 00:05:14 +08:00
|
|
|
mmax_shape0 = max(self.seq_meta.shape)
|
|
|
|
|
self.s_t_start.setMaximum(mmax_shape0)
|
|
|
|
|
self.s_t_end.setMaximum(mmax_shape0)
|
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-03-23 22:33:55 +08:00
|
|
|
elif isinstance(msg, SeqMetaMsg):
|
|
|
|
|
if msg.target == 'live':
|
|
|
|
|
self.l_live_seq_name.setText(msg.name)
|
|
|
|
|
self.b_live_seq_apply.setEnabled(True)
|
|
|
|
|
# elif isinstance(msg, DeviceOnlineMsg):
|
|
|
|
|
# if msg.value:
|
|
|
|
|
# # self.l_online.setStyleSheet("")
|
|
|
|
|
# # self.l_online.setText("Device Online")
|
|
|
|
|
# self.g_device.setEnabled(True)
|
|
|
|
|
# else:
|
|
|
|
|
# # self.l_online.setStyleSheet("background-color: pink;")
|
|
|
|
|
# # self.l_online.setText("Device Offline")
|
|
|
|
|
# self.g_device.setEnabled(False)
|
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-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):
|
|
|
|
|
print(msg, flush=True)
|
|
|
|
|
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-02-18 23:31:44 +08:00
|
|
|
@QtCore.pyqtSlot(int)
|
|
|
|
|
def on_cb_bscan(self, v):
|
|
|
|
|
if self.cb_bscan.sender() is None:
|
|
|
|
|
self.p.send(SetWindowVisibleMsg('ui', 'bscan', v == 2))
|
|
|
|
|
|
2025-01-06 11:21:04 +08:00
|
|
|
@QtCore.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)
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(int)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(int)
|
2025-02-14 11:29:55 +08:00
|
|
|
def on_select_plyayback_seq_name(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
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(int)
|
2025-02-19 00:05:14 +08:00
|
|
|
def on_s_sid(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
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(int)
|
|
|
|
|
def on_sp_sid(self, v):
|
|
|
|
|
if self.sp_sid.sender() is None:
|
|
|
|
|
self.p.send(SetSidMsg(v))
|
2025-01-19 18:27:26 +08:00
|
|
|
|
2025-03-23 22:33:55 +08:00
|
|
|
# @QtCore.pyqtSlot(int)
|
|
|
|
|
def on_seq_meta(self):
|
|
|
|
|
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)))
|
|
|
|
|
# self.p.send(SetSeqMetaMsg('live', self.c_live_seq_name.itemText(v)))
|
|
|
|
|
|
|
|
|
|
# if self.c_live_seq_name.sender() is None or isinstance(self.c_live_seq_name.sender(), QFrame):
|
|
|
|
|
# if self.c_live_seq_name.itemText(v) != 'Empty':
|
|
|
|
|
# self.b2 = True
|
|
|
|
|
# # self.update_b_play_live_enabled()
|
|
|
|
|
# self.p.send(SetDeviceConfigMsg(self.c_live_seq_name.itemData(v)))
|
|
|
|
|
# self.p.send(SetSeqMetaMsg('live', self.c_live_seq_name.itemText(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-02-18 23:31:44 +08:00
|
|
|
SeqListMsg, 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,
|
|
|
|
|
RecordFrameMsg, SeqMetaMsg]
|
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:
|
|
|
|
|
print(e)
|