Advertisement
Guest User

SIMPLE PYQT EXECUTE JS

a guest
Jan 7th, 2011
334
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None
  1. # -*- coding: utf-8 -*-
  2. from basebrowser import *
  3.  
  4. class SimpleJavaScript(BaseBrowser):
  5.     def __init__(self,  parent = None):
  6.         super(SimpleJavaScript, self).__init__(parent)
  7.         self.jsButton = QPushButton("ExecuteJS")
  8.         self.connect(self.jsButton, SIGNAL("clicked()"),  self.jsScript)
  9.         self.jsStringEdit = QLineEdit()
  10.         self.jsStringEdit.setSizePolicy(QSizePolicy.Expanding, self.jsStringEdit.sizePolicy().verticalPolicy())
  11.         self.jsStringEdit.setText("document.getElementById(\"tabs\").rows(0).cells.length")
  12.         self.connect(self.jsStringEdit, SIGNAL("returnPressed()"), self.jsScript)
  13.         self.jsReturnText = QTextEdit()
  14.         self.layout.addWidget(self.jsStringEdit, 2, 0,  1,  1)
  15.         self.layout.addWidget(self.jsButton, 2, 1,  1,  1)
  16.         self.layout.addWidget(self.jsReturnText, 3, 0,  1,  2)
  17.  
  18.     def jsScript(self):        
  19.         jsString = self.jsStringEdit.text()
  20.         jsReturn = self.webView.page().currentFrame().evaluateJavaScript(jsString)
  21.         self.jsReturnText.setPlainText(jsReturn.toString())
  22.  
  23. if __name__ == "__main__":
  24.     import sys
  25.     app = QApplication(sys.argv)
  26.     ui = SimpleJavaScript()
  27.     ui.show()
  28.     sys.exit(app.exec_())
Advertisement
RAW Paste Data Copied
Advertisement