def __init__(self, parent=None): SpyderPluginWidget.__init__(self, parent) show_fullpath = self.get_option('show_fullpath') show_all_files = self.get_option('show_all_files') group_cells = self.get_option('group_cells') show_comments = self.get_option('show_comments') self.explorer = OutlineExplorerWidget( self, show_fullpath=show_fullpath, show_all_files=show_all_files, group_cells=group_cells, show_comments=show_comments, options_button=self.options_button) layout = QVBoxLayout() layout.addWidget(self.explorer) self.setLayout(layout) # Menu as corner widget self.explorer.treewidget.header().hide() self.load_config() # Initialize plugin self.initialize_plugin()
def __init__(self, parent=None): SpyderPluginWidget.__init__(self, parent) show_fullpath = self.get_option('show_fullpath') show_all_files = self.get_option('show_all_files') group_cells = self.get_option('group_cells') show_comments = self.get_option('show_comments') sort_files_alphabetically = self.get_option( 'sort_files_alphabetically') follow_cursor = self.get_option('follow_cursor') display_variables = self.get_option('display_variables') self.explorer = OutlineExplorerWidget( self, show_fullpath=show_fullpath, show_all_files=show_all_files, group_cells=group_cells, show_comments=show_comments, sort_files_alphabetically=sort_files_alphabetically, display_variables=display_variables, follow_cursor=follow_cursor, options_button=self.options_button) layout = QVBoxLayout() layout.addWidget(self.explorer) self.setLayout(layout) # Menu as corner widget self.explorer.treewidget.header().hide() self.load_config()
def setup_outline_explorer(qtbot): """Set up outline_explorer.""" oew = OutlineExplorerWidget(None) qtbot.addWidget(oew) oe_proxy = OutlineExplorerProxyTest('test.py', oe_data) oew.set_current_editor(oe_proxy, update=True, clear=False) return oew, oe_proxy
def setup_outline_explorer(qtbot): """Set up outline_explorer.""" oew = OutlineExplorerWidget(None) qtbot.addWidget(oew) oe_proxy = OutlineExplorerProxyTest('test.py', oe_data) oew.set_current_editor(oe_proxy, update=True, clear=False) return oew, oe_proxy
def outlineexplorer(qtbot): """Set up an OutlineExplorerWidget.""" outlineexplorer = OutlineExplorerWidget( show_fullpath=False, show_all_files=True, group_cells=False, show_comments=True, sort_files_alphabetically=False) # Fix the size of the outline explorer to prevent an # 'Unable to set geometry ' warning if the test fails. outlineexplorer.setFixedSize(400, 350) qtbot.addWidget(outlineexplorer) outlineexplorer.show() return outlineexplorer
def editor_outline_explorer_bot(): """setup editor and outline_explorer.""" app = qapplication() editor = CodeEditor(parent=None) editor.setup_editor(language='Python') outlineexplorer = OutlineExplorerWidget(editor) editor.set_text(text) editor.oe_proxy = OutlineExplorerProxyEditor(editor, "test.py") outlineexplorer.set_current_editor(editor.oe_proxy, update=False, clear=False) outlineexplorer.setEnabled(True) return editor, outlineexplorer, editor.oe_proxy
def test_save_as_with_outline(editor_bot, mocker, tmpdir): """ Test EditorStack.save_as() when the outline explorer is not None. Regression test for issue #7754. """ editorstack, qtbot = editor_bot # Set and assert the initial state. editorstack.tabs.setCurrentIndex(1) assert editorstack.get_current_filename() == 'secondtab.py' # Add an outline explorer to the editor stack and refresh it. editorstack.set_outlineexplorer(OutlineExplorerWidget()) qtbot.addWidget(editorstack.outlineexplorer) editorstack.refresh() # No save name. mocker.patch.object(editorstack, 'select_savename', return_value=None) assert editorstack.save_as() is False assert editorstack.get_filenames() == ['foo.py', 'secondtab.py', __file__] # Save secondtab.py as foo2.py in a tmpdir new_filename = osp.join(tmpdir.strpath, 'foo2.py') editorstack.select_savename.return_value = new_filename assert not osp.exists(new_filename) assert editorstack.save_as() is True assert editorstack.get_filenames() == ['foo.py', new_filename, __file__] assert osp.exists(new_filename)
def _create_outlineexplorer(code, filename, follow_cursor=False): code_editor = CodeEditor(None) code_editor.set_language('py', filename) code_editor.set_text(code) editor = OutlineExplorerProxyEditor(code_editor, filename) outlineexplorer = OutlineExplorerWidget(follow_cursor=follow_cursor) outlineexplorer.set_current_editor(editor, False, False) outlineexplorer.show() outlineexplorer.setFixedSize(400, 350) qtbot.addWidget(outlineexplorer) return outlineexplorer
def outlineexplorer(qtbot): """Set up an OutlineExplorerWidget.""" outlineexplorer = OutlineExplorerWidget( show_fullpath=False, show_all_files=True, group_cells=False, show_comments=True, sort_files_alphabetically=False) # Fix the size of the outline explorer to prevent an # 'Unable to set geometry ' warning if the test fails. outlineexplorer.setFixedSize(400, 350) qtbot.addWidget(outlineexplorer) outlineexplorer.show() return outlineexplorer
def __init__(self, parent=None): Qt.QSplitter.__init__(self, parent) self.editorstacks = [] self.editorwindows = [] self.menu_actions, self.io_actions = self.createMenuActions() self.find_widget = FindReplace(self, enable_replace=True) self.outlineexplorer = OutlineExplorerWidget(self, show_fullpath=False, show_all_files=False) self.outlineexplorer.edit_goto.connect(self.go_to_file) self.editor_splitter = EditorSplitter(self, self, self.menu_actions, first=True) editor_widgets = Qt.QWidget(self) editor_layout = Qt.QVBoxLayout() editor_layout.setContentsMargins(0, 0, 0, 0) editor_widgets.setLayout(editor_layout) editor_layout.addWidget(self.editor_splitter) editor_layout.addWidget(self.find_widget) self.setContentsMargins(0, 0, 0, 0) self.addWidget(editor_widgets) self.addWidget(self.outlineexplorer) self.setStretchFactor(0, 5) self.setStretchFactor(1, 1) self.toolbar_list = None self.menu_list = None self.setup_window([], []) try: # spyder v3 from spyder.utils.introspection.manager import IntrospectionManager # Set introspector introspector = IntrospectionManager() editorstack = self.editor_splitter.editorstack editorstack.set_introspector(introspector) introspector.set_editor_widget(editorstack) except ImportError: pass # TODO: support introspection with spyder v4
def editor_outline_explorer_bot(): """setup editor and outline_explorer.""" app = qapplication() editor = CodeEditor(parent=None) editor.setup_editor(language='Python') outlineexplorer = OutlineExplorerWidget(editor) editor.set_text(text) editor.oe_proxy = OutlineExplorerProxyEditor(editor, "test.py") outlineexplorer.set_current_editor(editor.oe_proxy, update=False, clear=False) outlineexplorer.setEnabled(True) return editor, outlineexplorer, editor.oe_proxy
def empty_editor_bot(qtbot): """Set up an empty EditorStack with an OutlineExplorerWidget.""" outlineexplorer = OutlineExplorerWidget( show_fullpath=False, show_all_files=True, group_cells=False, show_comments=True) # Fix the size of the outline explorer to prevent an # 'Unable to set geometry ' warning if the test fails. outlineexplorer.setFixedSize(400, 350) qtbot.addWidget(outlineexplorer) outlineexplorer.show() editorstack = editor.EditorStack(None, []) editorstack.set_introspector(Mock()) editorstack.set_find_widget(Mock()) editorstack.set_io_actions(Mock(), Mock(), Mock(), Mock()) editorstack.analysis_timer = Mock() editorstack.save_dialog_on_tests = True editorstack.set_outlineexplorer(outlineexplorer) qtbot.addWidget(editorstack) editorstack.show() return editorstack, outlineexplorer, qtbot
class OutlineExplorer(SpyderPluginWidget): """Outline Explorer plugin.""" CONF_SECTION = 'outline_explorer' CONF_FILE = False # This is required for the new API NAME = 'outline_explorer' REQUIRES = [Plugins.Completions] OPTIONAL = [] def __init__(self, parent=None): SpyderPluginWidget.__init__(self, parent) show_fullpath = self.get_option('show_fullpath') show_all_files = self.get_option('show_all_files') group_cells = self.get_option('group_cells') show_comments = self.get_option('show_comments') sort_files_alphabetically = self.get_option( 'sort_files_alphabetically') follow_cursor = self.get_option('follow_cursor') display_variables = self.get_option('display_variables') self.explorer = OutlineExplorerWidget( self, show_fullpath=show_fullpath, show_all_files=show_all_files, group_cells=group_cells, show_comments=show_comments, sort_files_alphabetically=sort_files_alphabetically, display_variables=display_variables, follow_cursor=follow_cursor, options_button=self.options_button) layout = QVBoxLayout() layout.addWidget(self.explorer) self.setLayout(layout) # Menu as corner widget self.explorer.treewidget.header().hide() self.load_config() #------ SpyderPluginWidget API --------------------------------------------- def get_plugin_title(self): """Return widget title""" return _("Outline") def get_plugin_icon(self): """Return widget icon""" return ima.icon('outline_explorer') def get_focus_widget(self): """ Return the widget to give focus to when this plugin's dockwidget is raised on top-level """ return self.explorer.treewidget def get_plugin_actions(self): """Return a list of actions related to plugin""" return self.explorer.treewidget.get_menu_actions() def register_plugin(self): """Register plugin in Spyder's main window""" self.main.restore_scrollbar_position.connect( self.restore_scrollbar_position) self.main.completions.sig_language_completions_available.connect( self.start_symbol_services) self.main.completions.sig_stop_completions.connect( self.stop_symbol_services) self.add_dockwidget() def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.save_config() return True #------ BasePluginWidgetMixin API --------------------------------------------- def _visibility_changed(self, enable): """DockWidget visibility has changed""" super(SpyderPluginWidget, self)._visibility_changed(enable) if enable: self.explorer.is_visible.emit() #------ Public API --------------------------------------------------------- def restore_scrollbar_position(self): """Restoring scrollbar position after main window is visible""" scrollbar_pos = self.get_option('scrollbar_position', None) if scrollbar_pos is not None: self.explorer.treewidget.set_scrollbar_position(scrollbar_pos) def save_config(self): """Save configuration: tree widget state""" for option, value in list(self.explorer.get_options().items()): self.set_option(option, value) self.set_option('expanded_state', self.explorer.treewidget.get_expanded_state()) self.set_option('scrollbar_position', self.explorer.treewidget.get_scrollbar_position()) def load_config(self): """Load configuration: tree widget state""" expanded_state = self.get_option('expanded_state', None) # Sometimes the expanded state option may be truncated in .ini file # (for an unknown reason), in this case it would be converted to a # string by 'userconfig': if is_text_string(expanded_state): expanded_state = None if expanded_state is not None: self.explorer.treewidget.set_expanded_state(expanded_state) @Slot(dict, str) def start_symbol_services(self, capabilities, language): """Enable LSP symbols functionality.""" symbol_provider = capabilities.get('documentSymbolProvider', False) if symbol_provider: self.explorer.start_symbol_services(language) def stop_symbol_services(self, language): """Disable LSP symbols functionality.""" self.explorer.stop_symbol_services(language) def update_all_editors(self): """Update all editors with an associated LSP server.""" self.explorer.update_all_editors()
case_info = CASES[case] filename = case_info['file'] with open(case_info['file'], 'r') as f: text = f.read() symbol_info = json.load(open(case_info['data'], 'r')) expected_tree = json.load(open(case_info['tree'], 'r')) code_editor = CodeEditor(None) code_editor.set_language('py', filename) code_editor.set_text(text) editor = OutlineExplorerProxyEditor(code_editor, filename) outlineexplorer = OutlineExplorerWidget(follow_cursor=follow_cursor, display_variables=True, group_cells=True, show_comments=True) outlineexplorer.register_editor(editor) outlineexplorer.set_current_editor(editor, False, False) outlineexplorer.show() outlineexplorer.setFixedSize(400, 350) editor.update_outline_info(symbol_info) qtbot.addWidget(outlineexplorer) return outlineexplorer, expected_tree return _create_outlineexplorer # ---- Test OutlineExplorerWidget @pytest.mark.parametrize('case', AVAILABLE_CASES) def test_outline_explorer(case, create_outlineexplorer):
filename = case_info['file'] with open(case_info['file'], 'r') as f: text = f.read() symbol_info = json.load(open(case_info['data'], 'r')) expected_tree = json.load(open(case_info['tree'], 'r')) code_editor = CodeEditor(None) code_editor.set_language('py', filename) code_editor.set_text(text) editor = OutlineExplorerProxyEditor(code_editor, filename) plugin_mock = MagicMock() plugin_mock.NAME = 'outline_explorer' outlineexplorer = OutlineExplorerWidget('outline_explorer', plugin_mock, None) outlineexplorer.setup() outlineexplorer.set_conf('show_fullpath', True) outlineexplorer.set_conf('show_comments', True) outlineexplorer.set_conf('group_cells', True) outlineexplorer.set_conf('display_variables', True) outlineexplorer.set_conf('follow_cursor', follow_cursor) outlineexplorer.register_editor(editor) outlineexplorer.set_current_editor(editor, False, False) outlineexplorer.show() outlineexplorer.setFixedSize(400, 350) editor.update_outline_info(symbol_info) qtbot.addWidget(outlineexplorer)
def _create_outlineexplorer(case, follow_cursor=False): case_info = CASES[case] filename = case_info['file'] with open(case_info['file'], 'r') as f: text = f.read() symbol_info = json.load(open(case_info['data'], 'r')) expected_tree = json.load(open(case_info['tree'], 'r')) code_editor = CodeEditor(None) code_editor.set_language('py', filename) code_editor.set_text(text) editor = OutlineExplorerProxyEditor(code_editor, filename) outlineexplorer = OutlineExplorerWidget(follow_cursor=follow_cursor) outlineexplorer.set_current_editor(editor, False, False) outlineexplorer.show() outlineexplorer.setFixedSize(400, 350) editor.update_outline_info(symbol_info) qtbot.addWidget(outlineexplorer) return outlineexplorer, expected_tree return _create_outlineexplorer # ---- Test OutlineExplorerWidget @pytest.mark.parametrize('case', AVAILABLE_CASES) def test_outline_explorer(case, create_outlineexplorer): """
def outlineexplorer(qtbot): """Set up an OutlineExplorerWidget.""" outlineexplorer = OutlineExplorerWidget(None, None, None) outlineexplorer.set_conf('show_fullpath', False) outlineexplorer.set_conf('show_all_files', True) outlineexplorer.set_conf('group_cells', True) outlineexplorer.set_conf('show_comments', True) outlineexplorer.set_conf('sort_files_alphabetically', False) outlineexplorer.set_conf('display_variables', True) # Fix the size of the outline explorer to prevent an # 'Unable to set geometry ' warning if the test fails. outlineexplorer.setFixedSize(400, 350) qtbot.addWidget(outlineexplorer) outlineexplorer.show() return outlineexplorer
class OutlineExplorer(SpyderPluginWidget): """Outline Explorer plugin.""" CONF_SECTION = 'outline_explorer' def __init__(self, parent=None): SpyderPluginWidget.__init__(self, parent) show_fullpath = self.get_option('show_fullpath') show_all_files = self.get_option('show_all_files') group_cells = self.get_option('group_cells') show_comments = self.get_option('show_comments') self.explorer = OutlineExplorerWidget( self, show_fullpath=show_fullpath, show_all_files=show_all_files, group_cells=group_cells, show_comments=show_comments, options_button=self.options_button) layout = QVBoxLayout() layout.addWidget(self.explorer) self.setLayout(layout) # Menu as corner widget self.explorer.treewidget.header().hide() self.load_config() # Initialize plugin self.initialize_plugin() #------ SpyderPluginWidget API --------------------------------------------- def get_plugin_title(self): """Return widget title""" return _("Outline") def get_plugin_icon(self): """Return widget icon""" return ima.icon('outline_explorer') def get_focus_widget(self): """ Return the widget to give focus to when this plugin's dockwidget is raised on top-level """ return self.explorer.treewidget def get_plugin_actions(self): """Return a list of actions related to plugin""" return self.explorer.treewidget.get_menu_actions() def register_plugin(self): """Register plugin in Spyder's main window""" self.main.restore_scrollbar_position.connect( self.restore_scrollbar_position) self.main.add_dockwidget(self) def refresh_plugin(self): """Refresh project explorer widget""" pass def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" self.save_config() return True #------ SpyderPluginMixin API --------------------------------------------- def visibility_changed(self, enable): """DockWidget visibility has changed""" super(SpyderPluginWidget, self).visibility_changed(enable) if enable: self.explorer.is_visible.emit() #------ Public API --------------------------------------------------------- def restore_scrollbar_position(self): """Restoring scrollbar position after main window is visible""" scrollbar_pos = self.get_option('scrollbar_position', None) if scrollbar_pos is not None: self.explorer.treewidget.set_scrollbar_position(scrollbar_pos) def save_config(self): """Save configuration: tree widget state""" for option, value in list(self.explorer.get_options().items()): self.set_option(option, value) self.set_option('expanded_state', self.explorer.treewidget.get_expanded_state()) self.set_option('scrollbar_position', self.explorer.treewidget.get_scrollbar_position()) def load_config(self): """Load configuration: tree widget state""" expanded_state = self.get_option('expanded_state', None) # Sometimes the expanded state option may be truncated in .ini file # (for an unknown reason), in this case it would be converted to a # string by 'userconfig': if is_text_string(expanded_state): expanded_state = None if expanded_state is not None: self.explorer.treewidget.set_expanded_state(expanded_state)