PySideSimplicissimus Module 3 AboutBox: 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/2-a-propos/ French] ''[qt-devnet.developpez.com]'' [[PySideSimplicissimus Module 3 AboutBox Japanese|日本語]]
* '''Note:''' this article is a member of the multipart [[PySide-Newbie-Tutorials]]


=About Box=
'''English''' [&quot;French&amp;quot;:http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/2-a-propos/] [[PySideSimplicissimus_Module_3_AboutBox_Japanese|日本語]]
 
= About Box =


This dialog box shows the version of About Box itself, as well as versions of '''Qt''', '''PySide''' and '''Python''' beeing used, together with the '''platform''' on which the program is being run.
This dialog box shows the version of About Box itself, as well as versions of '''Qt''', '''PySide''' and '''Python''' beeing used, together with the '''platform''' on which the program is being run.
Line 9: Line 11:
First step is to use '''Qt Designer''' to visually design the main window and add one PushButton. We give the name by Saving As the file '''about.ui''' (ui extension is added by the '''Qt Designer''').
First step is to use '''Qt Designer''' to visually design the main window and add one PushButton. We give the name by Saving As the file '''about.ui''' (ui extension is added by the '''Qt Designer''').


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 /> If you do not have '''git''', pllease install it first.
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 />If you do not have '''git''', pllease install it first.
 
View the '''about.ui''' with '''Qt Designer''' at your leisure. The about.ui is an XML file. If you can not read it, do not let it bother you - Python can not read it, either… To make it readable to python we need to process it with a script from pyside-tools package:
 
</code><br />pyside-uic about.ui &gt; ui_about.py<br /><code>
 
The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing<br /></code><br />#!/usr/bin/env python<br /># about.py - display about box with info on platform etc.
 
import sys<br />import platform
 
import PySide<br />from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox


View the '''about.ui''' with '''Qt Designer''' at your leisure. The about.ui is an <span class="caps">XML</span> file. If you can not read it, do not let it bother you – Python can not read it, either… To make it readable to python we need to process it with a script from pyside-tools package:
from ui_about import Ui_MainWindow


The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing<br />
''version'' = '0.0.1'


The main program is right at the end. It mostly follows a common pattern. We call the application '''app''' and pass to it any <span class="caps">CLI</span> arguments in '''sys.argv'''. A chosen name for the '''window frame''' is '''frame''', but it could be anything at all. '''frame.show()''' tells the system to show the '''frame''' as soon as the application cycle starts running and finally, app.exec_() starts the application cycle, which enables user interaction by clicking on buttons and the like.
class MainWindow(QMainWindow, Ui_MainWindow):<br /> def ''init''(self, parent=None):<br /> super(MainWindow, self).''init''(parent)<br /> self.setupUi(self)<br /> self.aboutButton.clicked.connect(self.about)


A note about the listing of contents of the text in the about dialog popup box: the character '''copy;''' has been re-interpreted to what it represents in <span class="caps">HTML</span>, namely little c with a small circle around it. Actually, in the program it needs to be written just as shown in the previous sentence.
def about(self):<br /> '''Popup a box with about message.'''<br /> QMessageBox.about(self, &quot;About PySide, Platform and the like&amp;quot;,<br /> &quot;&quot;&quot;&lt;b&amp;gt;Platform Details&amp;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 platform details.<br /> &lt;p&amp;gt;Python %s - PySide version %s - Qt version %s on s&amp;quot;&quot;&quot; (''version'',<br /> platform.python_version(), PySide.''version'', PySide.QtCore.''version'',<br /> platform.system&amp;amp;#40;&amp;#41;))


The '''about.py''' can be run the same way as any other Python program. Enjoy!
if ''name'' == '''main''':<br /> app = QApplication(sys.argv)<br /> frame = MainWindow()<br /> frame.show()<br /> app.exec_()<br /><code>


[[PySide-Newbie-Tutorials|Return to PySideSimplicissimus]]
The main program is right at the end. It mostly follows a common pattern. We call the application '''app''' and pass to it any CLI arguments in '''sys.argv'''. A chosen name for the '''window frame''' is '''frame''', but it could be anything at all. '''frame.show()''' tells the system to show the '''frame''' as soon as the application cycle starts running and finally, app.exec_() starts the application cycle, which enables user interaction by clicking on buttons and the like.


===Categories:===
A note about the listing of contents of the text in the about dialog popup box: the character '''copy;''' has been re-interpreted to what it represents in HTML, namely little c with a small circle around it. Actually, in the program it needs to be written just as shown in the previous sentence.


* [[:Category:LanguageBindings|LanguageBindings]]
The '''about.py''' can be run the same way as any other Python program. Enjoy!
** [[:Category:LanguageBindings::PySide|PySide]]
* [[:Category:LanguageBindings::PySide::Newbie-Tutorials|Newbie Tutorials]]

Revision as of 14:30, 23 February 2015


English ["French&quot;:http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/2-a-propos/] 日本語

About Box

This dialog box shows the version of About Box itself, as well as versions of Qt, PySide and Python beeing used, together with the platform on which the program is being run.

First step is to use Qt Designer to visually design the main window and add one PushButton. We give the name by Saving As the file about.ui (ui extension is added by the Qt Designer).

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 />If you do not have '''git''', pllease install it first.

View the '''about.ui''' with '''Qt Designer''' at your leisure. The about.ui is an XML file. If you can not read it, do not let it bother you - Python can not read it, either To make it readable to python we need to process it with a script from pyside-tools package:


pyside-uic about.ui > ui_about.py

The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing<br />


#!/usr/bin/env python
# about.py - display about box with info on platform etc.

import sys
import platform

import PySide
from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox

from ui_about import Ui_MainWindow

version = '0.0.1'

class MainWindow(QMainWindow, Ui_MainWindow):
def init(self, parent=None):
super(MainWindow, self).init(parent)
self.setupUi(self)
self.aboutButton.clicked.connect(self.about)

def about(self):
Popup a box with about message.
QMessageBox.about(self, "About PySide, Platform and the like&quot;,
"""<b&gt;Platform Details&lt;/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 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_()

The main program is right at the end. It mostly follows a common pattern. We call the application app and pass to it any CLI arguments in sys.argv. A chosen name for the window frame is frame, but it could be anything at all. frame.show() tells the system to show the frame as soon as the application cycle starts running and finally, app.exec_() starts the application cycle, which enables user interaction by clicking on buttons and the like.

A note about the listing of contents of the text in the about dialog popup box: the character copy; has been re-interpreted to what it represents in HTML, namely little c with a small circle around it. Actually, in the program it needs to be written just as shown in the previous sentence.

The about.py can be run the same way as any other Python program. Enjoy!