~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderlib/plugins/onlinehelp.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2013-01-20 12:19:54 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20130120121954-1jt1xa924bshhvh0
Tags: 2.2.0~beta1+dfsg-2
fix typo ipython-qtconsol -> ipython-qtconsole

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
#
3
 
# Copyright © 2009-2010 Pierre Raybaut
4
 
# Licensed under the terms of the MIT License
5
 
# (see spyderlib/__init__.py for details)
6
 
 
7
 
"""Online Help Plugin"""
8
 
 
9
 
from spyderlib.qt.QtCore import Signal
10
 
 
11
 
import os.path as osp
12
 
 
13
 
# Local imports
14
 
from spyderlib.baseconfig import get_conf_path, _
15
 
from spyderlib.widgets.pydocgui import PydocBrowser
16
 
from spyderlib.plugins import SpyderPluginMixin
17
 
 
18
 
 
19
 
class OnlineHelp(PydocBrowser, SpyderPluginMixin):
20
 
    """
21
 
    Online Help Plugin
22
 
    """
23
 
    sig_option_changed = Signal(str, object)
24
 
    CONF_SECTION = 'onlinehelp'
25
 
    LOG_PATH = get_conf_path('.onlinehelp')
26
 
    def __init__(self, parent):
27
 
        self.main = parent
28
 
        PydocBrowser.__init__(self, parent)
29
 
        SpyderPluginMixin.__init__(self, parent)
30
 
 
31
 
        # Initialize plugin
32
 
        self.initialize_plugin()
33
 
 
34
 
        self.register_widget_shortcuts("Editor", self.find_widget)
35
 
        
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() )
39
 
        
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()]
46
 
        else:
47
 
            history = []
48
 
        return history
49
 
    
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()) ] ))
55
 
 
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():
61
 
            self.initialize()
62
 
    
63
 
    #------ SpyderPluginWidget API ---------------------------------------------
64
 
    def get_plugin_title(self):
65
 
        """Return widget title"""
66
 
        return _('Online help')
67
 
    
68
 
    def get_focus_widget(self):
69
 
        """
70
 
        Return the widget to give focus to when
71
 
        this plugin's dockwidget is raised on top-level
72
 
        """
73
 
        self.url_combo.lineEdit().selectAll()
74
 
        return self.url_combo
75
 
        
76
 
    def closing_plugin(self, cancelable=False):
77
 
        """Perform actions before parent main window is closed"""
78
 
        self.save_history()
79
 
        self.set_option('zoom_factor', self.webview.get_zoom_factor())
80
 
        return True
81
 
        
82
 
    def refresh_plugin(self):
83
 
        """Refresh widget"""
84
 
        pass
85
 
    
86
 
    def get_plugin_actions(self):
87
 
        """Return a list of actions related to plugin"""
88
 
        return []
89
 
    
90
 
    def register_plugin(self):
91
 
        """Register plugin in Spyder's main window"""
92
 
        self.main.add_dockwidget(self)
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright © 2009-2010 Pierre Raybaut
 
4
# Licensed under the terms of the MIT License
 
5
# (see spyderlib/__init__.py for details)
 
6
 
 
7
"""Online Help Plugin"""
 
8
 
 
9
from spyderlib.qt.QtCore import Signal
 
10
 
 
11
import os.path as osp
 
12
 
 
13
# Local imports
 
14
from spyderlib.baseconfig import get_conf_path, _
 
15
from spyderlib.widgets.pydocgui import PydocBrowser
 
16
from spyderlib.plugins import SpyderPluginMixin
 
17
 
 
18
 
 
19
class OnlineHelp(PydocBrowser, SpyderPluginMixin):
 
20
    """
 
21
    Online Help Plugin
 
22
    """
 
23
    sig_option_changed = Signal(str, object)
 
24
    CONF_SECTION = 'onlinehelp'
 
25
    LOG_PATH = get_conf_path('.onlinehelp')
 
26
    def __init__(self, parent):
 
27
        self.main = parent
 
28
        PydocBrowser.__init__(self, parent)
 
29
        SpyderPluginMixin.__init__(self, parent)
 
30
 
 
31
        # Initialize plugin
 
32
        self.initialize_plugin()
 
33
 
 
34
        self.register_widget_shortcuts("Editor", self.find_widget)
 
35
        
 
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() )
 
39
        
 
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()]
 
46
        else:
 
47
            history = []
 
48
        return history
 
49
    
 
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()) ] ))
 
55
 
 
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():
 
61
            self.initialize()
 
62
    
 
63
    #------ SpyderPluginWidget API ---------------------------------------------
 
64
    def get_plugin_title(self):
 
65
        """Return widget title"""
 
66
        return _('Online help')
 
67
    
 
68
    def get_focus_widget(self):
 
69
        """
 
70
        Return the widget to give focus to when
 
71
        this plugin's dockwidget is raised on top-level
 
72
        """
 
73
        self.url_combo.lineEdit().selectAll()
 
74
        return self.url_combo
 
75
        
 
76
    def closing_plugin(self, cancelable=False):
 
77
        """Perform actions before parent main window is closed"""
 
78
        self.save_history()
 
79
        self.set_option('zoom_factor', self.webview.get_zoom_factor())
 
80
        return True
 
81
        
 
82
    def refresh_plugin(self):
 
83
        """Refresh widget"""
 
84
        pass
 
85
    
 
86
    def get_plugin_actions(self):
 
87
        """Return a list of actions related to plugin"""
 
88
        return []
 
89
    
 
90
    def register_plugin(self):
 
91
        """Register plugin in Spyder's main window"""
 
92
        self.main.add_dockwidget(self)
93
93
        
 
 
b'\\ No newline at end of file'