Calling function with clicking actions on Qtoolbar created by QT designer - python

I'm using python 2.7 with pyqt 4.10 and I've created this UI using QT designer and I am trying to find the actions on the toolbar to add some function calling to it, but I can't find it
# -*- coding: utf-8 -*-
# Form implementation generated from reading UI file 'Warehouse.ui'
#
# Created: Mon Mar 19 19:13:01 2018
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import item_entry
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName(_fromUtf8("mainWindow"))
mainWindow.resize(1262, 698)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/wh.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
mainWindow.setWindowIcon(icon)
self.centralwidget = QtGui.QWidget(mainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout = QtGui.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.comboBox = QtGui.QComboBox(self.centralwidget)
self.comboBox.setObjectName(_fromUtf8("comboBox"))
self.gridLayout.addWidget(self.comboBox, 1, 0, 1, 1)
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.items_tab = QtGui.QWidget()
self.items_tab.setObjectName(_fromUtf8("items_tab"))
self.listView = QtGui.QListView(self.items_tab, )
self.listView.setGeometry(QtCore.QRect(0, 0, 481, 521))
self.listView.setObjectName(_fromUtf8("listView"))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/item_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tabWidget.addTab(self.items_tab, icon1, _fromUtf8(""))
self.category_tab = QtGui.QWidget()
self.category_tab.setObjectName(_fromUtf8("category_tab"))
self.listView_2 = QtGui.QListView(self.category_tab)
self.listView_2.setEnabled(True)
self.listView_2.setGeometry(QtCore.QRect(0, 0, 481, 521))
self.listView_2.setObjectName(_fromUtf8("listView_2"))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/cat_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tabWidget.addTab(self.category_tab, icon2, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidget, 2, 0, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.verticalLayout_3 = QtGui.QVBoxLayout()
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.label_3 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(16)
self.label_3.setFont(font)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.verticalLayout_3.addWidget(self.label_3)
self.label_2 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(16)
self.label_2.setFont(font)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.verticalLayout_3.addWidget(self.label_2)
self.horizontalLayout.addLayout(self.verticalLayout_3)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setEnabled(True)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.verticalLayout_2.addWidget(self.lineEdit)
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setEnabled(True)
self.lineEdit_3.setEchoMode(QtGui.QLineEdit.Password)
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.verticalLayout_2.addWidget(self.lineEdit_3)
self.horizontalLayout.addLayout(self.verticalLayout_2)
self.gridLayout.addLayout(self.horizontalLayout, 0, 2, 1, 1)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.label_5 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.label_5.setFont(font)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.verticalLayout.addWidget(self.label_5)
self.gridLayout.addLayout(self.verticalLayout, 0, 4, 1, 1)
self.label = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(36)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem, 0, 1, 1, 1)
self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.label_4 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_4.setFont(font)
self.label_4.setLineWidth(5)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalLayout_2.addWidget(self.label_4)
self.label_6 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(28)
self.label_6.setFont(font)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.horizontalLayout_2.addWidget(self.label_6)
self.verticalLayout_4.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.label_7 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(24)
self.label_7.setFont(font)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.horizontalLayout_3.addWidget(self.label_7)
self.lcdNumber = QtGui.QLCDNumber(self.centralwidget)
self.lcdNumber.setFrameShape(QtGui.QFrame.NoFrame)
self.lcdNumber.setObjectName(_fromUtf8("lcdNumber"))
self.horizontalLayout_3.addWidget(self.lcdNumber)
self.verticalLayout_4.addLayout(self.horizontalLayout_3)
self.gridLayout.addLayout(self.verticalLayout_4, 2, 1, 1, 2)
self.gridLayout_2 = QtGui.QGridLayout()
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.lcdNumber_4 = QtGui.QLCDNumber(self.centralwidget)
self.lcdNumber_4.setObjectName(_fromUtf8("lcdNumber_4"))
self.gridLayout_2.addWidget(self.lcdNumber_4, 2, 1, 1, 1)
self.label_10 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_10.setFont(font)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.gridLayout_2.addWidget(self.label_10, 2, 0, 1, 1)
self.lcdNumber_2 = QtGui.QLCDNumber(self.centralwidget)
self.lcdNumber_2.setObjectName(_fromUtf8("lcdNumber_2"))
self.gridLayout_2.addWidget(self.lcdNumber_2, 0, 1, 1, 1)
self.label_9 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_9.setFont(font)
self.label_9.setObjectName(_fromUtf8("label_9"))
self.gridLayout_2.addWidget(self.label_9, 0, 0, 1, 1)
self.lcdNumber_3 = QtGui.QLCDNumber(self.centralwidget)
self.lcdNumber_3.setObjectName(_fromUtf8("lcdNumber_3"))
self.gridLayout_2.addWidget(self.lcdNumber_3, 1, 1, 1, 1)
self.label_8 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_8.setFont(font)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.gridLayout_2.addWidget(self.label_8, 1, 0, 1, 1)
self.label_11 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_11.setFont(font)
self.label_11.setObjectName(_fromUtf8("label_11"))
self.gridLayout_2.addWidget(self.label_11, 0, 2, 1, 1)
self.label_12 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_12.setFont(font)
self.label_12.setObjectName(_fromUtf8("label_12"))
self.gridLayout_2.addWidget(self.label_12, 1, 2, 1, 1)
self.label_13 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
self.label_13.setFont(font)
self.label_13.setObjectName(_fromUtf8("label_13"))
self.gridLayout_2.addWidget(self.label_13, 2, 2, 1, 1)
self.gridLayout.addLayout(self.gridLayout_2, 2, 4, 1, 1)
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(14)
self.pushButton.setFont(font)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.gridLayout.addWidget(self.pushButton, 1, 2, 1, 1)
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setEnabled(False)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(16)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.gridLayout.addWidget(self.pushButton_2, 0, 3, 1, 1)
mainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(mainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1262, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menu = QtGui.QMenu(self.menubar)
self.menu.setObjectName(_fromUtf8("menu"))
self.menu_2 = QtGui.QMenu(self.menubar)
self.menu_2.setObjectName(_fromUtf8("menu_2"))
self.menu_3 = QtGui.QMenu(self.menubar)
self.menu_3.setObjectName(_fromUtf8("menu_3"))
self.menu_4 = QtGui.QMenu(self.menubar)
self.menu_4.setObjectName(_fromUtf8("menu_4"))
self.menu_5 = QtGui.QMenu(self.menubar)
self.menu_5.setObjectName(_fromUtf8("menu_5"))
mainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(mainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
mainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(mainWindow)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.toolBar.sizePolicy().hasHeightForWidth())
self.toolBar.setSizePolicy(sizePolicy)
self.toolBar.setMovable(False)
self.toolBar.setIconSize(QtCore.QSize(100, 100))
self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.toolBar.setFloatable(False)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
mainWindow.addToolBar(QtCore.Qt.RightToolBarArea, self.toolBar)
self.action = QtGui.QAction(mainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/in.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action.setIcon(icon3)
self.action.setObjectName(_fromUtf8("action"))
self.action_3 = QtGui.QAction(mainWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/edit.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_3.setIcon(icon4)
self.action_3.setObjectName(_fromUtf8("action_3"))
self.action_4 = QtGui.QAction(mainWindow)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/out.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_4.setIcon(icon5)
self.action_4.setObjectName(_fromUtf8("action_4"))
self.action_5 = QtGui.QAction(mainWindow)
self.action_5.setIcon(icon3)
self.action_5.setObjectName(_fromUtf8("action_5"))
self.action_7 = QtGui.QAction(mainWindow)
self.action_7.setIcon(icon1)
self.action_7.setObjectName(_fromUtf8("action_7"))
self.action_8 = QtGui.QAction(mainWindow)
self.action_8.setIcon(icon5)
self.action_8.setObjectName(_fromUtf8("action_8"))
self.new_item_entry = QtGui.QAction(mainWindow)
self.new_item_entry.setCheckable(False)
self.new_item_entry.setIcon(icon3)
self.new_item_entry.setObjectName(_fromUtf8("new_item_entry"))
self.exiting_item = QtGui.QAction(mainWindow)
self.exiting_item.setIcon(icon5)
self.exiting_item.setObjectName(_fromUtf8("exiting_item"))
self.item_edit_name = QtGui.QAction(mainWindow)
self.item_edit_name.setIcon(icon4)
self.item_edit_name.setObjectName(_fromUtf8("item_edit_name"))
self.action_9 = QtGui.QAction(mainWindow)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/close.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_9.setIcon(icon6)
self.action_9.setObjectName(_fromUtf8("action_9"))
self.action_10 = QtGui.QAction(mainWindow)
self.action_10.setIcon(icon3)
self.action_10.setObjectName(_fromUtf8("action_10"))
self.action_11 = QtGui.QAction(mainWindow)
self.action_11.setIcon(icon5)
self.action_11.setObjectName(_fromUtf8("action_11"))
self.action_13 = QtGui.QAction(mainWindow)
self.action_13.setIcon(icon4)
self.action_13.setObjectName(_fromUtf8("action_13"))
self.action_15 = QtGui.QAction(mainWindow)
self.action_15.setIcon(icon4)
self.action_15.setObjectName(_fromUtf8("action_15"))
self.action_16 = QtGui.QAction(mainWindow)
self.action_16.setIcon(icon6)
self.action_16.setObjectName(_fromUtf8("action_16"))
self.action_17 = QtGui.QAction(mainWindow)
self.action_17.setObjectName(_fromUtf8("action_17"))
self.action_18 = QtGui.QAction(mainWindow)
self.action_18.setObjectName(_fromUtf8("action_18"))
self.action_19 = QtGui.QAction(mainWindow)
icon7 = QtGui.QIcon()
icon7.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/save.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_19.setIcon(icon7)
self.action_19.setObjectName(_fromUtf8("action_19"))
self.action_20 = QtGui.QAction(mainWindow)
icon8 = QtGui.QIcon()
icon8.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/restore.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_20.setIcon(icon8)
self.action_20.setObjectName(_fromUtf8("action_20"))
self.action_22 = QtGui.QAction(mainWindow)
self.action_22.setIcon(icon6)
self.action_22.setObjectName(_fromUtf8("action_22"))
self.menu.addAction(self.action)
self.menu.addSeparator()
self.menu.addAction(self.action_3)
self.menu.addAction(self.action_4)
self.menu_2.addAction(self.action_5)
self.menu_2.addSeparator()
self.menu_2.addAction(self.action_7)
self.menu_2.addAction(self.action_8)
self.menu_3.addAction(self.action_10)
self.menu_3.addAction(self.action_11)
self.menu_3.addSeparator()
self.menu_3.addAction(self.action_13)
self.menu_3.addSeparator()
self.menu_3.addAction(self.action_15)
self.menu_3.addAction(self.action_16)
self.menu_4.addAction(self.action_17)
self.menu_4.addAction(self.action_18)
self.menu_5.addAction(self.action_19)
self.menu_5.addAction(self.action_20)
self.menu_5.addSeparator()
self.menu_5.addAction(self.action_22)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
self.menubar.addAction(self.menu_5.menuAction())
self.menubar.addAction(self.menu_4.menuAction())
self.toolBar.addAction(self.new_item_entry)
self.toolBar.addAction(self.exiting_item)
self.toolBar.addAction(self.item_edit_name)
self.toolBar.addAction(self.action_9)
self.retranslateUi(mainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
def retranslateUi(self, mainWindow):
mainWindow.setWindowTitle(_translate("mainWindow", "Town of technoloy - إدارة المخازن", None))
self.comboBox.setStatusTip(_translate("mainWindow", "قم بإختيار الفئة", None))
self.tabWidget.setStatusTip(_translate("mainWindow", "اختار ما بين الاصناف و الفئات", None))
self.listView.setStatusTip(_translate("mainWindow", "الاصناف فى المخزن", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.items_tab), _translate("mainWindow", "الأصناف", None))
self.listView_2.setStatusTip(_translate("mainWindow", "الفئات فى المخزن", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.category_tab), _translate("mainWindow", "الفئات", None))
self.label_3.setText(_translate("mainWindow", "إسم المستخدم", None))
self.label_2.setText(_translate("mainWindow", "كلمة المرور", None))
self.lineEdit.setStatusTip(_translate("mainWindow", "ادخل إسم المستخدم ", None))
self.lineEdit.setPlaceholderText(_translate("mainWindow", "إسم المستخدم هنا", None))
self.lineEdit_3.setStatusTip(_translate("mainWindow", "ادخل كلمة المرور", None))
self.lineEdit_3.setPlaceholderText(_translate("mainWindow", "كلمة المرور هنا", None))
self.label_5.setStatusTip(_translate("mainWindow", "Town of Technology", None))
self.label_5.setText(_translate("mainWindow", "<html><head/><body><p><img src=\":/media/media/town-of-technology.png\"/></p></body></html>", None))
self.label.setStatusTip(_translate("mainWindow", "برنامج إدارة المخازن من Town of Technology", None))
self.label.setText(_translate("mainWindow", "<html><head/><body><p><span style=\" color:#ff0000; vertical-align:super;\">T</span><span style=\" vertical-align:super;\">own of technology </span><img src=\":/media/media/wh.ico\"/><span style=\" vertical-align:sub;\">إدارة المخازن</span></p></body></html>", None))
self.label_4.setText(_translate("mainWindow", " إسم الصنف", None))
self.label_6.setStatusTip(_translate("mainWindow", "إسم الصنف ", None))
self.label_6.setText(_translate("mainWindow", "إختر صنف", None))
self.label_7.setText(_translate("mainWindow", " الكمية", None))
self.lcdNumber.setStatusTip(_translate("mainWindow", "الكمية الموجودة من الصنف", None))
self.label_10.setText(_translate("mainWindow", "عدد المستخدمين", None))
self.label_9.setText(_translate("mainWindow", "عدد الفئات فى المخزن", None))
self.label_8.setText(_translate("mainWindow", "عدد الاصناف فى المخزن", None))
self.label_11.setText(_translate("mainWindow", "فئة", None))
self.label_12.setText(_translate("mainWindow", "صنف", None))
self.label_13.setText(_translate("mainWindow", "مستخدم", None))
self.pushButton.setStatusTip(_translate("mainWindow", "اضغط لتسجيل الدخول", None))
self.pushButton.setText(_translate("mainWindow", "تسجيل الدخول", None))
self.pushButton_2.setText(_translate("mainWindow", "تسجيل الخروج", None))
self.menu.setTitle(_translate("mainWindow", "الفئات", None))
self.menu_2.setTitle(_translate("mainWindow", "المستخدمين", None))
self.menu_3.setTitle(_translate("mainWindow", "الأصناف", None))
self.menu_4.setTitle(_translate("mainWindow", "التقارير", None))
self.menu_5.setTitle(_translate("mainWindow", "البيانات", None))
self.toolBar.setWindowTitle(_translate("mainWindow", "toolBar", None))
self.action.setText(_translate("mainWindow", "فئة جديدة", None))
self.action_3.setText(_translate("mainWindow", "تعديل الفئات", None))
self.action_4.setText(_translate("mainWindow", "مسح الفئات", None))
self.action_5.setText(_translate("mainWindow", "مستخدم جديد", None))
self.action_7.setText(_translate("mainWindow", "تعديل المستخدمين", None))
self.action_8.setText(_translate("mainWindow", "مسح مستخدمين", None))
self.new_item_entry.setText(_translate("mainWindow", "إدخال صنف للمخزن", None))
self.new_item_entry.setToolTip(_translate("mainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">إدخال صنف للمخزن</span></p></body></html>", None))
self.exiting_item.setText(_translate("mainWindow", "خروج صنف من المخزن", None))
self.item_edit_name.setText(_translate("mainWindow", "تعديل اسم صنف", None))
self.action_9.setText(_translate("mainWindow", "خروج من البرنامج", None))
self.action_10.setText(_translate("mainWindow", "دخول أصناف", None))
self.action_11.setText(_translate("mainWindow", "خروج أصناف", None))
self.action_13.setText(_translate("mainWindow", "تعديل اسم صنف", None))
self.action_15.setText(_translate("mainWindow", "تعديل كمية الاصناف", None))
self.action_16.setText(_translate("mainWindow", "مسح اصناف", None))
self.action_17.setText(_translate("mainWindow", "عرض التقارير ( قريباً )", None))
self.action_18.setText(_translate("mainWindow", "طباعة التقارير ( قريباً )", None))
self.action_19.setText(_translate("mainWindow", "حفظ قاعدة البيانات", None))
self.action_20.setText(_translate("mainWindow", "إسترجاع قاعدة البيانات", None))
self.action_22.setText(_translate("mainWindow", "مسح قاعدة البيانات", None))
import resrcs
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setLayoutDirection(QtCore.Qt.RightToLeft)
app.setStyle('Plastique')
mainWindow = QtGui.QMainWindow()
mainWindow.showMaximized()
ui = Ui_mainWindow()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())
the coding and the OOP being used by the QT designer is a bit different than what I expected.
the function am trying to add is to call another window that is totally created in another file using the same QT designer version, so the import item_entry
statement am using is to call that other file and treat it as a module

You have to use the triggered signal of QAction, but to have an order create a new class that inherits from the widget selected in Qt Designer and the design created as shown below:
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
...
self.toolBar.addAction(self.new_item_entry)
self.toolBar.addAction(self.exiting_item)
self.toolBar.addAction(self.item_edit_name)
self.toolBar.addAction(self.action_9)
...
def retranslateUi(self, mainWindow):
...
import resrcs
class MainWindow(QtGui.QMainWindow, Ui_mainWindow):
def __init__(self, *args, **kwargs):
QtGui.QMainWindow.__init__(self, *args, **kwargs)
self.setupUi(self)
self.new_item_entry.triggered.connect(self.on_new_item_entry)
self.exiting_item.triggered.connect(self.on_exiting_item)
self.item_edit_name.connect(self.on_item_edit_name)
self.action_9.triggered.connect(self.on_action_9)
def on_new_item_entry(self):
# some code
def on_exiting_item(self):
# some code
def on_item_edit_name(self):
# some code
def on_action_9(self):
# some code
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setLayoutDirection(QtCore.Qt.RightToLeft)
app.setStyle('Plastique')
w = MainWindow()
w.show()
sys.exit(app.exec_())

Related

How pass data from second window to main?

I have a python app that change mac address with pyqt5 GUI. I have two python files. The main python file (mainWindow.py) that run main program then I press button to open the second window from second python file secondWindow.py. In second python file opens a window entry then I have to put letters and numbers like then I have to pass data in the first main app label window.
Can anyone help me to solve that?
I tried to reduce code.
mainWindow.py
#!/usr/bin/python3
import os
import sys
import subprocess
from PyQt5 import QtCore, QtGui, QtWidgets
from secondWindow import Ui_macSpecific
import macspoof_bash
import settings
macspoof_bash.write_to_ini()
# Read and write settings in macspoof.ini file
from configparser import ConfigParser
# instantiate
config = ConfigParser()
# parse existing file
config.read('/home/user/.config/macspoof/macspoof.ini')
# read values from a section
wired = config.get('ethernet', 'wired')
wireless = config.get('wifi', 'wireless')
class Ui_MainWindow(object):
def specificWindow(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_macSpecific()
#self.ui.setupUi(self.window)
self.ui.setupUi(self.window, self) # <--- assign MainWindow as parent to second window
self.window.show()
def aboutWindow(self):
self.aboutWindow = QtWidgets.QDialog()
self.ui = Ui_Dialog()
self.ui.setupUi(self.aboutWindow)
self.aboutWindow.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(480, 400)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.specificWindow())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_6.sizePolicy().hasHeightForWidth())
self.pushButton_6.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_6.setFont(font)
self.pushButton_6.setObjectName("pushButton_6")
self.gridLayout.addWidget(self.pushButton_6, 4, 1, 1, 1)
self.pushButton = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_vendor_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 2, 0, 1, 1)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_fully_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout.addWidget(self.pushButton_3, 3, 0, 1, 1)
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_original_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_8.sizePolicy().hasHeightForWidth())
self.pushButton_8.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_8.setFont(font)
self.pushButton_8.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton_8.setAutoFillBackground(False)
self.pushButton_8.setObjectName("pushButton_8")
self.gridLayout.addWidget(self.pushButton_8, 5, 1, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_vendor_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1)
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_original_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth())
self.pushButton_7.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_7.setFont(font)
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 5, 0, 1, 1)
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.specificWindow())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_5.setFont(font)
self.pushButton_5.setObjectName("pushButton_5")
self.gridLayout.addWidget(self.pushButton_5, 4, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_4.setObjectName("label_4")
self.label_4.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_4, 1, 1, 1, 1)
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_fully_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_4.setFont(font)
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout.addWidget(self.pushButton_4, 3, 1, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setMinimumSize(QtCore.QSize(0, 0))
self.label.setSizeIncrement(QtCore.QSize(0, 0))
self.label.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_2.setObjectName("label_2")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_2, 0, 1, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 480, 20))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuEdit = QtWidgets.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
self.menuHelp = QtWidgets.QMenu(self.menubar)
self.menuHelp.setObjectName("menuHelp")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionExit = QtWidgets.QAction(MainWindow)
self.actionExit.triggered.connect(lambda: self.close_window())
self.actionExit.setObjectName("actionExit")
self.actionPreferences = QtWidgets.QAction(MainWindow)
self.actionPreferences.setObjectName("actionPreferences")
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout.triggered.connect(lambda: self.aboutWindow())
self.actionAbout.setObjectName("actionAbout")
self.menuFile.addAction(self.actionExit)
self.menuEdit.addAction(self.actionPreferences)
self.menuHelp.addAction(self.actionAbout)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuEdit.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.update_wired_label(MainWindow)
self.update_wired_mac_address_label(MainWindow)
self.update_wireless_label(MainWindow)
self.update_wireless_mac_address_label(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MAC address spoofing"))
self.label_3.setText(_translate("MainWindow", "TextLabel"))
self.pushButton_6.setText(_translate("MainWindow", "Set the MAC"))
self.pushButton.setText(_translate("MainWindow", "Don\'t change vendor bytes"))
self.pushButton_3.setText(_translate("MainWindow", "Set fully random MAC"))
self.pushButton_8.setText(_translate("MainWindow", "Reset MAC address to its original"))
self.pushButton_2.setText(_translate("MainWindow", "Don\'t change vendor bytes"))
self.pushButton_7.setText(_translate("MainWindow", "Reset MAC address to its original"))
self.pushButton_5.setText(_translate("MainWindow", "Set the MAC"))
self.label_4.setText(_translate("MainWindow", "TextLabel"))
self.pushButton_4.setText(_translate("MainWindow", "Set fully random MAC"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.label_2.setText(_translate("MainWindow", "TextLabel"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuEdit.setTitle(_translate("MainWindow", "Settings"))
self.menuHelp.setTitle(_translate("MainWindow", "Help"))
self.actionExit.setText(_translate("MainWindow", "Exit"))
self.actionPreferences.setText(_translate("MainWindow", "Preferences"))
self.actionAbout.setText(_translate("MainWindow", "About"))
def update_wired_label(self, MainWindow):
print('update_wired_label')
self.wired = config.get('ethernet', 'wired')
self.label.setText(str(self.wired))
def update_wired_mac_address_label(self, MainWindow):
print('update_wired_mac_address_label')
config.read('/home/user/.config/macspoof/macspoof.ini')
self.wired_mac_address = config.get('ethernet', 'wired_mac_address')
self.label_3.setText(str(self.wired_mac_address))
def update_wireless_label(self, MainWindow):
print('update_wireless_label')
self.wireless = config.get('wifi', 'wireless')
self.label_2.setText(str(self.wireless))
def update_wireless_mac_address_label(self, MainWindow):
print('update_wireless_mac_address_label')
config.read('/home/user/.config/macspoof/macspoof.ini')
self.wireless_mac_address = config.get('wifi', 'wireless_mac_address')
self.label_4.setText(str(self.wireless_mac_address))
def button_vendor_wired(self):
print('vendor_wired')
subprocess.run(['macchanger', '-e', wired])
macspoof_bash.vendor_wired()
self.update_wired_mac_address_label(MainWindow)
def button_fully_wired(self):
print('fully wired')
subprocess.run(['macchanger', '-r', wired])
macspoof_bash.write_to_ini()
self.update_wired_mac_address_label(MainWindow)
#def button_specific_wired(self):
# print('specific wired')
# subprocess.run(["macchanger", "-m", wired])
def button_original_wired(self):
print('original wired')
subprocess.run(['macchanger', '-p', wired])
macspoof_bash.write_to_ini()
self.update_wired_mac_address_label(MainWindow)
def button_vendor_wireless(self):
print('vendor_wireless')
subprocess.run(['macchanger', '-e', wireless])
macspoof_bash.vendor_wireless()
self.update_wireless_mac_address_label(MainWindow)
def button_fully_wireless(self):
print('fully wireless')
#wireless = config.get("wifi", "wireless")
#subprocess.run(['macchanger', '-r', wired])
macspoof_bash.fully_wireless()
self.update_wireless_mac_address_label(MainWindow)
def button_specific_wireless(self):
print('specific wired')
subprocess.run(["macchanger", "-m", wireless])
def button_original_wireless(self):
print('original wireless')
subprocess.run(['macchanger', '-p', wireless])
macspoof_bash.write_to_ini()
self.update_wireless_mac_address_label(MainWindow)
def close_window(self):
print("Quit")
sys.exit()
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_())
secondWindow.py
from PyQt5 import QtCore, QtGui, QtWidgets
# Read and write settings in macspoof.ini file
from configparser import ConfigParser
# instantiate
config = ConfigParser()
# parse existing file
config.read('macspoof.ini')
# read values from a section
wired = config.get('ethernet', 'wired')
wired_mac_address = config.get('ethernet', 'wired_mac_address')
class Ui_macSpecific(object):
def setupUi(self, macSpecific, parent): # <--- add extra parameter parent
self.parent = parent # < --- create new attribute parent
#def setupUi(self, macSpecific):
macSpecific.setObjectName("macSpecific")
macSpecific.resize(301, 140)
self.gridLayout = QtWidgets.QGridLayout(macSpecific)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(macSpecific)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(macSpecific)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(14)
self.lineEdit.setFont(font)
self.lineEdit.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lineEdit.setAutoFillBackground(False)
self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
self.pushButton = QtWidgets.QPushButton(macSpecific, clicked = lambda: self.submit())
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 2, 0, 1, 1)
self.retranslateUi(macSpecific)
QtCore.QMetaObject.connectSlotsByName(macSpecific)
def retranslateUi(self, macSpecific):
_translate = QtCore.QCoreApplication.translate
macSpecific.setWindowTitle(_translate("macSpecific", "MAC address spoofing"))
self.label.setText(_translate("macSpecific", "Enter A MAC address"))
self.lineEdit.setText(_translate("macSpecific", "11:22:33:44:55:66"))
self.pushButton.setText(_translate("macSpecific", "Submit"))
def submit(self):
print("submit")
#self.parent.label_3.setText(str(self.wired_mac_address)) # use parent to set label text
self.parent.label_3.setText(str(self.parent.wired_mac_address)) # <-----Try this then.
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
macSpecific = QtWidgets.QDialog()
ui = Ui_macSpecific()
ui.setupUi(macSpecific)
macSpecific.show()
sys.exit(app.exec_())
One solution would be to assign the MainWindow as the parent of the SecondWindow. Then to get the label text all the SecondWindow has to do is self.parent.label.setText('something'). See the minor adjustments I made below.
mainWindow.py
class Ui_MainWindow(object):
def specificWindow(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_macSpecific()
self.ui.setupUi(self.window, self) # <--- assign MainWindow as parent to second window
self.window.show()
secondWindow.py
import macspoof_bash
class Ui_macSpecific(object):
def setupUi(self, macSpecific, master):
self.master = master
self.window = macSpecific
macSpecific.setObjectName("macSpecific")
macSpecific.resize(301, 140)
...
...
self.pushButton = QtWidgets.QPushButton(macSpecific, clicked = lambda: self.submit())
def submit(self):
print("submit")
text = self.lineEdit.text()
self.master.label_3.setText(text)
self.window.close()
config['ethernet']['wired_mac_address'] = text
with open("macspoof.ini", "w") as inifile:
config.write(inifile)

Embedding PyQtGraph plots within an existing Qt Window

I'm trying to embed PyQtGraphs into an existing Qt Window (designed with Qt Designer and converted to .py file). I'm having trouble getting the PyQt GraphicLayoutView to size correctly to the Qt Group which is also inside a Tab.
I had previously managed to get the plots to work using MatPlotLib but they are just too slow at updating once the dataset gets larger, so i decided to make the switch to PyQtGraph as several posts suggested.
Im unsure if im embedding the plots correctly or if it is a case of resizing the GrahpicLayoutView to fill the group.
Any help is appreciated, code and images attached:
Image showing how the graphicsView doesnt size to fit the group
emgWindow_ui.py
# Form implementation generated from reading ui file 'emgWindow.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import numpy as np
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
global win,curve
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(1239, 796)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralWidget = QtGui.QWidget(MainWindow)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.centralWidget.sizePolicy().hasHeightForWidth())
self.centralWidget.setSizePolicy(sizePolicy)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.gridLayout = QtGui.QGridLayout(self.centralWidget)
self.gridLayout.setMargin(11)
self.gridLayout.setSpacing(6)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.tabWidget = QtGui.QTabWidget(self.centralWidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tabWidget.sizePolicy().hasHeightForWidth())
self.tabWidget.setSizePolicy(sizePolicy)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.recordTab = QtGui.QWidget()
self.recordTab.setObjectName(_fromUtf8("recordTab"))
self.dirFrame = QtGui.QFrame(self.recordTab)
self.dirFrame.setGeometry(QtCore.QRect(10, 640, 711, 51))
self.dirFrame.setFrameShape(QtGui.QFrame.StyledPanel)
self.dirFrame.setFrameShadow(QtGui.QFrame.Raised)
self.dirFrame.setObjectName(_fromUtf8("dirFrame"))
self.dirTextBox = QtGui.QTextEdit(self.dirFrame)
self.dirTextBox.setGeometry(QtCore.QRect(10, 10, 511, 31))
self.dirTextBox.setObjectName(_fromUtf8("dirTextBox"))
self.recordBtn = QtGui.QPushButton(self.dirFrame)
self.recordBtn.setGeometry(QtCore.QRect(530, 10, 81, 31))
self.recordBtn.setObjectName(_fromUtf8("recordBtn"))
self.stopBtn = QtGui.QPushButton(self.dirFrame)
self.stopBtn.setGeometry(QtCore.QRect(620, 10, 81, 31))
self.stopBtn.setObjectName(_fromUtf8("stopBtn"))
self.trainingIMGBox = QtGui.QGroupBox(self.recordTab)
self.trainingIMGBox.setGeometry(QtCore.QRect(730, 400, 481, 291))
self.trainingIMGBox.setObjectName(_fromUtf8("trainingIMGBox"))
self.IMUBox = QtGui.QGroupBox(self.recordTab)
self.IMUBox.setGeometry(QtCore.QRect(730, 10, 481, 381))
self.IMUBox.setObjectName(_fromUtf8("IMUBox"))
self.EMGBox = QtGui.QGroupBox(self.recordTab)
self.EMGBox.setGeometry(QtCore.QRect(10, 10, 711, 621))
self.EMGBox.setObjectName(_fromUtf8("EMGBox"))
self.tabWidget.addTab(self.recordTab, _fromUtf8(""))
self.classifyTab = QtGui.QWidget()
self.classifyTab.setObjectName(_fromUtf8("classifyTab"))
self.frame_4 = QtGui.QFrame(self.classifyTab)
self.frame_4.setGeometry(QtCore.QRect(280, 10, 921, 681))
self.frame_4.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtGui.QFrame.Raised)
self.frame_4.setObjectName(_fromUtf8("frame_4"))
self.featuresBox = QtGui.QGroupBox(self.classifyTab)
self.featuresBox.setGeometry(QtCore.QRect(10, 10, 261, 191))
self.featuresBox.setObjectName(_fromUtf8("featuresBox"))
self.MAVCheck = QtGui.QCheckBox(self.featuresBox)
self.MAVCheck.setGeometry(QtCore.QRect(10, 20, 141, 17))
self.MAVCheck.setObjectName(_fromUtf8("MAVCheck"))
self.RMSCheck = QtGui.QCheckBox(self.featuresBox)
self.RMSCheck.setGeometry(QtCore.QRect(10, 40, 141, 17))
self.RMSCheck.setObjectName(_fromUtf8("RMSCheck"))
self.VARCheck = QtGui.QCheckBox(self.featuresBox)
self.VARCheck.setGeometry(QtCore.QRect(10, 60, 131, 17))
self.VARCheck.setObjectName(_fromUtf8("VARCheck"))
self.SSICheck = QtGui.QCheckBox(self.featuresBox)
self.SSICheck.setGeometry(QtCore.QRect(10, 80, 141, 17))
self.SSICheck.setObjectName(_fromUtf8("SSICheck"))
self.ZCCheck = QtGui.QCheckBox(self.featuresBox)
self.ZCCheck.setGeometry(QtCore.QRect(10, 100, 131, 17))
self.ZCCheck.setObjectName(_fromUtf8("ZCCheck"))
self.WLCheck = QtGui.QCheckBox(self.featuresBox)
self.WLCheck.setGeometry(QtCore.QRect(10, 120, 141, 17))
self.WLCheck.setObjectName(_fromUtf8("WLCheck"))
self.SSCCheck = QtGui.QCheckBox(self.featuresBox)
self.SSCCheck.setGeometry(QtCore.QRect(10, 140, 141, 17))
self.SSCCheck.setObjectName(_fromUtf8("SSCCheck"))
self.WACheck = QtGui.QCheckBox(self.featuresBox)
self.WACheck.setGeometry(QtCore.QRect(10, 160, 131, 17))
self.WACheck.setObjectName(_fromUtf8("WACheck"))
self.splitBox = QtGui.QGroupBox(self.classifyTab)
self.splitBox.setGeometry(QtCore.QRect(10, 210, 261, 91))
self.splitBox.setObjectName(_fromUtf8("splitBox"))
self.trainSpin = QtGui.QSpinBox(self.splitBox)
self.trainSpin.setGeometry(QtCore.QRect(110, 20, 42, 22))
self.trainSpin.setMinimum(1)
self.trainSpin.setMaximum(100)
self.trainSpin.setSingleStep(5)
self.trainSpin.setProperty("value", 70)
self.trainSpin.setObjectName(_fromUtf8("trainSpin"))
self.testSpin = QtGui.QSpinBox(self.splitBox)
self.testSpin.setGeometry(QtCore.QRect(110, 60, 42, 22))
self.testSpin.setMinimum(1)
self.testSpin.setMaximum(100)
self.testSpin.setSingleStep(5)
self.testSpin.setProperty("value", 30)
self.testSpin.setObjectName(_fromUtf8("testSpin"))
self.label = QtGui.QLabel(self.splitBox)
self.label.setGeometry(QtCore.QRect(10, 20, 91, 16))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.splitBox)
self.label_2.setGeometry(QtCore.QRect(10, 60, 91, 16))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.splitBtn = QtGui.QPushButton(self.splitBox)
self.splitBtn.setGeometry(QtCore.QRect(170, 20, 75, 61))
self.splitBtn.setObjectName(_fromUtf8("splitBtn"))
self.trainBtn = QtGui.QPushButton(self.classifyTab)
self.trainBtn.setGeometry(QtCore.QRect(40, 310, 181, 41))
self.trainBtn.setAutoFillBackground(False)
self.trainBtn.setObjectName(_fromUtf8("trainBtn"))
self.resultsBox = QtGui.QGroupBox(self.classifyTab)
self.resultsBox.setGeometry(QtCore.QRect(10, 360, 261, 331))
self.resultsBox.setObjectName(_fromUtf8("resultsBox"))
self.resultsScroll = QtGui.QScrollArea(self.resultsBox)
self.resultsScroll.setGeometry(QtCore.QRect(10, 20, 241, 301))
self.resultsScroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.resultsScroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.resultsScroll.setWidgetResizable(True)
self.resultsScroll.setObjectName(_fromUtf8("resultsScroll"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 222, 299))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.resultsScroll.setWidget(self.scrollAreaWidgetContents)
self.tabWidget.addTab(self.classifyTab, _fromUtf8(""))
self.testTab = QtGui.QWidget()
self.testTab.setObjectName(_fromUtf8("testTab"))
self.detectBox = QtGui.QGroupBox(self.testTab)
self.detectBox.setGeometry(QtCore.QRect(600, 10, 191, 681))
self.detectBox.setObjectName(_fromUtf8("detectBox"))
self.gestureTable = QtGui.QTableWidget(self.detectBox)
self.gestureTable.setGeometry(QtCore.QRect(10, 20, 171, 651))
font = QtGui.QFont()
font.setPointSize(12)
self.gestureTable.setFont(font)
self.gestureTable.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.gestureTable.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.gestureTable.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.gestureTable.setTextElideMode(QtCore.Qt.ElideMiddle)
self.gestureTable.setRowCount(10)
self.gestureTable.setColumnCount(1)
self.gestureTable.setObjectName(_fromUtf8("gestureTable"))
self.gestureTable.horizontalHeader().setVisible(False)
self.gestureTable.horizontalHeader().setDefaultSectionSize(170)
self.gestureTable.verticalHeader().setVisible(False)
self.gestureTable.verticalHeader().setDefaultSectionSize(65)
self.imgBox = QtGui.QFrame(self.testTab)
self.imgBox.setGeometry(QtCore.QRect(10, 10, 581, 571))
self.imgBox.setFrameShape(QtGui.QFrame.StyledPanel)
self.imgBox.setFrameShadow(QtGui.QFrame.Raised)
self.imgBox.setObjectName(_fromUtf8("imgBox"))
self.gestureSignal = QtGui.QLabel(self.testTab)
self.gestureSignal.setGeometry(QtCore.QRect(10, 590, 581, 21))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.gestureSignal.setFont(font)
self.gestureSignal.setAlignment(QtCore.Qt.AlignCenter)
self.gestureSignal.setObjectName(_fromUtf8("gestureSignal"))
self.startBtn = QtGui.QPushButton(self.testTab)
self.startBtn.setGeometry(QtCore.QRect(230, 630, 71, 51))
self.startBtn.setObjectName(_fromUtf8("startBtn"))
self.stopBtn_2 = QtGui.QPushButton(self.testTab)
self.stopBtn_2.setGeometry(QtCore.QRect(310, 630, 75, 51))
self.stopBtn_2.setObjectName(_fromUtf8("stopBtn_2"))
self.currentBox = QtGui.QGroupBox(self.testTab)
self.currentBox.setGeometry(QtCore.QRect(800, 10, 411, 681))
self.currentBox.setObjectName(_fromUtf8("currentBox"))
self.tabWidget.addTab(self.testTab, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtGui.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 1239, 21))
self.menuBar.setObjectName(_fromUtf8("menuBar"))
MainWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtGui.QToolBar(MainWindow)
self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtGui.QStatusBar(MainWindow)
self.statusBar.setObjectName(_fromUtf8("statusBar"))
MainWindow.setStatusBar(self.statusBar)
self.win = pg.GraphicsLayoutWidget(self.EMGBox)
#self.win = pg.GraphicsWindow()
pg.setConfigOptions(antialias=True)
self.p6 = self.win.addPlot(title="My Plot")
self.curve = self.p6.plot(pen='r')
data1 = np.random.normal(size=300)
curve1 = self.p6.plot(data1)
ptr1 = 0
def update1():
global data1, ptr1
data1[:-1] = data1[1:] # shift data in the array one sample left
# (see also: np.roll)
data1[-1] = np.random.normal()
curve1.setData(data1)
ptr1 += 1
curve1.setData(data1)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "EMG Gesute Classifier", None))
self.recordBtn.setText(_translate("MainWindow", "Record", None))
self.stopBtn.setText(_translate("MainWindow", "Stop", None))
self.trainingIMGBox.setTitle(_translate("MainWindow", "Gesture", None))
self.IMUBox.setTitle(_translate("MainWindow", "IMU Data", None))
self.EMGBox.setTitle(_translate("MainWindow", "EMG Data", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.recordTab), _translate("MainWindow", "Record", None))
self.featuresBox.setTitle(_translate("MainWindow", "Features", None))
self.MAVCheck.setText(_translate("MainWindow", "Mean Absolute Value", None))
self.RMSCheck.setText(_translate("MainWindow", "Root Mean Square", None))
self.VARCheck.setText(_translate("MainWindow", "Variance", None))
self.SSICheck.setText(_translate("MainWindow", "Simple Square Integral", None))
self.ZCCheck.setText(_translate("MainWindow", "Zero Crossings", None))
self.WLCheck.setText(_translate("MainWindow", "Wave Length", None))
self.SSCCheck.setText(_translate("MainWindow", "Slope Sign Changes", None))
self.WACheck.setText(_translate("MainWindow", "Willison Amplitude", None))
self.splitBox.setTitle(_translate("MainWindow", "Split Data", None))
self.label.setText(_translate("MainWindow", "Training Dataset:", None))
self.label_2.setText(_translate("MainWindow", "Test Dataset:", None))
self.splitBtn.setText(_translate("MainWindow", "Split", None))
self.trainBtn.setText(_translate("MainWindow", "Train", None))
self.resultsBox.setTitle(_translate("MainWindow", "Results", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.classifyTab), _translate("MainWindow", "Classify", None))
self.detectBox.setTitle(_translate("MainWindow", "Gesture Detected", None))
self.gestureSignal.setText(_translate("MainWindow", "SIGNAL", None))
self.startBtn.setText(_translate("MainWindow", "Start", None))
self.stopBtn_2.setText(_translate("MainWindow", "Stop", None))
self.currentBox.setTitle(_translate("MainWindow", "Current", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.testTab), _translate("MainWindow", "Test", None))
It is all executed from emgRun.py
import sys
import numpy as np
import pyqtgraph as pg
from PyQt4 import QtCore, QtGui
from emgesture import EMG_Classify as emg
from emgWindow_ui import Ui_MainWindow
data = emg.dataset
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())

