diff options
Diffstat (limited to 'sources/pyside2/doc/tutorials')
64 files changed, 0 insertions, 4727 deletions
diff --git a/sources/pyside2/doc/tutorials/basictutorial/clickablebutton.rst b/sources/pyside2/doc/tutorials/basictutorial/clickablebutton.rst deleted file mode 100644 index accb54aea..000000000 --- a/sources/pyside2/doc/tutorials/basictutorial/clickablebutton.rst +++ /dev/null @@ -1,90 +0,0 @@ -A Simple Button Tutorial -************************ - -In this tutorial, we'll show you how to handle **signals and slots** -using Qt for Python. **Signals and slots** is a Qt feature that lets -your graphical widgets communicate with other graphical widgets or -your python code. Our application creates a button that logs the -`Button clicked, Hello!` message to the python console each time you -click it. - -Let's start by importing the necessary PySide2 classes and python -`sys` module: -:: - - import sys - from PySide2.QtWidgets import QApplication, QPushButton - from PySide2.QtCore import Slot - -Let's also create a python function that logs the message to the -console: -:: - - # Greetings - @Slot() - def say_hello(): - print("Button clicked, Hello!") - -.. note:: The `@Slot()` is a decorator that identifies a function as - a slot. It is not important to understand why for now, - but use it always to avoid unexpected behavior. - -Now, as mentioned in previous examples you must create the -`QApplication` to run your PySide2 code: -:: - - # Create the Qt Application - app = QApplication(sys.argv) - -Let's create the clickable button, which is a `QPushButton` instance. -To label the button, we pass a python string to the constructor: -:: - - # Create a button - button = QPushButton("Click me") - -Before we show the button, we must connect it to the `say_hello()` -function that we defined earlier. There are two ways of doing this; -using the old style or the new style, which is more pythonic. Let's -use the new style in this case. You can find more information about -both these styles in the -`Signals and Slots in PySide2 <https://wiki.qt.io/Qt_for_Python_Signals_and_Slots>`_ -wiki page. - -The `QPushButton` has a predefined signal called **clicked**, which -is triggered every time the button is clicked. We'll connect this -signal to the `say_hello()` function: -:: - - # Connect the button to the function - button.clicked.connect(say_hello) - -Finally, we show the button and start the Qt main loop: -:: - - # Show the button - button.show() - # Run the main Qt loop - app.exec_() - -Here is the complete code for this example: -:: - - #!/usr/bin/python - - import sys - from PySide2.QtWidgets import QApplication, QPushButton - from PySide2.QtCore import Slot - - @Slot() - def say_hello(): - print("Button clicked, Hello!") - - # Create the Qt Application - app = QApplication(sys.argv) - # Create a button, connect it and show it - button = QPushButton("Click me") - button.clicked.connect(say_hello) - button.show() - # Run the main Qt loop - app.exec_() diff --git a/sources/pyside2/doc/tutorials/basictutorial/dialog.rst b/sources/pyside2/doc/tutorials/basictutorial/dialog.rst deleted file mode 100644 index cdb356b91..000000000 --- a/sources/pyside2/doc/tutorials/basictutorial/dialog.rst +++ /dev/null @@ -1,145 +0,0 @@ -Creating a Simple PySide2 Dialog Application -********************************************* - -This tutorial shows how to build a simple dialog with some -basic widgets. The idea is to let users provide their name -in a `QLineEdit`, and the dialog greets them on click of a -`QPushButton`. - -Let us just start with a simple stub that creates and shows -a dialog. This stub is updated during the course of this -tutorial, but you can use this stub as is if you need to: -:: - - import sys - from PySide2.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton - - class Form(QDialog): - - def __init__(self, parent=None): - super(Form, self).__init__(parent) - self.setWindowTitle("My Form") - - - if __name__ == '__main__': - # Create the Qt Application - app = QApplication(sys.argv) - # Create and show the form - form = Form() - form.show() - # Run the main Qt loop - sys.exit(app.exec_()) - -The imports aren't new to you, the same for the creation of the -`QApplication` and the execution of the Qt main loop. -The only novelty here is the **class definition**. - -You can create any class that subclasses PySide2 widgets. -In this case, we are subclassing `QDialog` to define a custom -dialog, which we name as **Form**. We have also implemented the -`init()` method that calls the `QDialog`'s init method with the -parent widget, if any. Also, the new `setWindowTitle()` method -just sets the title of the dialog window. In `main()`, you can see -that we are creating a *Form object* and showing it to the world. - -Create the Widgets -=================== - -We are going to create two widgets: a `QLineEdit` where users can -enter their name, and a `QPushButton` that prints the contents of -the `QLineEdit`. -So, let's add the following code to the `init()` method of our Form: -:: - - # Create widgets - self.edit = QLineEdit("Write my name here..") - self.button = QPushButton("Show Greetings") - -It's obvious from the code that both widgets will show the corresponding -texts. - -Create a layout to organize the Widgets -======================================== - -Qt comes with layout-support that helps you organize the widgets -in your application. In this case, let's use `QVBoxLayout` to lay out -the widgets vertically. Add the following code to the `init()` method, -after creating the widgets: -:: - - # Create layout and add widgets - layout = QVBoxLayout() - layout.addWidget(self.edit) - layout.addWidget(self.button) - # Set dialog layout - self.setLayout(layout) - -So, we create the layout, add the widgets with `addWidget()`, -and finally we say that our **Form** will have our `QVBoxLayout` -as its layout. - -Create the function to greet and connect the Button -==================================================== - -Finally, we just have to add a function to our custom **Form** -and *connect* our button to it. Our function will be a part of -the Form, so you have to add it after the `init()` function: -:: - - # Greets the user - def greetings(self): - print ("Hello {}".format(self.edit.text())) - -Our function just prints the contents of the `QLineEdit` to the -python console. We have access to the text by means of the -`QLineEdit.text()` method. - -Now that we have everything, we just need to *connect* the -`QPushButton` to the `Form.greetings()` method. To do so, add the -following line to the `init()` method: -:: - - # Add button signal to greetings slot - self.button.clicked.connect(self.greetings) - -Once executed, you can enter your name in the `QLineEdit` and watch -the console for greetings. - -Complete code -============= - -Here is the complete code for this tutorial: -:: - - import sys - from PySide2.QtWidgets import (QLineEdit, QPushButton, QApplication, - QVBoxLayout, QDialog) - - class Form(QDialog): - - def __init__(self, parent=None): - super(Form, self).__init__(parent) - # Create widgets - self.edit = QLineEdit("Write my name here") - self.button = QPushButton("Show Greetings") - # Create layout and add widgets - layout = QVBoxLayout() - layout.addWidget(self.edit) - layout.addWidget(self.button) - # Set dialog layout - self.setLayout(layout) - # Add button signal to greetings slot - self.button.clicked.connect(self.greetings) - - # Greets the user - def greetings(self): - print ("Hello %s" % self.edit.text()) - - if __name__ == '__main__': - # Create the Qt Application - app = QApplication(sys.argv) - # Create and show the form - form = Form() - form.show() - # Run the main Qt loop - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/basictutorial/qml.rst b/sources/pyside2/doc/tutorials/basictutorial/qml.rst deleted file mode 100644 index 81583096b..000000000 --- a/sources/pyside2/doc/tutorials/basictutorial/qml.rst +++ /dev/null @@ -1,63 +0,0 @@ -Your First Application Using PySide2 and QtQuick/QML -***************************************************** - -QML is a declarative language that lets you develop applications -faster than with traditional languages. It is ideal for designing the -UI of your application because of its declarative nature. In QML, a -user interface is specified as a tree of objects with properties. In -this tutorial, we will show how to make a simple "Hello World" -application with PySide2 and QML. - -A PySide2/QML application consists, at least, of two different files - -a file with the QML description of the user interface, and a python file -that loads the QML file. To make things easier, let's save both files in -the same directory. - -Here is a simple QML file called `view.qml`: -:: - import QtQuick 2.0 - - Rectangle { - width: 200 - height: 200 - color: "green" - - Text { - text: "Hello World" - anchors.centerIn: parent - } - } - -We start by importing `QtQuick 2.0`, which is a QML module. - -The rest of the QML code is pretty straightforward for those who -have previously used HTML or XML files. Basically, we are creating -a green rectangle with the size `200*200`, and adding a Text element -that reads "Hello World". The code `anchors.centerIn: parent` makes -the text appear centered in relation to its immediate parent, which -is the Rectangle in this case. - -Now, let's see how the code looks on the PySide2. -Let's call it `main.py`: -:: - from PySide2.QtWidgets import QApplication - from PySide2.QtQuick import QQuickView - from PySide2.QtCore import QUrl - - app = QApplication([]) - view = QQuickView() - url = QUrl("view.qml") - - view.setSource(url) - view.show() - app.exec_() - -If you are already familiar with PySide2 and have followed our -tutorials, you have already seen much of this code. -The only novelties are that you must `import QtQuick` and set the -source of the `QQuickView` object to the URL of your QML file. -Then, as any Qt widget, you call `QQuickView.show()`. - -.. note:: If you are programming for desktop, you should consider - adding `view.setResizeMode(QQuickView.SizeRootObjectToView)` - before showing the view. diff --git a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst b/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst deleted file mode 100644 index b00437bcb..000000000 --- a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst +++ /dev/null @@ -1,174 +0,0 @@ -Using UI Files -*************** - -This page describes the use of Qt Creator to create graphical -interfaces for your Qt for Python project. -You will need **Qt Creator** to design and modify your interface (UI file). - -If you don't know how to use Qt Creator, refer to the -`Using Qt Designer <http://doc.qt.io/qtcreator/creator-using-qt-designer.html>`_ -documentation page. - -At Qt Creator, create a new Qt Design Form, choose "Main Window" for template. -And save as `mainwindow.ui`. -Add a `QPushButton` to the center of the centralwidget. - -Your file (mainwindow.ui) should look something like this: -:: - - <?xml version="1.0" encoding="UTF-8"?> - <ui version="4.0"> - <class>MainWindow</class> - <widget class="QMainWindow" name="MainWindow"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>MainWindow</string> - </property> - <widget class="QWidget" name="centralWidget"> - <widget class="QPushButton" name="pushButton"> - <property name="geometry"> - <rect> - <x>110</x> - <y>80</y> - <width>201</width> - <height>81</height> - </rect> - </property> - <property name="text"> - <string>PushButton</string> - </property> - </widget> - </widget> - <widget class="QMenuBar" name="menuBar"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>20</height> - </rect> - </property> - </widget> - <widget class="QToolBar" name="mainToolBar"> - <attribute name="toolBarArea"> - <enum>TopToolBarArea</enum> - </attribute> - <attribute name="toolBarBreak"> - <bool>false</bool> - </attribute> - </widget> - <widget class="QStatusBar" name="statusBar"/> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections/> - </ui> - -Now we are ready to decide how to use the **UI file** from Python. - -Generating a Python class -========================= - -Another option to interact with a **UI file** is to generate a Python -class from it. This is possible thanks to the `pyside2-uic` tool. -To use this tool, you need to run the following command on a console: -:: - - pyside2-uic mainwindow.ui > ui_mainwindow.py - -We redirect all the output of the command to a file called `ui_mainwindow.py`, -which will be imported directly: -:: - - from ui_mainwindow import Ui_MainWindow - -Now to use it, we should create a personalized class for our widget -to **setup** this generated design. - -To understand the idea, let's take a look at the whole code: -:: - - import sys - from PySide2.QtWidgets import QApplication, QMainWindow - from PySide2.QtCore import QFile - from ui_mainwindow import Ui_MainWindow - - class MainWindow(QMainWindow): - def __init__(self): - super(MainWindow, self).__init__() - self.ui = Ui_MainWindow() - self.ui.setupUi(self) - - if __name__ == "__main__": - app = QApplication(sys.argv) - - window = MainWindow() - window.show() - - sys.exit(app.exec_()) - -What is inside the *if* statement is already known from the previous -examples, and our new basic class contains only two new lines -that are in charge of loading the generated python class from the UI -file: -:: - - self.ui = Ui_MainWindow() - self.ui.setupUi(self) - -.. note:: You must run `pyside2-uic` again every time you make changes -to the **UI file**. - -Loading it directly -==================== - -To load the UI file directly, we will need a class from the **QtUiTools** -module: -:: - - from PySide2.QtUiTools import QUiLoader - -The `QUiLoader` lets us load the **ui file** dynamically -and use it right away: -:: - ui_file = QFile("mainwindow.ui") - ui_file.open(QFile.ReadOnly) - - loader = QUiLoader() - window = loader.load(ui_file) - window.show() - -The complete code of this example looks like this: -:: - - # File: main.py - import sys - from PySide2.QtUiTools import QUiLoader - from PySide2.QtWidgets import QApplication - from PySide2.QtCore import QFile - - if __name__ == "__main__": - app = QApplication(sys.argv) - - ui_file = QFile("mainwindow.ui") - ui_file.open(QFile.ReadOnly) - - loader = QUiLoader() - window = loader.load(ui_file) - ui_file.close() - window.show() - - sys.exit(app.exec_()) - -Then to execute it we just need to run the following on a -command prompt: -:: - - python main.py diff --git a/sources/pyside2/doc/tutorials/basictutorial/widgets.rst b/sources/pyside2/doc/tutorials/basictutorial/widgets.rst deleted file mode 100644 index c864e3d47..000000000 --- a/sources/pyside2/doc/tutorials/basictutorial/widgets.rst +++ /dev/null @@ -1,39 +0,0 @@ -Your First QtWidgets Application -********************************* - -As with any other programming framework, -you start with the traditional "Hello World" program. - -Here is a simple example of a Hello World application in PySide2: -:: - import sys - from PySide2.QtWidgets import QApplication, QLabel - - app = QApplication(sys.argv) - label = QLabel("Hello World!") - label.show() - app.exec_() - - -For a widget application using PySide2, you must always start by -importing the appropriate class from the `PySide2.QtWidgets` module. - -After the imports, you create a `QApplication` instance. As Qt can -receive arguments from command line, you may pass any argument to -the QApplication object. Usually, you don't need to pass any -arguments so you can leave it as is, or use the following approach: -:: - app = QApplication([]) - -After the creation of the application object, we have created a -`QLabel` object. A `QLabel` is a widget that can present text -(simple or rich, like html), and images: -:: - # This HTML approach will be valid too! - label = QLabel("<font color=red size=40>Hello World!</font>") - -.. note:: After creating the label, we call `show()` on it. - -Finally, we call `app.exec_()` to enter the Qt main loop and start -to execute the Qt code. In reality, it is only here where the label -is shown, but this can be ignored for now. diff --git a/sources/pyside2/doc/tutorials/datavisualize/add_chart.rst b/sources/pyside2/doc/tutorials/datavisualize/add_chart.rst deleted file mode 100644 index 0c9803269..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/add_chart.rst +++ /dev/null @@ -1,20 +0,0 @@ -Chapter 5 - Add a chart view -============================= - -A table is nice to present data, but a chart is even better. For this, you -need the QtCharts module that provides many types of plots and options to -graphically represent data. - -The placeholder for a plot is a QChartView, and inside that Widget you can -place a QChart. As a first step, try including only this without any data to -plot. - -Make the following highlighted changes to :code:`main_widget.py` from the -previous chapter to add a QChartView: - -.. literalinclude:: datavisualize5/main_widget.py - :linenos: - :lines: 40- - :emphasize-lines: 2-3,6,22-37,48-51 - - diff --git a/sources/pyside2/doc/tutorials/datavisualize/add_mainwindow.rst b/sources/pyside2/doc/tutorials/datavisualize/add_mainwindow.rst deleted file mode 100644 index a9ff38a30..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/add_mainwindow.rst +++ /dev/null @@ -1,32 +0,0 @@ -Chapter 3 - Create an empty QMainWindow -========================================== - -You can now think of presenting your data in a UI. A QMainWindow provides a -convenient structure for GUI applications, such as a menu bar and status bar. -The following image shows the layout that QMainWindow offers out-of-the box: - -.. image:: images/QMainWindow-layout.png - :alt: QMainWindow layout - :align: right - -In this case, let your application inherit from QMainWindow, and add the -following UI elements: - -* A "File" menu to open a File dialog. -* An "Exit" menu close the window. -* A status message on the status bar when the application starts. - -In addition, you can define a fixed size for the window or adjust it based on -the resolution you currently have. In the following snippet, you will see how -window size is defined based on available screen width (80%) and height (70%). - -.. note:: You can achieve a similar structure using other Qt elements like - QMenuBar, QWidget, and QStatusBar. Refer the QMainWindow layout for - guidance. - -.. literalinclude:: datavisualize3/main_window.py - :language: python - :linenos: - :lines: 40- - -Try running the script to see what output you get with it. diff --git a/sources/pyside2/doc/tutorials/datavisualize/add_tableview.rst b/sources/pyside2/doc/tutorials/datavisualize/add_tableview.rst deleted file mode 100644 index bbf27f2da..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/add_tableview.rst +++ /dev/null @@ -1,68 +0,0 @@ -Chapter 4 - Add a QTableView -============================= - -Now that you have a QMainWindow, you can include a centralWidget to your -interface. Usually, a QWidget is used to display data in most data-driven -applications. Use a table view to display your data. - -The first step is to add a horizontal layout with just a QTableView. You -can create a QTableView object and place it inside a QHBoxLayout. Once the -QWidget is properly built, pass the object to the QMainWindow as its central -widget. - -Remember that a QTableView needs a model to display information. In this case, -you can use a QAbstractTableModel instance. - -.. note:: You could also use the default item model that comes with a - QTableWidget instead. QTableWidget is a convenience class that reduces - your codebase considerably as you don't need to implement a data model. - However, it's less flexible than a QTableView, as QTableWidget cannot be - used with just any data. For more insight about Qt's model-view framework, - refer to the - `Model View Programming <http://doc.qt.io/qt-5/model-view-programming.html>` - documentation. - -Implementing the model for your QTableView, allows you to: -- set the headers, -- manipulate the formats of the cell values (remember we have UTC time and float -numbers), -- set style properties like text alignment, -- and even set color properties for the cell or its content. - -To subclass the QAbstractTable, you must reimplement its virtual methods, -rowCount(), columnCount(), and data(). This way, you can ensure that the data -is handled properly. In addition, reimplement the headerData() method to -provide the header information to the view. - -Here is a script that implements the CustomTableModel: - -.. literalinclude:: datavisualize4/table_model.py - :language: python - :linenos: - :lines: 40- - -Now, create a QWidget that has a QTableView, and connect it to your -CustomTableModel. - -.. literalinclude:: datavisualize4/main_widget.py - :language: python - :linenos: - :emphasize-lines: 12-17 - :lines: 40- - -You also need minor changes to the :code:`main_window.py` and -:code:`main.py` from chapter 3 to include the Widget inside the -MainWindow. - -In the following snippets you'll see those changes highlighted: - -.. literalinclude:: datavisualize4/main_window.py - :language: python - :linenos: - :emphasize-lines: 8,11 - -.. literalinclude:: datavisualize4/main.py - :language: python - :linenos: - :emphasize-lines: 46-47 - diff --git a/sources/pyside2/doc/tutorials/datavisualize/all_hour.csv b/sources/pyside2/doc/tutorials/datavisualize/all_hour.csv deleted file mode 100644 index 400947c3c..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/all_hour.csv +++ /dev/null @@ -1,8 +0,0 @@ -time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net,id,updated,place,type,horizontalError,depthError,magError,magNst,status,locationSource,magSource -2019-01-10T12:11:24.810Z,34.1281662,-117.7754974,4.46,1.18,ml,22,69,0.04475,0.13,ci,ci38421072,2019-01-10T12:13:30.138Z,"3km NNW of La Verne, CA",earthquake,0.3,0.55,0.246,6,automatic,ci,ci -2019-01-10T12:04:26.320Z,19.4433327,-155.6159973,0.72,1.79,md,22,99,0.04026,0.3,hv,hv70763571,2019-01-10T12:07:28.690Z,"26km E of Honaunau-Napoopoo, Hawaii",earthquake,0.6,1.79,0.28,6,automatic,hv,hv -2019-01-10T11:57:48.980Z,33.3225,-116.3931667,4.84,0.62,ml,15,211,0.05776,0.16,ci,ci38421064,2019-01-10T12:01:29.166Z,"8km NNW of Borrego Springs, CA",earthquake,0.71,0.68,0.111,11,automatic,ci,ci -2019-01-10T11:52:09.490Z,38.8356667,-122.8366699,1.28,2.74,md,25,77,0.003061,0.04,nc,nc73131566,2019-01-10T12:14:02.757Z,"10km NW of The Geysers, CA",earthquake,0.19,0.29,0.06,7,automatic,nc,nc -2019-01-10T11:25:44.854Z,65.1082,-149.3701,20.6,2.1,ml,,,,1.02,ak,ak019gq2oer,2019-01-10T11:37:07.060Z,"60km NNW of North Nenana, Alaska",earthquake,,0.3,,,automatic,ak,ak -2019-01-10T11:25:23.786Z,69.1518,-144.4977,10.4,3.7,ml,,,,0.74,ak,ak019gq2ndz,2019-01-10T11:47:11.284Z,"114km SSW of Kaktovik, Alaska",earthquake,,1.6,,,reviewed,ak,ak -2019-01-10T11:16:11.761Z,61.3318,-150.0708,20.1,2.7,ml,,,,0.83,ak,ak019gq0ozj,2019-01-10T11:29:24.610Z,"15km NW of Anchorage, Alaska",earthquake,,0.4,,,automatic,ak,ak diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize.tar.bz2 b/sources/pyside2/doc/tutorials/datavisualize/datavisualize.tar.bz2 Binary files differdeleted file mode 100644 index 5fe12769a..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize.tar.bz2 +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize1/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize1/main.py deleted file mode 100644 index 8a8a1dfda..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize1/main.py +++ /dev/null @@ -1,55 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import argparse -import pandas as pd - - -def read_data(fname): - return pd.read_csv(fname) - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - print(data) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize2/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize2/main.py deleted file mode 100644 index 33bd34723..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize2/main.py +++ /dev/null @@ -1,78 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import argparse -import pandas as pd - -from PySide2.QtCore import QDateTime, QTimeZone - - -def transform_date(utc, timezone=None): - utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ" - new_date = QDateTime().fromString(utc, utc_fmt) - if timezone: - new_date.setTimeZone(timezone) - return new_date - - -def read_data(fname): - # Read the CSV content - df = pd.read_csv(fname) - - # Remove wrong magnitudes - df = df.drop(df[df.mag < 0].index) - magnitudes = df["mag"] - - # My local timezone - timezone = QTimeZone(b"Europe/Berlin") - - # Get timestamp transformed to our timezone - times = df["time"].apply(lambda x: transform_date(x, timezone)) - - return times, magnitudes - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - print(data) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main.py deleted file mode 100644 index dd07a689f..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main.py +++ /dev/null @@ -1,88 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -import argparse -import pandas as pd - -from PySide2.QtCore import QDateTime, QTimeZone -from PySide2.QtWidgets import QApplication -from main_window import MainWindow - - -def transform_date(utc, timezone=None): - utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ" - new_date = QDateTime().fromString(utc, utc_fmt) - if timezone: - new_date.setTimeZone(timezone) - return new_date - - -def read_data(fname): - # Read the CSV content - df = pd.read_csv(fname) - - # Remove wrong magnitudes - df = df.drop(df[df.mag < 0].index) - magnitudes = df["mag"] - - # My local timezone - timezone = QTimeZone(b"Europe/Berlin") - - # Get timestamp transformed to our timezone - times = df["time"].apply(lambda x: transform_date(x, timezone)) - - return times, magnitudes - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - - # Qt Application - app = QApplication(sys.argv) - - window = MainWindow() - window.show() - - sys.exit(app.exec_()) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main_window.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main_window.py deleted file mode 100644 index 64f831e5d..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize3/main_window.py +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Slot, qApp -from PySide2.QtGui import QKeySequence -from PySide2.QtWidgets import QMainWindow, QAction - - -class MainWindow(QMainWindow): - def __init__(self): - QMainWindow.__init__(self) - self.setWindowTitle("Eartquakes information") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut(QKeySequence.Quit) - exit_action.triggered.connect(self.close) - - self.file_menu.addAction(exit_action) - - # Status Bar - self.status = self.statusBar() - self.status.showMessage("Data loaded and plotted") - - # Window dimensions - geometry = qApp.desktop().availableGeometry(self) - self.setFixedSize(geometry.width() * 0.8, geometry.height() * 0.7) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main.py deleted file mode 100644 index 43c5cd521..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main.py +++ /dev/null @@ -1,90 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -import argparse -import pandas as pd - -from PySide2.QtCore import QDateTime, QTimeZone -from PySide2.QtWidgets import QApplication -from main_window import MainWindow -from main_widget import Widget - - -def transform_date(utc, timezone=None): - utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ" - new_date = QDateTime().fromString(utc, utc_fmt) - if timezone: - new_date.setTimeZone(timezone) - return new_date - - -def read_data(fname): - # Read the CSV content - df = pd.read_csv(fname) - - # Remove wrong magnitudes - df = df.drop(df[df.mag < 0].index) - magnitudes = df["mag"] - - # My local timezone - timezone = QTimeZone(b"Europe/Berlin") - - # Get timestamp transformed to our timezone - times = df["time"].apply(lambda x: transform_date(x, timezone)) - - return times, magnitudes - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - - # Qt Application - app = QApplication(sys.argv) - - widget = Widget(data) - window = MainWindow(widget) - window.show() - - sys.exit(app.exec_()) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_widget.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_widget.py deleted file mode 100644 index 0c780241a..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_widget.py +++ /dev/null @@ -1,80 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtWidgets import (QHBoxLayout, QHeaderView, QSizePolicy, - QTableView, QWidget) - -from table_model import CustomTableModel - - -class Widget(QWidget): - def __init__(self, data): - QWidget.__init__(self) - - # Getting the Model - self.model = CustomTableModel(data) - - # Creating a QTableView - self.table_view = QTableView() - self.table_view.setModel(self.model) - - # QTableView Headers - self.horizontal_header = self.table_view.horizontalHeader() - self.vertical_header = self.table_view.verticalHeader() - self.horizontal_header.setSectionResizeMode( - QHeaderView.ResizeToContents - ) - self.vertical_header.setSectionResizeMode( - QHeaderView.ResizeToContents - ) - self.horizontal_header.setStretchLastSection(True) - - # QWidget Layout - self.main_layout = QHBoxLayout() - size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - - ## Left layout - size.setHorizontalStretch(1) - self.table_view.setSizePolicy(size) - self.main_layout.addWidget(self.table_view) - - # Set the layout to the QWidget - self.setLayout(self.main_layout) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_window.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_window.py deleted file mode 100644 index 9f7c6814f..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/main_window.py +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Slot, qApp -from PySide2.QtGui import QKeySequence -from PySide2.QtWidgets import QMainWindow, QAction - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Eartquakes information") - self.setCentralWidget(widget) - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - ## Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut(QKeySequence.Quit) - exit_action.triggered.connect(self.close) - - self.file_menu.addAction(exit_action) - - # Status Bar - self.status = self.statusBar() - self.status.showMessage("Data loaded and plotted") - - # Window dimensions - geometry = qApp.desktop().availableGeometry(self) - self.setFixedSize(geometry.width() * 0.8, geometry.height() * 0.7) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/table_model.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/table_model.py deleted file mode 100644 index d2eafb244..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize4/table_model.py +++ /dev/null @@ -1,88 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Qt, QAbstractTableModel, QModelIndex -from PySide2.QtGui import QColor - - -class CustomTableModel(QAbstractTableModel): - def __init__(self, data=None): - QAbstractTableModel.__init__(self) - self.load_data(data) - - def load_data(self, data): - self.input_dates = data[0].values - self.input_magnitudes = data[1].values - - self.column_count = 2 - self.row_count = len(self.input_magnitudes) - - def rowCount(self, parent=QModelIndex()): - return self.row_count - - def columnCount(self, parent=QModelIndex()): - return self.column_count - - def headerData(self, section, orientation, role): - if role != Qt.DisplayRole: - return None - if orientation == Qt.Horizontal: - return ("Date", "Magnitude")[section] - else: - return "{}".format(section) - - def data(self, index, role=Qt.DisplayRole): - column = index.column() - row = index.row() - - if role == Qt.DisplayRole: - if column == 0: - raw_date = self.input_dates[row] - date = "{}".format(raw_date.toPython()) - return date[:-3] - elif column == 1: - return "{:.2f}".format(self.input_magnitudes[row]) - elif role == Qt.BackgroundRole: - return QColor(Qt.white) - elif role == Qt.TextAlignmentRole: - return Qt.AlignRight - - return None - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main.py deleted file mode 100644 index 43c5cd521..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main.py +++ /dev/null @@ -1,90 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -import argparse -import pandas as pd - -from PySide2.QtCore import QDateTime, QTimeZone -from PySide2.QtWidgets import QApplication -from main_window import MainWindow -from main_widget import Widget - - -def transform_date(utc, timezone=None): - utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ" - new_date = QDateTime().fromString(utc, utc_fmt) - if timezone: - new_date.setTimeZone(timezone) - return new_date - - -def read_data(fname): - # Read the CSV content - df = pd.read_csv(fname) - - # Remove wrong magnitudes - df = df.drop(df[df.mag < 0].index) - magnitudes = df["mag"] - - # My local timezone - timezone = QTimeZone(b"Europe/Berlin") - - # Get timestamp transformed to our timezone - times = df["time"].apply(lambda x: transform_date(x, timezone)) - - return times, magnitudes - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - - # Qt Application - app = QApplication(sys.argv) - - widget = Widget(data) - window = MainWindow(widget) - window.show() - - sys.exit(app.exec_()) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_widget.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_widget.py deleted file mode 100644 index 08406d341..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_widget.py +++ /dev/null @@ -1,91 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import QDateTime, Qt -from PySide2.QtGui import QPainter -from PySide2.QtWidgets import (QWidget, QHeaderView, QHBoxLayout, QTableView, - QSizePolicy) -from PySide2.QtCharts import QtCharts - -from table_model import CustomTableModel - - -class Widget(QWidget): - def __init__(self, data): - QWidget.__init__(self) - - # Getting the Model - self.model = CustomTableModel(data) - - # Creating a QTableView - self.table_view = QTableView() - self.table_view.setModel(self.model) - - # QTableView Headers - self.horizontal_header = self.table_view.horizontalHeader() - self.vertical_header = self.table_view.verticalHeader() - self.horizontal_header.setSectionResizeMode(QHeaderView.ResizeToContents) - self.vertical_header.setSectionResizeMode(QHeaderView.ResizeToContents) - self.horizontal_header.setStretchLastSection(True) - - # Creating QChart - self.chart = QtCharts.QChart() - self.chart.setAnimationOptions(QtCharts.QChart.AllAnimations) - - # Creating QChartView - self.chart_view = QtCharts.QChartView(self.chart) - self.chart_view.setRenderHint(QPainter.Antialiasing) - - # QWidget Layout - self.main_layout = QHBoxLayout() - size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - - ## Left layout - size.setHorizontalStretch(1) - self.table_view.setSizePolicy(size) - self.main_layout.addWidget(self.table_view) - - ## Right Layout - size.setHorizontalStretch(4) - self.chart_view.setSizePolicy(size) - self.main_layout.addWidget(self.chart_view) - - # Set the layout to the QWidget - self.setLayout(self.main_layout) diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_window.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_window.py deleted file mode 100644 index 4786365e8..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/main_window.py +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Slot, qApp -from PySide2.QtGui import QKeySequence -from PySide2.QtWidgets import QMainWindow, QAction - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Eartquakes information") - self.setCentralWidget(widget) - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut(QKeySequence.Quit) - exit_action.triggered.connect(self.close) - - self.file_menu.addAction(exit_action) - - # Status Bar - self.status = self.statusBar() - self.status.showMessage("Data loaded and plotted") - - # Window dimensions - geometry = qApp.desktop().availableGeometry(self) - self.setFixedSize(geometry.width() * 0.8, geometry.height() * 0.7) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/table_model.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/table_model.py deleted file mode 100644 index d2eafb244..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize5/table_model.py +++ /dev/null @@ -1,88 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Qt, QAbstractTableModel, QModelIndex -from PySide2.QtGui import QColor - - -class CustomTableModel(QAbstractTableModel): - def __init__(self, data=None): - QAbstractTableModel.__init__(self) - self.load_data(data) - - def load_data(self, data): - self.input_dates = data[0].values - self.input_magnitudes = data[1].values - - self.column_count = 2 - self.row_count = len(self.input_magnitudes) - - def rowCount(self, parent=QModelIndex()): - return self.row_count - - def columnCount(self, parent=QModelIndex()): - return self.column_count - - def headerData(self, section, orientation, role): - if role != Qt.DisplayRole: - return None - if orientation == Qt.Horizontal: - return ("Date", "Magnitude")[section] - else: - return "{}".format(section) - - def data(self, index, role=Qt.DisplayRole): - column = index.column() - row = index.row() - - if role == Qt.DisplayRole: - if column == 0: - raw_date = self.input_dates[row] - date = "{}".format(raw_date.toPython()) - return date[:-3] - elif column == 1: - return "{:.2f}".format(self.input_magnitudes[row]) - elif role == Qt.BackgroundRole: - return QColor(Qt.white) - elif role == Qt.TextAlignmentRole: - return Qt.AlignRight - - return None - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main.py deleted file mode 100644 index 441d81a32..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main.py +++ /dev/null @@ -1,92 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -import argparse -import pandas as pd - -from PySide2.QtCore import QDateTime, QTimeZone -from PySide2.QtWidgets import QApplication - -from main_window import MainWindow -from main_widget import Widget - - -def transform_date(utc, timezone=None): - utc_fmt = "yyyy-MM-ddTHH:mm:ss.zzzZ" - new_date = QDateTime().fromString(utc, utc_fmt) - if timezone: - new_date.setTimeZone(timezone) - return new_date - - -def read_data(fname): - # Read the CSV content - df = pd.read_csv(fname) - - # Remove wrong magnitudes - df = df.drop(df[df.mag < 0].index) - magnitudes = df["mag"] - - # My local timezone - timezone = QTimeZone(b"Europe/Berlin") - - # Get timestamp transformed to our timezone - times = df["time"].apply(lambda x: transform_date(x, timezone)) - - return times, magnitudes - - -if __name__ == "__main__": - options = argparse.ArgumentParser() - options.add_argument("-f", "--file", type=str, required=True) - args = options.parse_args() - data = read_data(args.file) - - # Qt Application - app = QApplication(sys.argv) - - # QWidget - widget = Widget(data) - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - - window.show() - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_widget.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_widget.py deleted file mode 100644 index 2d2452bf9..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_widget.py +++ /dev/null @@ -1,131 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import QDateTime, Qt -from PySide2.QtGui import QPainter -from PySide2.QtWidgets import (QWidget, QHeaderView, QHBoxLayout, QTableView, - QSizePolicy) -from PySide2.QtCharts import QtCharts - -from table_model import CustomTableModel - - -class Widget(QWidget): - def __init__(self, data): - QWidget.__init__(self) - - # Getting the Model - self.model = CustomTableModel(data) - - # Creating a QTableView - self.table_view = QTableView() - self.table_view.setModel(self.model) - - # QTableView Headers - resize = QHeaderView.ResizeToContents - self.horizontal_header = self.table_view.horizontalHeader() - self.vertical_header = self.table_view.verticalHeader() - self.horizontal_header.setSectionResizeMode(resize) - self.vertical_header.setSectionResizeMode(resize) - self.horizontal_header.setStretchLastSection(True) - - # Creating QChart - self.chart = QtCharts.QChart() - self.chart.setAnimationOptions(QtCharts.QChart.AllAnimations) - self.add_series("Magnitude (Column 1)", [0, 1]) - - # Creating QChartView - self.chart_view = QtCharts.QChartView(self.chart) - self.chart_view.setRenderHint(QPainter.Antialiasing) - - # QWidget Layout - self.main_layout = QHBoxLayout() - size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - - # Left layout - size.setHorizontalStretch(1) - self.table_view.setSizePolicy(size) - self.main_layout.addWidget(self.table_view) - - # Right Layout - size.setHorizontalStretch(4) - self.chart_view.setSizePolicy(size) - self.main_layout.addWidget(self.chart_view) - - # Set the layout to the QWidget - self.setLayout(self.main_layout) - - def add_series(self, name, columns): - # Create QLineSeries - self.series = QtCharts.QLineSeries() - self.series.setName(name) - - # Filling QLineSeries - for i in range(self.model.rowCount()): - # Getting the data - t = self.model.index(i, 0).data() - date_fmt = "yyyy-MM-dd HH:mm:ss.zzz" - - x = QDateTime().fromString(t, date_fmt).toSecsSinceEpoch() - y = float(self.model.index(i, 1).data()) - - if x > 0 and y > 0: - self.series.append(x, y) - - self.chart.addSeries(self.series) - - # Setting X-axis - self.axis_x = QtCharts.QDateTimeAxis() - self.axis_x.setTickCount(10) - self.axis_x.setFormat("dd.MM (h:mm)") - self.axis_x.setTitleText("Date") - self.chart.addAxis(self.axis_x, Qt.AlignBottom) - self.series.attachAxis(self.axis_x) - # Setting Y-axis - self.axis_y = QtCharts.QValueAxis() - self.axis_y.setTickCount(10) - self.axis_y.setLabelFormat("%.2f") - self.axis_y.setTitleText("Magnitude") - self.chart.addAxis(self.axis_y, Qt.AlignLeft) - self.series.attachAxis(self.axis_y) - - # Getting the color from the QChart to use it on the QTableView - self.model.color = "{}".format(self.series.pen().color().name()) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_window.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_window.py deleted file mode 100644 index c223aa69b..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/main_window.py +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Slot, qApp -from PySide2.QtGui import QKeySequence -from PySide2.QtWidgets import QMainWindow, QAction - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Eartquakes information") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut(QKeySequence.Quit) - exit_action.triggered.connect(self.close) - - self.file_menu.addAction(exit_action) - - # Status Bar - self.status = self.statusBar() - self.status.showMessage("Data loaded and plotted") - - # Window dimensions - geometry = qApp.desktop().availableGeometry(self) - self.setFixedSize(geometry.width() * 0.8, geometry.height() * 0.7) - self.setCentralWidget(widget) - diff --git a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/table_model.py b/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/table_model.py deleted file mode 100644 index 99e1cf19b..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/datavisualize6/table_model.py +++ /dev/null @@ -1,88 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -from PySide2.QtCore import Qt, QAbstractTableModel, QModelIndex -from PySide2.QtGui import QColor - - -class CustomTableModel(QAbstractTableModel): - def __init__(self, data=None): - QAbstractTableModel.__init__(self) - self.color = None - self.load_data(data) - - def load_data(self, data): - self.input_dates = data[0].values - self.input_magnitudes = data[1].values - - self.column_count = 2 - self.row_count = len(self.input_magnitudes) - - def rowCount(self, parent=QModelIndex()): - return self.row_count - - def columnCount(self, parent=QModelIndex()): - return self.column_count - - def headerData(self, section, orientation, role): - if role != Qt.DisplayRole: - return None - if orientation == Qt.Horizontal: - return ("Date", "Magnitude")[section] - else: - return "{}".format(section) - - def data(self, index, role=Qt.DisplayRole): - column = index.column() - row = index.row() - - if role == Qt.DisplayRole: - if column == 0: - raw_date = self.input_dates[row] - date = "{}".format(raw_date.toPython()) - return date[:-3] - elif column == 1: - return "{:.2f}".format(self.input_magnitudes[row]) - elif role == Qt.BackgroundRole: - return (QColor(Qt.white), QColor(self.color))[column] - elif role == Qt.TextAlignmentRole: - return Qt.AlignRight - - return None diff --git a/sources/pyside2/doc/tutorials/datavisualize/filter_data.rst b/sources/pyside2/doc/tutorials/datavisualize/filter_data.rst deleted file mode 100644 index f54ba217c..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/filter_data.rst +++ /dev/null @@ -1,30 +0,0 @@ -Chapter 2 - Filtering data -=========================== - -In the previous chapter, you learned how to read and print data that is a -bit raw. Now, try to select a few columns and handle them properly. - -Start with these two columns: Time (time) and Magnitude (mag). After getting -the information from these columns, filter and adapt the data. Try formatting -the date to Qt types. - -There is not much to do for the Magnitude column, as it's just a floating point -number. You could take special care to check if the data is correct. This could -be done by filtering the data that follows the condition, "magnitude > 0", to -avoid faulty data or unexpected behavior. - -The Date column provides data in UTC format (for example, -2018-12-11T21:14:44.682Z), so you could easily map it to a QDateTime object -defining the structure of the string. Additionally, you can adapt the time -based on the timezone you are in, using QTimeZone. - -The following script filters and formats the CSV data as described earlier: - -.. literalinclude:: datavisualize2/main.py - :language: python - :linenos: - :emphasize-lines: 44,47-69 - :lines: 40- - -Now that you have a tuple of QDateTime and float data, try improving the -output further. That's what you'll learn in the following chapters. diff --git a/sources/pyside2/doc/tutorials/datavisualize/images/QMainWindow-layout.png b/sources/pyside2/doc/tutorials/datavisualize/images/QMainWindow-layout.png Binary files differdeleted file mode 100644 index 075d796b8..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/images/QMainWindow-layout.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/datavisualize/images/datavisualization_app.png b/sources/pyside2/doc/tutorials/datavisualize/images/datavisualization_app.png Binary files differdeleted file mode 100644 index ddac43fc3..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/images/datavisualization_app.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/datavisualize/index.rst b/sources/pyside2/doc/tutorials/datavisualize/index.rst deleted file mode 100644 index ff18c654e..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/index.rst +++ /dev/null @@ -1,26 +0,0 @@ -Data Visualization Tool Tutorial -********************************* - -In this tutorial, you'll learn about the data visualization capabilities -of |project|. To start with, find some open data to visualize. For example, -data about the magnitude of earthquakes during the last hour published on the -US Geological Survey website. You could download the -`All earthquakes <https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.csv>`_ -open data in a CSV format for this tutorial. - -In the following chapters of this tutorial you'll learn how to -visualize data from a CSV in a line chart. - -.. toctree:: - :glob: - :titlesonly: - - read* - filter* - add_main* - add_tab* - add_chart* - plot* - -You can download the sources from :download:`here <datavisualize.tar.bz2>`. - diff --git a/sources/pyside2/doc/tutorials/datavisualize/plot_datapoints.rst b/sources/pyside2/doc/tutorials/datavisualize/plot_datapoints.rst deleted file mode 100644 index 8ebdd2b08..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/plot_datapoints.rst +++ /dev/null @@ -1,25 +0,0 @@ -Chapter 6 - Plot the data in the ChartView -=========================================== - -The last step of this tutorial is to plot the CSV data inside our QChart. For -this, you need to go over our data and include the data on a QLineSeries. - -After adding the data to the series, you can modify the axis to properly -display the QDateTime on the X-axis, and the magnitude values on the Y-axis. - -Here is the updated :code:`main_widget.py` that includes an additional -function to plot data using a QLineSeries: - -.. literalinclude:: datavisualize6/main_widget.py - :language: python - :linenos: - :lines: 40- - :emphasize-lines: 33,56-91 - -Now, run the application to visualize the earthquake magnitudes -data at different times. - -.. image:: images/datavisualization_app.png - -Try modifying the sources to get different output. For example, you could try -to plot more data from the CSV. diff --git a/sources/pyside2/doc/tutorials/datavisualize/read_data.rst b/sources/pyside2/doc/tutorials/datavisualize/read_data.rst deleted file mode 100644 index f7bf9337a..000000000 --- a/sources/pyside2/doc/tutorials/datavisualize/read_data.rst +++ /dev/null @@ -1,41 +0,0 @@ -Chapter 1 - Reading data from a CSV -=================================== - -There are several ways to read data from a CSV file. The following are the most -common ways: - -- Native reading -- the `CSV module <https://docs.python.org/3/library/csv.html>`_ -- the `numpy module <https://www.numpy.org>`_ -- the `pandas module <https://pandas.pydata.org/>`_ - -In this chapter, you will learn to use pandas to read and filter CSV data. -In addition, you could pass the data file through a command-line option to your -script. - -The following python script, :code:`main.py`, demonstrates how to do it: - -.. literalinclude:: datavisualize1/main.py - :language: python - :linenos: - :lines: 40- - -The Python script uses the :code:`argparse` module to accept and parse input -from the command line. It then uses the input, which in this case is the filename, -to read and print data to the prompt. - -Try running the script in the following way to check if you get desired output: - -:: - - $python datavisualize1/main.py -f all_hour.csv - time latitude longitude depth ... magNst status locationSource magSource - 0 2019-01-10T12:11:24.810Z 34.128166 -117.775497 4.46 ... 6.0 automatic ci ci - 1 2019-01-10T12:04:26.320Z 19.443333 -155.615997 0.72 ... 6.0 automatic hv hv - 2 2019-01-10T11:57:48.980Z 33.322500 -116.393167 4.84 ... 11.0 automatic ci ci - 3 2019-01-10T11:52:09.490Z 38.835667 -122.836670 1.28 ... 7.0 automatic nc nc - 4 2019-01-10T11:25:44.854Z 65.108200 -149.370100 20.60 ... NaN automatic ak ak - 5 2019-01-10T11:25:23.786Z 69.151800 -144.497700 10.40 ... NaN reviewed ak ak - 6 2019-01-10T11:16:11.761Z 61.331800 -150.070800 20.10 ... NaN automatic ak ak - - [7 rows x 22 columns] diff --git a/sources/pyside2/doc/tutorials/examples/images/tabbedbrowser.png b/sources/pyside2/doc/tutorials/examples/images/tabbedbrowser.png Binary files differdeleted file mode 100644 index 27c3daa09..000000000 --- a/sources/pyside2/doc/tutorials/examples/images/tabbedbrowser.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/examples/tabbedbrowser.rst b/sources/pyside2/doc/tutorials/examples/tabbedbrowser.rst deleted file mode 100644 index c34c50647..000000000 --- a/sources/pyside2/doc/tutorials/examples/tabbedbrowser.rst +++ /dev/null @@ -1,58 +0,0 @@ -********************** -Web Browser Example -********************** - -The example demonstrates the power and simplicity offered by |project| to developers. -It uses several |pymodname| submodules to offer a fluid and modern-looking UI that -is apt for a web browser. The application offers the following features: - - * Tab-based browsing experience using QTabWidget. - * Download manager using a QProgressBar and QWebEngineDownloadItem. - * Bookmark manager using QTreeView. - -.. image:: images/tabbedbrowser.png - -The application's code is organized in several parts for ease of maintenance. For example, -:code:`DownloadWidget` provides a widget to track progress of a download item. In the following -sections, these different parts are discussed briefly to help you understand the Python code behind -them a little better. - -BookmarkWidget or :code:`bookmarkwidget.py` -=========================================== - -This widget docks to the left of the main window by default. It inherits QTreeView and -loads a default set of bookmarks using a QStandardItemModel. The model is populated at startup -from a JSON file, which is updated when you add or remove bookmarks from the tree view. - -.. automodule:: bookmarkwidget - :members: - -DownloadWidget or :code:`downloadwidget.py` -============================================= - -The widget tracks progress of the download item. It inherits QProgressBar to display -progress of the QWebEngineDownloadItem instance, and offers a context-menu with actions such as Launch, -Show in folder, Cancel, and Remove. - -.. automodule:: downloadwidget - :members: - -BrowserTabWidget or :code:`browsertabwidget.py` -=============================================== - -The widget includes a QWebEngineView to enable viewing web content. It docks to the right -of BookmarkWidget in the main window. - -.. automodule:: browsertabwidget - :members: - -MainWindow or :code:`main.py` -============================= - -This is the parent window that collates all the other widgets together to offer the complete package. - -.. automodule:: main - :members: - - -Try running the example to explore it further. diff --git a/sources/pyside2/doc/tutorials/expenses/expenses.rst b/sources/pyside2/doc/tutorials/expenses/expenses.rst deleted file mode 100644 index c34d18669..000000000 --- a/sources/pyside2/doc/tutorials/expenses/expenses.rst +++ /dev/null @@ -1,313 +0,0 @@ -###################### -Expenses Tool Tutorial -###################### - -In this tutorial you will learn the following concepts: -* creating user interfaces programatically, -* layouts and widgets, -* overloading Qt classes, -* connecting signal and slots, -* interacting with QWidgets, -* and building your own application. - -The requirements: - * A simple window for the application - (`QMainWindow <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QMainWindow.html>`_). - * A table to keep track of the expenses - (`QTableWidget <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QTableWidget.html>`_). - * Two input fields to add expense information - (`QLineEdit <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLineEdit.html>`_). - * Buttons to add information to the table, plot data, clear table, and exit the application - (`QPushButton <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QPushButton.html>`_). - * A verification step to avoid invalid data entry. - * A chart to visualize the expense data - (`QChart <https://doc.qt.io/qtforpython/PySide2/QtCharts/QtCharts.QChart.html>`_) that will - be embedded in a chart view - (`QChartView <https://doc.qt.io/qtforpython/PySide2/QtCharts/QtCharts.QChartView.html>`_). - -Empty window ------------- - -The base structure for a `QApplication` is located inside the `if __name__ == "__main__":` -code block. - - .. code:: - - if __name__ == "__main__": - app = QApplication([]) - # ... - sys.exit(app.exec_()) - -Now, to start the development, create an empty window called `MainWindow`. -You could do that by defining a class that inherits from `QMainWindow`. - - .. literalinclude:: steps/01-expenses.py - :linenos: - :lines: 45-59 - :emphasize-lines: 45-48 - -Now that our class is defined, create an instance of it and call `show()`. - - .. literalinclude:: steps/01-expenses.py - :linenos: - :lines: 45-59 - :emphasize-lines: 54-56 - -Menu bar --------- - -Using a `QMainWindow` gives some features for free, among them a *menu bar*. To use it, you need -to call the method `menuBar()` and populate it inside the `MainWindow` class. - - .. literalinclude:: steps/02-expenses.py - :linenos: - :lines: 46-58 - :emphasize-lines: 51 - -Notice that the code snippet adds a *File* menu with the *Exit* option only. - -First signal/slot connection ----------------------------- - -The *Exit* option must be connected to a slot that triggers the application to exit. The main -idea to achieve this, is the following: - - .. code:: - - element.signal_name.connect(slot_name) - -All the interface's elements could be connected through signals to certain slots, -in the case of a `QAction`, the signal `triggered` can be used: - - .. code:: - - exit_action.triggered.connect(slot_name) - -.. note:: Now a *slot* needs to be defined to exit the application, which can be done using - `QApplication.quit()`. If we put all these concepts together you will end up with the - following code: - - .. literalinclude:: steps/03-expenses.py - :linenos: - :lines: 56-65 - :emphasize-lines: 59, 63-65 - -Notice that the decorator `@Slot()` is required for each slot you declare to properly -register them. Slots are normal functions, but the main difference is that they -will be invokable from `Signals` of QObjects when connected. - -Empty widget and data ---------------------- - -The `QMainWindow` enables us to set a central widget that will be displayed when showing the window -(`read more <https://doc.qt.io/qt-5/qmainwindow.html#details>`_). -This central widget could be another class derived from `QWidget`. - -Additionally, you will define example data to visualize later. - - .. literalinclude:: steps/04-expenses.py - :linenos: - :lines: 46-53 - -With the `Widget` class in place, modify `MainWindow`'s initialization code - - .. literalinclude:: steps/04-expenses.py - :linenos: - :lines: 80-84 - -Window layout -------------- - -Now that the main empty window is in place, you need to start adding widgets to achieve the main -goal of creating an expenses application. - -After declaring the example data, you can visualize it on a simple `QTableWidget`. To do so, you -will add this procedure to the `Widget` constructor. - - .. warning:: Only for the example purpose a QTableWidget will be used, - but for more performance-critical applications the combination - of a model and a QTableView is encouraged. - - .. literalinclude:: steps/05-expenses.py - :linenos: - :lines: 48-73 - -As you can see, the code also includes a `QHBoxLayout` that provides the container to place widgets -horizontally. - -Additionally, the `QTableWidget` allows for customizing it, like adding the labels for the two -columns that will be used, and to *stretch* the content to use the whole `Widget` space. - -The last line of code refers to *filling the table**, and the code to perform that task is -displayed below. - - .. literalinclude:: steps/05-expenses.py - :linenos: - :lines: 75-81 - -Having this process on a separate method is a good practice to leave the constructor more readable, -and to split the main functions of the class in independent processes. - - -Right side layout ------------------ - -Because the data that is being used is just an example, you are required to include a mechanism to -input items to the table, and extra buttons to clear the table's content, and also quit the -application. - -To distribute these input lines and buttons, you will use a `QVBoxLayout` that allows you to place -elements vertically inside a layout. - - .. literalinclude:: steps/06-expenses.py - :linenos: - :lines: 64-80 - -Leaving the table on the left side and these newly included widgets to the right side -will be just a matter to add a layout to our main `QHBoxLayout` as you saw in the previous -example: - - .. literalinclude:: steps/06-expenses.py - :linenos: - :lines: 42-47 - -The next step will be connecting those new buttons to slots. - - -Adding elements ---------------- - -Each `QPushButton` have a signal called *clicked*, that is emitted when you click on the button. -This will be more than enough for this example, but you can see other signals in the `official -documentation <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QAbstractButton.html#signals>`_. - - .. literalinclude:: steps/07-expenses.py - :linenos: - :lines: 92-95 - -As you can see on the previous lines, we are connecting each *clicked* signal to different slots. -In this example slots are normal class methods in charge of perform a determined task associated -with our buttons. It is really important to decorate each method declaration with a `@Slot()`, in -that way PySide2 knows internally how to register them into Qt. - - .. literalinclude:: steps/07-expenses.py - :linenos: - :lines: 1000-129 - :emphasize-lines: 101,115,127 - -Since these slots are methods, we can access the class variables, like our `QTableWidget` to -interact with it. - -The mechanism to add elements into the table is described as the following: - - * get the *description* and *price* from the fields, - * insert a new empty row to the table, - * set the values for the empty row in each column, - * clear the input text fields, - * include the global count of table rows. - -To exit the application you can use the `quit()` method of the unique `QApplication` instance, and -to clear the content of the table you can just set the table *row count*, and the internal count to -zero. - -Verification step ------------------ - -Adding information to the table needs to be a critical action that require a verification step -to avoid adding invalid information, for example, empty information. - -You can use a signal from `QLineEdit` called *textChanged[str]* which will be emitted every -time something inside changes, i.e.: each key stroke. -Notice that this time, there is a *[str]* section on the signal, this means that the signal -will also emit the value of the text that was changed, which will be really useful to verify -the current content of the `QLineEdit`. - -You can connect two different object's signal to the same slot, and this will be the case -for your current application: - - .. literalinclude:: steps/08-expenses.py - :linenos: - :lines: 99-100 - -The content of the *check_disable* slot will be really simple: - - .. literalinclude:: steps/08-expenses.py - :linenos: - :lines: 119-124 - -You have two options, write a verification based on the current value -of the string you retrieve, or manually get the whole content of both -`QLineEdit`. The second is preferred in this case, so you can verify -if the two inputs are not empty to enable the button *Add*. - -.. note:: Qt also provides a special class called - `QValidator <https://doc.qt.io/qtforpython/PySide2/QtGui/QValidator.html?highlight=qvalidator>`_ - that you can use to validate any input. - -Empty chart view ----------------- - -New items can be added to the table, and the visualization is so far -OK, but you can accomplish more by representing the data graphically. - -First you will include an empty `QChartView` placeholder into the right -side of your application. - - .. literalinclude:: steps/09-expenses.py - :linenos: - :lines: 66-68 - -Additionally the order of how you include widgets to the right -`QVBoxLayout` will also change. - - .. literalinclude:: steps/09-expenses.py - :linenos: - :lines: 81-91 - :emphasize-lines: 89 - -Notice that before we had a line with `self.right.addStretch()` -to fill up the vertical space between the *Add* and the *Clear* buttons, -but now, with the `QChartView` it will not be necessary. - -Also, you need include a *Plot* button if you want to do it on-demand. - -Full application ----------------- - -For the final step, you will need to connect the *Plot* button -to a slot that creates a chart and includes it into your `QChartView`. - - .. literalinclude:: steps/10-expenses.py - :linenos: - :lines: 103-109 - :emphasize-lines: 106 - -That is nothing new, since you already did it for the other buttons, -but now take a look at how to create a chart and include it into -your `QChartView`. - - .. literalinclude:: steps/10-expenses.py - :linenos: - :lines: 139-151 - -The following steps show how to fill a `QPieSeries`: - - * create a `QPieSeries`, - * iterate over the table row IDs, - * get the items at the *i* position, - * add those values to the *series*. - -Once the series has been populated with our data, you create a new `QChart`, -add the series on it, and optionally set an alignment for the legend. - -The final line `self.chart_view.setChart(chart)` is in charge of bringing -your newly created chart to the `QChartView`. - -The application will look like this: - - .. image:: expenses_tool.png - -And now you can see the whole code: - - .. literalinclude:: main.py - :linenos: diff --git a/sources/pyside2/doc/tutorials/expenses/expenses_tool.png b/sources/pyside2/doc/tutorials/expenses/expenses_tool.png Binary files differdeleted file mode 100644 index 7a6f6d1f0..000000000 --- a/sources/pyside2/doc/tutorials/expenses/expenses_tool.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/expenses/main.py b/sources/pyside2/doc/tutorials/expenses/main.py deleted file mode 100644 index 6cc911671..000000000 --- a/sources/pyside2/doc/tutorials/expenses/main.py +++ /dev/null @@ -1,207 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Qt, Slot -from PySide2.QtGui import QPainter -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) -from PySide2.QtCharts import QtCharts - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Chart - self.chart_view = QtCharts.QChartView() - self.chart_view.setRenderHint(QPainter.Antialiasing) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - self.plot = QPushButton("Plot") - - # Disabling 'Add' button - self.add.setEnabled(False) - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addWidget(self.plot) - self.right.addWidget(self.chart_view) - self.right.addWidget(self.clear) - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Signals and Slots - self.add.clicked.connect(self.add_element) - self.quit.clicked.connect(self.quit_application) - self.plot.clicked.connect(self.plot_data) - self.clear.clicked.connect(self.clear_table) - self.description.textChanged[str].connect(self.check_disable) - self.price.textChanged[str].connect(self.check_disable) - - # Fill example data - self.fill_table() - - @Slot() - def add_element(self): - des = self.description.text() - price = self.price.text() - - self.table.insertRow(self.items) - description_item = QTableWidgetItem(des) - price_item = QTableWidgetItem("{:.2f}".format(float(price))) - price_item.setTextAlignment(Qt.AlignRight) - - self.table.setItem(self.items, 0, description_item) - self.table.setItem(self.items, 1, price_item) - - self.description.setText("") - self.price.setText("") - - self.items += 1 - - @Slot() - def check_disable(self, s): - if not self.description.text() or not self.price.text(): - self.add.setEnabled(False) - else: - self.add.setEnabled(True) - - @Slot() - def plot_data(self): - # Get table information - series = QtCharts.QPieSeries() - for i in range(self.table.rowCount()): - text = self.table.item(i, 0).text() - number = float(self.table.item(i, 1).text()) - series.append(text, number) - - chart = QtCharts.QChart() - chart.addSeries(series) - chart.legend().setAlignment(Qt.AlignLeft) - self.chart_view.setChart(chart) - - @Slot() - def quit_application(self): - QApplication.quit() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - description_item = QTableWidgetItem(desc) - price_item = QTableWidgetItem("{:.2f}".format(price)) - price_item.setTextAlignment(Qt.AlignRight) - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, description_item) - self.table.setItem(self.items, 1, price_item) - self.items += 1 - - @Slot() - def clear_table(self): - self.table.setRowCount(0) - self.items = 0 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/01-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/01-expenses.py deleted file mode 100644 index 12d5f0b1a..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/01-expenses.py +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtWidgets import QApplication, QMainWindow - - -class MainWindow(QMainWindow): - def __init__(self): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - - window = MainWindow() - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/02-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/02-expenses.py deleted file mode 100644 index 0546bc9f3..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/02-expenses.py +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtWidgets import QAction, QApplication, QMainWindow - - -class MainWindow(QMainWindow): - def __init__(self): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - - self.file_menu.addAction(exit_action) - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - - window = MainWindow() - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/03-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/03-expenses.py deleted file mode 100644 index bc753309f..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/03-expenses.py +++ /dev/null @@ -1,77 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import QAction, QApplication, QMainWindow -from PySide2.QtCharts import QtCharts - - -class MainWindow(QMainWindow): - def __init__(self): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - - window = MainWindow() - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/04-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/04-expenses.py deleted file mode 100644 index 78e9b1d1d..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/04-expenses.py +++ /dev/null @@ -1,89 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import QAction, QApplication, QMainWindow, QWidget - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/05-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/05-expenses.py deleted file mode 100644 index 6fd515f40..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/05-expenses.py +++ /dev/null @@ -1,117 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QMainWindow, - QTableWidget, QTableWidgetItem, QWidget) - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Fill example data - self.fill_table() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(desc)) - self.table.setItem(self.items, 1, QTableWidgetItem(str(price))) - self.items += 1 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/06-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/06-expenses.py deleted file mode 100644 index 38fa881bf..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/06-expenses.py +++ /dev/null @@ -1,137 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addStretch() - self.right.addWidget(self.clear) - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Fill example data - self.fill_table() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(desc)) - self.table.setItem(self.items, 1, QTableWidgetItem(str(price))) - self.items += 1 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/07-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/07-expenses.py deleted file mode 100644 index 6b915806d..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/07-expenses.py +++ /dev/null @@ -1,164 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addStretch() - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Signals and Slots - self.add.clicked.connect(self.add_element) - self.quit.clicked.connect(self.quit_application) - self.clear.clicked.connect(self.clear_table) - - # Fill example data - self.fill_table() - - @Slot() - def add_element(self): - des = self.description.text() - price = self.price.text() - - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(des)) - self.table.setItem(self.items, 1, QTableWidgetItem(price)) - - self.description.setText("") - self.price.setText("") - - self.items += 1 - - @Slot() - def quit_application(self): - QApplication.quit() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(desc)) - self.table.setItem(self.items, 1, QTableWidgetItem(str(price))) - self.items += 1 - - @Slot() - def clear_table(self): - self.table.setRowCount(0) - self.items = 0 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/08-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/08-expenses.py deleted file mode 100644 index 2f18dff9f..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/08-expenses.py +++ /dev/null @@ -1,177 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - - # Disabling 'Add' button - self.add.setEnabled(False) - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addStretch() - self.right.addWidget(self.clear) - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Signals and Slots - self.add.clicked.connect(self.add_element) - self.quit.clicked.connect(self.quit_application) - self.clear.clicked.connect(self.clear_table) - self.description.textChanged[str].connect(self.check_disable) - self.price.textChanged[str].connect(self.check_disable) - - # Fill example data - self.fill_table() - - @Slot() - def add_element(self): - des = self.description.text() - price = self.price.text() - - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(des)) - self.table.setItem(self.items, 1, QTableWidgetItem(price)) - - self.description.setText("") - self.price.setText("") - - self.items += 1 - - @Slot() - def check_disable(self, s): - if not self.description.text() or not self.price.text(): - self.add.setEnabled(False) - else: - self.add.setEnabled(True) - - @Slot() - def quit_application(self): - QApplication.quit() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(desc)) - self.table.setItem(self.items, 1, QTableWidgetItem(str(price))) - self.items += 1 - - @Slot() - def clear_table(self): - self.table.setRowCount(0) - self.items = 0 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/09-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/09-expenses.py deleted file mode 100644 index 6b5d87e2e..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/09-expenses.py +++ /dev/null @@ -1,185 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Slot -from PySide2.QtGui import QPainter -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) -from PySide2.QtCharts import QtCharts - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Chart - self.chart_view = QtCharts.QChartView() - self.chart_view.setRenderHint(QPainter.Antialiasing) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - self.plot = QPushButton("Plot") - - # Disabling 'Add' button - self.add.setEnabled(False) - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addWidget(self.plot) - self.right.addWidget(self.chart_view) - self.right.addWidget(self.clear) - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Signals and Slots - self.add.clicked.connect(self.add_element) - self.quit.clicked.connect(self.quit_application) - self.clear.clicked.connect(self.clear_table) - self.description.textChanged[str].connect(self.check_disable) - self.price.textChanged[str].connect(self.check_disable) - - # Fill example data - self.fill_table() - - @Slot() - def add_element(self): - des = self.description.text() - price = self.price.text() - - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(des)) - self.table.setItem(self.items, 1, QTableWidgetItem(price)) - - self.description.setText("") - self.price.setText("") - - self.items += 1 - - @Slot() - def check_disable(self, s): - if not self.description.text() or not self.price.text(): - self.add.setEnabled(False) - else: - self.add.setEnabled(True) - - @Slot() - def quit_application(self): - QApplication.quit() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, QTableWidgetItem(desc)) - self.table.setItem(self.items, 1, QTableWidgetItem(str(price))) - self.items += 1 - - @Slot() - def clear_table(self): - self.table.setRowCount(0) - self.items = 0 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/expenses/steps/10-expenses.py b/sources/pyside2/doc/tutorials/expenses/steps/10-expenses.py deleted file mode 100644 index 6cc911671..000000000 --- a/sources/pyside2/doc/tutorials/expenses/steps/10-expenses.py +++ /dev/null @@ -1,207 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from PySide2.QtCore import Qt, Slot -from PySide2.QtGui import QPainter -from PySide2.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QLabel, QLineEdit, - QMainWindow, QPushButton, QTableWidget, QTableWidgetItem, - QVBoxLayout, QWidget) -from PySide2.QtCharts import QtCharts - - -class Widget(QWidget): - def __init__(self): - QWidget.__init__(self) - self.items = 0 - - # Example data - self._data = {"Water": 24.5, "Electricity": 55.1, "Rent": 850.0, - "Supermarket": 230.4, "Internet": 29.99, "Bars": 21.85, - "Public transportation": 60.0, "Coffee": 22.45, "Restaurants": 120} - - # Left - self.table = QTableWidget() - self.table.setColumnCount(2) - self.table.setHorizontalHeaderLabels(["Description", "Price"]) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # Chart - self.chart_view = QtCharts.QChartView() - self.chart_view.setRenderHint(QPainter.Antialiasing) - - # Right - self.description = QLineEdit() - self.price = QLineEdit() - self.add = QPushButton("Add") - self.clear = QPushButton("Clear") - self.quit = QPushButton("Quit") - self.plot = QPushButton("Plot") - - # Disabling 'Add' button - self.add.setEnabled(False) - - self.right = QVBoxLayout() - self.right.setMargin(10) - self.right.addWidget(QLabel("Description")) - self.right.addWidget(self.description) - self.right.addWidget(QLabel("Price")) - self.right.addWidget(self.price) - self.right.addWidget(self.add) - self.right.addWidget(self.plot) - self.right.addWidget(self.chart_view) - self.right.addWidget(self.clear) - self.right.addWidget(self.quit) - - # QWidget Layout - self.layout = QHBoxLayout() - - #self.table_view.setSizePolicy(size) - self.layout.addWidget(self.table) - self.layout.addLayout(self.right) - - # Set the layout to the QWidget - self.setLayout(self.layout) - - # Signals and Slots - self.add.clicked.connect(self.add_element) - self.quit.clicked.connect(self.quit_application) - self.plot.clicked.connect(self.plot_data) - self.clear.clicked.connect(self.clear_table) - self.description.textChanged[str].connect(self.check_disable) - self.price.textChanged[str].connect(self.check_disable) - - # Fill example data - self.fill_table() - - @Slot() - def add_element(self): - des = self.description.text() - price = self.price.text() - - self.table.insertRow(self.items) - description_item = QTableWidgetItem(des) - price_item = QTableWidgetItem("{:.2f}".format(float(price))) - price_item.setTextAlignment(Qt.AlignRight) - - self.table.setItem(self.items, 0, description_item) - self.table.setItem(self.items, 1, price_item) - - self.description.setText("") - self.price.setText("") - - self.items += 1 - - @Slot() - def check_disable(self, s): - if not self.description.text() or not self.price.text(): - self.add.setEnabled(False) - else: - self.add.setEnabled(True) - - @Slot() - def plot_data(self): - # Get table information - series = QtCharts.QPieSeries() - for i in range(self.table.rowCount()): - text = self.table.item(i, 0).text() - number = float(self.table.item(i, 1).text()) - series.append(text, number) - - chart = QtCharts.QChart() - chart.addSeries(series) - chart.legend().setAlignment(Qt.AlignLeft) - self.chart_view.setChart(chart) - - @Slot() - def quit_application(self): - QApplication.quit() - - def fill_table(self, data=None): - data = self._data if not data else data - for desc, price in data.items(): - description_item = QTableWidgetItem(desc) - price_item = QTableWidgetItem("{:.2f}".format(price)) - price_item.setTextAlignment(Qt.AlignRight) - self.table.insertRow(self.items) - self.table.setItem(self.items, 0, description_item) - self.table.setItem(self.items, 1, price_item) - self.items += 1 - - @Slot() - def clear_table(self): - self.table.setRowCount(0) - self.items = 0 - - -class MainWindow(QMainWindow): - def __init__(self, widget): - QMainWindow.__init__(self) - self.setWindowTitle("Tutorial") - - # Menu - self.menu = self.menuBar() - self.file_menu = self.menu.addMenu("File") - - # Exit QAction - exit_action = QAction("Exit", self) - exit_action.setShortcut("Ctrl+Q") - exit_action.triggered.connect(self.exit_app) - - self.file_menu.addAction(exit_action) - self.setCentralWidget(widget) - - @Slot() - def exit_app(self, checked): - QApplication.quit() - - -if __name__ == "__main__": - # Qt Application - app = QApplication(sys.argv) - # QWidget - widget = Widget() - # QMainWindow using QWidget as central widget - window = MainWindow(widget) - window.resize(800, 600) - window.show() - - # Execute application - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/index.rst b/sources/pyside2/doc/tutorials/index.rst deleted file mode 100644 index 5a97aecb9..000000000 --- a/sources/pyside2/doc/tutorials/index.rst +++ /dev/null @@ -1,32 +0,0 @@ -Qt for Python examples and tutorials -************************************* - -A collection of examples and tutorials with "walkthrough" guides are -provided with |project| to help new users get started. These -documents were ported from C++ to Python and cover a range of topics, -from basic use of widgets to step-by-step tutorials that show how an -application is put together. - -Examples and demos -=================== - -.. toctree:: - :maxdepth: 1 - - examples/tabbedbrowser.rst - -Tutorials -========== - -.. toctree:: - :maxdepth: 2 - - basictutorial/widgets.rst - basictutorial/qml.rst - basictutorial/clickablebutton.rst - basictutorial/dialog.rst - basictutorial/uifiles.rst - datavisualize/index.rst - expenses/expenses.rst - qmlapp/qmlapplication.rst - qmlintegration/qmlintegration.rst diff --git a/sources/pyside2/doc/tutorials/qmlapp/logo.png b/sources/pyside2/doc/tutorials/qmlapp/logo.png Binary files differdeleted file mode 100644 index 30c621c9c..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/logo.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/main.py b/sources/pyside2/doc/tutorials/qmlapp/main.py deleted file mode 100644 index 54edf0e37..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/main.py +++ /dev/null @@ -1,82 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -#!/usr/bin/env python -# -*- conding: utf-8 -*- - -import os, sys, urllib.request, json -import PySide2.QtQml -from PySide2.QtQuick import QQuickView -from PySide2.QtCore import QStringListModel, Qt, QUrl -from PySide2.QtGui import QGuiApplication - -if __name__ == '__main__': - - #get our data - url = "http://country.io/names.json" - response = urllib.request.urlopen(url) - data = json.loads(response.read().decode('utf-8')) - - #Format and sort the data - data_list = list(data.values()) - data_list.sort() - - #Set up the application window - app = QGuiApplication(sys.argv) - view = QQuickView() - view.setResizeMode(QQuickView.SizeRootObjectToView) - - #Expose the list to the Qml code - my_model = QStringListModel() - my_model.setStringList(data_list) - view.rootContext().setContextProperty("myModel",my_model) - - #Load the QML file - qml_file = os.path.join(os.path.dirname(__file__),"view.qml") - view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file))) - - #Show the window - if view.status() == QQuickView.Error: - sys.exit(-1) - view.show() - - #execute and cleanup - app.exec_() - del view diff --git a/sources/pyside2/doc/tutorials/qmlapp/newpyproject.png b/sources/pyside2/doc/tutorials/qmlapp/newpyproject.png Binary files differdeleted file mode 100644 index 93968a52d..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/newpyproject.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/projectsmode.png b/sources/pyside2/doc/tutorials/qmlapp/projectsmode.png Binary files differdeleted file mode 100644 index c66d88723..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/projectsmode.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/pyprojname.png b/sources/pyside2/doc/tutorials/qmlapp/pyprojname.png Binary files differdeleted file mode 100644 index 98328074d..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/pyprojname.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/pyprojxplor.png b/sources/pyside2/doc/tutorials/qmlapp/pyprojxplor.png Binary files differdeleted file mode 100644 index e01e2ebeb..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/pyprojxplor.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.png b/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.png Binary files differdeleted file mode 100644 index ec0ad3dea..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.rst b/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.rst deleted file mode 100644 index 0cb296071..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/qmlapplication.rst +++ /dev/null @@ -1,132 +0,0 @@ -######################### -QML Application Tutorial -######################### - -This tutorial provides a quick walk-through of a python application -that loads a QML file. QML is a declarative language that lets you -design UIs faster than a traditional language, such as C++. The -QtQml and QtQuick modules provides the necessary infrastructure for -QML-based UIs. - -In this tutorial, you'll also learn how to provide data from Python -as a QML context property, which is then consumed by the ListView -defined in the QML file. - -Before you begin, install the following prerequisites: - -* The `PySide2 <https://pypi.org/project/PySide2/>`_ Python packages. -* Qt Creator v4.9 beta1 or later from - `http://download.qt.io - <http://download.qt.io/snapshots/qtcreator/4.9/4.9.0-beta1/>`_. - - -The following step-by-step instructions guide you through application -development process using Qt Creator: - -#. Open Qt Creator and select **File > New File or Project..** menu item - to open following dialog: - - .. image:: newpyproject.png - -#. Select **Qt for Python - Empty** from the list of application templates - and select **Choose**. - - .. image:: pyprojname.png - -#. Give a **Name** to your project, choose its location in the - filesystem, and select **Finish** to create an empty ``main.py`` - and ``main.pyproject``. - - .. image:: pyprojxplor.png - - This should create a ``main.py`` and ```main.pyproject`` files - for the project. - -#. Download :download:`view.qml<view.qml>` and :download:`logo.png <logo.png>` - and move them to your project folder. - -#. Double-click on ``main.pyproject`` to open it in edit mode, and append - ``view.qml`` and ``logo.png`` to the **files** list. This is how your - project file should look after this change: - - .. code:: - - { - "files": ["main.py", "view.qml", "logo.png"] - } - -#. Now that you have the necessary bits for the application, import the - Python modules in your ``main.py``, and download country data and - format it: - - .. literalinclude:: main.py - :linenos: - :lines: 40-60 - :emphasize-lines: 12-20 - -#. Now, set up the application window using - :ref:`PySide2.QtGui.QGuiApplication<qguiapplication>`, which manages the application-wide - settings. - - .. literalinclude:: main.py - :linenos: - :lines: 40-65 - :emphasize-lines: 23-25 - - .. note:: Setting the resize policy is important if you want the - root item to resize itself to fit the window or vice-a-versa. - Otherwise, the root item will retain its original size on - resizing the window. - -#. You can now expose the ``data_list`` variable as a QML context - property, which will be consumed by the QML ListView item in ``view.qml``. - - .. literalinclude:: main.py - :linenos: - :lines: 40-70 - :emphasize-lines: 27-30 - -#. Load the ``view.qml`` to the ``QQuickView`` and call ``show()`` to - display the application window. - - .. literalinclude:: main.py - :linenos: - :lines: 40-79 - :emphasize-lines: 33-39 - -#. Finally, execute the application to start the event loop and clean up. - - .. literalinclude:: main.py - :linenos: - :lines: 40- - :emphasize-lines: 41-43 - -#. Your application is ready to be run now. Select **Projects** mode to - choose the Python version to run it. - - .. image:: projectsmode.png - -Run the application by using the ``CTRL+R`` keyboard shortcut to see if it -looks like this: - -.. image:: qmlapplication.png - -You could also watch the following video tutorial for guidance to develop -this application: - -.. raw:: html - - <div style="position: relative; padding-bottom: 56.25%; height: 0; - overflow: hidden; max-width: 100%; height: auto;"> - <iframe src="https://www.youtube.com/embed/JxfiUx60Mbg" frameborder="0" - allowfullscreen style="position: absolute; top: 0; left: 0; - width: 100%; height: 100%;"> - </iframe> - </div> - -******************** -Related information -******************** - -* `QML Reference <https://doc.qt.io/qt-5/qmlreference.html>`_ -* :doc:`../qmlintegration/qmlintegration` diff --git a/sources/pyside2/doc/tutorials/qmlapp/view.qml b/sources/pyside2/doc/tutorials/qmlapp/view.qml deleted file mode 100644 index c75052b29..000000000 --- a/sources/pyside2/doc/tutorials/qmlapp/view.qml +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of Qt for Python. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 - -Page { - width: 640 - height: 480 - - header: Label { - color: "#15af15" - text: qsTr("Where do people use Qt?") - font.pointSize: 17 - font.bold: true - font.family: "Arial" - renderType: Text.NativeRendering - horizontalAlignment: Text.AlignHCenter - padding: 10 - } - Rectangle { - id: root - width: parent.width - height: parent.height - - Image { - id: image - fillMode: Image.PreserveAspectFit - anchors.centerIn: root - source: "./logo.png" - opacity: 0.5 - - } - - ListView { - id: view - anchors.fill: root - anchors.margins: 25 - model: myModel - delegate: Text { - anchors.leftMargin: 50 - font.pointSize: 15 - horizontalAlignment: Text.AlignHCenter - text: display - } - } - } - NumberAnimation { - id: anim - running: true - target: view - property: "contentY" - duration: 500 - } -} diff --git a/sources/pyside2/doc/tutorials/qmlintegration/main.py b/sources/pyside2/doc/tutorials/qmlintegration/main.py deleted file mode 100644 index 3451c65b5..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/main.py +++ /dev/null @@ -1,113 +0,0 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -import sys -from os.path import abspath, dirname, join - -from PySide2.QtCore import QObject, Slot -from PySide2.QtGui import QGuiApplication -from PySide2.QtQml import QQmlApplicationEngine - -from style_rc import * - - -class Bridge(QObject): - - @Slot(str, result=str) - def getColor(self, color_name): - if color_name.lower() == "red": - return "#ef9a9a" - elif color_name.lower() == "green": - return "#a5d6a7" - elif color_name.lower() == "blue": - return "#90caf9" - else: - return "white" - - @Slot(float, result=int) - def getSize(self, s): - size = int(s * 42) # Maximum font size - if size <= 0: - return 1 - else: - return size - - @Slot(str, result=bool) - def getItalic(self, s): - if s.lower() == "italic": - return True - else: - return False - - @Slot(str, result=bool) - def getBold(self, s): - if s.lower() == "bold": - return True - else: - return False - - @Slot(str, result=bool) - def getUnderline(self, s): - if s.lower() == "underline": - return True - else: - return False - - -if __name__ == '__main__': - app = QGuiApplication(sys.argv) - engine = QQmlApplicationEngine() - - # Instance of the Python object - bridge = Bridge() - - # Expose the Python object to QML - context = engine.rootContext() - context.setContextProperty("con", bridge) - - # Get the path of the current directory, and then add the name - # of the QML file, to load it. - qmlFile = join(dirname(__file__), 'view.qml') - engine.load(abspath(qmlFile)) - - if not engine.rootObjects(): - sys.exit(-1) - - sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/tutorials/qmlintegration/qmlintegration.rst b/sources/pyside2/doc/tutorials/qmlintegration/qmlintegration.rst deleted file mode 100644 index 36a12381d..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/qmlintegration.rst +++ /dev/null @@ -1,111 +0,0 @@ -######################## -QML Integration Tutorial -######################## - -This tutorial provides a quick walk-through of a python application that loads, and interacts with -a QML file. QML is a declarative language that lets you design UIs faster than a traditional -language, such as C++. The QtQml and QtQuick modules provides the necessary infrastructure for -QML-based UIs. - -In this tutorial, you will learn how to integrate Python with a QML application through a context -property. This mechanism will help us to understand how to use Python as a backend for certain -signals from the UI elements in the QML interface. Additionally, you will learn how to provide -a modern look to your QML application using one of the features from Qt Quick Controls 2. - -The tutorial is based on an application that allow you to set many text properties, like increasing -the font size, changing the color, changing the style, and so on. Before you begin, install the -`PySide2 <https://pypi.org/project/PySide2/>`_ Python packages. - -The following step-by-step process will guide you through the key elements of the QML based -application and PySide2 integration: - -#. First, let's start with the following QML-based UI: - - .. image:: textproperties_default.png - - The design is based on a `GridLayout`, containing two `ColumnLayout`. - Inside the UI you will find many `RadioButton`, `Button`, and a `Slider`. - -#. With the QML file in place, you can load it from Python: - - .. literalinclude:: main.py - :linenos: - :lines: 98-108 - :emphasize-lines: 103,107 - - Notice that we specify the name of the context property, **con**, - and also we explicitly load our QML file. - -#. Define the `Bridge` class, containing all the logic for the context property: - - .. literalinclude:: main.py - :linenos: - :lines: 51-91 - -#. Now, go back to the QML file and connect the signals to the slots defined in the `Bridge` class: - - .. literalinclude:: view.qml - :linenos: - :lines: 85-93 - :emphasize-lines: 89-91 - - The properties *Italic*, *Bold*, and *Underline* are mutually - exclusive, this means only one can be active at any time. - To achieve this each time we select one of these options, we - check the three properties via the context property as you can - see in the above snippet. - Only one of the three will return *True*, while the other two - will return *False*, that is how we make sure only one is being - applied to the text. - -#. Each slot verifies if the selected option contains the text associated - to the property: - - .. literalinclude:: main.py - :linenos: - :lines: 79-84 - :emphasize-lines: 82,84 - - Returning *True* or *False* allows you to activate and deactivate - the properties of the QML UI elements. - - It is also possible to return other values that are not *Boolean*, - like the slot in charge of returning the font size: - - .. literalinclude:: main.py - :linenos: - :lines: 64-70 - -#. Now, for changing the look of our application, you have two options: - - 1. Use the command line: execute the python file adding the option, `--style`:: - - python main.py --style material - - 2. Use a `qtquickcontrols2.conf` file: - - .. literalinclude:: qtquickcontrols2.conf - :linenos: - - Then add it to your `.qrc` file: - - .. literalinclude:: style.qrc - :linenos: - - Generate the *rc* file running, `pyside2-rcc style.qrc > style_rc.py` - And finally import it from your `main.py` script. - - .. literalinclude:: main.py - :linenos: - :lines: 41-48 - :emphasize-lines: 48 - - You can read more about this configuration file - `here <https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html>`_. - - The final look of your application will be: - - .. image:: textproperties_material.png - -You can download `view.qml <view.qml>`_ and `main.py <main.py>`_ -to try this example. diff --git a/sources/pyside2/doc/tutorials/qmlintegration/qtquickcontrols2.conf b/sources/pyside2/doc/tutorials/qmlintegration/qtquickcontrols2.conf deleted file mode 100644 index 850646021..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/qtquickcontrols2.conf +++ /dev/null @@ -1,10 +0,0 @@ -[Controls] -Style=Material - -[Universal] -Theme=System -Accent=Red - -[Material] -Theme=Dark -Accent=Red diff --git a/sources/pyside2/doc/tutorials/qmlintegration/style.qrc b/sources/pyside2/doc/tutorials/qmlintegration/style.qrc deleted file mode 100644 index e313f5ed6..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/style.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/"> - <file>qtquickcontrols2.conf</file> -</qresource> -</RCC> diff --git a/sources/pyside2/doc/tutorials/qmlintegration/textproperties_default.png b/sources/pyside2/doc/tutorials/qmlintegration/textproperties_default.png Binary files differdeleted file mode 100644 index cfeac9368..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/textproperties_default.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlintegration/textproperties_material.png b/sources/pyside2/doc/tutorials/qmlintegration/textproperties_material.png Binary files differdeleted file mode 100644 index 47866c10e..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/textproperties_material.png +++ /dev/null diff --git a/sources/pyside2/doc/tutorials/qmlintegration/view.qml b/sources/pyside2/doc/tutorials/qmlintegration/view.qml deleted file mode 100644 index 97968d691..000000000 --- a/sources/pyside2/doc/tutorials/qmlintegration/view.qml +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt for Python examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -import QtQuick 2.0 -import QtQuick.Layouts 1.12 -import QtQuick.Controls 2.12 -import QtQuick.Window 2.12 -import QtQuick.Controls.Material 2.12 - -ApplicationWindow { - id: page - width: 800 - height: 400 - visible: true - - GridLayout { - id: grid - columns: 2 - rows: 3 - - ColumnLayout { - spacing: 2 - Layout.preferredWidth: 400 - - Text { - id: leftlabel - Layout.alignment: Qt.AlignHCenter - color: "white" - font.pointSize: 16 - text: "Qt for Python" - Layout.preferredHeight: 100 - Material.accent: Material.Green - } - - RadioButton { - id: italic - text: "Italic" - onToggled: { - leftlabel.font.italic = con.getItalic(italic.text) - leftlabel.font.bold = con.getBold(italic.text) - leftlabel.font.underline = con.getUnderline(italic.text) - - } - } - RadioButton { - id: bold - text: "Bold" - onToggled: { - leftlabel.font.italic = con.getItalic(bold.text) - leftlabel.font.bold = con.getBold(bold.text) - leftlabel.font.underline = con.getUnderline(bold.text) - } - } - RadioButton { - id: underline - text: "Underline" - onToggled: { - leftlabel.font.italic = con.getItalic(underline.text) - leftlabel.font.bold = con.getBold(underline.text) - leftlabel.font.underline = con.getUnderline(underline.text) - } - } - RadioButton { - id: noneradio - text: "None" - checked: true - onToggled: { - leftlabel.font.italic = con.getItalic(noneradio.text) - leftlabel.font.bold = con.getBold(noneradio.text) - leftlabel.font.underline = con.getUnderline(noneradio.text) - } - } - } - - ColumnLayout { - id: rightcolumn - spacing: 2 - Layout.columnSpan: 1 - Layout.preferredWidth: 400 - Layout.preferredHeight: 400 - Layout.fillWidth: true - - RowLayout { - Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter - - - Button { - id: red - text: "Red" - highlighted: true - Material.accent: Material.Red - onClicked: { - leftlabel.color = con.getColor(red.text) - } - } - Button { - id: green - text: "Green" - highlighted: true - Material.accent: Material.Green - onClicked: { - leftlabel.color = con.getColor(green.text) - } - } - Button { - id: blue - text: "Blue" - highlighted: true - Material.accent: Material.Blue - onClicked: { - leftlabel.color = con.getColor(blue.text) - } - } - Button { - id: nonebutton - text: "None" - highlighted: true - Material.accent: Material.BlueGrey - onClicked: { - leftlabel.color = con.getColor(nonebutton.text) - } - } - } - RowLayout { - Layout.fillWidth: true - Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter - Text { - id: rightlabel - color: "white" - text: "Font size" - Material.accent: Material.White - } - Slider { - width: rightcolumn.width*0.6 - Layout.alignment: Qt.AlignRight - id: slider - value: 0.5 - onValueChanged: { - leftlabel.font.pointSize = con.getSize(value) - } - } - } - } - } -} |