kuka示教器嵌套UR界面操作ros中rviz的UR机器人-CSDN博客
接上一篇,探索了两个页面互相跳转的操作。
1.两个页面
页面:UrWin,主要显示Ur机器人的VNC远程控制界面
页面:ZcWin,主要是选择插针的长度
在Ur远程界面点击下一步会跳转到针选择界面,在针选择界面点击上一步按钮会跳转到Ur远程界面。而且只保留一个界面。原界面会非销毁掉。
2.界面实现的代码
ur界面参考上一篇博客,针选择界面也是类似的操作一遍即可
2.1 针选择界面
pyside6-uic zhen_choose.ui -o ui_zhen_choose.py
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'zhen_choose.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QPushButton, QSizePolicy,
QWidget)
class Ui_Zhen_choose(object):
def setupUi(self, Zhen_choose):
if not Zhen_choose.objectName():
Zhen_choose.setObjectName(u"Zhen_choose")
Zhen_choose.resize(1050, 747)
Zhen_choose.setStyleSheet(u"background-image: url(:/kuka_top.png);")
self.label = QLabel(Zhen_choose)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(370, 320, 101, 17))
self.label_2 = QLabel(Zhen_choose)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(370, 350, 101, 17))
self.label_3 = QLabel(Zhen_choose)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(370, 380, 101, 17))
self.Bt_lastone = QPushButton(Zhen_choose)
self.Bt_lastone.setObjectName(u"Bt_lastone")
self.Bt_lastone.setGeometry(QRect(500, 570, 89, 25))
self.retranslateUi(Zhen_choose)
QMetaObject.connectSlotsByName(Zhen_choose)
# setupUi
def retranslateUi(self, Zhen_choose):
Zhen_choose.setWindowTitle(QCoreApplication.translate("Zhen_choose", u"\u9009\u62e9\u9488", None))
self.label.setText(QCoreApplication.translate("Zhen_choose", u"\u94881\uff1a50mm", None))
self.label_2.setText(QCoreApplication.translate("Zhen_choose", u"\u94882\uff1a60mm", None))
self.label_3.setText(QCoreApplication.translate("Zhen_choose", u"\u94881\uff1a80mm", None))
self.Bt_lastone.setText(QCoreApplication.translate("Zhen_choose", u"\u4e0a\u4e00\u6b65", None))
# retranslateUi
2.1 Ur界面
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'urVnc.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QPushButton, QSizePolicy, QWidget)
from PySide6.QtWebEngineWidgets import QWebEngineView
#from QtWebKitWidgets.QWebView import QWebView
class Ui_urVNC(object):
def setupUi(self, urVNC):
if not urVNC.objectName():
urVNC.setObjectName(u"urVNC")
urVNC.resize(1056, 750)
urVNC.setStyleSheet(u"background-image: url(:/kuka_top.png);")
self.Bt_next = QPushButton(urVNC)
self.Bt_next.setObjectName(u"Bt_next")
self.Bt_next.setGeometry(QRect(710, 570, 89, 25))
self.webView = QWebEngineView(urVNC)
self.webView.setObjectName(u"webView")
self.webView.setGeometry(QRect(230, 190, 601, 371))
self.webView.setUrl(QUrl(u"http://192.168.56.101:6080/vnc.html"))
self.webView.setZoomFactor(0.500000000000000)
self.Bt_lastone = QPushButton(urVNC)
self.Bt_lastone.setObjectName(u"Bt_lastone")
self.Bt_lastone.setGeometry(QRect(580, 570, 89, 25))
self.retranslateUi(urVNC)
QMetaObject.connectSlotsByName(urVNC)
# setupUi
def retranslateUi(self, urVNC):
urVNC.setWindowTitle(QCoreApplication.translate("urVNC", u"UR VNC", None))
self.Bt_next.setText(QCoreApplication.translate("urVNC", u"\u4e0b\u4e00\u6b65", None))
self.Bt_lastone.setText(QCoreApplication.translate("urVNC", u"\u4e0a\u4e00\u6b65", None))
# retranslateUi
3.主程序
这个实现主要是在主程序里面增加几行代码即可,如下图所示,给相关的按钮赋予点击操作,操作函数显示窗口和关闭窗口。
相关按钮的名字可以在相关ui的python文件中找。如下图,这些名字就是这么一 一对应,选择调用即可。
# This Python file uses the following encoding: utf-8
# if __name__ == "__main__":
# pass
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
from PySide6.QtCore import QFile
from ui_urVnc import Ui_urVNC
from ui_zhen_choose import Ui_Zhen_choose
import images
class UrWin(QMainWindow):
def __init__(self):
super(UrWin, self).__init__()
self.ui = Ui_urVNC()
self.ui.setupUi(self)
self.ui.Bt_next.clicked.connect(self.show_ZcWin)
def show_ZcWin(self, checked):
print("dian ji")
self.w = ZcWin()
self.w.show()
self.close()
class ZcWin(QMainWindow):
def __init__(self):
super(ZcWin, self).__init__()
self.ui = Ui_Zhen_choose()
self.ui.setupUi(self)
self.ui.Bt_lastone.clicked.connect(self.show_urvnc)
def show_urvnc(self,checked):
self.win_urvnc = UrWin()
self.win_urvnc.show()
self.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = UrWin()
window.show()
sys.exit(app.exec())
4.运行测试
所需要的文件放到一个文件里面就可以了,
就是这些文件,就可以正常的运行了