Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

PySideSimplicissimus Module 6 AlternativeCombine: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
* '''Note:''' this article is a member of the multipart [[PySide-Newbie-Tutorials|PySide Newbie Tutorials]]
[[Category:LanguageBindings]]<br />[[Category:LanguageBindings::PySide::Newbie Tutorials]]


'''English''' [http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/5-combinaison-alternative/ French] ''[qt-devnet.developpez.com]'' [[PySideSimplicissimus Module 6 AlternativeCombine Japanese|日本語]]
* '''Note:''' this article is a member of the multipart [[PySide-Newbie-Tutorials]]


=Alternative Combine=
'''English''' [&quot;French&amp;quot;:http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/5-combinaison-alternative/] [[PySideSimplicissimus_Module_6_AlternativeCombine_Japanese|日本語]]


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
= Alternative Combine =


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:<br /> Program listing follows.<br />
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 &quot;''alter&amp;quot; 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
<br />All current source code for &quot;Close&amp;quot;, &quot;About&amp;quot;, &quot;Show Licence&amp;quot;, all versions of &quot;Combined&amp;quot;, &quot;Engineering Application&amp;quot; aka &quot;truss&amp;quot; are stored in one repository '''tuts4pyside'''. For your convenience, please install a copy of the repository with the following command:<br /><code> git clone https://github.com/OldAl/tuts4pyside<code><br />Program listing follows.<br /></code><br />#!/usr/bin/env python<br /># combine_alter.py - combination of ShowGPL, About, Close scripts
<br />import sys<br />import platform
<br />import PySide<br />from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox, QIcon
<br />version''_ = '0.0.0'<br />from ui_combine import Ui_MainWindow as Ui<br />import qrc_combine


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.
class MainWindow(QMainWindow):<br /> def ''init''(self, parent=None):<br /> super(MainWindow, self).''init''(parent)<br /> # Store Ui() as class variable self.ui<br /> self.ui = Ui()<br /> ui.setupUi(self)<br /> ui.actionShow_GPL.triggered.connect(self.showGPL)<br /> ui.action_About.triggered.connect(self.about)<br /> iconToolBar = self.addToolBar(&quot;iconBar.png&amp;quot;)<br />#——————————————————<br /># Add icons to appear in tool bar - step 1<br /> ui.actionShow_GPL.setIcon(QIcon(&quot;:/showgpl.png&amp;quot;))<br /> ui.action_About.setIcon(QIcon(&quot;:/about.png&amp;quot;))<br /> ui.action_Close.setIcon(QIcon(&quot;:/quit.png&amp;quot;))<br />#——————————————————<br /># Show a tip on the Status Bar - step 2<br /> ui.actionShow_GPL.setStatusTip(&quot;Show GPL Licence&amp;quot;)<br /> ui.action_About.setStatusTip(&quot;Pop up the About dialog.&quot;)<br /> ui.action_Close.setStatusTip(&quot;Close the program.&quot;)<br />#——————————————————<br /> iconToolBar.addAction(ui.actionShow_GPL)<br /> iconToolBar.addAction(ui.action_About)<br /> iconToolBar.addAction(ui.action_Close)


Enjoy the slightly different presentation of this very basic program setup! [[PySide-Newbie-Tutorials|Return to PySideSimplicissimus]]
def showGPL(self):<br /> '''Read and display GPL licence.'''<br /> self.ui.textEdit.setText(open('COPYING.txt').read())


===Categories:===
def about(self):<br /> '''Popup a box with about message.'''<br /> QMessageBox.about(self, &quot;About PyQt, Platform and the like&amp;quot;,<br /> &quot;&quot;&quot;&lt;b&amp;gt; About this program &lt;/b&amp;gt; v %s<br /> &lt;p&amp;gt;Copyright &amp;copy; 2010 Joe Bloggs.<br /> All rights reserved in accordance with<br /> GPL v2 or later - NO WARRANTIES!<br /> &lt;p&amp;gt;This application can be used for<br /> displaying OS and platform details.<br /> &lt;p&amp;gt;Python %s - PySide version %s - Qt version %s on s&amp;quot;&quot;&quot;  (''version'', platform.python_version(), PySide.''version'', PySide.QtCore.''version'', platform.system&amp;amp;#40;&amp;#41;))


* [[:Category:LanguageBindings|LanguageBindings]]
if ''name'' == '''main''':<br /> app = QApplication(sys.argv)<br /> frame = MainWindow()<br /> frame.show()<br /> app.exec_()<br /><code>
** [[:Category:LanguageBindings::PySide|PySide]]
 
* [[:Category:LanguageBindings::PySide::Newbie-Tutorials|Newbie Tutorials]]
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!

Revision as of 09:23, 24 February 2015


English ["French&quot;:http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/5-combinaison-alternative/] 日本語

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&quot; 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&quot;, "About&quot;, "Show Licence&quot;, all versions of "Combined&quot;, "Engineering Application&quot; aka "truss&quot; 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<code><br />Program listing follows.<br />


#!/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&quot;)
#——————————————————
# Add icons to appear in tool bar - step 1
ui.actionShow_GPL.setIcon(QIcon(":/showgpl.png&quot;))
ui.action_About.setIcon(QIcon(":/about.png&quot;))
ui.action_Close.setIcon(QIcon(":/quit.png&quot;))
#——————————————————
# Show a tip on the Status Bar - step 2
ui.actionShow_GPL.setStatusTip("Show GPL Licence&quot;)
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&quot;,
"""<b&gt; About this program </b&gt; v %s
<p&gt;Copyright &copy; 2010 Joe Bloggs.
All rights reserved in accordance with
GPL v2 or later - NO WARRANTIES!
<p&gt;This application can be used for
displaying OS and platform details.
<p&gt;Python %s - PySide version %s - Qt version %s on s&quot;"" (version, platform.python_version(), PySide.version, PySide.QtCore.version, platform.system&amp;#40;&#41;))

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!