Python Beginners error

I have this really "big" code
class ClassePrincipal(object):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
def setupUi(self, MainWindow):
MainWindow.setObjectName
MainWindow.setObjectName("MainWindow")
MainWindow.resize(464, 501)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName("gridLayout_2")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 427, 719))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.gridLayout = QtWidgets.QGridLayout(self.scrollAreaWidgetContents)
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout.addWidget(self.lineEdit)
self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_2.setObjectName("lineEdit_2")
self.verticalLayout.addWidget(self.lineEdit_2)
self.label_3 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_3.setObjectName("label_3")
self.verticalLayout.addWidget(self.label_3)
self.lineEdit_3 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_3.setObjectName("lineEdit_3")
self.verticalLayout.addWidget(self.lineEdit_3)
self.label_4 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_4.setObjectName("label_4")
self.verticalLayout.addWidget(self.label_4)
self.lineEdit_4 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_4.setObjectName("lineEdit_4")
self.verticalLayout.addWidget(self.lineEdit_4)
self.label_5 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_5.setObjectName("label_5")
self.verticalLayout.addWidget(self.label_5)
self.lineEdit_5 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_5.setObjectName("lineEdit_5")
self.verticalLayout.addWidget(self.lineEdit_5)
self.label_6 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_6.setObjectName("label_6")
self.verticalLayout.addWidget(self.label_6)
self.lineEdit_6 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_6.setObjectName("lineEdit_6")
self.verticalLayout.addWidget(self.lineEdit_6)
self.label_7 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_7.setObjectName("label_7")
self.verticalLayout.addWidget(self.label_7)
self.dateEdit = QtWidgets.QDateEdit(self.scrollAreaWidgetContents)
self.dateEdit.setObjectName("dateEdit")
self.verticalLayout.addWidget(self.dateEdit)
self.label_8 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_8.setObjectName("label_8")
self.verticalLayout.addWidget(self.label_8)
self.lineEdit_8 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_8.setObjectName("lineEdit_8")
self.verticalLayout.addWidget(self.lineEdit_8)
self.label_9 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_9.setObjectName("label_9")
self.verticalLayout.addWidget(self.label_9)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.radioButton_4 = QtWidgets.QRadioButton(self.scrollAreaWidgetContents)
self.radioButton_4.setObjectName("radioButton_4")
self.horizontalLayout_3.addWidget(self.radioButton_4)
self.radioButton_3 = QtWidgets.QRadioButton(self.scrollAreaWidgetContents)
self.radioButton_3.setObjectName("radioButton_3")
self.horizontalLayout_3.addWidget(self.radioButton_3)
self.radioButton_2 = QtWidgets.QRadioButton(self.scrollAreaWidgetContents)
self.radioButton_2.setObjectName("radioButton_2")
self.horizontalLayout_3.addWidget(self.radioButton_2)
self.radioButton = QtWidgets.QRadioButton(self.scrollAreaWidgetContents)
self.radioButton.setObjectName("radioButton")
self.horizontalLayout_3.addWidget(self.radioButton)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.label_10 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_10.setObjectName("label_10")
self.verticalLayout.addWidget(self.label_10)
self.lineEdit_7 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_7.setObjectName("lineEdit_7")
self.verticalLayout.addWidget(self.lineEdit_7)
self.label_11 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_11.setObjectName("label_11")
self.verticalLayout.addWidget(self.label_11)
self.textEdit = QtWidgets.QTextEdit(self.scrollAreaWidgetContents)
self.textEdit.setObjectName("textEdit")
self.verticalLayout.addWidget(self.textEdit)
self.label_12 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_12.setObjectName("label_12")
self.verticalLayout.addWidget(self.label_12)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.graphicsView = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
self.graphicsView.setObjectName("graphicsView")
self.horizontalLayout_4.addWidget(self.graphicsView)
self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_4.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_5.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_5.addWidget(self.pushButton_3)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem)
self.pushButton_4 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout_5.addWidget(self.pushButton_4)
self.verticalLayout.addLayout(self.horizontalLayout_5)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.pushButton_5 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_5.setObjectName("pushButton_5")
self.horizontalLayout_6.addWidget(self.pushButton_5)
self.comboBox = QtWidgets.QComboBox(self.scrollAreaWidgetContents)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.horizontalLayout_6.addWidget(self.comboBox)
self.lineEdit_9 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_9.setObjectName("lineEdit_9")
self.horizontalLayout_6.addWidget(self.lineEdit_9)
self.verticalLayout.addLayout(self.horizontalLayout_6)
self.gridLayout.addLayout(self.verticalLayout, 1, 0, 1, 1)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.gridLayout_2.addWidget(self.scrollArea, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 464, 21))
self.menubar.setObjectName("menubar")
self.menuArquivos = QtWidgets.QMenu(self.menubar)
self.menuArquivos.setObjectName("menuArquivos")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionSalvar = QtWidgets.QAction(MainWindow)
self.actionSalvar.setObjectName("actionSalvar")
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setObjectName("actionClose")
self.actionClose_2 = QtWidgets.QAction(MainWindow)
self.actionClose_2.setObjectName("actionClose_2")
self.menuArquivos.addAction(self.actionSalvar)
self.menuArquivos.addAction(self.actionClose)
self.menuArquivos.addAction(self.actionClose_2)
self.menubar.addAction(self.menuArquivos.menuAction())
self.retranslateUi(MainWindow)
self.actionClose_2.triggered.connect(MainWindow.close)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Nome do Solicitante"))
self.label_2.setText(_translate("MainWindow", "CNPJ"))
self.label_3.setText(_translate("MainWindow", "Email do Solicitante"))
self.label_4.setText(_translate("MainWindow", "Razão Social"))
self.label_5.setText(_translate("MainWindow", "Endereço do Solicitante"))
self.label_6.setText(_translate("MainWindow", "Endereço do Serviço"))
self.label_7.setText(_translate("MainWindow", "Data"))
self.label_8.setText(_translate("MainWindow", "Valor so Serviço"))
self.label_9.setText(_translate("MainWindow", "Forma de Pagamento"))
self.radioButton_4.setText(_translate("MainWindow", "RadioButton"))
self.radioButton_3.setText(_translate("MainWindow", "RadioButton"))
self.radioButton_2.setText(_translate("MainWindow", "RadioButton"))
self.radioButton.setText(_translate("MainWindow", "RadioButton"))
self.label_10.setText(_translate("MainWindow", "Equipamentos Usados"))
self.label_11.setText(_translate("MainWindow", "Descrição do Serviço"))
self.label_12.setText(_translate("MainWindow", "Imagem"))
self.pushButton.setText(_translate("MainWindow", "Procurar..."))
self.pushButton_2.setText(_translate("MainWindow", "Enviar via Email"))
self.pushButton_3.setText(_translate("MainWindow", "Salvar"))
self.pushButton_4.setText(_translate("MainWindow", "Cancelar"))
self.pushButton_5.setText(_translate("MainWindow", "Busca Banco de Dados"))
self.comboBox.setItemText(0, _translate("MainWindow", "CNPJ"))
self.comboBox.setItemText(1, _translate("MainWindow", "Nome do Solicitante"))
self.comboBox.setItemText(2, _translate("MainWindow", "Data"))
self.menuArquivos.setTitle(_translate("MainWindow", "Arquivos"))
self.actionSalvar.setText(_translate("MainWindow", "Salvar"))
self.actionClose.setText(_translate("MainWindow", "Apagar"))
self.actionClose_2.setText(_translate("MainWindow", "Close"))
def main():
app = QApplication(sys.argv)
Mw = ClassePrincipal()
Mw.show()
app.exec_()
if __name__ == '__main__':
main()
But I'm having this error msg
Traceback (most recent call last):
File "C:/Users/Alexandre/Documents/Python/FinalmenteUltimo.py", line 221, in <module>
main()
File "C:/Users/Alexandre/Documents/Python/FinalmenteUltimo.py", line 215, in main
Mw = ClassePrincipal()
File "C:/Users/Alexandre/Documents/Python/FinalmenteUltimo.py", line 14, in __init__
self.setupUi(self)
File "C:/Users/Alexandre/Documents/Python/FinalmenteUltimo.py", line 17, in setupUi
MainWindow.setObjectName
AttributeError: 'ClassePrincipal' object has no attribute 'setObjectName'
But, I've been reading about this module, and there is this attribute.
Can someone help me, I'm realy noob about python, This is my firt program, and I have no idea what is happening.
Since now, thank you.
Ps: I used QT Designer.
As the error message implies, there is an error in line 17:
I guess you mistakenly wrote 'MainWindow.setObjectName' two times, but the first time without parameter. So Python is "thinking" you refer to an attribute with this name instead of a method and the underlying class does not have such an attribute (as described in the error).
I believe this file is generated by pyuic5. You should avoid editing computer generated file by hand. If you have .ui file you can try to generate py file using pyuic5 link below might help you out
http://pyqt.sourceforge.net/Docs/PyQt5/designer.html
Can you make your class extend QMainWindow and change the parts with MainWindow to self like below in setupUi. If this doesnt work create your file using Main Window option use -x flag on pyuic5 it will give you executable python code which is better option. also the link below should be helpful
self.setObjectName("MainWindow")
self.resize(464, 501)
http://www.rkblog.rk.edu.pl/w/p/simple-text-editor-pyqt4/
I did it, to fix that i just did
instead:
class ClassePrincipal(object):
I used
class ClassePrincipal(QMainWindow):
Thank you anyway.

