Issue with scrollarea in pyqt? - python

This is the file I generated using qt-designer.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(1024, 600)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
Dialog.setSizePolicy(sizePolicy)
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.graphicsView = QtGui.QGraphicsView(Dialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth())
self.graphicsView.setSizePolicy(sizePolicy)
self.graphicsView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.graphicsView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
self.verticalLayout.addWidget(self.graphicsView)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 4)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout_2.addWidget(self.pushButton)
self.gridLayout.addLayout(self.verticalLayout_2, 1, 0, 1, 1)
self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
self.pushButton_2 = QtGui.QPushButton(Dialog)
self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "Delete", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.verticalLayout_4.addWidget(self.pushButton_2)
self.gridLayout.addLayout(self.verticalLayout_4, 1, 1, 1, 1)
self.verticalLayout_5 = QtGui.QVBoxLayout()
self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
self.pushButton_3 = QtGui.QPushButton(Dialog)
self.pushButton_3.setText(QtGui.QApplication.translate("Dialog", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout_5.addWidget(self.pushButton_3)
self.gridLayout.addLayout(self.verticalLayout_5, 1, 2, 1, 1)
self.verticalLayout_3 = QtGui.QVBoxLayout()
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.label = QtGui.QLabel(Dialog)
self.label.setText(QtGui.QApplication.translate("Dialog", "Connected", None, QtGui.QApplication.UnicodeUTF8))
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout_3.addWidget(self.label)
self.gridLayout.addLayout(self.verticalLayout_3, 1, 3, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.tableWidget = QtGui.QTableWidget(Dialog)
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.setColumnCount(0)
self.tableWidget.setRowCount(0)
self.horizontalLayout.addWidget(self.tableWidget)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 3)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.tabWidget = QtGui.QTabWidget(Dialog)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.tab = QtGui.QWidget()
self.tab.setObjectName(_fromUtf8("tab"))
self.verticalLayout_6 = QtGui.QVBoxLayout(self.tab)
self.verticalLayout_6.setObjectName(_fromUtf8("verticalLayout_6"))
self.scrollArea = QtGui.QScrollArea(self.tab)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 701, 292))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.verticalLayout_7 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
self.dockWidget = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget.setObjectName(_fromUtf8("dockWidget"))
self.dockWidgetContents = QtGui.QWidget()
self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
self.verticalLayout_8 = QtGui.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout_8.setObjectName(_fromUtf8("verticalLayout_8"))
self.plainTextEdit = QtGui.QPlainTextEdit(self.dockWidgetContents)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit.sizePolicy().hasHeightForWidth())
self.plainTextEdit.setSizePolicy(sizePolicy)
self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
self.verticalLayout_8.addWidget(self.plainTextEdit)
self.dockWidget.setWidget(self.dockWidgetContents)
self.verticalLayout_7.addWidget(self.dockWidget)
self.dockWidget_2 = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget_2.setObjectName(_fromUtf8("dockWidget_2"))
self.dockWidgetContents_2 = QtGui.QWidget()
self.dockWidgetContents_2.setObjectName(_fromUtf8("dockWidgetContents_2"))
self.verticalLayout_9 = QtGui.QVBoxLayout(self.dockWidgetContents_2)
self.verticalLayout_9.setObjectName(_fromUtf8("verticalLayout_9"))
self.plainTextEdit_2 = QtGui.QPlainTextEdit(self.dockWidgetContents_2)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit_2.sizePolicy().hasHeightForWidth())
self.plainTextEdit_2.setSizePolicy(sizePolicy)
self.plainTextEdit_2.setObjectName(_fromUtf8("plainTextEdit_2"))
self.verticalLayout_9.addWidget(self.plainTextEdit_2)
self.dockWidget_2.setWidget(self.dockWidgetContents_2)
self.verticalLayout_7.addWidget(self.dockWidget_2)
self.dockWidget_3 = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget_3.setObjectName(_fromUtf8("dockWidget_3"))
self.dockWidgetContents_3 = QtGui.QWidget()
self.dockWidgetContents_3.setObjectName(_fromUtf8("dockWidgetContents_3"))
self.verticalLayout_10 = QtGui.QVBoxLayout(self.dockWidgetContents_3)
self.verticalLayout_10.setObjectName(_fromUtf8("verticalLayout_10"))
self.plainTextEdit_3 = QtGui.QPlainTextEdit(self.dockWidgetContents_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit_3.sizePolicy().hasHeightForWidth())
self.plainTextEdit_3.setSizePolicy(sizePolicy)
self.plainTextEdit_3.setObjectName(_fromUtf8("plainTextEdit_3"))
self.verticalLayout_10.addWidget(self.plainTextEdit_3)
self.dockWidget_3.setWidget(self.dockWidgetContents_3)
self.verticalLayout_7.addWidget(self.dockWidget_3)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_6.addWidget(self.scrollArea)
self.tabWidget.addTab(self.tab, _fromUtf8(""))
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName(_fromUtf8("tab_2"))
self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
self.horizontalLayout_2.addWidget(self.tabWidget)
self.gridLayout.addLayout(self.horizontalLayout_2, 2, 3, 1, 1)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("Dialog", "Tab 1", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("Dialog", "Tab 2", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
The output is in the screenshot: The problem is that the Tab1 is not showing any scrollbar even I set the layout under scrollArea. The region where I am expecting a scrollbar is shown by a red rectangle.

I remember this similar question :-) How to associate a horizontal scrollbar to multiple groupbox.?
The reason you are still not getting proper scrollbars is because your widgets inside the scrollarea don't have a minimum height and are being allowed to shrink far enough down that they would never force the scrollarea to display its scrollbars.
In code, you can fix this by:
self.dockWidgetContents.setMinimumHeight(100)
Althought, you shouldn't be making any direct edits to this file being generated from Qt Designer. What you should do is go into QtDesigner, select the widgets, and at the top of their property list, set a minimum height for them.

Related

pyqt5 button click event works in debug but not when runing

i have a main code that runs a main UI window, from the main UI window im passing to other window, i tried to implement a back button but for some reason it works only when im in debug mode.
main UI window:
from PyQt5 import QtCore, QtGui, QtWidgets
import UI.plantManagment as plantManagment
class Ui_MainWindow(object):
def __init__(self,MainWindow,loadedgreenhouses) -> None:
self.MainWindow=MainWindow
self.loadedgreenhouses=loadedgreenhouses
def setupUi(self):
self.MainWindow.setObjectName("MainWindow")
self.MainWindow.resize(480, 480)
self.MainWindow.setMinimumSize(QtCore.QSize(480, 480))
self.MainWindow.setMaximumSize(QtCore.QSize(480, 480))
self.MainWindow.setTabletTracking(False)
self.MainWindow.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
self.MainWindow.setAnimated(True)
self.MainWindow.setDocumentMode(False)
self.MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(self.MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(70, 70, 321, 361))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.btn_managePlants = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_managePlants.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_managePlants.setFont(font)
self.btn_managePlants.setObjectName("btn_managePlants")
self.verticalLayout.addWidget(self.btn_managePlants)
self.btn_managePlants.clicked.connect(self.loadPalntsUI)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem1)
self.btn_manageGreenHouses = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_manageGreenHouses.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_manageGreenHouses.setFont(font)
self.btn_manageGreenHouses.setObjectName("btn_manageGreenHouses")
self.verticalLayout.addWidget(self.btn_manageGreenHouses)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
self.btn_harvestAll = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.btn_harvestAll.setMinimumSize(QtCore.QSize(0, 80))
font = QtGui.QFont()
font.setPointSize(24)
self.btn_harvestAll.setFont(font)
self.btn_harvestAll.setCheckable(False)
self.btn_harvestAll.setChecked(False)
self.btn_harvestAll.setObjectName("btn_harvestAll")
self.verticalLayout.addWidget(self.btn_harvestAll)
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem3)
self.lable_harvestableNum = QtWidgets.QLabel(self.centralwidget)
self.lable_harvestableNum.setGeometry(QtCore.QRect(70, 20, 321, 41))
font = QtGui.QFont()
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(False)
self.lable_harvestableNum.setFont(font)
self.lable_harvestableNum.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lable_harvestableNum.setScaledContents(False)
self.lable_harvestableNum.setAlignment(QtCore.Qt.AlignCenter)
self.lable_harvestableNum.setWordWrap(False)
self.lable_harvestableNum.setIndent(2)
self.lable_harvestableNum.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
self.lable_harvestableNum.setObjectName("lable_harvestableNum")
self.MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(self.MainWindow)
self.statusbar.setObjectName("statusbar")
self.MainWindow.setStatusBar(self.statusbar)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.btn_managePlants.setText(_translate("MainWindow", "manage plants"))
self.btn_manageGreenHouses.setText(_translate("MainWindow", "manage greenhouses"))
self.btn_harvestAll.setText(_translate("MainWindow", "harvest all"))
self.lable_harvestableNum.setText(_translate("MainWindow", f"plant ready for harvest: {self.calcRadyToHarvest()}"))
def calcRadyToHarvest(self):
cnt=0
for gh in self.loadedgreenhouses:
for pp in gh.palntingPoints:
if pp.harvestPlant():
cnt+=1
return cnt
def loadPalntsUI(self):
ui = plantManagment.Ui_MainWindow(self.MainWindow,self.loadedgreenhouses)
ui.setupUi()
ui.MainWindow.show()
here the event is working as intended when i click on self.btn_managePlants.clicked.connect(self.loadPalntsUI) and it loads me the next window witouth a problem.
the second window (where the button doesn't work):
from time import sleep
from PyQt5 import QtCore, QtGui, QtWidgets
import Plant
import UI.mainWindow as mainWindow
class Ui_MainWindow(object):
def __init__(self,MainWindow,loadedgreenhouses) -> None:
self.MainWindow=MainWindow
self.loadedgreenhouses=loadedgreenhouses
def setupUi(self):
self.MainWindow.setObjectName("MainWindow")
self.MainWindow.setWindowModality(QtCore.Qt.NonModal)
self.MainWindow.setEnabled(True)
self.MainWindow.resize(627, 409)
self.MainWindow.setMinimumSize(QtCore.QSize(627, 409))
self.MainWindow.setMaximumSize(QtCore.QSize(627, 409))
self.MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(self.MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 20, 591, 361))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label_plants = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(18)
self.label_plants.setFont(font)
self.label_plants.setObjectName("label_plants")
self.verticalLayout.addWidget(self.label_plants)
self.tableWidget = QtWidgets.QTableWidget(self.verticalLayoutWidget)
self.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(4)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setVisible(False)
self.tableWidget.verticalHeader().setHighlightSections(False)
self.verticalLayout.addWidget(self.tableWidget)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) #forbid editing
self.tableWidget.setRowCount(len(Plant.Plant.kindsList)) #len of number of plants
for i,p in enumerate(Plant.Plant.plantsLst): #add to the table
self.tableWidget.setItem(i, 0, QtWidgets.QTableWidgetItem(p.kind))
self.tableWidget.setItem(i, 1, QtWidgets.QTableWidgetItem(str(p.grow_time)))
self.tableWidget.setItem(i, 2, QtWidgets.QTableWidgetItem(str(p.temp_min)))
self.tableWidget.setItem(i, 3, QtWidgets.QTableWidgetItem(str(p.temp_max)))
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.btn_back = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_back.setFont(font)
self.btn_back.setObjectName("btn_back")
self.horizontalLayout.addWidget(self.btn_back)
self.btn_back.clicked.connect(self.backBtn)
self.btn_delete = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_delete.setFont(font)
self.btn_delete.setObjectName("btn_delete")
self.horizontalLayout.addWidget(self.btn_delete)
self.btn_addPlant = QtWidgets.QPushButton(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(20)
self.btn_addPlant.setFont(font)
self.btn_addPlant.setObjectName("btn_addPlant")
self.horizontalLayout.addWidget(self.btn_addPlant)
self.verticalLayout.addLayout(self.horizontalLayout)
self.MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(self.MainWindow)
self.statusbar.setObjectName("statusbar")
self.MainWindow.setStatusBar(self.statusbar)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.MainWindow.setWindowTitle(_translate("MainWindow", "plant managment"))
self.label_plants.setText(_translate("MainWindow", "plants:"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "kind"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "grow time"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "min temperature"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "max temperature"))
self.btn_back.setText(_translate("MainWindow", "back"))
self.btn_delete.setText(_translate("MainWindow", "delete"))
self.btn_addPlant.setText(_translate("MainWindow", "add plant"))
self.tableWidget.show()
def backBtn(self):
print("the lalala")
ui = mainWindow.Ui_MainWindow(self.MainWindow,self.loadedgreenhouses)
ui.setupUi()
self.MainWindow.show()
the event should be triggered by self.btn_back.clicked.connect(self.backBtn) but as i said it would work only in debug mode.
i tried to self.btn_back.clicked.connect(lambda : self.backBtn()) which did took me back to the main UI window but then none of the buttons in that window worked :|

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)

