SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Using QtWebKit in PyQt as a N00b

                                                   @tewson




          BarcampBangkok 3, Sripathum University        1
WebKit

                          ●   Open Source Layout Engine
                              ●   Safari
                              ●   Google Chrome
                              ●   WebOS
                              ●   Epiphany
                              ●   Arora


         BarcampBangkok 3, Sripathum University       2
Qt


       ●   Open Source Application Framework
             ●   Google Earth
             ●   VLC
             ●   Skype




     BarcampBangkok 3, Sripathum University   3
QtWebKit lets you...



   ●   Embed a Web browser in an application
   ●   Interact between Document Object Model
       and other environment




                 BarcampBangkok 3, Sripathum University   4
Dependencies




      sudo apt-get install python-qt4
       with libqt4-core and libqt4-webkit?




               BarcampBangkok 3, Sripathum University   5
Let's Try...

       import sys
       from PyQt4.QtCore import *
       from PyQt4.QtGui import *
       from PyQt4.QtWebKit import *
       app = QApplication(sys.argv)
       web = QWebView()
       web.load(QUrl(quot;http://barcampbangkok.orgquot;))
       web.show()
       sys.exit(app.exec_())
                    BarcampBangkok 3, Sripathum University   6
Create Your Own Web Browser


     ●   Use QtDesigner to Create UI
     ●   Import UI to the Program
     ●   Connect Signals and Slots:
         clicked(), urlChanged(), loadProgress(), etc.
     ●   app.show()!



                  BarcampBangkok 3, Sripathum University   7
Run JavaScript



    web = QwebView()
    frame = web.page().mainFrame()
    frame.evaluateJavaScript(quot;alert('Hello, World!');quot;)




                BarcampBangkok 3, Sripathum University    8
Cross the Border
     x = QObject()
     x.setObjectName(quot;xquot;)
     x.setProperty(quot;fooquot;,QVariant(quot;quot;))
     x.setProperty(quot;barquot;,QVariant(quot;quot;))
     frame.addToJavaScriptWindowObject(quot;xquot;,x)
     frame.evaluateJavaScript(quot;x.foo = 'foo'; x.bar = 5;quot;)
     print x.property(“foo”).toString()
     print x.property(“bar”).toInt()
                 BarcampBangkok 3, Sripathum University   9
Injecting Firebug Lite
                                    * Use signals and slots to check first
                                          if the page has finished loading. *
frame.evaluateJavaScript(quot;var firebug = document.createElement('script');
firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.2/firebug-lite-
compressed.js'); document.body.appendChild(firebug); (function()
{if(window.firebug.version){firebug.init();} else {setTimeout(arguments.callee);}})();
void(firebug);quot;)


Get this from Firebug Lite bookmarklet.
http://getfirebug.com/lite.html
                             BarcampBangkok 3, Sripathum University                 10
Injecting jQuery




 It's the same idea as injecting Firebug Lite.




               BarcampBangkok 3, Sripathum University   11
Many More Interesting Examples at...


   http://labs.trolltech.com/blogs
   http://riverbankcomputing.com
   and Google, of course!



              BarcampBangkok 3, Sripathum University   12
Thanks




                                           @tewson
                                         tewson.com
BarcampBangkok 3, Sripathum University          13

Weitere ähnliche Inhalte

Ähnlich wie Using QtWebKit in PyQt as a N00b

When third parties stop being polite... and start getting real
When third parties stop being polite... and start getting realWhen third parties stop being polite... and start getting real
When third parties stop being polite... and start getting real
Charles Vazac
 
When Third Parties Stop Being Polite... and Start Getting Real
When Third Parties Stop Being Polite... and Start Getting RealWhen Third Parties Stop Being Polite... and Start Getting Real
When Third Parties Stop Being Polite... and Start Getting Real
Nicholas Jansma
 
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Provectus
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
Ariya Hidayat
 

Ähnlich wie Using QtWebKit in PyQt as a N00b (20)

Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Denver JUG 2020
 
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Switzerl...
 
BA-ST project ecosystem by Maxi Tabacman
BA-ST project ecosystem by Maxi TabacmanBA-ST project ecosystem by Maxi Tabacman
BA-ST project ecosystem by Maxi Tabacman
 
JSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph PicklJSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph Pickl
 
When third parties stop being polite... and start getting real
When third parties stop being polite... and start getting realWhen third parties stop being polite... and start getting real
When third parties stop being polite... and start getting real
 
The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
Fluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting realFluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting real
 
When Third Parties Stop Being Polite... and Start Getting Real
When Third Parties Stop Being Polite... and Start Getting RealWhen Third Parties Stop Being Polite... and Start Getting Real
When Third Parties Stop Being Polite... and Start Getting Real
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
 
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
 
Getting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in JavaGetting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in Java
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
 
Reverse Ajax
Reverse AjaxReverse Ajax
Reverse Ajax
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Using QtWebKit in PyQt as a N00b

  • 1. Using QtWebKit in PyQt as a N00b @tewson BarcampBangkok 3, Sripathum University 1
  • 2. WebKit ● Open Source Layout Engine ● Safari ● Google Chrome ● WebOS ● Epiphany ● Arora BarcampBangkok 3, Sripathum University 2
  • 3. Qt ● Open Source Application Framework ● Google Earth ● VLC ● Skype BarcampBangkok 3, Sripathum University 3
  • 4. QtWebKit lets you... ● Embed a Web browser in an application ● Interact between Document Object Model and other environment BarcampBangkok 3, Sripathum University 4
  • 5. Dependencies sudo apt-get install python-qt4 with libqt4-core and libqt4-webkit? BarcampBangkok 3, Sripathum University 5
  • 6. Let's Try... import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * app = QApplication(sys.argv) web = QWebView() web.load(QUrl(quot;http://barcampbangkok.orgquot;)) web.show() sys.exit(app.exec_()) BarcampBangkok 3, Sripathum University 6
  • 7. Create Your Own Web Browser ● Use QtDesigner to Create UI ● Import UI to the Program ● Connect Signals and Slots: clicked(), urlChanged(), loadProgress(), etc. ● app.show()! BarcampBangkok 3, Sripathum University 7
  • 8. Run JavaScript web = QwebView() frame = web.page().mainFrame() frame.evaluateJavaScript(quot;alert('Hello, World!');quot;) BarcampBangkok 3, Sripathum University 8
  • 9. Cross the Border x = QObject() x.setObjectName(quot;xquot;) x.setProperty(quot;fooquot;,QVariant(quot;quot;)) x.setProperty(quot;barquot;,QVariant(quot;quot;)) frame.addToJavaScriptWindowObject(quot;xquot;,x) frame.evaluateJavaScript(quot;x.foo = 'foo'; x.bar = 5;quot;) print x.property(“foo”).toString() print x.property(“bar”).toInt() BarcampBangkok 3, Sripathum University 9
  • 10. Injecting Firebug Lite * Use signals and slots to check first if the page has finished loading. * frame.evaluateJavaScript(quot;var firebug = document.createElement('script'); firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.2/firebug-lite- compressed.js'); document.body.appendChild(firebug); (function() {if(window.firebug.version){firebug.init();} else {setTimeout(arguments.callee);}})(); void(firebug);quot;) Get this from Firebug Lite bookmarklet. http://getfirebug.com/lite.html BarcampBangkok 3, Sripathum University 10
  • 11. Injecting jQuery It's the same idea as injecting Firebug Lite. BarcampBangkok 3, Sripathum University 11
  • 12. Many More Interesting Examples at... http://labs.trolltech.com/blogs http://riverbankcomputing.com and Google, of course! BarcampBangkok 3, Sripathum University 12
  • 13. Thanks @tewson tewson.com BarcampBangkok 3, Sripathum University 13