How do I reference the GUI?

Basic for connecting code pages.

Page 1 of 1

1 Replies - 1462 Views - Last Post: 25 September 2008 - 06:15 AM Rate Topic: -----

#1 Glock G20 Owner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-September 08

How do I reference the GUI?

Posted 24 September 2008 - 09:22 AM

Okay I have created a ui using QT Designer by Trolltech. Even converted it to a .py file. The book (Rapid GUI Programming with Python and Qt) goes on to tell how to use it but I don't understand what they are writing.

I guess my question is how do I use this file?

Do I create another file that calls the ui file and put my "action" code in the other file? To clarify:

The python, or .py file I created with QT Designer is called ui_frmco2calcs.py

It has all the code for creating my user interface, all created by using the command --> pyuic -o ui_frmco2calc.py frmco2calc.ui

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'frmco2calc.ui'
#
# Created: Thu Sep 18 12:06:24 2008
#	  by: The PyQt User Interface Compiler (pyuic) 3.17.4
#
# WARNING! All changes made in this file will be lost!


from qt import *


class frmCo2Calc(QDialog):
	def __init__(self,parent = None,name = None,modal = 0,fl = 0):
		QDialog.__init__(self,parent,name,modal,fl)

		if not name:
			self.setName("frmCo2Calc")



		self.lblHeaderOne = QLabel(self,"lblHeaderOne")
		self.lblHeaderOne.setGeometry(QRect(30,10,150,21))
		self.lblHeaderOne.setPaletteForegroundColor(QColor(18,18,234))
		lblHeaderOne_font = QFont(self.lblHeaderOne.font())
		lblHeaderOne_font.setFamily("Arial")
		lblHeaderOne_font.setPointSize(12)
		self.lblHeaderOne.setFont(lblHeaderOne_font)

		self.lblHeaderTwo = QLabel(self,"lblHeaderTwo")
		self.lblHeaderTwo.setGeometry(QRect(220,10,181,21))
		self.lblHeaderTwo.setPaletteForegroundColor(QColor(28,38,213))
		lblHeaderTwo_font = QFont(self.lblHeaderTwo.font())
		lblHeaderTwo_font.setFamily("Arial")
		lblHeaderTwo_font.setPointSize(12)
		self.lblHeaderTwo.setFont(lblHeaderTwo_font)

		self.framCalcOutput = QFrame(self,"framCalcOutput")
		self.framCalcOutput.setGeometry(QRect(220,40,200,220))
		self.framCalcOutput.setPaletteBackgroundColor(QColor(173,238,237))
		self.framCalcOutput.setFrameShape(QFrame.StyledPanel)
		self.framCalcOutput.setFrameShadow(QFrame.Raised)

		self.lblPpmCo2 = QLabel(self.framCalcOutput,"lblPpmCo2")
		self.lblPpmCo2.setGeometry(QRect(10,10,60,20))

		self.txtPpmCo2 = QLineEdit(self.framCalcOutput,"txtPpmCo2")
		self.txtPpmCo2.setGeometry(QRect(90,10,70,20))

		self.lblLbsHr = QLabel(self.framCalcOutput,"lblLbsHr")
		self.lblLbsHr.setGeometry(QRect(10,40,70,20))

		self.txtLbPerhr = QLineEdit(self.framCalcOutput,"txtLbPerhr")
		self.txtLbPerhr.setGeometry(QRect(90,40,70,20))

		self.lblLbPerMw = QLabel(self.framCalcOutput,"lblLbPerMw")
		self.lblLbPerMw.setGeometry(QRect(10,70,70,21))

		self.txtLbsPerMw = QLineEdit(self.framCalcOutput,"txtLbsPerMw")
		self.txtLbsPerMw.setGeometry(QRect(90,70,70,20))

		self.lblDscfm = QLabel(self.framCalcOutput,"lblDscfm")
		self.lblDscfm.setGeometry(QRect(10,100,65,20))

		self.txtDscfm = QLineEdit(self.framCalcOutput,"txtDscfm")
		self.txtDscfm.setGeometry(QRect(91,100,70,20))

		self.lblEnterDate = QLabel(self.framCalcOutput,"lblEnterDate")
		self.lblEnterDate.setGeometry(QRect(10,130,60,20))

		self.txtEnterDate = QLineEdit(self.framCalcOutput,"txtEnterDate")
		self.txtEnterDate.setGeometry(QRect(90,130,90,20))

		self.framInputs = QFrame(self,"framInputs")
		self.framInputs.setGeometry(QRect(20,40,190,220))
		self.framInputs.setPaletteBackgroundColor(QColor(19,238,22))
		self.framInputs.setFrameShape(QFrame.StyledPanel)
		self.framInputs.setFrameShadow(QFrame.Raised)

		self.txtTestTemp = QLineEdit(self.framInputs,"txtTestTemp")
		self.txtTestTemp.setGeometry(QRect(120,40,60,20))

		self.txtCo2Perc = QLineEdit(self.framInputs,"txtCo2Perc")
		self.txtCo2Perc.setGeometry(QRect(80,10,100,20))

		self.lblTestTemp = QLabel(self.framInputs,"lblTestTemp")
		self.lblTestTemp.setGeometry(QRect(10,40,100,21))

		self.lblCo2Perc = QLabel(self.framInputs,"lblCo2Perc")
		self.lblCo2Perc.setGeometry(QRect(10,10,70,21))

		self.lblAvgCogenEout = QLabel(self.framInputs,"lblAvgCogenEout")
		self.lblAvgCogenEout.setGeometry(QRect(10,70,101,21))

		self.txtAvgCogenEout = QLineEdit(self.framInputs,"txtAvgCogenEout")
		self.txtAvgCogenEout.setGeometry(QRect(120,70,60,20))

		self.lblTherms = QLabel(self.framInputs,"lblTherms")
		self.lblTherms.setGeometry(QRect(10,100,81,21))

		self.txtTherms = QLineEdit(self.framInputs,"txtTherms")
		self.txtTherms.setGeometry(QRect(81,100,100,20))

		self.lblStackO2 = QLabel(self.framInputs,"lblStackO2")
		self.lblStackO2.setGeometry(QRect(10,130,86,21))

		self.txtStackO2Perc = QLineEdit(self.framInputs,"txtStackO2Perc")
		self.txtStackO2Perc.setGeometry(QRect(100,130,80,20))

		self.lblTestDate = QLabel(self.framInputs,"lblTestDate")
		self.lblTestDate.setGeometry(QRect(10,160,70,20))

		self.txtTestDate = QLineEdit(self.framInputs,"txtTestDate")
		self.txtTestDate.setGeometry(QRect(90,160,90,20))

		self.btnExit = QPushButton(self,"btnExit")
		self.btnExit.setGeometry(QRect(350,290,70,30))

		self.btnCalculate = QPushButton(self,"btnCalculate")
		self.btnCalculate.setGeometry(QRect(20,290,70,30))

		self.languageChange()

		self.resize(QSize(440,330).expandedTo(self.minimumSizeHint()))
		self.clearWState(Qt.WState_Polished)


	def languageChange(self):
		self.setCaption(self.__tr("UCSC Cogen CO2 Calculator"))
		self.lblHeaderOne.setText(self.__tr("Enter engine data here"))
		self.lblHeaderTwo.setText(self.__tr("Results diplayed here"))
		self.lblPpmCo2.setText(self.__tr("PPM CO2"))
		self.lblLbsHr.setText(self.__tr("LB per Hour"))
		self.lblLbPerMw.setText(self.__tr("LB per MW"))
		self.lblDscfm.setText(self.__tr("DSCFM"))
		self.lblEnterDate.setText(self.__tr("Enter Date"))
		self.txtEnterDate.setText(self.__tr("--"))
		self.txtEnterDate.setInputMask(self.__tr("99-XXX-99; "))
		QToolTip.add(self.framInputs,self.__tr("Enter Manual Data Here"))
		self.lblTestTemp.setText(self.__tr("Test Temperature"))
		self.lblCo2Perc.setText(self.__tr("CO2 %age"))
		self.lblAvgCogenEout.setText(self.__tr("Avg Cogen E Out"))
		self.lblTherms.setText(self.__tr("Therms"))
		self.lblStackO2.setText(self.__tr("Stack O2 %age"))
		self.lblTestDate.setText(self.__tr("Test Date"))
		self.txtTestDate.setText(self.__tr("--"))
		self.txtTestDate.setInputMask(self.__tr("99-XXX-99; "))
		self.btnExit.setText(self.__tr("E&xit"))
		self.btnExit.setAccel(QKeySequence(self.__tr("Alt+X")))
		self.btnCalculate.setText(self.__tr("Calc&ulate"))
		self.btnCalculate.setAccel(QKeySequence(self.__tr("Alt+U")))


	def __tr(self,s,c = None):
		return qApp.translate("frmCo2Calc",s,c)



