|
24 | 24 |
|
25 | 25 | show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. |
26 | 26 | """ |
| 27 | +import os |
| 28 | +import sys |
27 | 29 | from html.parser import HTMLParser |
28 | 30 | from os.path import abspath, dirname, isfile, join |
29 | 31 | from platform import python_version |
|
35 | 37 | from idlelib.config import idleConf |
36 | 38 | from idlelib.colorizer import color_config |
37 | 39 |
|
| 40 | +from idlelib.editor import EditorWindow |
| 41 | + |
| 42 | + |
38 | 43 | ## About IDLE ## |
39 | 44 |
|
40 | 45 |
|
@@ -289,6 +294,44 @@ def show_idlehelp(parent): |
289 | 294 | return HelpWindow(parent, filename, 'IDLE Doc (%s)' % python_version()) |
290 | 295 |
|
291 | 296 |
|
| 297 | +def _get_dochome(): |
| 298 | + dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') |
| 299 | + if sys.platform.count('linux'): |
| 300 | + # look for html docs in a couple of standard places |
| 301 | + pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] |
| 302 | + if os.path.isdir('/var/www/html/python/'): # "python2" rpm |
| 303 | + dochome = '/var/www/html/python/index.html' |
| 304 | + else: |
| 305 | + basepath = '/usr/share/doc/' # standard location |
| 306 | + dochome = os.path.join(basepath, pyver, |
| 307 | + 'Doc', 'index.html') |
| 308 | + elif sys.platform[:3] == 'win': |
| 309 | + import winreg # Windows only, block only executed once. |
| 310 | + docfile = '' |
| 311 | + KEY = (rf"Software\Python\PythonCore\{sys.winver}" |
| 312 | + r"\Help\Main Python Documentation") |
| 313 | + try: |
| 314 | + docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY) |
| 315 | + except FileNotFoundError: |
| 316 | + try: |
| 317 | + docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, KEY) |
| 318 | + except FileNotFoundError: |
| 319 | + pass |
| 320 | + if os.path.isfile(docfile): |
| 321 | + dochome = docfile |
| 322 | + elif sys.platform == 'darwin': |
| 323 | + # documentation may be stored inside a python framework |
| 324 | + dochome = os.path.join(sys.base_prefix, |
| 325 | + 'Resources/English.lproj/Documentation/index.html') |
| 326 | + dochome = os.path.normpath(dochome) |
| 327 | + if os.path.isfile(dochome): |
| 328 | + if sys.platform == 'darwin': |
| 329 | + # Safari requires real file:-URLs |
| 330 | + return 'file://' + dochome |
| 331 | + return dochome |
| 332 | + else: |
| 333 | + return "https://docs.python.org/%d.%d/" % sys.version_info[:2] |
| 334 | + |
292 | 335 | if __name__ == '__main__': |
293 | 336 | from unittest import main |
294 | 337 | main('idlelib.idle_test.test_help', verbosity=2, exit=False) |
|
0 commit comments