SHARE
TWEET

Untitled

a guest Feb 16th, 2012 399 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## example PySide panel that implements a simple web browser in Nuke
  2. ## JW 12/10/11
  3.  
  4. import nuke
  5. import nukescripts
  6. from nukescripts import panels
  7.  
  8. from PySide.QtGui import *
  9. from PySide.QtCore import *
  10. from PySide.QtWebKit import *
  11.  
  12.  
  13. class WebBrowserWidget(QWidget):
  14.   def changeLocation(self):
  15.     url = self.locationEdit.text()
  16.     if not url.startswith( 'http://' ):
  17.       url = 'http://' + url
  18.     self.webView.load( QUrl(url) )
  19.  
  20.   def urlChanged(self, url):
  21.     self.locationEdit.setText( url.toString() )
  22.  
  23.   def __init__(self):
  24.     QWidget.__init__(self)
  25.     self.webView = QWebView()
  26.    
  27.     self.setLayout( QVBoxLayout() )  
  28.    
  29.     self.locationEdit = QLineEdit( 'http://www.google.com' )
  30.     self.locationEdit.setSizePolicy( QSizePolicy.Expanding, self.locationEdit.sizePolicy().verticalPolicy() )
  31.    
  32.     QObject.connect( self.locationEdit, SIGNAL('returnPressed()'),  self.changeLocation )
  33.     QObject.connect( self.webView,   SIGNAL('urlChanged(QUrl)'),     self.urlChanged )
  34.  
  35.     self.layout().addWidget( self.locationEdit )
  36.  
  37.     bar = QToolBar()
  38.     bar.addAction( self.webView.pageAction(QWebPage.Back))
  39.     bar.addAction( self.webView.pageAction(QWebPage.Forward))
  40.     bar.addAction( self.webView.pageAction(QWebPage.Stop))
  41.     bar.addAction( self.webView.pageAction(QWebPage.Reload))
  42.     bar.addSeparator()
  43.    
  44.     self.layout().addWidget( bar )
  45.     self.layout().addWidget( self.webView )
  46.  
  47.     url = 'http://www.nukepedia.com/'
  48.     self.webView.load( QUrl( url ) )
  49.     self.locationEdit.setText( url )
  50.     self.setSizePolicy( QSizePolicy( QSizePolicy.Expanding,  QSizePolicy.Expanding))
  51.  
  52. ## make this work in a .py file and in 'copy and paste' into the script editor
  53. moduleName = __name__
  54. if moduleName == '__main__':
  55.   moduleName = ''
  56. else:
  57.   moduleName = moduleName + '.'
  58.  
  59. panels.registerWidgetAsPanel( moduleName + 'WebBrowserWidget', 'Web Browser','uk.co.thefoundry.WebBrowserWidget')
RAW Paste Data
Top