So do I create another .py file that has calls to the ui form (code above) in it to access the buttons and fields that I have created? If so, then do I use an import statement to import the ui_frmco2calc.py file information? And then how do I run these things? The book was written with a primary focus on Windows all though it does occasionally mention Linux and Mac. I just don't understand how to "connect" all the different pages with code so they work together as one. :blink:

The application I am working on is a simple one that takes 7 inputs, of which 5 are used to calculate a total of 4 answers. Then that is all stored in a simple single table SQLite database. I think I have the database connection thing pretty much figured out... (might be back on that one later)

This is really confusing when you don't have a tutor or teacher available to help. That and I really got ruined by Microsoft Access. Ugh... enough drive a person batty. :crazy:

Thank you for your time and assistance. Once I figure this out I think I will be able to move forward again. I have been stuck on this one problem for about 2 months now. Mainly because I have only limited time at work to try and resolve it and lastly because I have asked but not received an answer yet.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I reference the GUI?

#2 itpro4470  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 156
  • Joined: 17-June 07

Re: How do I reference the GUI?

Posted 25 September 2008 - 06:15 AM

While I'm not good with QT in all other GUIs I've used there is some sort of signal or eventhandler which basically is a function hooked up to the button's click event. Check out chapter 10 in that book according to the table of contents that should be Event Handlers
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1