PDA

View Full Version : Function who return a layout



mcanonic
30th May 2019, 10:37
HI,
my gui has one horizontalbox layout, who has a left panel and a right panel.

I have wrote a function to populate the left panel with the widgets that I need. They are inside a verticalbox:

def rightPanel(self):
verticalboxRP=QVBoxLayout()
welcomeText = QLabel("Android Forensic Automator (AnForA)\n a software tool that automates the forensic analysis of Android applications", self)
verticalboxRP.addWidget(welcomeText)
self.setLayout(verticalboxRP)
self.show()

I have a similar function for the left panel.

Now the problem is: since I like to keep the creation of the left and right panel in separate functions, how can I use these functions in order to add them in the main gui who has a horizontal box layout.

My attempt to create the main window was something like this:

def UI(self):
horizontalbox=QHBoxLayout()
rightPanel(horizontalbox)
leftPanel(horizontalbox)

#horizontalbox.addLayout(lp)
#horizontalbox.addLayout(rp)

self.setLayout(horizontalbox)
self.show()

but, of course, I get error since I'm not very confident with pyqt and with python too (sorry).

Could you help me to figure out how can I manage a horizontal box who contains two vertical box layouts?
Below my signature, my current code.

Thanks.

Massimo


import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap

class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("some text")
#self.setGeometry(50,50,500,500) #if I want set the size
self.UI()

def UI(self):
horizontalbox=QHBoxLayout()
rightPanel(horizontalbox)
leftPanel(horizontalbox)

#horizontalbox.addLayout(lp)
#horizontalbox.addLayout(rp)

self.setLayout(horizontalbox)
self.show()


def rightPanel(horizontalbox):
verticalboxRP=QVBoxLayout()
welcomeText = QLabel("some text", self)
verticalboxRP.addWidget(welcomeText)
self.setLayout(verticalboxRP)

#self.show()

def leftPanel(self):
verticalboxLP=QVBoxLayout()

image = QLabel(self)
image.setPixmap(QPixmap('logoUPO.png'))
text = QLabel("AnForA\n Android Forensic Automator", self)
installAPKBtn = QPushButton("Install APK on the device", self)
detectPathBtn = QPushButton("Detect analysis paths", self)
startExpBtn = QPushButton("Start experiment", self)
analyzeResBtn = QPushButton("Analyze results", self)
quitBtn = QPushButton("quit", self)

verticalbox.addWidget(image)
verticalbox.addWidget(text)
verticalbox.addWidget(installAPKBtn)
verticalbox.addWidget(detectPathBtn)
verticalbox.addWidget(startExpBtn)
verticalbox.addWidget(analyzeResBtn)
verticalbox.addWidget(quitBtn)

self.setLayout(verticalboxLP)

self.show()

def installAPK(self):
pass

def detectPath(self):
pass

def main():
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())

if __name__=='__main__':
main()

mcanonic
30th May 2019, 14:40
I think I have solved it by using what you see at the end of this post (maybe someone will have the same problem).
Sorry
M


def UI(self):
mainScreen=QHBoxLayout()

leftPanel = QVBoxLayout()
rightPanel = QVBoxLayout()

self.loadLeftPanel(leftPanel)
self.loadRightPanel(rightPanel)

#horizontalbox.addLayout(lp)
#horizontalbox.addLayout(rp)

mainScreen.addLayout(leftPanel)
mainScreen.addWidget(line)
mainScreen.addLayout(rightPanel)

self.setLayout(mainScreen)
self.show()