- Note: this article is a member of the multipart PySide Newbie Tutorials
Please note that this example shows the GPL license, whereas PySide is released under LGPL. So make sure that you are displaying the right license.
This time we have to store in an external repository for your convenience several files: COPYING..txt, licence.ui and licence.py. All those files are in the following location: COPYING.txt [akabaila.pcug.org.au], licence.ui [akabaila.pcug.org.au] and licence.py [akabaila.pcug.org.au].
After downloading, place the COPYING.txt in the same directory as the program. The file has the GPL v 2 text. licence.ui needs to be converted to Python file as follows:
- pyside-uic licence.ui > ui_licence.py
Program Listing: follows:
- #!/usr/bin/env python
- # licence.py - display GPL licence
- import sys
- from ui_licence import Ui_MainWindow
- class MainWindow(QMainWindow, Ui_MainWindow):
- def __init__(self, parent=None):
- '''Mandatory initialisation of a class.'''
- super(MainWindow, self).__init__(parent)
- def fileRead(self):
- '''Read and display GPL licence.'''
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- frame = MainWindow()
If you run the program and click the button, it will show in the TextEdit window the listing of the licence. Clcik following link to l show you an image, stored externally:
All of the code mimics closely that of About and Close scripts. Two statements are of some interest:
The purpose of the pushButton is to show the licence, so it has been named showButton. The above statement connects the showButton.clicked event with a class method fileRead. Thus when showButton is clicked, the Python class method fileRead is executed. That method has a single “Pythonised” statement:
Not the simplest way to show what happens, but Python programmers like to do such things to us, readers. The code is equivalent to a series of statements as follows:
- #open file
- fl = open('COPYING.txt')
- tmp = fl.read()
It may be clearer, but a lot more typing and somewhat slower as Python is an interpreter. It is a subjective judgement which of the two styles is better.