1
# -*- coding: utf-8 -*-
3
# Copyright © 2009-2010 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Online Help Plugin"""
9
from spyderlib.qt.QtCore import Signal
14
from spyderlib.baseconfig import get_conf_path, _
15
from spyderlib.widgets.pydocgui import PydocBrowser
16
from spyderlib.plugins import SpyderPluginMixin
19
class OnlineHelp(PydocBrowser, SpyderPluginMixin):
23
sig_option_changed = Signal(str, object)
24
CONF_SECTION = 'onlinehelp'
25
LOG_PATH = get_conf_path('.onlinehelp')
26
def __init__(self, parent):
28
PydocBrowser.__init__(self, parent)
29
SpyderPluginMixin.__init__(self, parent)
32
self.initialize_plugin()
34
self.register_widget_shortcuts("Editor", self.find_widget)
36
self.webview.set_zoom_factor(self.get_option('zoom_factor'))
37
self.url_combo.setMaxCount(self.get_option('max_history_entries'))
38
self.url_combo.addItems( self.load_history() )
40
#------ Public API ---------------------------------------------------------
41
def load_history(self, obj=None):
42
"""Load history from a text file in user home directory"""
43
if osp.isfile(self.LOG_PATH):
44
history = [line.replace('\n','')
45
for line in file(self.LOG_PATH, 'r').readlines()]
50
def save_history(self):
51
"""Save history to a text file in user home directory"""
52
file(self.LOG_PATH, 'w').write("\n".join( \
53
[ unicode( self.url_combo.itemText(index) )
54
for index in range(self.url_combo.count()) ] ))
56
#------ SpyderPluginMixin API ---------------------------------------------
57
def visibility_changed(self, enable):
58
"""DockWidget visibility has changed"""
59
SpyderPluginMixin.visibility_changed(self, enable)
60
if enable and not self.is_server_running():
63
#------ SpyderPluginWidget API ---------------------------------------------
64
def get_plugin_title(self):
65
"""Return widget title"""
66
return _('Online help')
68
def get_focus_widget(self):
70
Return the widget to give focus to when
71
this plugin's dockwidget is raised on top-level
73
self.url_combo.lineEdit().selectAll()
76
def closing_plugin(self, cancelable=False):
77
"""Perform actions before parent main window is closed"""
79
self.set_option('zoom_factor', self.webview.get_zoom_factor())
82
def refresh_plugin(self):
86
def get_plugin_actions(self):
87
"""Return a list of actions related to plugin"""
90
def register_plugin(self):
91
"""Register plugin in Spyder's main window"""
92
self.main.add_dockwidget(self)
1
# -*- coding: utf-8 -*-
3
# Copyright © 2009-2010 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Online Help Plugin"""
9
from spyderlib.qt.QtCore import Signal
14
from spyderlib.baseconfig import get_conf_path, _
15
from spyderlib.widgets.pydocgui import PydocBrowser
16
from spyderlib.plugins import SpyderPluginMixin
19
class OnlineHelp(PydocBrowser, SpyderPluginMixin):
23
sig_option_changed = Signal(str, object)
24
CONF_SECTION = 'onlinehelp'
25
LOG_PATH = get_conf_path('.onlinehelp')
26
def __init__(self, parent):
28
PydocBrowser.__init__(self, parent)
29
SpyderPluginMixin.__init__(self, parent)
32
self.initialize_plugin()
34
self.register_widget_shortcuts("Editor", self.find_widget)
36
self.webview.set_zoom_factor(self.get_option('zoom_factor'))
37
self.url_combo.setMaxCount(self.get_option('max_history_entries'))
38
self.url_combo.addItems( self.load_history() )
40
#------ Public API ---------------------------------------------------------
41
def load_history(self, obj=None):
42
"""Load history from a text file in user home directory"""
43
if osp.isfile(self.LOG_PATH):
44
history = [line.replace('\n','')
45
for line in file(self.LOG_PATH, 'r').readlines()]
50
def save_history(self):
51
"""Save history to a text file in user home directory"""
52
file(self.LOG_PATH, 'w').write("\n".join( \
53
[ unicode( self.url_combo.itemText(index) )
54
for index in range(self.url_combo.count()) ] ))
56
#------ SpyderPluginMixin API ---------------------------------------------
57
def visibility_changed(self, enable):
58
"""DockWidget visibility has changed"""
59
SpyderPluginMixin.visibility_changed(self, enable)
60
if enable and not self.is_server_running():
63
#------ SpyderPluginWidget API ---------------------------------------------
64
def get_plugin_title(self):
65
"""Return widget title"""
66
return _('Online help')
68
def get_focus_widget(self):
70
Return the widget to give focus to when
71
this plugin's dockwidget is raised on top-level
73
self.url_combo.lineEdit().selectAll()
76
def closing_plugin(self, cancelable=False):
77
"""Perform actions before parent main window is closed"""
79
self.set_option('zoom_factor', self.webview.get_zoom_factor())
82
def refresh_plugin(self):
86
def get_plugin_actions(self):
87
"""Return a list of actions related to plugin"""
90
def register_plugin(self):
91
"""Register plugin in Spyder's main window"""
92
self.main.add_dockwidget(self)
b'\\ No newline at end of file'