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


=Show Licence=
'''English''' [&quot;French&amp;quot;:http://qt-devnet.developpez.com/tutoriels/pyside/simplissimus/3-licence/] [[PySideSimplicissimus_Module_4_ShowLicence_Japanese|日本語]]


Please note that this example shows the '''<span class="caps">CCPL</span>''' license, whereas [[PySide]] is released under '''<span class="caps">LGPL</span>'''. So make sure that you are displaying the right license.
= Show Licence =


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.
Please note that this example shows the '''CCPL''' license, whereas [[PySide]] is released under '''LGPL'''. So make sure that you are displaying the right license.


After downloading, place the '''<span class="caps">CCPL</span>.txt''' in the same directory as the program. The file has the '''Creative Commons Attribution-Share alike Licence''' text. '''licence.ui''' needs to be converted to Python file as follows:<br />'''Program Listing:''' follows:<br /> If you run the program and click the button, it will show in the TextEdit window the listing of the licence. All of the code mimics closely that of '''About''' and '''Close''' scripts. Two statements are of some interest:<br /> 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:<br /> 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:<br /> 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.
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.


[[PySide-Newbie-Tutorials|Return to PySideSimplicissimus]]
After downloading, place the '''CCPL.txt''' in the same directory as the program. The file has the '''Creative Commons Attribution-Share alike Licence''' text. '''licence.ui''' needs to be converted to Python file as follows:<br /></code><br />pyside-uic licence.ui &gt; ui_licence.py<br /><code><br />'''Program Listing:''' follows:<br /></code><br />#!/usr/bin/env python<br /># licence.py - display GPL licence


===Categories:===
import sys


* [[:Category:LanguageBindings|LanguageBindings]]
from PySide.QtGui import QApplication, QMainWindow, QTextEdit, QPushButton
** [[:Category:LanguageBindings::PySide|PySide]]
 
* [[:Category:LanguageBindings::PySide::Newbie-Tutorials|Newbie Tutorials]]
from ui_licence import Ui_MainWindow
 
class MainWindow(QMainWindow, Ui_MainWindow):<br /> def ''init''(self, parent=None):<br /> '''Mandatory initialisation of a class.'''<br /> super(MainWindow, self).''init''(parent)<br /> self.setupUi(self)<br /> self.showButton.clicked.connect(self.fileRead)
 
def fileRead(self):<br /> '''Read and display GPL licence.'''<br /> self.textEdit.setText(open('COPYING.txt').read())
 
if ''name'' == '''main''':<br /> app = QApplication(sys.argv)<br /> frame = MainWindow()<br /> frame.show()<br /> app.exec_()<br /><code><br />If you run the program and click the button, it will show in the TextEdit window the listing of the licence. All of the code mimics closely that of '''About''' and '''Close''' scripts. Two statements are of some interest:<br /></code><br />self.showButton.clicked.connect(self.fileRead)<br /><code><br />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 &quot;Pythonised&amp;quot; statement:<br /></code><br />self.textEdit.setText(open('COPYING.txt').read())<br /><code><br />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:<br /></code><br />#open file<br />fl = open('COPYING.txt')<br />tmp = fl.read()<br />self.textEdit.setText(tmp)<br /><code><br />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.

Revision as of 08:54, 24 February 2015


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

Show Licence

Please note that this example shows the CCPL license, whereas PySide is released under LGPL. So make sure that you are displaying the right license.

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.

After downloading, place the '''CCPL.txt''' in the same directory as the program. The file has the '''Creative Commons Attribution-Share alike Licence''' text. '''licence.ui''' needs to be converted to Python file as follows:<br />


pyside-uic licence.ui > ui_licence.py

<br />'''Program Listing:''' follows:<br />


#!/usr/bin/env python
# licence.py - display GPL licence

import sys

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

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)
self.setupUi(self)
self.showButton.clicked.connect(self.fileRead)

def fileRead(self):
Read and display GPL licence.
self.textEdit.setText(open('COPYING.txt').read())

if name == main:
app = QApplication(sys.argv)
frame = MainWindow()
frame.show()
app.exec_()

<br />If you run the program and click the button, it will show in the TextEdit window the listing of the licence. All of the code mimics closely that of '''About''' and '''Close''' scripts. Two statements are of some interest:<br />


self.showButton.clicked.connect(self.fileRead)

<br />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 &quot;Pythonised&amp;quot; statement:<br />


self.textEdit.setText(open('COPYING.txt').read())

<br />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:<br />


#open file
fl = open('COPYING.txt')
tmp = fl.read()
self.textEdit.setText(tmp)

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.