PySideSimplicissimus Module 6 AlternativeCombine: Difference between revisions
No edit summary |
AutoSpider (talk | contribs) (Change category "LanguageBindings" -> "PySide") |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category: | {{Cleanup | reason=Auto-imported from ExpressionEngine.}} | ||
[[Category | |||
[[Category:PySide]] | |||
[[Category:PySide]] | |||
* '''Note:''' this article is a member of the multipart [[PySide-Newbie-Tutorials]] | * '''Note:''' this article is a member of the multipart [[PySide-Newbie-Tutorials]] | ||
'''English''' [ | '''English''' [[http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/5-combinaison-alternative/ French]] [[PySideSimplicissimus_Module_6_AlternativeCombine_Japanese|日本語]] | ||
= Alternative Combine = | = Alternative Combine = | ||
Line 11: | Line 13: | ||
All current source code for "Close", "About", "Show Licence", all versions of "Combined", "Engineering Application" aka "truss" are stored in one repository '''tuts4pyside'''. For your convenience, please install a copy of the repository with the following command: | All current source code for "Close", "About", "Show Licence", all versions of "Combined", "Engineering Application" aka "truss" are stored in one repository '''tuts4pyside'''. For your convenience, please install a copy of the repository with the following command: | ||
<code> git clone https://github.com/OldAl/tuts4pyside<code> | <code> git clone https://github.com/OldAl/tuts4pyside</code> | ||
Program listing follows. | Program listing follows. | ||
< | <code> | ||
#!/usr/bin/env python | #!/usr/bin/env python | ||
# combine_alter.py - combination of ShowGPL, About, Close scripts | # combine_alter.py - combination of ShowGPL, About, Close scripts | ||
Line 59: | Line 61: | ||
QMessageBox.about(self, "About PyQt, Platform and the like", | QMessageBox.about(self, "About PyQt, Platform and the like", | ||
"""<b> About this program </b> v %s | """<b> About this program </b> v %s | ||
<p>Copyright & | <p>Copyright © 2010 Joe Bloggs. | ||
All rights reserved in accordance with | All rights reserved in accordance with | ||
GPL v2 or later - NO WARRANTIES! | GPL v2 or later - NO WARRANTIES! | ||
Line 71: | Line 73: | ||
frame.show() | frame.show() | ||
app.exec_() | app.exec_() | ||
<code> | </code> | ||
Basically, it is a matter of taste which method one uses - with multiple inheritance or without. Anyhow, it may well be easier ot adopt one or the other. Even though, it is good to have some familiarity with both methods, as one meets both when reading programs. | Basically, it is a matter of taste which method one uses - with multiple inheritance or without. Anyhow, it may well be easier ot adopt one or the other. Even though, it is good to have some familiarity with both methods, as one meets both when reading programs. | ||
Enjoy the slightly different presentation of this very basic program setup! | Enjoy the slightly different presentation of this very basic program setup! |
Latest revision as of 05:16, 5 June 2016
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. |
- Note: this article is a member of the multipart PySide-Newbie-Tutorials
Alternative Combine
We call this program combine_alter.py. Actually it does no more and no less than the combine.py program, though it does it somewhat differently - it circumvents the multiple inheritance. Though multiple inheritance is a nice Python feature, many programmers, particularly those migrating from other language may well prefer to avoid it, because Python is almost unique in its support of multiple inheritance (note that C++ does support it, but not Java, C# or other usual object-oriented languages). Though we started of with multiple inheritance, some may well prefer this or some other alternative way. By using the name of combine_alter.py we show that its difference from combine.py by appending "alter" to the name. The combine.ui and qrc_combine.py programs remain unaltered, so we simply use them without bothering to make it available from an upload. The program itself is available from the usual place
All current source code for "Close", "About", "Show Licence", all versions of "Combined", "Engineering Application" aka "truss" are stored in one repository tuts4pyside. For your convenience, please install a copy of the repository with the following command:
git clone https://github.com/OldAl/tuts4pyside
Program listing follows.
#!/usr/bin/env python
# combine_alter.py - combination of ShowGPL, About, Close scripts
import sys
import platform
import PySide
from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox, QIcon
version''_ = '0.0.0'
from ui_combine import Ui_MainWindow as Ui
import qrc_combine
class MainWindow(QMainWindow):
def ''init''(self, parent=None):
super(MainWindow, self).''init''(parent)
# Store Ui() as class variable self.ui
self.ui = Ui()
ui.setupUi(self)
ui.actionShow_GPL.triggered.connect(self.showGPL)
ui.action_About.triggered.connect(self.about)
iconToolBar = self.addToolBar("iconBar.png")
#——————————————————
# Add icons to appear in tool bar - step 1
ui.actionShow_GPL.setIcon(QIcon(":/showgpl.png"))
ui.action_About.setIcon(QIcon(":/about.png"))
ui.action_Close.setIcon(QIcon(":/quit.png"))
#——————————————————
# Show a tip on the Status Bar - step 2
ui.actionShow_GPL.setStatusTip("Show GPL Licence")
ui.action_About.setStatusTip("Pop up the About dialog.")
ui.action_Close.setStatusTip("Close the program.")
#——————————————————
iconToolBar.addAction(ui.actionShow_GPL)
iconToolBar.addAction(ui.action_About)
iconToolBar.addAction(ui.action_Close)
def showGPL(self):
'''Read and display GPL licence.'''
self.ui.textEdit.setText(open('COPYING.txt').read())
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 © 2010 Joe Bloggs.
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()
frame.show()
app.exec_()
Basically, it is a matter of taste which method one uses - with multiple inheritance or without. Anyhow, it may well be easier ot adopt one or the other. Even though, it is good to have some familiarity with both methods, as one meets both when reading programs.
Enjoy the slightly different presentation of this very basic program setup!