PySideSimplicissimus Module 3 AboutBox: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Change category "LanguageBindings" -> "PySide")
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:LanguageBindings]]
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
[[Category:LanguageBindings::PySide::Newbie Tutorials]]
 
[[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''' ["French":http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/2-a-propos/] [[PySideSimplicissimus_Module_3_AboutBox_Japanese|日本語]]
'''English''' [[http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/2-a-propos/ French]] [[PySideSimplicissimus_Module_3_AboutBox_Japanese|日本語]]


= About Box =
= About Box =
Line 13: Line 15:


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>
If you do not have '''git''', pllease install it first.
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:
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>
pyside-uic about.ui > ui_about.py
</code>
</code>
pyside-uic about.ui > ui_about.py
<code>


The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing
The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing
</code>
<code>
#!/usr/bin/env python
#!/usr/bin/env python
# about.py - display about box with info on platform etc.
# about.py - display about box with info on platform etc.
Line 35: Line 37:
from ui_about import Ui_MainWindow
from ui_about import Ui_MainWindow


''version'' = '0.0.1'
__version__ = '0.0.1'


class MainWindow(QMainWindow, Ui_MainWindow):
class MainWindow(QMainWindow, Ui_MainWindow):
  def ''init''(self, parent=None):
  def __init__(self, parent=None):
  super(MainWindow, self).''init''(parent)
  super(MainWindow, self).__init__(parent)
  self.setupUi(self)
  self.setupUi(self)
  self.aboutButton.clicked.connect(self.about)
  self.aboutButton.clicked.connect(self.about)
Line 46: Line 48:
  '''Popup a box with about message.'''
  '''Popup a box with about message.'''
  QMessageBox.about(self, "About PySide, Platform and the like",
  QMessageBox.about(self, "About PySide, Platform and the like",
  """<b>Platform Details</b> v %s
  """<b>Platform Details</b> v {}
  <p>Copyright &amp;copy; 2010 Joe Bloggs.
  <p>Copyright &copy; 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!
  <p>This application can be used for
  <p>This application can be used for
  displaying platform details.
  displaying platform details.
  <p>Python %s - PySide version %s - Qt version %s on s""" (''version'',
  <p>Python {} - PySide version {} - Qt version {} on {}""".format(__version__,
  platform.python_version(), PySide.''version'', PySide.QtCore.''version'',
  platform.python_version(), PySide.__version__, PySide.QtCore.__version__,
  platform.system()))
  platform.system()))


if ''name'' == '''main''':
if __name__ == '__main__':
  app = QApplication(sys.argv)
  app = QApplication(sys.argv)
  frame = MainWindow()
  frame = MainWindow()
  frame.show()
  frame.show()
  app.exec_()
  app.exec_()
<code>
</code>


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.
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.

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.

English [French] 日本語

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", "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

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

#!/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",
 """<b>Platform Details</b> v {}
 <p>Copyright &copy; 2010 Joe Bloggs.
 All rights reserved in accordance with
 GPL v2 or later - NO WARRANTIES!
 <p>This application can be used for
 displaying platform details.
 <p>Python {} - PySide version {} - Qt version {} on {}""".format(__version__,
 platform.python_version(), PySide.__version__, PySide.QtCore.__version__,
 platform.system()))

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!