PySideSimplicissimus Module 7 CombineAllIn1

From Qt Wiki
Jump to: navigation, search
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

English 日本語

Combine All In One

This is the last version of different layout of program. In this version we will eliminate altogether the combine.ui file and its derivative file. There is a clear advantage in that - there are fewer files. The disadvantage is that if later we decide to change the appearnce we no longer can have the benefits of using Qt Designer without modifying back the setup. When the program is simply a GUI for an underlying program, it is sometimes worth while to use this modified format. In any case, my favourite GUI design book uses this form, suggesting that it is just as easy to design the forms without visual aids.

As in earlier version, all the required bits of code and other resources are available for a download from the following "repository":

 git clone

The modification of program is implemented by first of all copying the procedure setupUi() from into the body of the program itself, Then all the statements are transferred into the procedure init of the main program. That requires several modifications. Fortunately these modifications are very good opportunity to check once understanding of the process of program. We also use this opportunity to determine which widgets we need to import, as we no longer use explicitly the names of QtCore and QtGui in the code. The code looks cleaner then!

Here is the program listing:

#[[Image:/usr/bin/env python
# - combination of ShowGPL, About, Close scripts
# The purpose of this version of program is to show implementation 
# of most code in one file - all_in_1|]].
import sys
import platform
import PySide
from PySide.QtCore import QRect
from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox, QIcon, QAction, QWidget, QGridLayout, QTextEdit, QMenuBar, QMenu, QStatusBar
''version'' = '0.0.0'
import qrc_combine
class MainWindow(QMainWindow):
 def ''init''(self, parent=None):
 super(MainWindow, self).''init''(parent)
 self.resize(731, 475)
 centralwidget = QWidget(self)
 gridLayout = QGridLayout(centralwidget)
 # textEdit needs to be a class variable.
 self.textEdit = QTextEdit(centralwidget)
 gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)
 menubar = QMenuBar(self)
 menubar.setGeometry(QRect(0, 0, 731, 29))
 menu_File = QMenu(menubar)
 statusbar = QStatusBar(self)
 actionShow_GPL = QAction(self)
 action_About = QAction(self)
 iconToolBar = self.addToolBar("iconBar.png")
# Add icons to appear in tool bar - step 1
 action_Close = QAction(self)
# Show a tip on the Status Bar - step 2
 actionShow_GPL.setStatusTip("Show GPL Licence")
 action_About.setStatusTip("Pop up the About dialog.")
 action_Close.setStatusTip("Close the program.")
def showGPL(self):
 '''Read and display GPL licence.'''
def about(self):
 '''Popup a box with about message.'''
 QMessageBox.about(self, "About PyQt, Platform and the like",
 """<b> About this program </b> v %s
 <p>Copyright &copy; 2011 Your Name.
 All rights reserved in accordance with
 GPL v2 or later - NO WARRANTIES!
 <p>This application can be used for
 displaying OS and platform details.
 <p>Python %s - PySide version %s - Qt version %s on s"""  (''version'', platform.python_version(), PySide.''version'', PySide.QtCore.''version'', platform.system()))
if ''name'' == '''main''':
 app = QApplication(sys.argv)
 frame = MainWindow()

No doubt you have noticed that one type of statement is left intact but commented out - these are the statements that include the command setObjetName('name_string'). The reason for commenting it out is that these commands are not used in this example at all - the program executes as well without them. They are, however, not just deleted - since they are the direct result of working with the aid of Qt Designer and conversion with pyside-uic script, perhaps they may be useful for certain types of debugging situations. So it does not cost much (actually it costs nothing!) to just comment them out. It is a kind of compromise.

This is the last variation of that we explore. I think the time is ripe for us to explore a simple engineering problem and use PySide for the GUI design for the underlying program. The problem is very simple - determination of forces in a truss. The method of doing it and data handling is realistic, but not too extensive, so that it is useful for newbie to newbie tutorials. ¡Hasta la vista!