Linking PyQt buttons with Python actions

I'm having trouble getting buttons in a GUI laid out in QT Designer and converted into a python script to do anything when clicked.
At the moment my code looks like this:
import sys
from PyQt4.QtGui import QApplication, QDialog
from punchmenuui import *
from PyQt4.QtGui import *
from PyQt4.QtCore import pyqtSignal
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.closemenubutton.clicked.connect(self.closemenu)
def closemenu(self):
sys.exit()
app = QApplication(sys.argv)
window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
As you can see, its simple. I have a button specified in the layout .py file and I'm trying to capture the "clicked" signal from it and have that trigger a clean exit event. The trouble is: nothing seems to achieve that.
I've tried both the newer and older style PyQt signal/slot bindings to no avail.
Can anyone spot what I'm doing wrong?
EDIT:
Thanks for the responses so far guys. I've tried every combination of all of your answers, but none of them work so far. My current code for the launcher .py script stands as:
import sys
from PyQt4.QtGui import QApplication, QDialog
from punchmenuui import *
from PyQt4.QtGui import *
from PyQt4.QtCore import pyqtSignal
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.closemenubutton.clicked.connect(self.closemenu)
def closemenu():
sys.exit()
app = QApplication(sys.argv)
window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
and the script for the QT-Designed ui is:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'punchmenu.ui'
#
# Created: Tue Mar 10 01:30:31 2015
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(480, 320)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(-1, 0, 481, 301))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tabWidget.sizePolicy().hasHeightForWidth())
self.tabWidget.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.tabWidget.setFont(font)
self.tabWidget.setStyleSheet(_fromUtf8("QTabBar::scroller { /* the width of the scroll buttons */ width: 50px; } "))
self.tabWidget.setTabPosition(QtGui.QTabWidget.North)
self.tabWidget.setTabShape(QtGui.QTabWidget.Rounded)
self.tabWidget.setElideMode(QtCore.Qt.ElideNone)
self.tabWidget.setUsesScrollButtons(True)
self.tabWidget.setDocumentMode(True)
self.tabWidget.setTabsClosable(False)
self.tabWidget.setMovable(False)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.hometab = QtGui.QWidget()
self.hometab.setObjectName(_fromUtf8("hometab"))
self.label = QtGui.QLabel(self.hometab)
self.label.setGeometry(QtCore.QRect(60, 0, 371, 231))
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("vtc punch logo.jpg")))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.hometab)
self.label_2.setGeometry(QtCore.QRect(10, 240, 81, 31))
font = QtGui.QFont()
font.setPointSize(18)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.flipscreenbutton = QtGui.QPushButton(self.hometab)
self.flipscreenbutton.setGeometry(QtCore.QRect(150, 240, 191, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.flipscreenbutton.setFont(font)
self.flipscreenbutton.setObjectName(_fromUtf8("flipscreenbutton"))
self.tabWidget.addTab(self.hometab, _fromUtf8(""))
self.powertab = QtGui.QWidget()
self.powertab.setObjectName(_fromUtf8("powertab"))
self.groupBox_5 = QtGui.QGroupBox(self.powertab)
self.groupBox_5.setGeometry(QtCore.QRect(10, 10, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_5.setFont(font)
self.groupBox_5.setObjectName(_fromUtf8("groupBox_5"))
self.restartbutton = QtGui.QPushButton(self.groupBox_5)
self.restartbutton.setGeometry(QtCore.QRect(130, 20, 181, 111))
font = QtGui.QFont()
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.restartbutton.setFont(font)
self.restartbutton.setObjectName(_fromUtf8("restartbutton"))
self.shutdownbutton = QtGui.QPushButton(self.groupBox_5)
self.shutdownbutton.setGeometry(QtCore.QRect(130, 140, 181, 111))
font = QtGui.QFont()
font.setPointSize(18)
self.shutdownbutton.setFont(font)
self.shutdownbutton.setObjectName(_fromUtf8("shutdownbutton"))
self.tabWidget.addTab(self.powertab, _fromUtf8(""))
self.lanipconfigtab = QtGui.QWidget()
self.lanipconfigtab.setObjectName(_fromUtf8("lanipconfigtab"))
self.groupBox = QtGui.QGroupBox(self.lanipconfigtab)
self.groupBox.setGeometry(QtCore.QRect(10, 10, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox.setFont(font)
self.groupBox.setObjectName(_fromUtf8("groupBox"))
self.dhcpbutton = QtGui.QPushButton(self.groupBox)
self.dhcpbutton.setGeometry(QtCore.QRect(10, 80, 201, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.dhcpbutton.setFont(font)
self.dhcpbutton.setObjectName(_fromUtf8("dhcpbutton"))
self.staticbutton = QtGui.QPushButton(self.groupBox)
self.staticbutton.setGeometry(QtCore.QRect(250, 80, 201, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.staticbutton.setFont(font)
self.staticbutton.setObjectName(_fromUtf8("staticbutton"))
self.tabWidget.addTab(self.lanipconfigtab, _fromUtf8(""))
self.wificonfigtab = QtGui.QWidget()
self.wificonfigtab.setObjectName(_fromUtf8("wificonfigtab"))
self.scrollArea = QtGui.QScrollArea(self.wificonfigtab)
self.scrollArea.setGeometry(QtCore.QRect(0, 0, 481, 281))
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 477, 277))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.groupBox_9 = QtGui.QGroupBox(self.scrollAreaWidgetContents)
self.groupBox_9.setGeometry(QtCore.QRect(0, 10, 471, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_9.setFont(font)
self.groupBox_9.setObjectName(_fromUtf8("groupBox_9"))
self.layoutWidget = QtGui.QWidget(self.groupBox_9)
self.layoutWidget.setGeometry(QtCore.QRect(10, 20, 451, 241))
self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.scanforaccesspointsbutton = QtGui.QPushButton(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(16)
self.scanforaccesspointsbutton.setFont(font)
self.scanforaccesspointsbutton.setObjectName(_fromUtf8("scanforaccesspointsbutton"))
self.verticalLayout.addWidget(self.scanforaccesspointsbutton)
self.connectwifibutton = QtGui.QPushButton(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(16)
self.connectwifibutton.setFont(font)
self.connectwifibutton.setObjectName(_fromUtf8("connectwifibutton"))
self.verticalLayout.addWidget(self.connectwifibutton)
self.disconnectwifibutton = QtGui.QPushButton(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(16)
self.disconnectwifibutton.setFont(font)
self.disconnectwifibutton.setObjectName(_fromUtf8("disconnectwifibutton"))
self.verticalLayout.addWidget(self.disconnectwifibutton)
self.erasestoredwifinetworksbutton = QtGui.QPushButton(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(16)
self.erasestoredwifinetworksbutton.setFont(font)
self.erasestoredwifinetworksbutton.setObjectName(_fromUtf8("erasestoredwifinetworksbutton"))
self.verticalLayout.addWidget(self.erasestoredwifinetworksbutton)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.tabWidget.addTab(self.wificonfigtab, _fromUtf8(""))
self.captivportallogintab = QtGui.QWidget()
self.captivportallogintab.setObjectName(_fromUtf8("captivportallogintab"))
self.webView = QtWebKit.QWebView(self.captivportallogintab)
self.webView.setGeometry(QtCore.QRect(0, 0, 481, 271))
self.webView.setUrl(QtCore.QUrl(_fromUtf8("http://www.briancourt.co.uk/")))
self.webView.setZoomFactor(0.40000000596)
self.webView.setRenderHints(QtGui.QPainter.SmoothPixmapTransform|QtGui.QPainter.TextAntialiasing)
self.webView.setObjectName(_fromUtf8("webView"))
self.tabWidget.addTab(self.captivportallogintab, _fromUtf8(""))
self.wifiapconfigtab = QtGui.QWidget()
self.wifiapconfigtab.setObjectName(_fromUtf8("wifiapconfigtab"))
self.groupBox_4 = QtGui.QGroupBox(self.wifiapconfigtab)
self.groupBox_4.setGeometry(QtCore.QRect(10, 10, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_4.setFont(font)
self.groupBox_4.setObjectName(_fromUtf8("groupBox_4"))
self.tabWidget.addTab(self.wifiapconfigtab, _fromUtf8(""))
self.vpnconfigtab = QtGui.QWidget()
self.vpnconfigtab.setObjectName(_fromUtf8("vpnconfigtab"))
self.groupBox_6 = QtGui.QGroupBox(self.vpnconfigtab)
self.groupBox_6.setGeometry(QtCore.QRect(10, 10, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_6.setFont(font)
self.groupBox_6.setObjectName(_fromUtf8("groupBox_6"))
self.disconnectvpnbutton = QtGui.QPushButton(self.groupBox_6)
self.disconnectvpnbutton.setGeometry(QtCore.QRect(10, 150, 211, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.disconnectvpnbutton.setFont(font)
self.disconnectvpnbutton.setObjectName(_fromUtf8("disconnectvpnbutton"))
self.connectvpnbutton = QtGui.QPushButton(self.groupBox_6)
self.connectvpnbutton.setGeometry(QtCore.QRect(240, 150, 211, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.connectvpnbutton.setFont(font)
self.connectvpnbutton.setObjectName(_fromUtf8("connectvpnbutton"))
self.switchtotcpbutton = QtGui.QPushButton(self.groupBox_6)
self.switchtotcpbutton.setGeometry(QtCore.QRect(240, 40, 211, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.switchtotcpbutton.setFont(font)
self.switchtotcpbutton.setObjectName(_fromUtf8("switchtotcpbutton"))
self.switchtoudpbutton = QtGui.QPushButton(self.groupBox_6)
self.switchtoudpbutton.setGeometry(QtCore.QRect(10, 40, 211, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.switchtoudpbutton.setFont(font)
self.switchtoudpbutton.setObjectName(_fromUtf8("switchtoudpbutton"))
self.tabWidget.addTab(self.vpnconfigtab, _fromUtf8(""))
self.statusdisplaytab = QtGui.QWidget()
self.statusdisplaytab.setObjectName(_fromUtf8("statusdisplaytab"))
self.lanipbox = QtGui.QGroupBox(self.statusdisplaytab)
self.lanipbox.setGeometry(QtCore.QRect(10, 0, 461, 71))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.lanipbox.setFont(font)
self.lanipbox.setObjectName(_fromUtf8("lanipbox"))
self.lanipshow = QtGui.QLabel(self.lanipbox)
self.lanipshow.setGeometry(QtCore.QRect(10, 20, 451, 41))
font = QtGui.QFont()
font.setPointSize(16)
self.lanipshow.setFont(font)
self.lanipshow.setAlignment(QtCore.Qt.AlignCenter)
self.lanipshow.setObjectName(_fromUtf8("lanipshow"))
self.groupBox_2 = QtGui.QGroupBox(self.statusdisplaytab)
self.groupBox_2.setGeometry(QtCore.QRect(10, 80, 461, 91))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_2.setFont(font)
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
self.wifiipshow = QtGui.QLabel(self.groupBox_2)
self.wifiipshow.setGeometry(QtCore.QRect(10, 30, 451, 41))
font = QtGui.QFont()
font.setPointSize(16)
self.wifiipshow.setFont(font)
self.wifiipshow.setAlignment(QtCore.Qt.AlignCenter)
self.wifiipshow.setObjectName(_fromUtf8("wifiipshow"))
self.groupBox_3 = QtGui.QGroupBox(self.statusdisplaytab)
self.groupBox_3.setGeometry(QtCore.QRect(10, 180, 461, 91))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_3.setFont(font)
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
self.vpnipshow = QtGui.QLabel(self.groupBox_3)
self.vpnipshow.setGeometry(QtCore.QRect(10, 30, 451, 41))
font = QtGui.QFont()
font.setPointSize(16)
self.vpnipshow.setFont(font)
self.vpnipshow.setAlignment(QtCore.Qt.AlignCenter)
self.vpnipshow.setObjectName(_fromUtf8("vpnipshow"))
self.tabWidget.addTab(self.statusdisplaytab, _fromUtf8(""))
self.softwareupdatetab = QtGui.QWidget()
self.softwareupdatetab.setObjectName(_fromUtf8("softwareupdatetab"))
self.label_7 = QtGui.QLabel(self.softwareupdatetab)
self.label_7.setGeometry(QtCore.QRect(50, 40, 311, 41))
font = QtGui.QFont()
font.setPointSize(20)
self.label_7.setFont(font)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.label_8 = QtGui.QLabel(self.softwareupdatetab)
self.label_8.setGeometry(QtCore.QRect(370, 40, 121, 41))
font = QtGui.QFont()
font.setPointSize(20)
self.label_8.setFont(font)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.groupBox_7 = QtGui.QGroupBox(self.softwareupdatetab)
self.groupBox_7.setGeometry(QtCore.QRect(10, 9, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_7.setFont(font)
self.groupBox_7.setObjectName(_fromUtf8("groupBox_7"))
self.checkforupdatebutton = QtGui.QPushButton(self.groupBox_7)
self.checkforupdatebutton.setGeometry(QtCore.QRect(110, 90, 231, 91))
font = QtGui.QFont()
font.setPointSize(16)
self.checkforupdatebutton.setFont(font)
self.checkforupdatebutton.setObjectName(_fromUtf8("checkforupdatebutton"))
self.tabWidget.addTab(self.softwareupdatetab, _fromUtf8(""))
self.devmenutab = QtGui.QWidget()
self.devmenutab.setObjectName(_fromUtf8("devmenutab"))
self.groupBox_8 = QtGui.QGroupBox(self.devmenutab)
self.groupBox_8.setGeometry(QtCore.QRect(9, 10, 461, 261))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.groupBox_8.setFont(font)
self.groupBox_8.setObjectName(_fromUtf8("groupBox_8"))
self.closemenubutton = QtGui.QPushButton(self.groupBox_8)
self.closemenubutton.setGeometry(QtCore.QRect(20, 40, 191, 61))
font = QtGui.QFont()
font.setPointSize(16)
self.closemenubutton.setFont(font)
self.closemenubutton.setObjectName(_fromUtf8("closemenubutton"))
self.iteratenewpunch = QtGui.QPushButton(self.groupBox_8)
self.iteratenewpunch.setGeometry(QtCore.QRect(20, 180, 421, 61))
font = QtGui.QFont()
font.setPointSize(16)
self.iteratenewpunch.setFont(font)
self.iteratenewpunch.setObjectName(_fromUtf8("iteratenewpunch"))
self.cloneexistingpunchbutton = QtGui.QPushButton(self.groupBox_8)
self.cloneexistingpunchbutton.setGeometry(QtCore.QRect(20, 110, 421, 61))
font = QtGui.QFont()
font.setPointSize(16)
self.cloneexistingpunchbutton.setFont(font)
self.cloneexistingpunchbutton.setObjectName(_fromUtf8("cloneexistingpunchbutton"))
self.restartmenubutton = QtGui.QPushButton(self.groupBox_8)
self.restartmenubutton.setGeometry(QtCore.QRect(250, 40, 191, 61))
font = QtGui.QFont()
font.setPointSize(16)
self.restartmenubutton.setFont(font)
self.restartmenubutton.setObjectName(_fromUtf8("restartmenubutton"))
self.tabWidget.addTab(self.devmenutab, _fromUtf8(""))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setSizeGripEnabled(False)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(9)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Punch Menu", None))
self.label_2.setText(_translate("MainWindow", "Beta 2", None))
self.flipscreenbutton.setText(_translate("MainWindow", "Flip Screen", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.hometab), _translate("MainWindow", "Home", None))
self.groupBox_5.setTitle(_translate("MainWindow", "Select Action", None))
self.restartbutton.setText(_translate("MainWindow", "Restart", None))
self.shutdownbutton.setText(_translate("MainWindow", "Shutdown", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.powertab), _translate("MainWindow", "Power", None))
self.groupBox.setTitle(_translate("MainWindow", "Select Connection Type", None))
self.dhcpbutton.setText(_translate("MainWindow", "DHCP (Auto)", None))
self.staticbutton.setText(_translate("MainWindow", "Static (Manual)", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.lanipconfigtab), _translate("MainWindow", "LAN IP Config", None))
self.groupBox_9.setTitle(_translate("MainWindow", "Select Action", None))
self.scanforaccesspointsbutton.setText(_translate("MainWindow", "Scan for Access Points", None))
self.connectwifibutton.setText(_translate("MainWindow", "Connect Wifi", None))
self.disconnectwifibutton.setText(_translate("MainWindow", "Disconnect Wifi", None))
self.erasestoredwifinetworksbutton.setText(_translate("MainWindow", "Erase Stored Wifi Networks", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.wificonfigtab), _translate("MainWindow", "Wifi IP Config", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.captivportallogintab), _translate("MainWindow", "Captive Portal Login", None))
self.groupBox_4.setTitle(_translate("MainWindow", "Feature Not Yet Implemented", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.wifiapconfigtab), _translate("MainWindow", "Wifi A/P Config", None))
self.groupBox_6.setTitle(_translate("MainWindow", "Select Action", None))
self.disconnectvpnbutton.setText(_translate("MainWindow", "Disconnect VPN", None))
self.connectvpnbutton.setText(_translate("MainWindow", "Connect VPN", None))
self.switchtotcpbutton.setText(_translate("MainWindow", "Switch to TCP", None))
self.switchtoudpbutton.setText(_translate("MainWindow", "Switch to UDP", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.vpnconfigtab), _translate("MainWindow", "VPN Config", None))
self.lanipbox.setTitle(_translate("MainWindow", "LAN IP", None))
self.lanipshow.setText(_translate("MainWindow", "IP GOES HERE", None))
self.groupBox_2.setTitle(_translate("MainWindow", "WIFI IP", None))
self.wifiipshow.setText(_translate("MainWindow", "IP GOES HERE", None))
self.groupBox_3.setTitle(_translate("MainWindow", "VPN IP", None))
self.vpnipshow.setText(_translate("MainWindow", "IP GOES HERE", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.statusdisplaytab), _translate("MainWindow", "Status Display", None))
self.label_7.setText(_translate("MainWindow", "Current Software Version:", None))
self.label_8.setText(_translate("MainWindow", "016", None))
self.groupBox_7.setTitle(_translate("MainWindow", "Software Version", None))
self.checkforupdatebutton.setText(_translate("MainWindow", "Check For Update", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.softwareupdatetab), _translate("MainWindow", "Software Update", None))
self.groupBox_8.setTitle(_translate("MainWindow", "Select Action", None))
self.closemenubutton.setText(_translate("MainWindow", "Close Menu", None))
self.iteratenewpunch.setText(_translate("MainWindow", "Iterate and Deploy New Punch!", None))
self.cloneexistingpunchbutton.setText(_translate("MainWindow", "Clone Existing Punch!", None))
self.restartmenubutton.setText(_translate("MainWindow", "Restart Menu", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.devmenutab), _translate("MainWindow", "Dev Menu", None))
from PyQt4 import QtWebKit
Does this help nail-down what isn't doing what it should be?
Your closemenu function needs to be part of your class.
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.closemenubutton.clicked.connect(self.closemenu)
# Notice this has been brought into the class
def closemenu(self):
sys.exit()
You didn't provide your UI file, so I can't perform an exact test, but I can show you that this works with a simple example:
This code creates a single button:
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.closebutton = QtGui.QPushButton('Exit', self)
self.closebutton.clicked.connect(self.exit_button)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.closebutton)
def exit_button(self):
sys.exit()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
It looks like this:
When the button is clicked, the application closes with an exit status of 0 (a clean exit)
C:\Sandbox>python exit_button.py
C:\Sandbox>echo %ERRORLEVEL%
0
Whatever the underlying problem was, I was able to remedy it by switching to using Eric IDE in conjunction with Qt designer and following this tutorial: http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html to learn about the benefits of a development "environment" over what amounts to basically notepad that I was using before!
Defining actions is so much easier when you can see the handles you're attaching them too!
Other noobs reading this - follow that guide, it got me off the ground with object orientated programming and GUIs.

Assigning value to the variable in Qt

Here is the converted .ui of Qt to the .py:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_NewWindow(object):
def setupUi(self, NewWindow):
NewWindow.setObjectName(_fromUtf8("NewWindow"))
NewWindow.resize(439, 225)
self.centralwidget = QtGui.QWidget(NewWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(170, 140, 99, 27))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(40, 30, 365, 89))
self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.label_3 = QtGui.QLabel(self.widget)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout_2.addWidget(self.label_3)
self.lineEdit = QtGui.QLineEdit(self.widget)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.horizontalLayout_2.addWidget(self.lineEdit)
self.label_4 = QtGui.QLabel(self.widget)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalLayout_2.addWidget(self.label_4)
self.lineEdit_2 = QtGui.QLineEdit(self.widget)
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.pushButton = QtGui.QPushButton(self.widget)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout.addWidget(self.pushButton)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label = QtGui.QLabel(self.widget)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.label_2 = QtGui.QLabel(self.widget)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.horizontalLayout.addWidget(self.label_2)
self.verticalLayout.addLayout(self.horizontalLayout)
NewWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(NewWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 439, 25))
self.menubar.setObjectName(_fromUtf8("menubar"))
NewWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(NewWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
NewWindow.setStatusBar(self.statusbar)
self.retranslateUi(NewWindow)
QtCore.QMetaObject.connectSlotsByName(NewWindow)
def retranslateUi(self, NewWindow):
NewWindow.setWindowTitle(QtGui.QApplication.translate("NewWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("NewWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("NewWindow", "A = ", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("NewWindow", "B = ", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_2.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("NewWindow", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("NewWindow", "Answer : ", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
NewWindow = QtGui.QMainWindow()
ui = Ui_NewWindow()
ui.setupUi(NewWindow)
NewWindow.show()
sys.exit(app.exec_())
After running the above python program it shows the window as:
But I have to assign the value from the line edit to the variable A and B so I can add them as:
sum = A + B
and I have show this value sum in the label Answer when we clicked on push button "Add" in above window, so please suggest proper change in above code.
You need to create a news action (ad_values in this case). Then, you need to connect this action to the Buttons signal (clicked for example). After the signal emits (i.e. the button is clicked), the actions reads the values from lineEdit and lineEdit_2, adds them up and set's the text of the label_2-widget (you might convert the values to int before [see the other answer for a simple implementation])
from PySide import QtCore, QtGui
from PySide.QtCore import Slot
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_NewWindow(object):
def setupUi(self, NewWindow):
NewWindow.setObjectName(_fromUtf8("NewWindow"))
NewWindow.resize(439, 225)
self.centralwidget = QtGui.QWidget(NewWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(170, 140, 99, 27))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(40, 30, 365, 89))
self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
#self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.label_3 = QtGui.QLabel(self.widget)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout_2.addWidget(self.label_3)
self.lineEdit = QtGui.QLineEdit(self.widget)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.horizontalLayout_2.addWidget(self.lineEdit)
self.label_4 = QtGui.QLabel(self.widget)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalLayout_2.addWidget(self.label_4)
self.lineEdit_2 = QtGui.QLineEdit(self.widget)
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.pushButton = QtGui.QPushButton(self.widget)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout.addWidget(self.pushButton)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label = QtGui.QLabel(self.widget)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.label_2 = QtGui.QLabel(self.widget)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.horizontalLayout.addWidget(self.label_2)
self.verticalLayout.addLayout(self.horizontalLayout)
NewWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(NewWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 439, 25))
self.menubar.setObjectName(_fromUtf8("menubar"))
NewWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(NewWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
NewWindow.setStatusBar(self.statusbar)
self.retranslateUi(NewWindow)
QtCore.QMetaObject.connectSlotsByName(NewWindow)
self.pushButton.clicked.connect(self.add_values)
def retranslateUi(self, NewWindow):
NewWindow.setWindowTitle(QtGui.QApplication.translate("NewWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("NewWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("NewWindow", "A = ", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("NewWindow", "B = ", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_2.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("NewWindow", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("NewWindow", "Answer : ", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("NewWindow", "0.0", None, QtGui.QApplication.UnicodeUTF8))
#Slot()
def add_values(self):
# you should convert the values to integers for a less error-prone code
summed = float(self.lineEdit.text()) + float(self.lineEdit_2.text())
self.label_2.setText(str(summed))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
NewWindow = QtGui.QMainWindow()
ui = Ui_NewWindow()
ui.setupUi(NewWindow)
NewWindow.show()
sys.exit(app.exec_())
I´m using PySide, but it should work with PyQT as well.
You can do it like:
def sum(self):
summed = float(self.lineEdit.text()) + float(self.lineEdit_2.text())
self.label_2.setText(str(summed))

Categories

Resources