Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create only one instance of IntrospectionManager for the application #3234

Merged
merged 4 commits into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions spyderlib/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from spyderlib.py3compat import getcwd, PY2, qbytearray_to_str, to_text_string
from spyderlib.utils import codeanalysis, encoding, programs, sourcecode
from spyderlib.utils import icon_manager as ima
from spyderlib.utils.introspection.manager import IntrospectionManager
from spyderlib.utils.qthelpers import (add_actions, add_shortcut_to_tooltip,
create_action, get_filetype_icon)
from spyderlib.widgets.findreplace import FindReplace
Expand Down Expand Up @@ -387,7 +388,7 @@ def __init__(self, parent, ignore_last_opened_files=False):
self.editorstacks = None
self.editorwindows = None
self.editorwindows_to_be_created = None

self.file_dependent_actions = []
self.pythonfile_dependent_actions = []
self.dock_toolbar_actions = None
Expand Down Expand Up @@ -424,7 +425,9 @@ def __init__(self, parent, ignore_last_opened_files=False):
self.editorwindows_to_be_created = []
self.toolbar_list = None
self.menu_list = None


self.introspector = IntrospectionManager()

# Setup new windows:
self.main.all_actions_defined.connect(self.setup_other_windows)

Expand Down Expand Up @@ -1093,8 +1096,7 @@ def save_focus_editorstack(self):
for win in [self]+self.editorwindows:
if win.isAncestorOf(editorstack):
self.set_last_focus_editorstack(win, editorstack)



#------ Handling editorstacks
def register_editorstack(self, editorstack):
self.editorstacks.append(editorstack)
Expand Down Expand Up @@ -1122,6 +1124,8 @@ def register_editorstack(self, editorstack):
editorstack.set_io_actions(self.new_action, self.open_action,
self.save_action, self.revert_action)
editorstack.set_tempfile_path(self.TEMPFILE_PATH)
editorstack.set_introspector(self.introspector)

settings = (
('set_pyflakes_enabled', 'code_analysis/pyflakes'),
('set_pep8_enabled', 'code_analysis/pep8'),
Expand Down Expand Up @@ -1174,6 +1178,7 @@ def register_editorstack(self, editorstack):
editorstack.update_plugin_title.connect(
lambda: self.update_plugin_title.emit())
editorstack.editor_focus_changed.connect(self.save_focus_editorstack)
editorstack.editor_focus_changed.connect(self.set_editorstack_for_introspection)
editorstack.editor_focus_changed.connect(self.main.plugin_focus_changed)
editorstack.zoom_in.connect(lambda: self.zoom(1))
editorstack.zoom_out.connect(lambda: self.zoom(-1))
Expand Down Expand Up @@ -1243,8 +1248,29 @@ def file_renamed_in_data_in_editorstack(self, editorstack_id_str,
if str(id(editorstack)) != editorstack_id_str:
editorstack.rename_in_data(index, filename)

def set_editorstack_for_introspection(self):
"""
Set the current editorstack to be used by the IntrospectionManager
instance
"""
editorstack = self.__get_focus_editorstack()
if editorstack is not None:
self.introspector.set_editor_widget(editorstack)

# Disconnect active signals
try:
self.introspector.send_to_help.disconnect()
self.introspector.edit_goto.disconnect()
except TypeError:
pass

# Reconnect signals again
self.introspector.send_to_help.connect(editorstack.send_to_help)
self.introspector.edit_goto.connect(
lambda fname, lineno, name:
editorstack.edit_goto.emit(fname, lineno, name))

#------ Handling editor windows
#------ Handling editor windows
def setup_other_windows(self):
"""Setup toolbars and menus for 'New window' instances"""
self.toolbar_list = (
Expand Down
7 changes: 5 additions & 2 deletions spyderlib/utils/introspection/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ class IntrospectionManager(QObject):
send_to_help = Signal(str, str, str, str, bool)
edit_goto = Signal(str, int, str)

def __init__(self, editor_widget, executable=None):
def __init__(self, executable=None):
super(IntrospectionManager, self).__init__()
self.editor_widget = editor_widget
self.editor_widget = None
self.pending = None
self.plugin_manager = PluginManager(executable)
self.plugin_manager.introspection_complete.connect(
Expand All @@ -174,6 +174,9 @@ def change_executable(self, executable):
self.plugin_manager.introspection_complete.connect(
self._introspection_complete)

def set_editor_widget(self, editor_widget):
self.editor_widget = editor_widget

def _get_code_info(self, name, position=None, **kwargs):

editor = self.editor_widget.get_current_editor()
Expand Down
24 changes: 14 additions & 10 deletions spyderlib/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from spyderlib.utils import icon_manager as ima
from spyderlib.utils import (codeanalysis, encoding, sourcecode,
syntaxhighlighters)
from spyderlib.utils.introspection.manager import IntrospectionManager
from spyderlib.utils.qthelpers import (add_actions, create_action,
create_toolbutton, get_filetype_icon,
mimedata2url)
Expand Down Expand Up @@ -402,13 +401,7 @@ def __init__(self, parent, actions):
if ccs not in syntaxhighlighters.COLOR_SCHEME_NAMES:
ccs = syntaxhighlighters.COLOR_SCHEME_NAMES[0]
self.color_scheme = ccs
self.introspector = IntrospectionManager(self)

self.introspector.send_to_help.connect(self.send_to_help)
self.introspector.edit_goto.connect(
lambda fname, lineno, name:
self.edit_goto.emit(fname, lineno, name))

self.introspector = None
self.__file_status_flag = False

# Real-time code analysis
Expand Down Expand Up @@ -862,6 +855,9 @@ def set_always_remove_trailing_spaces(self, state):
def set_focus_to_editor(self, state):
self.focus_to_editor = state

def set_introspector(self, introspector):
self.introspector = introspector

#------ Stacked widget management
def get_stack_index(self):
return self.tabs.currentIndex()
Expand Down Expand Up @@ -2192,13 +2188,14 @@ def __init__(self):
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, menu_actions,
first=True)

editor_widgets = QWidget(self)
editor_layout = QVBoxLayout()
editor_layout.setContentsMargins(0, 0, 0, 0)
editor_widgets.setLayout(editor_layout)
editor_layout.addWidget(EditorSplitter(self, self, menu_actions,
first=True))
editor_layout.addWidget(self.editor_splitter)
editor_layout.addWidget(self.find_widget)

self.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -2331,13 +2328,20 @@ def register_widget_shortcuts(self, context, widget):
def test():
from spyderlib.utils.qthelpers import qapplication
from spyderlib.config.base import get_module_path
from spyderlib.utils.introspection.manager import IntrospectionManager

cur_dir = osp.join(get_module_path('spyderlib'), 'widgets')
app = qapplication(test_time=8)
introspector = IntrospectionManager()

test = EditorPluginExample()
test.resize(900, 700)
test.show()

editorstack = test.editor_splitter.editorstack
editorstack.set_introspector(introspector)
introspector.set_editor_widget(editorstack)

import time
t0 = time.time()
test.load(osp.join(cur_dir, "editor.py"))
Expand Down