Python Forum
[PyQt] Creating Application Logic
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Creating Application Logic
#1
I'm trying to make a very simple application involving three different widgets using PyQt and Panda3D. I have the GUIs set up in three different scripts, but I don't know how to combine scripts to make a working application.

I'm trying to get the load button from this widget:

#MAIN WINDOW

import sys
import PyQt5
from PyQt5.QtWidgets import (QMainWindow, QWidget, QToolTip, QPushButton, QApplication,
	QHBoxLayout, QVBoxLayout)

app = QApplication(sys.argv)
screenres = app.desktop().screenGeometry()
scrW, scrH = screenres.width(), screenres.height()
width = 500
height = 500

#########################################################

class MainWindow(QMainWindow):

	def __init__(self):

		super().__init__()

		self.initHomeScreen()

	#-----------------------------------------------------------

	def setWindow(self):

		self.setGeometry((scrW - width)/2, (scrH - height)/2, width, height) #(xpos, ypos, width, height)
		self.setWindowTitle("Dragon's World")

	#-----------------------------------------------------------

	def initHomeScreen(self):

		self.setWindow()

		#____________BUTTONS

		#The quit button
		btnW = (width *.15)
		btnH = (height *.05)

		quitbtn = QPushButton('Quit', self) #self stands for the parent widget, in this case the application object
		quitbtn.resize(btnW, btnH)
		quitbtn.clicked.connect(QApplication.instance().quit)

		#Load game button
		loadbtn = QPushButton('Load Game', self)
		loadbtn.resize(btnW, btnH)
		#loadscrn = MainWindow.initLoadScreen()
		#loadbtn.clicked.connect(loadscrn)

		#____________LAYOUTS

		hbox = QHBoxLayout()
		hbox.addStretch(1)
		hbox.addWidget(loadbtn)
		hbox.addWidget(quitbtn)
		hbox.addStretch(1)

		vbox = QVBoxLayout()
		vbox.addStretch(4)
		vbox.addLayout(hbox)
		vbox.addStretch(1)

		#_____________

		homewidg = QWidget()
		homewidg.setLayout(vbox)

		self.setCentralWidget(homewidg)
		self.show()

	#------------------------------------------------------------

	def initLoadScreen(self):

		pass


##########################################################

if __name__ == '__main__':

	window = MainWindow()
	sys.exit(app.exec_())
to change the main window's display to this widget:

#PANDA 3D WINDOW
from math import pi, sin, cos

from direct.showbase.ShowBase import ShowBase
from direct.task import Task
 
class MyApp(ShowBase):
 
    def __init__(self):

        ShowBase.__init__(self)

        # Load the environment model.
        self.scene = self.loader.loadModel("models/environment")

        # Reparent the model to render.
        self.scene.reparentTo(self.render)

        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)

        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
 
    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont
 
app = MyApp()
app.run()
with this overlayed as GUI on top:

#GUI IMPOSED ON PANDA3D

import PyQt5
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout

import sys

app = QApplication(sys.argv)

####################################################

class GameScreen(QWidget):

	def __init__(self):

		super().__init__()

		self.initHomeButton()

		self.show()

	#-------------------------------------------

	def initHomeButton(self):

		homebtn = QPushButton('Home')
		homebtn.resize(100, 25)

		hbox = QHBoxLayout()
		hbox.addStretch(1)
		hbox.addWidget(homebtn)

		vbox = QVBoxLayout()
		vbox.addStretch(1)
		vbox.addLayout(hbox)

		self.setLayout(vbox)

#####################################################

if __name__ == '__main__':

	window = GameScreen()
	sys.exit(app.exec_())
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020