Guest User

Zert

a guest
Feb 10th, 2010
879
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from urlparse import urlparse
  5.  
  6. from PyQt4 import QtCore, QtGui, QtWebKit
  7.  
  8. UA_STRING = """Yaris (AppleWebKit (KHTML, like Gecko, Safari/419.3)"""
  9.  
  10. class YWebPage(QtWebKit.QWebPage):
  11. def __init__(self):
  12. super(QtWebKit.QWebPage, self).__init__()
  13.  
  14. def userAgentForUrl(self, url):
  15. return UA_STRING
  16.  
  17.  
  18. class Yaris(QtGui.QMainWindow):
  19. def __init__(self):
  20. super(Yaris, self).__init__()
  21.  
  22. widget = QtGui.QWidget()
  23. self.setCentralWidget(widget)
  24.  
  25. self.buffers = []
  26. self.codecs = [QtCore.QLatin1String(QtCore.QTextCodec.codecForMib(mib).name())
  27. for mib in QtCore.QTextCodec.availableMibs()]
  28. self.codecs.sort()
  29.  
  30. topFiller = QtGui.QWidget()
  31. topFiller.setSizePolicy(QtGui.QSizePolicy.Expanding,
  32. QtGui.QSizePolicy.Expanding)
  33.  
  34. self.yPage = YWebPage()
  35.  
  36. self.webview = QtWebKit.QWebView(self)
  37. self.webview.urlChanged.connect(self.updStatusUrl)
  38. self.webview.loadProgress.connect(self.updProgress)
  39. self.webview.setPage(self.yPage)
  40.  
  41. self.minibuffer = QtGui.QLineEdit()
  42. self.minibuffer.hide()
  43. self.minibuffer.returnPressed.connect(self.mbExec)
  44.  
  45. bottomFiller = QtGui.QWidget()
  46. bottomFiller.setSizePolicy(QtGui.QSizePolicy.Expanding,
  47. QtGui.QSizePolicy.Expanding)
  48.  
  49. vbox = QtGui.QVBoxLayout()
  50. vbox.setMargin(5)
  51. vbox.addWidget(topFiller)
  52. vbox.addWidget(self.webview)
  53. vbox.addWidget(bottomFiller)
  54. vbox.addWidget(self.minibuffer)
  55. widget.setLayout(vbox)
  56.  
  57. self.setWindowTitle(self.tr("Yaris"))
  58. self.setMinimumSize(160,160)
  59. self.resize(1024,600)
  60.  
  61. def loadUrl(self, url):
  62. self.webview.load(QtCore.QUrl(url))
  63. self.webview.show()
  64. self.updStatusUrl()
  65.  
  66. def miniBuffer(self, prompt):
  67. pass
  68.  
  69. def mbExec(self):
  70. text = str(self.minibuffer.text())
  71. if urlparse(text).scheme == '':
  72. text = 'http://' + text
  73. self.loadUrl(text)
  74. self.minibuffer.hide()
  75. self.minibuffer.clear()
  76.  
  77. def updStatusUrl(self, url=None):
  78. url = self.webview.url()
  79. message = url.toString()
  80. self.statusBar().showMessage(message)
  81. self.updTitle()
  82.  
  83.  
  84. def updTitle(self):
  85. self.setWindowTitle(self.webview.title())
  86.  
  87. def updProgress(self, p):
  88. pass
  89.  
  90. def keyPressEvent(self, event):
  91. key = event.key()
  92. if event.modifiers() == QtCore.Qt.ControlModifier:
  93. if key == QtCore.Qt.Key_G:
  94. self.webview.stop()
  95. self.minibuffer.hide()
  96. else:
  97. if key == QtCore.Qt.Key_G:
  98. self.minibuffer.show()
  99. self.minibuffer.setFocus()
  100. elif key == QtCore.Qt.Key_B:
  101. self.webview.back()
  102. elif key == QtCore.Qt.Key_F:
  103. self.webview.forward()
  104. elif key == QtCore.Qt.Key_R:
  105. self.webview.reload()
  106. elif key == QtCore.Qt.Key_N:
  107. print "N pressed"
  108. else:
  109. super(Yaris, self).keyPressEvent(event)
  110.  
  111.  
  112. if __name__ == "__main__":
  113.  
  114. import sys
  115.  
  116. app = QtGui.QApplication(sys.argv)
  117. #QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("UTF-8"))
  118. yaris = Yaris()
  119. yaris.show()
  120.  
  121. yaris.loadUrl("file:///usr/doc/qt-4.5.1/html/index.html")
  122. #yaris.loadUrl("file:///home/zert/Work/Prog/Python/yaris/test.html")
  123.  
  124. sys.exit(app.exec_())
  125.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×