SlideShare a Scribd company logo
PySide + QtQuick
 Daker Fernandes / Marcel Caraciolo
                         Python Aula 09

            1
O que é PySide?


   PySide = Python + Qt Framework




                           Python Aula 09

                   2
Qt
•  Biblioteca C++
•  Cross-Platform
•  Licença dual (LGPL ou Comercial)
•  Extensa:




                                       Python Aula 09

                           3
Qt




           Python Aula 09

      4
Qt




           Python Aula 09

      5
Qt




           Python Aula 09

      6
Qt – Quem usa?




                  Python Aula 09

            7
>>>PySide == PyQT
. . . False

   PySide – LGPL
   PyQT – GPL
                     Python Aula 09

             8
Como Instalar - Qt




   http://qt.nokia.com/downloads

                            Python Aula 09

                 9
Documentação - Qt




 http://doc.qt.nokia.com/4.7/index.html
                               Python Aula 09

                    10
Como Instalar - PySide




  http://developer.qt.nokia.com/wiki/
            PySideDownloads/
                             Python Aula 09

                  11
Documentação - PySide




  http://developer.qt.nokia.com/wiki/
          PySideDocumentation/
                             Python Aula 09

                  12
Hello Qt
import sys
from PySide import QtGui # GUI module

app = QtGui.QApplication(sys.argv)

hello = QtGui.QPushButton(Hello world!)

hello.resize(100, 30)

hello.show()

sys.exit(app.exec_())




                                         Python Aula 09

                          13
Hello Qt
import sys
from PySide import QtGui

def hello():
   
print “Hello!”

app = QtGui.QApplication(sys.argv)

helloButton = QtGui.QPushButton(“Hello!)

helloButton.clicked.connect(hello)

helloButton.show()

sys.exit(app.exec_())


                                       Python Aula 09

                            14
Signals e Slots

readButton.clicked.connect(increment)

# helloButton = QObject
# clicked = Signal
# increment = Slot




                                    Python Aula 09

                       15
Signals e Slots
from PySide.QtCore import Qobject, Slot, Signal

class Counter(QObject):
   
def __init__(self, count=0):
   
    
QObject.__init__(self) # super
   
    
self.count = count

   
# criando sinal
   
countChanged = Signal(int)

   
@Slot()
   
def increment(self):
   
   
self.count += 1
   
   
self.countChanged.emit(self.count)
                                       Python Aula 09

                          16
Signals e Slots
@Slot(int)
def console_print(number):
   
print ‘counter value is %d’ % number

counter = Counter()
counter.counterChanged.connect(console_print)

counter.increment()
counter.increment()
counter.increment()




                                      Python Aula 09

                          17
Signals e Slots
class Counter(QObject):
    
def __init__(self, parent=None):
    
    
QObject.__init__(self, parent)
    
    
self._count = 0

   
def getCount(self):
   
    
return self._count

   
def   setCount(self, count):
   
      
if count != self._count:
   
      
    
self._count = count
   
      
    
self.countChanged.emit(count)
   
…

   
countChanged = Signal(int)

    
count = Property(int, getCount, setCount,
notify=countChanged)
                                                 Python Aula 09

                               18
QWidget
class WidgetContador(QWidget):
       def __init__(self, counter = Counter()):
            self._counter = counter
            self.label = QLabel(“”)
   
   self.button = QPushButton(“Incremento”)
   
   self.button.clicked.connect(lambda:
   
    

   
    
self._counter.increment())
   
 self._counter.countChanged.connect(lambda:


self.label.setText(str(self._counter.count)))

   
   layout = QVBoxLayout()
   
   layout.addWidget(self.label)
    Python Aula 09
   
   layout.addWidget(self.button)
                          19
   
   self.setLayout(layout)
QWidget
           Exercicio:




                         Python Aula 09

                20
Fluid Interfaces
•  http://www.youtube.com/watch?v=tSBQ63bL0_Y
•  http://www.youtube.com/watch?
   v=P37PaOZJzEsfeature=related