Open new window in main window pyqt5

I want to design second window opens when button clicked like in image but there are problem I can't understand it
class SubWindow(QWidget):
def __init__(self):
super(SubWindow, self).__init__()
self.resize(673, 349)
sizePolicy = QSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
self.setSizePolicy(sizePolicy)
self.setWindowTitle("")
self.centralwidget = QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.scrollArea = QScrollArea(self.centralwidget)
self.scrollArea.setFrameShape(QFrame.NoFrame)
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 638, 331))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_2 = QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.frame = QFrame(self.scrollAreaWidgetContents)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setMinimumSize(QtCore.QSize(0, 100))
self.frame.setStyleSheet("background-color: rgb(71, 71, 71);")
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.frame.setObjectName("frame")
self.horizontalLayout = QHBoxLayout(self.frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QLabel(self.frame)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setMinimumSize(QtCore.QSize(100, 0))
self.label.setMaximumSize(QtCore.QSize(0, 100))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(r"D:\project(AHR)\WhatsApp Image 2022-03-02 at 8.22.06 PM.jpeg"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.scrollArea_2 = QScrollArea(self.frame)
self.scrollArea_2.setFrameShape(QFrame.NoFrame)
self.scrollArea_2.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 494, 63))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
self.horizontalLayout.addWidget(self.scrollArea_2)
self.verticalLayout_2.addWidget(self.frame)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)
self.setCentralWidget(self)

