/usr/share/pyshared/spyderlib/widgets/pydocgui.py is in python-spyderlib 2.1.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | # -*- coding: utf-8 -*-
#
# Copyright © 2009-2010 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)
"""pydoc widget"""
from spyderlib.qt.QtGui import QApplication, QCursor
from spyderlib.qt.QtCore import QThread, QUrl, Qt
import sys
import os.path as osp
# Local imports
from spyderlib.baseconfig import _
from spyderlib.widgets.browser import WebBrowser
from spyderlib.utils.misc import select_port
class PydocServer(QThread):
"""Pydoc server"""
def __init__(self, port=7464):
QThread.__init__(self)
self.port = port
self.server = None
self.complete = False
def run(self):
import pydoc
pydoc.serve(self.port, self.callback, self.completer)
def callback(self, server):
self.server = server
def completer(self):
self.complete = True
def quit_server(self):
self.server.quit = 1
class PydocBrowser(WebBrowser):
"""
pydoc widget
"""
DEFAULT_PORT = 30128
def __init__(self, parent):
WebBrowser.__init__(self, parent)
self.server = None
self.port = None
def initialize(self):
"""Start pydoc server and load home page"""
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
QApplication.processEvents()
self.start_server()
self.go_home()
QApplication.restoreOverrideCursor()
def is_server_running(self):
"""Return True if pydoc server is already running"""
return self.server is not None
def closeEvent(self, event):
self.server.quit_server()
# while not self.server.complete: #XXX Is it really necessary?
# pass
event.accept()
#------ Public API -----------------------------------------------------
def start_server(self):
"""Start pydoc server"""
if self.server is None:
self.port = select_port(default_port=self.DEFAULT_PORT)
self.set_home_url('http://localhost:%d/' % self.port)
elif self.server.isRunning():
self.server.quit()
self.server = PydocServer(port=self.port)
self.server.start()
#------ WebBrowser API -----------------------------------------------------
def get_label(self):
"""Return address label text"""
return _("Module or package:")
def reload(self):
"""Reload page"""
self.start_server()
WebBrowser.reload(self)
def text_to_url(self, text):
"""Convert text address into QUrl object"""
if text.startsWith('/'):
text = text[1:]
return QUrl(self.home_url.toString()+text+'.html')
def url_to_text(self, url):
"""Convert QUrl object to displayed text in combo box"""
return osp.splitext(unicode(url.path()))[0][1:]
def main():
"""Run web browser"""
from spyderlib.utils.qthelpers import qapplication
app = qapplication()
widget = PydocBrowser(None)
widget.show()
widget.initialize()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
|