This is the Code i am trying below.
I want to play .avi, .mp4, etc.
I am able to select video but unable to play.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia, QtMultimediaWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.mediaPlayer = QtMultimedia.QMediaPlayer(None, QtMultimedia.QMediaPlayer.VideoSurface)
videoWidget = QtMultimediaWidgets.QVideoWidget()
MainWindow.setObjectName("MainWindow")
MainWindow.resize(881, 578)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.gridLayout_2 = QtWidgets.QGridLayout(self.frame)
self.gridLayout_2.setObjectName("gridLayout_2")
self.widget = QVideoWidget(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
self.widget.setSizePolicy(sizePolicy)
self.widget.setMinimumSize(QtCore.QSize(711, 471))
self.widget.setMaximumSize(QtCore.QSize(711, 471))
self.widget.setObjectName("widget")
self.gridLayout_2.addWidget(self.widget, 0, 0, 3, 1)
self.audiobar = QtWidgets.QSlider(self.frame)
self.audiobar.setMinimumSize(QtCore.QSize(22, 160))
self.audiobar.setMaximumSize(QtCore.QSize(22, 160))
self.audiobar.setOrientation(QtCore.Qt.Vertical)
self.audiobar.setObjectName("audiobar")
self.gridLayout_2.addWidget(self.audiobar, 2, 2, 1, 1)
self.videobar = QtWidgets.QSlider(self.frame)
self.videobar.setMinimumSize(QtCore.QSize(711, 22))
self.videobar.setMaximumSize(QtCore.QSize(711, 22))
self.videobar.setOrientation(QtCore.Qt.Horizontal)
self.videobar.setObjectName("videobar")
self.gridLayout_2.addWidget(self.videobar, 3, 0, 1, 1)
self.frame_2 = QtWidgets.QFrame(self.frame)
self.frame_2.setMinimumSize(QtCore.QSize(120, 111))
self.frame_2.setMaximumSize(QtCore.QSize(120, 111))
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.playbtn = QtWidgets.QPushButton(self.frame_2)
self.playbtn.setGeometry(QtCore.QRect(20, 10, 75, 23))
self.playbtn.setObjectName("playbtn")
self.playbtn.setEnabled(False)
self.pausebtn = QtWidgets.QPushButton(self.frame_2)
self.pausebtn.setGeometry(QtCore.QRect(20, 40, 75, 23))
self.pausebtn.setObjectName("pausebtn")
self.stopbtn = QtWidgets.QPushButton(self.frame_2)
self.stopbtn.setGeometry(QtCore.QRect(20, 70, 75, 23))
self.stopbtn.setObjectName("stopbtn")
self.gridLayout_2.addWidget(self.frame_2, 0, 2, 1, 1)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem, 0, 1, 1, 1)
self.gridLayout.addWidget(self.frame, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 881, 21))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setObjectName("actionClose")
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionClose)
self.menubar.addAction(self.menuFile.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.mediaPlayer.setVideoOutput(videoWidget)
self.actionOpen.triggered.connect(self.openFile)
self.playbtn.clicked.connect(self.play)
self.mediaPlayer.setVideoOutput(videoWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MPlayer"))
self.playbtn.setText(_translate("MainWindow", "Play"))
self.pausebtn.setText(_translate("MainWindow", "Pause"))
self.stopbtn.setText(_translate("MainWindow", "Stop"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.actionOpen.setText(_translate("MainWindow", "Open"))
self.actionClose.setText(_translate("MainWindow", "Close"))
def openFile(self):
fileName, _ = QFileDialog.getOpenFileName(None, "Select Video", " ", "Video Files (*.mp4 *.avi)",
QtCore.QDir.homePath())
if fileName != '':
self.mediaPlayer.setMedia(
QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(fileName)))
self.playbtn.setEnabled(True)
self.statusbar.showMessage(fileName)
self.play()
def play(self):
if self.mediaPlayer.state() == QtMultimedia.QMediaPlayer.PlayingState:
self.mediaPlayer.pause()
else:
self.mediaPlayer.play()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
You set the video output to videoWidget, but you didn't add it to the interface.
You already created a video widget, though, and it is self.widget, so you just have to use that (and only once):
self.mediaPlayer.setVideoOutput(self.widget)
Note that you are using the output of pyuic for your program, which is highly discouraged. Follow the guidelines about using Designer instead.
Related
This question already has answers here:
argument 1 has unexpected type 'Ui_mainWindow'
(4 answers)
Closed 3 years ago.
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
if fileName:
print(fileName)
For this code, this is my output ,
fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files ();;Python Files (.py)", options=options)
TypeError: getOpenFileName(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = '', initialFilter: str = '', options: Union[QFileDialog.Options, QFileDialog.Option] = 0): argument 1 has unexpected type 'Ui_MainWindow'
How do I fix this ?
(Post Edit) :
This is my GUI code :
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(443, 427)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(350, 100, 75, 23))
self.pushButton.setObjectName("pushButton")
**self.pushButton.clicked.connect(self.openFileNameDialog)**
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(40, 100, 281, 21))
self.lineEdit.setObjectName("lineEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 443, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Browse"))
The error is thrown when I run the python script.
Thanks for providing the GUI code. I believe the error most likely arises from inheritance complications. I am not sure why you are passing a separate MainWindow object to various functions. Instead, try to inherit from QMainWindow() and assign all the UI elements to self.
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setObjectName("MainWindow")
self.resize(443, 427)
self.centralwidget = QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QPushButton(self.centralwidget)
self.pushButton.setGeometry(QRect(350, 100, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.openFileNameDialog)
self.lineEdit = QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QRect(40, 100, 281, 21))
self.lineEdit.setObjectName("lineEdit")
self.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QRect(0, 0, 443, 21))
self.menubar.setObjectName("menubar")
self.setMenuBar(self.menubar)
self.statusbar = QStatusBar(self)
self.statusbar.setObjectName("statusbar")
self.setStatusBar(self.statusbar)
self.retranslateUi()
QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
_translate = QCoreApplication.translate
self.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Browse"))
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
if fileName:
print(fileName)
if __name__ == '__main__':
app = QApplication(sys.argv)
MW = MainWindow()
MW.show()
sys.exit(app.exec_())
im pretty new to working with pyqt5 in python, everything is kinda running how it is supposed to be. the only issue i have is that when im triggering to start the function stepperaction(self, index) with the "START" button, i can see the code running in the console, but the UI crashes while the code is running if i click anywhere on the ui with my mouse. i would like to be able to press the "STOP" button in the UI even while the function is running. How am i able to fix this?
# -*- coding: utf-8 -*-
# Created by: PyQt5 UI code generator 5.13.0
import time
import sys
# import RPi.GPIO as GPIO
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QVariant
stepcount = 0
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
mainWindow.resize(557, 320)
self.centralwidget = QtWidgets.QWidget(mainWindow)
self.centralwidget.setEnabled(True)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(360, 40, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(360, 70, 75, 23))
self.pushButton_4.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(270, 70, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(150, 40, 101, 22))
self.comboBox.setEditable(False)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("", QVariant(10*1600))
self.comboBox.addItem("", QVariant(20))
self.comboBox.addItem("", QVariant(30))
self.comboBox.addItem("", QVariant(40))
self.comboBox.addItem("", QVariant(50))
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 30, 121, 31))
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar.setGeometry(QtCore.QRect(20, 250, 118, 23))
self.progressBar.setProperty("value", 24)
self.progressBar.setObjectName("progressBar")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(270, 40, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(400, 252, 71, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(480, 252, 51, 21))
self.label_3.setObjectName("label_3")
mainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(mainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 557, 21))
self.menubar.setObjectName("menubar")
self.menuSmart_Spray_Booth_Configuration = QtWidgets.QMenu(self.menubar)
self.menuSmart_Spray_Booth_Configuration.setObjectName("menuSmart_Spray_Booth_Configuration")
mainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(mainWindow)
self.statusbar.setObjectName("statusbar")
mainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menuSmart_Spray_Booth_Configuration.menuAction())
self.retranslateUi(mainWindow)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
self.comboBox.activated.connect(self.handleactivated)
self.pushButton.clicked.connect(lambda: self.stepperaction(index=self.comboBox.currentIndex()))
self.pushButton_2.clicked.connect(lambda: self.stop())
def handleactivated(self, index):
print(self.comboBox.itemText(index), "handle")
print(self.comboBox.itemData(index), "handle")
self.label_3.setText(self.comboBox.itemText(index))
def retranslateUi(self, mainWindow):
_translate = QtCore.QCoreApplication.translate
mainWindow.setWindowTitle(_translate("mainWindow", "Smart Spray Booth - Configuration"))
self.pushButton.setText(_translate("mainWindow", "START"))
self.pushButton_2.setText(_translate("mainWindow", "STOP"))
self.pushButton_3.setText(_translate("mainWindow", "Nullpunkt"))
self.comboBox.setItemText(0, _translate("mainWindow", "5cm"))
self.comboBox.setItemText(1, _translate("mainWindow", "10cm"))
self.comboBox.setItemText(2, _translate("mainWindow", "15cm"))
self.comboBox.setItemText(3, _translate("mainWindow", "20cm"))
self.comboBox.setItemText(4, _translate("mainWindow", "25cm"))
self.label.setText(_translate("mainWindow", "Bauteilgröße:"))
self.label_2.setText(_translate("mainWindow", "Bauteilgröße:"))
self.label_3.setText(_translate("mainWindow", "0 cm"))
self.menuSmart_Spray_Booth_Configuration.setTitle(_translate("mainWindow", "Smart Spray Booth - Configuration"))
if self.comboBox.currentTextChanged:
print(self.comboBox.currentData(), "from if")
def stop(self):
print("programm wird beendet")
sys.exit()
def stepperaction(self, index):
# GPIO.setmode(GPIO.BOARD) # read the pin as board instead of BCM pin
global stepcount
stepcount = self.comboBox.itemData(index)
print(stepcount, "this is given step")
# return stepcount
FastSpeed = 0.0001 # old = 0.001 Change this depends on your stepper motor
LowSpeed = 0.0001 # old = 0.001 Change this depends on your stepper motor
counter = 0
countery = 0
while True and counter < 3:
print("Move Up", stepcount, "steps")
for i in range(stepcount):
countery = countery + 1
print(countery)
time.sleep(LowSpeed)
print(countery)
time.sleep(LowSpeed)
time.sleep(1)
print("Move Down", stepcount, "steps")
for i in range(stepcount):
countery = countery + 1
print(countery)
time.sleep(FastSpeed)
print(countery)
time.sleep(FastSpeed)
time.sleep(1)
counter += 1
print("success")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
mainWindow = QtWidgets.QMainWindow()
ui = Ui_mainWindow()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())
I can't test on PyQt5, but on PySide you just need to pass the name of the function to connect, not execute it. It might also be better to avoid using lambdas in QT slots.
Try this modification:
....
self.pushButton.clicked.connect(self.stepperaction)
....
def stepperaction(self, index=None):
if index is None:
index = self.comboBox.currentIndex()
# GPIO.setmode(GPIO.BOARD) # read the pin as board instead of BCM pin
global stepcount
....
I have This Qt MainWindow Shown Below:
I want my Browse button to Open a Dialog box for selecting Specific Directory.
I Went through the various post on Stack Overflow, I tried implementing the solution in the post, but It's not working for me.
Here is my Code :
from PyQt5 import QtCore, QtGui, QtWidgets
import os
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.start_button = QtWidgets.QPushButton(self.centralwidget)
self.start_button.setAutoFillBackground(False)
self.start_button.setAutoDefault(False)
self.start_button.setDefault(False)
self.start_button.setFlat(False)
self.start_button.setObjectName("start_button")
self.start_button.clicked.connect(lambda: self.start_button_click())
self.gridLayout_2.addWidget(self.start_button, 0, 0, 1, 1)
self.Br_button = QtWidgets.QPushButton(self.centralwidget)
self.Br_button.setObjectName("Br_button")
self.Br_button.clicked.connect(lambda: self.browse_button())
self.gridLayout_2.addWidget(self.Br_button, 2, 0, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.gridLayout_2.addWidget(self.label, 2, 1, 1, 1, QtCore.Qt.AlignHCenter)
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(0)
self.tableWidget.setRowCount(0)
self.gridLayout_2.addWidget(self.tableWidget, 3, 0, 1, 2)
self.gridLayout.addLayout(self.gridLayout_2, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.start_button.setToolTip(_translate("MainWindow", "Start The Program"))
self.start_button.setText(_translate("MainWindow", "Start"))
self.Br_button.setToolTip(_translate("MainWindow", "Browse the File Location to Watch on"))
self.Br_button.setText(_translate("MainWindow", "Browse"))
def start_button_click(self):
self.label.setText("Hello")
def browse_button(self):
fileName = QtWidgets.QFileDialog.getExistingDirectory(QtWidgets.QFileDialog,None,"Open Directory",os.getcwd(), QtWidgets.QFileDialog.ShowDirsOnly)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
When I Click on the Browse button it closes the Application abruptly after few seconds and I am Getting This Error Shown below:
Try it:
import sys
import os
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Form(QMainWindow):
def __init__(self,parent=None):
super().__init__(parent)
self.plainTextEdit = QPlainTextEdit()
self.plainTextEdit.setFont(QFont('Arial', 11))
openDirButton = QPushButton("Open Directory")
openDirButton.clicked.connect(self.browse_button)
layoutV = QVBoxLayout()
layoutV.addWidget(openDirButton)
layoutH = QHBoxLayout()
layoutH.addLayout(layoutV)
layoutH.addWidget(self.plainTextEdit)
centerWidget = QWidget()
centerWidget.setLayout(layoutH)
self.setCentralWidget(centerWidget)
def browse_button(self):
fileName = QFileDialog.getExistingDirectory(
#QtWidgets.QFileDialog, # ???
None,
"Open Directory",
os.getcwd(),
QFileDialog.ShowDirsOnly)
self.plainTextEdit.appendHtml("<br>Chose a folder: <b>{}</b>".format(fileName))
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Form()
ex.resize(740,480)
ex.setWindowTitle("PyQt5-QFileDialog")
ex.show()
sys.exit(app.exec_())
i have two .ui files that converted to python using pyuic5. first converted ui file is (LoginWindowUI.py) as below:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_LoginWindow(object):
def setupUi(self, LoginWindow):
LoginWindow.setObjectName("LoginWindow")
LoginWindow.setWindowModality(QtCore.Qt.NonModal)
LoginWindow.setEnabled(True)
LoginWindow.resize(446, 182)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(LoginWindow.sizePolicy().hasHeightForWidth())
LoginWindow.setSizePolicy(sizePolicy)
LoginWindow.setMouseTracking(False)
LoginWindow.setLayoutDirection(QtCore.Qt.RightToLeft)
LoginWindow.setLocale(QtCore.QLocale(QtCore.QLocale.Persian, QtCore.QLocale.Iran))
LoginWindow.setDocumentMode(False)
self.centralwidget = QtWidgets.QWidget(LoginWindow)
self.centralwidget.setObjectName("centralwidget")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(194, 30, 187, 77))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.password_ldt = QtWidgets.QLineEdit(self.layoutWidget)
self.password_ldt.setLocale(QtCore.QLocale(QtCore.QLocale.Persian, QtCore.QLocale.Iran))
self.password_ldt.setText("")
self.password_ldt.setEchoMode(QtWidgets.QLineEdit.Password)
self.password_ldt.setCursorPosition(0)
self.password_ldt.setAlignment(QtCore.Qt.AlignCenter)
self.password_ldt.setObjectName("password_ldt")
self.gridLayout.addWidget(self.password_ldt, 1, 1, 1, 1)
self.password_lbl = QtWidgets.QLabel(self.layoutWidget)
self.password_lbl.setAlignment(QtCore.Qt.AlignCenter)
self.password_lbl.setObjectName("password_lbl")
self.gridLayout.addWidget(self.password_lbl, 1, 0, 1, 1)
self.username_lbl = QtWidgets.QLabel(self.layoutWidget)
self.username_lbl.setAlignment(QtCore.Qt.AlignCenter)
self.username_lbl.setObjectName("username_lbl")
self.gridLayout.addWidget(self.username_lbl, 0, 0, 1, 1)
self.username_ldt = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.username_ldt.sizePolicy().hasHeightForWidth())
self.username_ldt.setSizePolicy(sizePolicy)
self.username_ldt.setLocale(QtCore.QLocale(QtCore.QLocale.Persian, QtCore.QLocale.Iran))
self.username_ldt.setText("")
self.username_ldt.setEchoMode(QtWidgets.QLineEdit.Normal)
self.username_ldt.setAlignment(QtCore.Qt.AlignCenter)
self.username_ldt.setObjectName("username_ldt")
self.gridLayout.addWidget(self.username_ldt, 0, 1, 1, 1)
self.login_btn = QtWidgets.QPushButton(self.layoutWidget)
self.login_btn.setCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
self.login_btn.setAutoDefault(False)
self.login_btn.setDefault(False)
self.login_btn.setObjectName("login_btn")
self.gridLayout.addWidget(self.login_btn, 2, 1, 1, 1)
self.description_lbl = QtWidgets.QLabel(self.centralwidget)
self.description_lbl.setGeometry(QtCore.QRect(30, 40, 141, 41))
self.description_lbl.setText("")
self.description_lbl.setAlignment(QtCore.Qt.AlignCenter)
self.description_lbl.setWordWrap(True)
self.description_lbl.setObjectName("description_lbl")
LoginWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(LoginWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 446, 21))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
LoginWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(LoginWindow)
self.statusbar.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.statusbar.setObjectName("statusbar")
LoginWindow.setStatusBar(self.statusbar)
self.action_cra = QtWidgets.QAction(LoginWindow)
self.action_cra.setObjectName("action_cra")
self.action_db = QtWidgets.QAction(LoginWindow)
self.action_db.setObjectName("action_db")
self.action_exit = QtWidgets.QAction(LoginWindow)
self.action_exit.setObjectName("action_exit")
self.menu.addAction(self.action_cra)
self.menu.addAction(self.action_db)
self.menu.addSeparator()
self.menu.addAction(self.action_exit)
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(LoginWindow)
self.action_exit.triggered.connect(LoginWindow.close)
QtCore.QMetaObject.connectSlotsByName(LoginWindow)
LoginWindow.setTabOrder(self.username_ldt, self.password_ldt)
LoginWindow.setTabOrder(self.password_ldt, self.login_btn)
def retranslateUi(self, LoginWindow):
_translate = QtCore.QCoreApplication.translate
self.password_ldt.setToolTip(_translate("LoginWindow", "رمز عبور خود را وارد کنید."))
self.password_lbl.setText(_translate("LoginWindow", " رمز عبور "))
self.username_lbl.setText(_translate("LoginWindow", "نام کاربری"))
self.username_ldt.setToolTip(_translate("LoginWindow", "لطفاً نام کاربری خود را وارد نمایید."))
self.login_btn.setText(_translate("LoginWindow", "ورود"))
self.menu.setTitle(_translate("LoginWindow", "درباره ما"))
self.action_cra.setText(_translate("LoginWindow", "A"))
self.action_db.setText(_translate("LoginWindow", "B"))
self.action_exit.setText(_translate("LoginWindow", "خروج"))
self.action_exit.setStatusTip(_translate("LoginWindow", "خروج"))
self.action_exit.setShortcut(_translate("LoginWindow", "Ctrl+Q"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
LoginWindow = QtWidgets.QMainWindow()
ui = Ui_LoginWindow()
ui.setupUi(LoginWindow)
LoginWindow.show()
sys.exit(app.exec_())
and the second converted .ui file is (MainWindowUI.py) as below:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(452, 432)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.cralogo_lbl = QtWidgets.QLabel(self.centralwidget)
self.cralogo_lbl.setGeometry(QtCore.QRect(90, 30, 171, 161))
self.cralogo_lbl.setText("")
self.cralogo_lbl.setPixmap(QtGui.QPixmap("../../.designer/backup/ICONS/CraLogo.png"))
self.cralogo_lbl.setScaledContents(True)
self.cralogo_lbl.setObjectName("cralogo_lbl")
self.exit_btn = QtWidgets.QPushButton(self.centralwidget)
self.exit_btn.setGeometry(QtCore.QRect(140, 340, 125, 40))
self.exit_btn.setMinimumSize(QtCore.QSize(125, 40))
self.exit_btn.setLayoutDirection(QtCore.Qt.LeftToRight)
self.exit_btn.setCheckable(False)
self.exit_btn.setChecked(False)
self.exit_btn.setObjectName("exit_btn")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(20, 10, 389, 152))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.mobile_btn = QtWidgets.QPushButton(self.layoutWidget)
self.mobile_btn.setEnabled(False)
self.mobile_btn.setMinimumSize(QtCore.QSize(125, 40))
self.mobile_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
self.mobile_btn.setCheckable(False)
self.mobile_btn.setChecked(False)
self.mobile_btn.setObjectName("mobile_btn")
self.gridLayout.addWidget(self.mobile_btn, 1, 0, 1, 1)
self.dataentry_btn = QtWidgets.QPushButton(self.layoutWidget)
self.dataentry_btn.setMinimumSize(QtCore.QSize(125, 40))
self.dataentry_btn.setLayoutDirection(QtCore.Qt.LeftToRight)
self.dataentry_btn.setCheckable(False)
self.dataentry_btn.setChecked(False)
self.dataentry_btn.setObjectName("dataentry_btn")
self.gridLayout.addWidget(self.dataentry_btn, 0, 2, 1, 1)
self.village_btn = QtWidgets.QPushButton(self.layoutWidget)
self.village_btn.setEnabled(False)
self.village_btn.setMinimumSize(QtCore.QSize(125, 40))
self.village_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
self.village_btn.setCheckable(False)
self.village_btn.setChecked(False)
self.village_btn.setObjectName("village_btn")
self.gridLayout.addWidget(self.village_btn, 1, 1, 1, 1)
self.fix_btn = QtWidgets.QPushButton(self.layoutWidget)
self.fix_btn.setEnabled(False)
self.fix_btn.setMinimumSize(QtCore.QSize(125, 40))
self.fix_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
self.fix_btn.setCheckable(False)
self.fix_btn.setChecked(False)
self.fix_btn.setObjectName("fix_btn")
self.gridLayout.addWidget(self.fix_btn, 0, 0, 1, 1)
self.post_btn = QtWidgets.QPushButton(self.layoutWidget)
self.post_btn.setEnabled(False)
self.post_btn.setMinimumSize(QtCore.QSize(125, 40))
self.post_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
self.post_btn.setCheckable(False)
self.post_btn.setChecked(False)
self.post_btn.setObjectName("post_btn")
self.gridLayout.addWidget(self.post_btn, 2, 0, 1, 1)
self.city_btn = QtWidgets.QPushButton(self.layoutWidget)
self.city_btn.setEnabled(False)
self.city_btn.setMinimumSize(QtCore.QSize(125, 40))
self.city_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
self.city_btn.setCheckable(False)
self.city_btn.setChecked(False)
self.city_btn.setObjectName("city_btn")
self.gridLayout.addWidget(self.city_btn, 0, 1, 1, 1)
self.layoutWidget1 = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget1.setGeometry(QtCore.QRect(20, 190, 389, 134))
self.layoutWidget1.setObjectName("layoutWidget1")
self.gridLayout_2 = QtWidgets.QGridLayout(self.layoutWidget1)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.rep4_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep4_btn.setEnabled(False)
self.rep4_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep4_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep4_btn.setCheckable(False)
self.rep4_btn.setObjectName("rep4_btn")
self.gridLayout_2.addWidget(self.rep4_btn, 0, 0, 1, 1)
self.rep1_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep1_btn.setEnabled(False)
self.rep1_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep1_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep1_btn.setCheckable(False)
self.rep1_btn.setObjectName("rep1_btn")
self.gridLayout_2.addWidget(self.rep1_btn, 0, 1, 1, 1)
self.report_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.report_btn.setMinimumSize(QtCore.QSize(125, 40))
self.report_btn.setMaximumSize(QtCore.QSize(125, 40))
self.report_btn.setCheckable(False)
self.report_btn.setObjectName("report_btn")
self.gridLayout_2.addWidget(self.report_btn, 0, 2, 1, 1)
self.rep5_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep5_btn.setEnabled(False)
self.rep5_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep5_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep5_btn.setCheckable(False)
self.rep5_btn.setObjectName("rep5_btn")
self.gridLayout_2.addWidget(self.rep5_btn, 1, 0, 1, 1)
self.rep2_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep2_btn.setEnabled(False)
self.rep2_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep2_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep2_btn.setCheckable(False)
self.rep2_btn.setObjectName("rep2_btn")
self.gridLayout_2.addWidget(self.rep2_btn, 1, 1, 1, 1)
self.rep6_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep6_btn.setEnabled(False)
self.rep6_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep6_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep6_btn.setCheckable(False)
self.rep6_btn.setObjectName("rep6_btn")
self.gridLayout_2.addWidget(self.rep6_btn, 2, 0, 1, 1)
self.rep3_btn = QtWidgets.QPushButton(self.layoutWidget1)
self.rep3_btn.setEnabled(False)
self.rep3_btn.setMinimumSize(QtCore.QSize(125, 40))
self.rep3_btn.setMaximumSize(QtCore.QSize(125, 40))
self.rep3_btn.setCheckable(False)
self.rep3_btn.setObjectName("rep3_btn")
self.gridLayout_2.addWidget(self.rep3_btn, 2, 1, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 452, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.exit_btn.clicked.connect(MainWindow.close)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.cralogo_lbl.setStatusTip(_translate("MainWindow", "www.cra.ir"))
self.exit_btn.setText(_translate("MainWindow", "خروج"))
self.mobile_btn.setText(_translate("MainWindow", "4"))
self.dataentry_btn.setText(_translate("MainWindow", "A"))
self.village_btn.setText(_translate("MainWindow", "2"))
self.fix_btn.setText(_translate("MainWindow", "3"))
self.post_btn.setText(_translate("MainWindow", "5"))
self.city_btn.setText(_translate("MainWindow", "1"))
self.rep4_btn.setText(_translate("MainWindow", "4"))
self.rep1_btn.setText(_translate("MainWindow", "1"))
self.report_btn.setText(_translate("MainWindow", "B"))
self.rep5_btn.setText(_translate("MainWindow", "5"))
self.rep2_btn.setText(_translate("MainWindow", "2"))
self.rep6_btn.setText(_translate("MainWindow", "6"))
self.rep3_btn.setText(_translate("MainWindow", "3"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
and my main python file is:
from LoginWindowUI import Ui_LoginWindow
from MainWindowUI import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class Main_Window(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, db_user, db_pass, parent=None):
super(Main_Window, self).__init__(parent)
self.setupUi(self)
class LoginWindow(QtWidgets.QMainWindow, Ui_LoginWindow):
logged = QtCore.pyqtSignal()
def __init__(self, parent=None):
super(LoginWindow, self).__init__(parent)
self.setupUi(self)
self.login_btn.clicked.connect(self.authenticate)
#QtCore.pyqtSlot()
def authenticate(self):
self.db_user = self.username_ldt.text()
self.db_pass = self.password_ldt.text()
if self.db_user == 'admin' and self.db_pass=='admin':
self.logged.emit()
self.close()
def call_Main_Window(username,password):
w = Main_Window(username, password)
w.setWindowTitle=username
w.show()
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
login = LoginWindow()
login.show()
login.logged.connect(lambda :call_Main_Window(login.db_user, login.db_pass))
sys.exit(app.exec_())
if __name__ == '__main__':
main()
I want that when user enter "admin","admin" in username and password this window colsed and open second ui file .
The main problem is that "w" is a local variable that will be deleted after running the function. One possible solution is to create the second window and not show it, in that second window you will have a method that receives the credentials and shows the window. In the case of the first window it is advisable to modify the signal so that it transmits both data.
from LoginWindowUI import Ui_LoginWindow
from MainWindowUI import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class Main_Window(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Main_Window, self).__init__(parent)
self.setupUi(self)
#QtCore.pyqtSlot(str, str)
def setCredentials(self, db_user, db_pass):
print(db_user, db_pass)
self.show()
class LoginWindow(QtWidgets.QMainWindow, Ui_LoginWindow):
logged = QtCore.pyqtSignal(str, str)
def __init__(self, parent=None):
super(LoginWindow, self).__init__(parent)
self.setupUi(self)
self.login_btn.clicked.connect(self.authenticate)
#QtCore.pyqtSlot()
def authenticate(self):
self.db_user = self.username_ldt.text()
self.db_pass = self.password_ldt.text()
if self.db_user == 'admin' and self.db_pass=='admin':
self.logged.emit(self.db_user, self.db_pass)
self.close()
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
w = Main_Window()
login = LoginWindow()
login.logged.connect(w.setCredentials)
login.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
I am having a pyhton script having some code as follows and and .ui file converted into the .py file. Now i want to execute the python script in widget code of gui widget?
Please help me how can i do that .
from PyQt5 import QtCore, QtGui, QtWidgets
import DC_gimbal as backend
import hudsup as hp
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(978, 600)
self.hudsup = hudsup()
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 291, 261))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.Heads_up = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.Heads_up.setContentsMargins(0, 0, 0, 0)
self.Heads_up.setObjectName("Heads_up")
self.widget = QtWidgets.QWidget(self.verticalLayoutWidget)
self.widget.setObjectName("widget")
self.HeadsWidget = QtWidgets.QWidget(self.widget)
self.HeadsWidget.setGeometry(QtCore.QRect(0, 0, 291, 261))
self.HeadsWidget.setObjectName("HeadsWidget")
self.Heads_up.addWidget(self.widget)
self.Heads_up.addWidget(self.huds_Up())
self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(0, 260, 291, 291))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.widget_3 = QtWidgets.QWidget(self.verticalLayoutWidget_2)
self.widget_3.setObjectName("widget_3")
self.displayWidget = QtWidgets.QWidget(self.widget_3)
self.displayWidget.setGeometry(QtCore.QRect(0, 0, 291, 281))
self.displayWidget.setObjectName("displayWidget")
self.verticalLayout.addWidget(self.widget_3)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(500, 10, 93, 28))
self.pushButton.setObjectName("connect")
self.pushButton.clicked.connect(backend.Noctua_initialise())
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(620, 10, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(740, 10, 93, 28))
self.pushButton_3.setObjectName("pushButton_3")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(290, 330, 561, 211))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.tabWidget.addTab(self.tab_2, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 978, 26))
self.menubar.setObjectName("menubar")
self.menuconnect = QtWidgets.QMenu(self.menubar)
self.menuconnect.setObjectName("menuconnect")
self.menuDisconnect = QtWidgets.QMenu(self.menubar)
self.menuDisconnect.setObjectName("menuDisconnect")
self.menuMode = QtWidgets.QMenu(self.menubar)
self.menuMode.setObjectName("menuMode")
self.menuSensors = QtWidgets.QMenu(self.menubar)
self.menuSensors.setObjectName("menuSensors")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionLIDAR = QtWidgets.QAction(MainWindow)
self.actionLIDAR.setObjectName("actionLIDAR")
self.actionOpen_CV = QtWidgets.QAction(MainWindow)
self.actionOpen_CV.setObjectName("actionOpen_CV")
self.actionManual = QtWidgets.QAction(MainWindow)
self.actionManual.setObjectName("actionManual")
self.actionAuto = QtWidgets.QAction(MainWindow)
self.actionAuto.setObjectName("actionAuto")
self.actionSettings = QtWidgets.QAction(MainWindow)
self.actionSettings.setObjectName("actionSettings")
self.actionCalib = QtWidgets.QAction(MainWindow)
self.actionCalib.setObjectName("actionCalib")
self.actionDisconnect = QtWidgets.QAction(MainWindow)
self.actionDisconnect.setObjectName("actionDisconnect")
self.menuconnect.addAction(self.actionDisconnect)
self.menuDisconnect.addAction(self.actionSettings)
self.menuDisconnect.addAction(self.actionCalib)
self.menuMode.addAction(self.actionManual)
self.menuMode.addAction(self.actionAuto)
self.menuSensors.addAction(self.actionLIDAR)
self.menuSensors.addAction(self.actionOpen_CV)
self.menubar.addAction(self.menuconnect.menuAction())
self.menubar.addAction(self.menuDisconnect.menuAction())
self.menubar.addAction(self.menuMode.menuAction())
self.menubar.addAction(self.menuSensors.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.pushButton_2.setText(_translate("MainWindow", "PushButton"))
self.pushButton_3.setText(_translate("MainWindow", "PushButton"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Tab 1"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Tab 2"))
self.menuconnect.setTitle(_translate("MainWindow", "connect"))
self.menuDisconnect.setTitle(_translate("MainWindow", "configure"))
self.menuMode.setTitle(_translate("MainWindow", "Mode"))
self.menuSensors.setTitle(_translate("MainWindow", "Sensors"))
self.actionLIDAR.setText(_translate("MainWindow", "LIDAR"))
self.actionOpen_CV.setText(_translate("MainWindow", "Open CV"))
self.actionManual.setText(_translate("MainWindow", "Manual"))
self.actionAuto.setText(_translate("MainWindow", "Auto"))
self.actionSettings.setText(_translate("MainWindow", "Settings"))
self.actionCalib.setText(_translate("MainWindow", "Calib"))
self.actionDisconnect.setText(_translate("MainWindow", "Disconnect"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
This is my gui code and i want to add the below file in the headswidget and the file name is hudsup.py :
import sys
import math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
def rec_line_cord(i,list,xc,origin_list,pitch,roll):
.
.
def rec_drawLine(self,i,list,painter,roll,metrics):
.
.
.
def drawMarkings(self, painter):
.
.
.
def drawNeedle(self, painter,roll):
.
.
.
def Compass(self,painter,yaw,r):
.
.
.
class Manager(QObject):
changedValue = pyqtSignal(tuple)
def __init__(self):
QObject.__init__(self)
filename = "Attitude_data_Manual_1232018_1158.txt"
res = self.read_content(filename)
self.results = zip(*res)
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_value)
self.timer.start(100)
#pyqtSlot()
def update_value(self):
try:
self.changedValue.emit(next(self.results))
except StopIteration:
self.timer.stop()
def read_content(self, filename):
.
.
.
class Widget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.v = None
#pyqtSlot(tuple)
def update_value(self, v):
self.v = v
self.update()
def paintEvent(self, event):
QWidget.paintEvent(self, event)
painter = QPainter(self)
r = self.rect()
.
.
if __name__ == '__main__':
app = QApplication(sys.argv)
manager = Manager()
w = Widget()
manager.changedValue.connect(w.update_value)
w.show()
sys.exit(app.exec_())
This is my example of python script.
here is hudsup.py output :
animated huds_up display
and my ui looks like this and i want my hudsup to displayed as mentioned :
Gui
You should not use the generated code directly, instead, create a new widget class and inherit from it:
class MainWindow(Ui_MainWindow, QMainWindow):
def __init__(self):
Ui_MainWindow.__init__(self)
QMainWindow.__init__(self)
self.setupUi(self)
To integrate your second widget you can just add it to Heads_up like you are doing now but don't need to call exec_:
self.hud_sup = HudSup()
self.Heads_up.addWidget(self.hud_sup)