Exemple #1
0
    def __init__(self, parent):
        SpyderPluginWidget.__init__(self, parent)

        self.pydocbrowser = PydocBrowser(self, self.options_button)

        layout = QVBoxLayout()
        layout.addWidget(self.pydocbrowser)
        self.setLayout(layout)

        self.register_widget_shortcuts(self.pydocbrowser.find_widget)
        self.pydocbrowser.webview.set_zoom_factor(
            self.get_option('zoom_factor'))
        self.pydocbrowser.url_combo.setMaxCount(
            self.get_option('max_history_entries'))
        self.pydocbrowser.url_combo.addItems(self.load_history())
Exemple #2
0
def pydocbrowser(qtbot):
    """Set up pydocbrowser."""
    widget = PydocBrowser(parent=None, name='pydoc')
    options = PydocBrowser.DEFAULT_OPTIONS.copy()
    widget._setup(options)
    widget.setup(options)

    with qtbot.waitSignal(widget.sig_load_finished, timeout=6000):
        widget.initialize()

    qtbot.addWidget(widget)
    return qtbot, widget
Exemple #3
0
def pydocbrowser(qtbot):
    """Set up pydocbrowser."""
    plugin_mock = MagicMock()
    plugin_mock.CONF_SECTION = 'onlinehelp'
    widget = PydocBrowser(parent=None, plugin=plugin_mock, name='pydoc')
    widget._setup()
    widget.setup()

    with qtbot.waitSignal(widget.sig_load_finished, timeout=6000):
        widget.initialize()

    qtbot.addWidget(widget)
    return qtbot, widget
Exemple #4
0
def pydocbrowser(qtbot):
    """Set up pydocbrowser."""
    plugin_mock = MagicMock()
    plugin_mock.CONF_SECTION = 'onlinehelp'
    widget = PydocBrowser(parent=None, plugin=plugin_mock, name='pydoc')
    with qtbot.waitSignal(widget.webview.loadFinished, timeout=20000):
        widget._setup()
        widget.setup()
        widget.resize(640, 480)
        widget.show()
        widget.initialize(force=True)
    yield widget
    widget.close()
Exemple #5
0
class OnlineHelp(SpyderPluginWidget):
    """Online Help Plugin."""

    CONF_SECTION = 'onlinehelp'
    CONF_FILE = False
    LOG_PATH = get_conf_path(CONF_SECTION)

    def __init__(self, parent):
        SpyderPluginWidget.__init__(self, parent)

        self.pydocbrowser = PydocBrowser(self, self.options_button)

        layout = QVBoxLayout()
        layout.addWidget(self.pydocbrowser)
        self.setLayout(layout)

        self.register_widget_shortcuts(self.pydocbrowser.find_widget)
        self.pydocbrowser.webview.set_zoom_factor(
            self.get_option('zoom_factor'))
        self.pydocbrowser.url_combo.setMaxCount(
            self.get_option('max_history_entries'))
        self.pydocbrowser.url_combo.addItems(self.load_history())

    #------ Public API ---------------------------------------------------------
    def load_history(self, obj=None):
        """Load history from a text file in user home directory"""
        if osp.isfile(self.LOG_PATH):
            history = [line.replace('\n', '')
                       for line in open(self.LOG_PATH, 'r').readlines()]
        else:
            history = []
        return history
    
    def save_history(self):
        """Save history to a text file in user home directory"""
        open(self.LOG_PATH, 'w').write("\n".join( \
                [to_text_string(self.pydocbrowser.url_combo.itemText(index))
                 for index in range(self.pydocbrowser.url_combo.count())]))

    #------ SpyderPluginWidget API ---------------------------------------------
    def toggle_view(self, checked):
        """Toggle view action."""
        if checked:
            if not self.pydocbrowser.is_server_running():
                self.pydocbrowser.initialize()
            self.dockwidget.show()
            self.dockwidget.raise_()
        else:
            self.dockwidget.hide()

    def get_plugin_title(self):
        """Return widget title"""
        return _('Online help')
    
    def get_focus_widget(self):
        """
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        """
        self.pydocbrowser.url_combo.lineEdit().selectAll()
        return self.pydocbrowser.url_combo
        
    def closing_plugin(self, cancelable=False):
        """Perform actions before parent main window is closed"""
        self.save_history()
        self.set_option('zoom_factor',
                        self.pydocbrowser.webview.get_zoom_factor())
        return True

    def on_first_registration(self):
        """Action to be performed on first plugin registration"""
        self.tabify(self.main.help)
Exemple #6
0
def setup_pydocbrowser(qtbot):
    """Set up pydocbrowser."""
    widget = PydocBrowser(None)
    qtbot.addWidget(widget)
    return widget
Exemple #7
0
class OnlineHelp(SpyderPluginWidget):
    """Online Help Plugin."""

    CONF_SECTION = 'onlinehelp'
    LOG_PATH = get_conf_path(CONF_SECTION)

    def __init__(self, parent):
        SpyderPluginWidget.__init__(self, parent)

        # Initialize plugin
        self.initialize_plugin()

        self.pydocbrowser = PydocBrowser(self, self.options_button)

        layout = QVBoxLayout()
        layout.addWidget(self.pydocbrowser)
        self.setLayout(layout)

        self.register_widget_shortcuts(self.pydocbrowser.find_widget)
        self.pydocbrowser.webview.set_zoom_factor(
                                                self.get_option('zoom_factor'))
        self.pydocbrowser.url_combo.setMaxCount(
                                        self.get_option('max_history_entries'))
        self.pydocbrowser.url_combo.addItems( self.load_history() )

    #------ Public API ---------------------------------------------------------
    def load_history(self, obj=None):
        """Load history from a text file in user home directory"""
        if osp.isfile(self.LOG_PATH):
            history = [line.replace('\n', '')
                       for line in open(self.LOG_PATH, 'r').readlines()]
        else:
            history = []
        return history
    
    def save_history(self):
        """Save history to a text file in user home directory"""
        open(self.LOG_PATH, 'w').write("\n".join( \
                [to_text_string(self.pydocbrowser.url_combo.itemText(index))
                 for index in range(self.pydocbrowser.url_combo.count())]))

    #------ SpyderPluginMixin API ---------------------------------------------
    def visibility_changed(self, enable):
        """DockWidget visibility has changed"""
        super(SpyderPluginWidget, self).visibility_changed(enable)
        if enable and not self.pydocbrowser.is_server_running():
            self.pydocbrowser.initialize()
    
    #------ SpyderPluginWidget API ---------------------------------------------
    def get_plugin_title(self):
        """Return widget title"""
        return _('Online help')
    
    def get_focus_widget(self):
        """
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        """
        self.pydocbrowser.url_combo.lineEdit().selectAll()
        return self.pydocbrowser.url_combo
        
    def closing_plugin(self, cancelable=False):
        """Perform actions before parent main window is closed"""
        self.save_history()
        self.set_option('zoom_factor',
                        self.pydocbrowser.webview.get_zoom_factor())
        return True
        
    def refresh_plugin(self):
        """Refresh widget"""
        pass
    
    def get_plugin_actions(self):
        """Return a list of actions related to plugin"""
        return []
    
    def register_plugin(self):
        """Register plugin in Spyder's main window"""
        self.main.add_dockwidget(self)
Exemple #8
0
def pydocbrowser(qtbot):
    """Set up pydocbrowser."""
    widget = PydocBrowser(None)
    widget.start_server()
    qtbot.addWidget(widget)
    return widget