•  http://www.youtube.com/watch?v=2x_bS4M3jhY
•  http://www.youtube.com/watch?v=GYlyDKqzNC0
•  http://www.youtube.com/watch?v=6J3QV115cSU
•  http://www.youtube.com/watch?v=RTJKzJWOsbUNR=1
•  http://www.youtube.com/watch?v=U7IgwNrcln8
•  http://www.youtube.com/watch?
   v=P37PaOZJzEsfeature=related
•  http://www.youtube.com/watch?v=n3W5O2biSPU
•  http://www.youtube.com/watch?v=Wq-XJMJEAnE
•  http://www.youtube.com/watch?v=9NjLVTIi_ZY
•  http://www.youtube.com/watch?v=g_cf-7uoK5o
 Aula 09
                                            Python

                              21
QtQuick
•  Módulo QDeclarative
•  QML
   •  Linguagem Javascript based
   •  Árvore de Elementos (Semelhante ao HTML)
   •  Integração com Qt


•  Aprenda:
http://doc.qt.nokia.com/latest/qtquick.html
•  Referências:
http://doc.qt.nokia.com/latest/qml-groups.html
http://doc.qt.nokia.com/latest/qdeclarativeelements.html
http://doc.qt.nokia.com/latest/qtdeclarative.html
                                                  Python Aula 09

                                 22
QML – Hello World
import QtQuick 1.0

Text {
   
width: 200
   
height: 60
   
text: Hello World!
   
font.pixelSize: 32
}



                            Python Aula 09

                      23
QML - DeclarativeView
import sys
from PySide.QtCore import QUrl
from PySide.QtGui import QApplication, QSizePolicy
from PySide.QtDeclarative import QDeclarativeView

app = QApplication(sys.argv)