Calling function with clicking actions on Qtoolbar created by QT designer

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_())

How to add a custom widget to another using python

I created this widget using Qt creator and generated this code
from PySide import QtCore, QtGui
class Ui_DATA_Entries_Widget(QtGui.QWidget):
def setupUi(self, DATA_Entries_Widget):
DATA_Entries_Widget.setObjectName("DATA_Entries_Widget")
DATA_Entries_Widget.resize(676, 50)
DATA_Entries_Widget.setMinimumSize(QtCore.QSize(676, 50))
DATA_Entries_Widget.setMaximumSize(QtCore.QSize(676, 50))
self.horizontalLayout = QtGui.QHBoxLayout(DATA_Entries_Widget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtGui.QLabel(DATA_Entries_Widget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtGui.QLineEdit(DATA_Entries_Widget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.label_2 = QtGui.QLabel(DATA_Entries_Widget)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.lineEdit_2 = QtGui.QLineEdit(DATA_Entries_Widget)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout.addWidget(self.lineEdit_2)
self.label_3 = QtGui.QLabel(DATA_Entries_Widget)
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.label_3)
self.lineEdit_3 = QtGui.QLineEdit(DATA_Entries_Widget)
self.lineEdit_3.setObjectName("lineEdit_3")
self.horizontalLayout.addWidget(self.lineEdit_3)
self.label_5 = QtGui.QLabel(DATA_Entries_Widget)
self.label_5.setMinimumSize(QtCore.QSize(47, 32))
self.label_5.setObjectName("label_5")
self.horizontalLayout.addWidget(self.label_5)
self.lineEdit_4 = QtGui.QLineEdit(DATA_Entries_Widget)
self.lineEdit_4.setObjectName("lineEdit_4")
self.horizontalLayout.addWidget(self.lineEdit_4)
self.label_4 = QtGui.QLabel(DATA_Entries_Widget)
self.label_4.setObjectName("label_4")
self.horizontalLayout.addWidget(self.label_4)
self.lineEdit_5 = QtGui.QLineEdit(DATA_Entries_Widget)
self.lineEdit_5.setObjectName("lineEdit_5")
self.horizontalLayout.addWidget(self.lineEdit_5)
self.pushButton = QtGui.QPushButton(DATA_Entries_Widget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.retranslateUi(DATA_Entries_Widget)
QtCore.QMetaObject.connectSlotsByName(DATA_Entries_Widget)
def retranslateUi(self, DATA_Entries_Widget):
DATA_Entries_Widget.setWindowTitle(QtGui.QApplication.translate("DATA_Entries_Widget", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "A", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "B", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "C", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "D", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "E", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("DATA_Entries_Widget", "Delete", None, QtGui.QApplication.UnicodeUTF8))
Now I need to add this widget dinamically, much like the the Test widget, that I got from another question:
from PySide import QtGui, QtCore
import sys
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
# main button
self.addButton = QtGui.QPushButton('button to add other widgets')
self.addButton.clicked.connect(self.addWidget)
# scroll area widget contents - layout
self.scrollLayout = QtGui.QFormLayout()
# scroll area widget contents
self.scrollWidget = QtGui.QWidget()
self.scrollWidget.setLayout(self.scrollLayout)
# scroll area
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.scrollWidget)
# main layout
self.mainLayout = QtGui.QVBoxLayout()
# add all main to the main vLayout
self.mainLayout.addWidget(self.addButton)
self.mainLayout.addWidget(self.scrollArea)
# central widget
self.centralWidget = QtGui.QWidget()
self.centralWidget.setLayout(self.mainLayout)
# set central widget
self.setCentralWidget(self.centralWidget)
def addWidget(self):
self.scrollLayout.addRow(TestButton())
class TestButton(QtGui.QPushButton):
def __init__( self, parent=None):
super(TestButton, self).__init__(parent)
self.setText("I am in Test widget")
self.clicked.connect(self.deleteLater)
app = QtGui.QApplication(sys.argv)
myWidget = Main()
myWidget.show()
app.exec_()
How can I subtitute the TestButton in the second code with my custom widget easily?
Any help is much appreciated!

Categories

Resources