view = QDeclarativeView()
view.setSource(QUrl(‘minhaUI.qml'))   # carrega
arquivo QML
view.show()

sys.exit(app.exec_())
                                        Python Aula 09

                          24
QML - Recursos
import QtQuick 1.0

Item {
   
width: 1000
   
height: 500
   
Image {
   
    
x: 0; y: 0
   
    
width: 500; height: 500
   
    
source: monera.png // No mesmo diretório
que o .qml
   
}
   
Image {
   
    
x: 500; y: 0
   
    
width: 500; height: 500
   
    
// Imagem na web
   
    
source: http://imgs.xkcd.com/comics/na.png 
   
    
fillMode: Image.PreserveAspectFit
 09
                                        Python Aula

   
}
                     25

}
QML - Âncoras
import QtQuick 1.0

Item {
   
Image {
   
    
id: image1 // identificado do objeto
   
    
anchors { left: parent.left; top: parent.top
   
    
   
bottom: parent.bottom }
   
    
source: monera.png“
   
}
   
Image {
   
    
anchors { top: parent.top; bottom:
parent.bottom
   
    
   
right: parent.right; left: image1.right }
   
    
source: http://imgs.xkcd.com/comics/na.png 
   
    
fillMode: Image.PreserveAspectFit
   
}
}
                                      Python Aula 09

                          26
QML – Property Binding
Rectangle {
   
width: 200
   
height: 200
   
color: 'tomato' // Nome da cor
   
Text {
   
    
anchors.centerIn: parent
   
    
rotation: x // Property Binding
   
    
opacity: y / 300 // Expression Binding
   
    
text: 'Rotated'
   
    
color: '#990099' // Código hexadecimal
   
    
font {
   
    
   
family: Helvetica
   
    
   
pixelSize: 90
   
    
}
   
    
smooth: true
   
}
}
                                     Python Aula 09

                              27
QML - Eventos
import QtQuick 1.0

Image {
    
width: sourceSize.width / 2
    
height: sourceSize.height / 2

     
source: ocean.jpg

     
Image {
     
    
id: monera
     
    
source: monera.png
     
    
width: 150
     
    
height: 150   

     
    
    

     
    
MouseArea {
     
    
    
    
anchors.fill: parent
     
    
    
    
onClicked: { monera.x = 300; monera.y = 300 }
     
    
}
     
}
                                               Python Aula 09
}
                                28
QML – Comportamento
import QtQuick 1.0

Image {
     
width: sourceSize.width / 2
     
height: sourceSize.height / 2

    
source: ocean.jpg

     
Image {
     
     
id: monera
     
     
source: monera.png
     
     
width: 150
     
     
height: 150

     
     

     
     
Behavior on x { NumberAnimation { duration: 2000 ; easing.type:
Easing.OutElastic }}
     
     
Behavior on y { NumberAnimation { duration: 2000 ; easing.type:
Easing.OutElastic }}
     
     
     

     
     
MouseArea {
     
     
     
anchors.fill: parent
     
     
     
hoverEnabled: true
     
     
     
onEntered: { monera.x = Math.random() Python Aula 09
; 
                                                         * 500
     
     
     
     
monera.y = Math.random() * 500 }
     
     
}
                        29
     
}
QML – Componentes QML
Monera.qml
                              Ocean.qml
import QtQuick 1.0
                              import QtQuick 1.0
Image {
                              Image {
     
id: monera
                                   width:
     
source: monera.png“
                              sourceSize.width / 2
                                   height:
     
property int size: 150
                              sourceSize.height / 2
     
width: size
                                      source: ocean.jpg
     
height: size     

                                      Repeater {
     
...
                                           model: 10
                                           Monera {
     
MouseArea {
                                      
   size: 180
     
     
anchors.fill:
                        parent
                                      
 x: Math.random() * 500
     
     
hoverEnabled: true
                                      
   y: Math.random() *
     
     
onEntered: { ... }
                               500
     
}
                                              }
}
                                       }
                              }

                                                             Python Aula 09

                                            30
QML – Python Values
monera.py
context = view.rootContext()
context.setContextProperty(‘moneraCount’,
20)
context.setContextProperty(‘moneraSize’,
120)

Ocean.qml
Repeater {
   
model: moneraCount
   
Monera { size: moneraSize ; ... }
}
                              Python Aula 09

                     31
QML - Model
// Model
ListModel {
   
id: todoList
   
ListElement {
   
 
task: ‘Aula de Python’
   
}
   
ListElement {
   
 
task: ‘Aula de QML’
   
}
   
ListElement {
   
 
task: ‘Happy Hour’
   
}
}
                              Python Aula 09

                    32
QML - ListView
import QtQuick 1.0

ListView {
    
id: notes
    
width: 600; height: 800
    
model: todoList
    
delegate: Component {
    
    
Text {
    
    
    
height: 60; width: 600
    
    
    
text: task
    
    
    
font.pixelSize: 32
    
    
    
MouseArea {
    
    
    
    
anchors.fill: parent
    
    
    
    
onClicked: console.log(modelData.task)
    
    
    
}   
    
    

    
    
}
    
}
}
                                             Python Aula 09

                               33
QML – Modelo Python
todo.py
view = QDeclarativeView()
context = view.rootContext()
pymodel = [{'task':'Aula Python'},
    
{'task':'Aula QML'},
    
{'task':'Happy Hour'}]
context.setContextProperty('pymodel', pymodel)           


TodoList.qml
import QtQuick 1.0

ListView {
    
id: notes
    
width: 600; height: 800
    
model: pymodel
    
delegate: Component {
    
    
TodoElement { text: modelData.task; ... }
    
}
                                              Python Aula 09
}
                                    34
Mais sobre model View:
•  ModelView:
•  http://doc.qt.nokia.com/latest/qdeclarativemodels.html
•  http://developer.qt.nokia.com/wiki/
   Selectable_list_of_Python_objects_in_QML

•  http://developer.qt.nokia.com/wiki/
   Updating_QML_content_from_Python_threads

•  http://blog.rburchell.com/2010/02/pyside-tutorial-model-
   view-programming_22.html



                                                 Python Aula 09

                                  35
PySide + QtQuick
   Daker Fernandes / Marcel Caraciolo
                     Python Aula 09

        36

More Related Content

PDF
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
 
PDF
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
PDF
Javascript Uncommon Programming
jeffz
 
PDF
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
PDF
Jscex: Write Sexy JavaScript
jeffz
 
KEY
Python Yield
yangjuven
 
PDF
Kotlin Coroutines Reloaded
Roman Elizarov
 
PDF
Advanced python
EU Edge
 
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
Javascript Uncommon Programming
jeffz
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
Jscex: Write Sexy JavaScript
jeffz
 
Python Yield
yangjuven
 
Kotlin Coroutines Reloaded
Roman Elizarov
 
Advanced python
EU Edge
 

What's hot (20)

PPT
SDC - Einführung in Scala
Christian Baranowski
 
PDF
响应式编程及框架
jeffz
 
PDF
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
PDF
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
PyData
 
KEY
Pyimproved again
rik0
 
KEY
Endless fun with Arduino and Eventmachine
Bodo Tasche
 
PDF
Scale Up with Lock-Free Algorithms @ JavaOne
Roman Elizarov
 
KEY
openFrameworks 007 - video
roxlu
 
PDF
Introduction to kotlin coroutines
NAVER Engineering
 
PDF
Deep dive into Coroutines on JVM @ KotlinConf 2017
Roman Elizarov
 
KEY
Google Go For Ruby Hackers
Eleanor McHugh
 
PDF
Current State of Coroutines
Guido Pio Mariotti
 
KEY
openFrameworks 007 - graphics
roxlu
 
PDF
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
JaeYeoul Ahn
 
PDF
Snickers: Open Source HTTP API for Media Encoding
Flávio Ribeiro
 
KEY
openFrameworks 007 - 3D
roxlu
 
PDF
Fresh Async with Kotlin @ QConSF 2017
Roman Elizarov
 
PDF
От Java Threads к лямбдам, Андрей Родионов
Yandex
 
PPTX
Introduction to kotlin
Shaul Rosenzwieg
 
PDF
Metaprogramming and Reflection in Common Lisp
Damien Cassou
 
SDC - Einführung in Scala
Christian Baranowski
 
响应式编程及框架
jeffz
 
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
PyData
 
Pyimproved again
rik0
 
Endless fun with Arduino and Eventmachine
Bodo Tasche
 
Scale Up with Lock-Free Algorithms @ JavaOne
Roman Elizarov
 
openFrameworks 007 - video
roxlu
 
Introduction to kotlin coroutines
NAVER Engineering
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Roman Elizarov
 
Google Go For Ruby Hackers
Eleanor McHugh
 
Current State of Coroutines
Guido Pio Mariotti
 
openFrameworks 007 - graphics
roxlu
 
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
JaeYeoul Ahn
 
Snickers: Open Source HTTP API for Media Encoding
Flávio Ribeiro
 
openFrameworks 007 - 3D
roxlu
 
Fresh Async with Kotlin @ QConSF 2017
Roman Elizarov
 
От Java Threads к лямбдам, Андрей Родионов
Yandex
 
Introduction to kotlin
Shaul Rosenzwieg
 
Metaprogramming and Reflection in Common Lisp
Damien Cassou
 
Ad

Similar to CITi - PySide (20)

PDF
Toonz code leaves much to be desired
PVS-Studio
 
PDF
服务框架: Thrift & PasteScript
Qiangning Hong
 
PDF
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
PDF
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
Andrey Karpov
 
ZIP
Google Developer Fest 2010
Chris Ramsdale
 
PDF
Scripting Your Qt Application
account inactive
 
PDF
PVS-Studio for Linux Went on a Tour Around Disney
PVS-Studio
 
PPTX
Witekio custom modern qt quick components
Witekio
 
PDF
The Ring programming language version 1.7 book - Part 88 of 196
Mahmoud Samir Fayed
 
ZIP
Building Web Apps Sanely - EclipseCon 2010
Chris Ramsdale
 
PDF
Best Practices in Qt Quick/QML - Part 1 of 4
ICS
 
PDF
Fun with QML
ICS
 
PDF
The Ring programming language version 1.5.3 book - Part 92 of 184
Mahmoud Samir Fayed
 
PDF
Integrazione QML / C++
Paolo Sereno
 
PDF
Porting Motif Applications to Qt - Webinar
ICS
 
PDF
Porting Motif Applications to Qt - Webinar
Janel Heilbrunn
 
PDF
Appium Automation with Kotlin
RapidValue
 
PDF
Aplicações Assíncronas no Android com Coroutines e Jetpack
Nelson Glauber Leal
 
PDF
Hybrid Apps (Native + Web) via QtWebKit
Ariya Hidayat
 
PDF
Working in the multi-cloud with libcloud
Grig Gheorghiu
 
Toonz code leaves much to be desired
PVS-Studio
 
服务框架: Thrift & PasteScript
Qiangning Hong
 
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
Andrey Karpov
 
Google Developer Fest 2010
Chris Ramsdale
 
Scripting Your Qt Application
account inactive
 
PVS-Studio for Linux Went on a Tour Around Disney
PVS-Studio
 
Witekio custom modern qt quick components
Witekio
 
The Ring programming language version 1.7 book - Part 88 of 196
Mahmoud Samir Fayed
 
Building Web Apps Sanely - EclipseCon 2010
Chris Ramsdale
 
Best Practices in Qt Quick/QML - Part 1 of 4
ICS
 
Fun with QML
ICS
 
The Ring programming language version 1.5.3 book - Part 92 of 184
Mahmoud Samir Fayed
 
Integrazione QML / C++
Paolo Sereno
 
Porting Motif Applications to Qt - Webinar
ICS
 
Porting Motif Applications to Qt - Webinar
Janel Heilbrunn
 
Appium Automation with Kotlin
RapidValue
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Nelson Glauber Leal
 
Hybrid Apps (Native + Web) via QtWebKit
Ariya Hidayat
 
Working in the multi-cloud with libcloud
Grig Gheorghiu
 
Ad

More from Daker Fernandes (9)

PDF
Functional Pattern Matching on Python
Daker Fernandes
 
PDF
Why is Python slow? Python Nordeste 2013
Daker Fernandes
 
PDF
Raspberry Pi + Python
Daker Fernandes
 
PDF
Opengl aula-01
Daker Fernandes
 
PDF
Plasmaquick Workshop - FISL 13
Daker Fernandes
 
PDF
Jogos em Qt
Daker Fernandes
 
PDF
Dominando Modelos Ocultos de Markov com Python e GHMM
Daker Fernandes
 
PDF
QtQuick - WSL II
Daker Fernandes
 
PDF
Mongodb workshop cinlug
Daker Fernandes
 
Functional Pattern Matching on Python
Daker Fernandes
 
Why is Python slow? Python Nordeste 2013
Daker Fernandes
 
Raspberry Pi + Python
Daker Fernandes
 
Opengl aula-01
Daker Fernandes
 
Plasmaquick Workshop - FISL 13
Daker Fernandes
 
Jogos em Qt
Daker Fernandes
 
Dominando Modelos Ocultos de Markov com Python e GHMM
Daker Fernandes
 
QtQuick - WSL II
Daker Fernandes
 
Mongodb workshop cinlug
Daker Fernandes
 

Recently uploaded (20)

PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Doc9.....................................
SofiaCollazos
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Future of Artificial Intelligence (AI)
Mukul
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 

CITi - PySide

  • 1. PySide + QtQuick Daker Fernandes / Marcel Caraciolo Python Aula 09 1
  • 2. O que é PySide? PySide = Python + Qt Framework Python Aula 09 2
  • 3. Qt •  Biblioteca C++ •  Cross-Platform •  Licença dual (LGPL ou Comercial) •  Extensa: Python Aula 09 3
  • 4. Qt Python Aula 09 4
  • 5. Qt Python Aula 09 5
  • 6. Qt Python Aula 09 6
  • 7. Qt – Quem usa? Python Aula 09 7
  • 8. >>>PySide == PyQT . . . False PySide – LGPL PyQT – GPL Python Aula 09 8
  • 9. Como Instalar - Qt http://qt.nokia.com/downloads Python Aula 09 9
  • 10. Documentação - Qt http://doc.qt.nokia.com/4.7/index.html Python Aula 09 10
  • 11. Como Instalar - PySide http://developer.qt.nokia.com/wiki/ PySideDownloads/ Python Aula 09 11
  • 12. Documentação - PySide http://developer.qt.nokia.com/wiki/ PySideDocumentation/ Python Aula 09 12
  • 13. Hello Qt import sys from PySide import QtGui # GUI module app = QtGui.QApplication(sys.argv)
 hello = QtGui.QPushButton(Hello world!)
 hello.resize(100, 30)
 hello.show()
 sys.exit(app.exec_()) Python Aula 09 13
  • 14. Hello Qt import sys from PySide import QtGui def hello(): print “Hello!” app = QtGui.QApplication(sys.argv)
 helloButton = QtGui.QPushButton(“Hello!)
 helloButton.clicked.connect(hello)
 helloButton.show()
 sys.exit(app.exec_()) Python Aula 09 14
  • 15. Signals e Slots readButton.clicked.connect(increment) # helloButton = QObject # clicked = Signal # increment = Slot Python Aula 09 15
  • 16. Signals e Slots from PySide.QtCore import Qobject, Slot, Signal class Counter(QObject): def __init__(self, count=0): QObject.__init__(self) # super self.count = count # criando sinal countChanged = Signal(int) @Slot() def increment(self): self.count += 1 self.countChanged.emit(self.count) Python Aula 09 16
  • 17. Signals e Slots @Slot(int) def console_print(number): print ‘counter value is %d’ % number counter = Counter() counter.counterChanged.connect(console_print) counter.increment() counter.increment() counter.increment() Python Aula 09 17
  • 18. Signals e Slots class Counter(QObject): def __init__(self, parent=None): QObject.__init__(self, parent) self._count = 0 def getCount(self): return self._count def setCount(self, count): if count != self._count: self._count = count self.countChanged.emit(count) … countChanged = Signal(int) count = Property(int, getCount, setCount, notify=countChanged) Python Aula 09 18
  • 19. QWidget class WidgetContador(QWidget): def __init__(self, counter = Counter()): self._counter = counter self.label = QLabel(“”) self.button = QPushButton(“Incremento”) self.button.clicked.connect(lambda: self._counter.increment()) self._counter.countChanged.connect(lambda: self.label.setText(str(self._counter.count))) layout = QVBoxLayout() layout.addWidget(self.label) Python Aula 09 layout.addWidget(self.button) 19 self.setLayout(layout)
  • 20. QWidget Exercicio: Python Aula 09 20
  • 21. Fluid Interfaces •  http://www.youtube.com/watch?v=tSBQ63bL0_Y •  http://www.youtube.com/watch? v=P37PaOZJzEsfeature=related •  http://www.youtube.com/watch?v=2x_bS4M3jhY •  http://www.youtube.com/watch?v=GYlyDKqzNC0 •  http://www.youtube.com/watch?v=6J3QV115cSU •  http://www.youtube.com/watch?v=RTJKzJWOsbUNR=1 •  http://www.youtube.com/watch?v=U7IgwNrcln8 •  http://www.youtube.com/watch? v=P37PaOZJzEsfeature=related •  http://www.youtube.com/watch?v=n3W5O2biSPU •  http://www.youtube.com/watch?v=Wq-XJMJEAnE •  http://www.youtube.com/watch?v=9NjLVTIi_ZY •  http://www.youtube.com/watch?v=g_cf-7uoK5o Aula 09 Python 21
  • 22. QtQuick •  Módulo QDeclarative •  QML •  Linguagem Javascript based •  Árvore de Elementos (Semelhante ao HTML) •  Integração com Qt •  Aprenda: http://doc.qt.nokia.com/latest/qtquick.html •  Referências: http://doc.qt.nokia.com/latest/qml-groups.html http://doc.qt.nokia.com/latest/qdeclarativeelements.html http://doc.qt.nokia.com/latest/qtdeclarative.html Python Aula 09 22
  • 23. QML – Hello World import QtQuick 1.0 Text { width: 200 height: 60 text: Hello World! font.pixelSize: 32 } Python Aula 09 23
  • 24. QML - DeclarativeView import sys from PySide.QtCore import QUrl from PySide.QtGui import QApplication, QSizePolicy from PySide.QtDeclarative import QDeclarativeView app = QApplication(sys.argv) view = QDeclarativeView() view.setSource(QUrl(‘minhaUI.qml')) # carrega arquivo QML view.show() sys.exit(app.exec_()) Python Aula 09 24
  • 25. QML - Recursos import QtQuick 1.0 Item { width: 1000 height: 500 Image { x: 0; y: 0 width: 500; height: 500 source: monera.png // No mesmo diretório que o .qml } Image { x: 500; y: 0 width: 500; height: 500 // Imagem na web source: http://imgs.xkcd.com/comics/na.png fillMode: Image.PreserveAspectFit 09 Python Aula } 25 }
  • 26. QML - Âncoras import QtQuick 1.0 Item { Image { id: image1 // identificado do objeto anchors { left: parent.left; top: parent.top bottom: parent.bottom } source: monera.png“ } Image { anchors { top: parent.top; bottom: parent.bottom right: parent.right; left: image1.right } source: http://imgs.xkcd.com/comics/na.png fillMode: Image.PreserveAspectFit } } Python Aula 09 26
  • 27. QML – Property Binding Rectangle { width: 200 height: 200 color: 'tomato' // Nome da cor Text { anchors.centerIn: parent rotation: x // Property Binding opacity: y / 300 // Expression Binding text: 'Rotated' color: '#990099' // Código hexadecimal font { family: Helvetica pixelSize: 90 } smooth: true } } Python Aula 09 27
  • 28. QML - Eventos import QtQuick 1.0 Image { width: sourceSize.width / 2 height: sourceSize.height / 2 source: ocean.jpg Image { id: monera source: monera.png width: 150 height: 150 MouseArea { anchors.fill: parent onClicked: { monera.x = 300; monera.y = 300 } } } Python Aula 09 } 28
  • 29. QML – Comportamento import QtQuick 1.0 Image { width: sourceSize.width / 2 height: sourceSize.height / 2 source: ocean.jpg Image { id: monera source: monera.png width: 150 height: 150 Behavior on x { NumberAnimation { duration: 2000 ; easing.type: Easing.OutElastic }} Behavior on y { NumberAnimation { duration: 2000 ; easing.type: Easing.OutElastic }} MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { monera.x = Math.random() Python Aula 09 ; * 500 monera.y = Math.random() * 500 } } 29 }
  • 30. QML – Componentes QML Monera.qml Ocean.qml import QtQuick 1.0 import QtQuick 1.0 Image { Image { id: monera width: source: monera.png“ sourceSize.width / 2 height: property int size: 150 sourceSize.height / 2 width: size source: ocean.jpg height: size Repeater { ... model: 10 Monera { MouseArea { size: 180 anchors.fill: parent x: Math.random() * 500 hoverEnabled: true y: Math.random() * onEntered: { ... } 500 } } } } } Python Aula 09 30
  • 31. QML – Python Values monera.py context = view.rootContext() context.setContextProperty(‘moneraCount’, 20) context.setContextProperty(‘moneraSize’, 120) Ocean.qml Repeater { model: moneraCount Monera { size: moneraSize ; ... } } Python Aula 09 31
  • 32. QML - Model // Model ListModel { id: todoList ListElement { task: ‘Aula de Python’ } ListElement { task: ‘Aula de QML’ } ListElement { task: ‘Happy Hour’ } } Python Aula 09 32
  • 33. QML - ListView import QtQuick 1.0 ListView { id: notes width: 600; height: 800 model: todoList delegate: Component { Text { height: 60; width: 600 text: task font.pixelSize: 32 MouseArea { anchors.fill: parent onClicked: console.log(modelData.task) } } } } Python Aula 09 33
  • 34. QML – Modelo Python todo.py view = QDeclarativeView() context = view.rootContext() pymodel = [{'task':'Aula Python'}, {'task':'Aula QML'}, {'task':'Happy Hour'}] context.setContextProperty('pymodel', pymodel) TodoList.qml import QtQuick 1.0 ListView { id: notes width: 600; height: 800 model: pymodel delegate: Component { TodoElement { text: modelData.task; ... } } Python Aula 09 } 34
  • 35. Mais sobre model View: •  ModelView: •  http://doc.qt.nokia.com/latest/qdeclarativemodels.html •  http://developer.qt.nokia.com/wiki/ Selectable_list_of_Python_objects_in_QML •  http://developer.qt.nokia.com/wiki/ Updating_QML_content_from_Python_threads •  http://blog.rburchell.com/2010/02/pyside-tutorial-model- view-programming_22.html Python Aula 09 35
  • 36. PySide + QtQuick Daker Fernandes / Marcel Caraciolo Python Aula 09 36