Repository: spyder-ide/spyder

Issue:
Error when opening a new project
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 148, in <lambda>
    lambda v: self.editor.setup_open_files())
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/plugins/editor.py", line 2662, in setup_open_files
    self.close_all_files()
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/plugins/editor.py", line 1974, in close_all_files
    self.editorstacks[0].close_all_files()
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/editor.py", line 1408, in close_all_files
    while self.close_file():
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/editor.py", line 1370, in close_file
    self.remove_from_data(index)
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/editor.py", line 1163, in remove_from_data
    self.update_fileswitcher_dlg()
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/editor.py", line 822, in update_fileswitcher_dlg
    self.fileswitcher_dlg.setup()
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/fileswitcher.py", line 757, in setup
    current_path = self.current_path
  File "/home/srt/anaconda3/lib/python3.6/site-packages/spyder/widgets/fileswitcher.py", line 346, in current_path
    return self.paths_by_widget[self.get_widget()]
KeyError: None
WARNING:traitlets:kernel died: 6.005160331726074


## Version and main components

* Spyder Version: 3.2.3 
* Python Version: 3.6.2
* Qt Versions: 5.6.2, PyQt5 5.6 on Linux

## Dependencies
```
pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.1.3 (OK)
pandas >=0.13.1  :  0.19.2 (OK)
numpy >=1.7      :  1.11.3 (OK)
sphinx >=0.6.6   :  1.5.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.9.0 (OK)
psutil >=0.3     :  5.1.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
IPython >=4.0    :  5.1.0 (OK)
pylint >=0.25    :  1.6.4 (OK)

```



Discussion:
@ccordoba12 There it is, our full traceback for Issue #5277 :)
Yep, that's right. Thanks for noticing it @jnsebgosselin!

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -2794,7 +2794,6 @@ def open_fileswitcher(self, symbol=False):
             self.fileswitcher.plugin = self.editor
         else:
             self.fileswitcher.set_search_text('')
-        self.fileswitcher.setup()
         self.fileswitcher.show()
         self.fileswitcher.is_visible = True
 
diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py
--- a/spyder/widgets/editor.py
+++ b/spyder/widgets/editor.py
@@ -817,7 +817,6 @@ def open_fileswitcher_dlg(self):
         self.fileswitcher_dlg = FileSwitcher(self, self, self.tabs, self.data,
                                              ima.icon('TextFileIcon'))
         self.fileswitcher_dlg.sig_goto_file.connect(self.set_stack_index)
-        self.fileswitcher_dlg.setup()
         self.fileswitcher_dlg.show()
         self.fileswitcher_dlg.is_visible = True
 
@@ -826,11 +825,6 @@ def open_symbolfinder_dlg(self):
         self.open_fileswitcher_dlg()
         self.fileswitcher_dlg.set_search_text('@')
         
-    def update_fileswitcher_dlg(self):
-        """Synchronize file list dialog box with editor widget tabs"""
-        if self.fileswitcher_dlg:
-            self.fileswitcher_dlg.setup()
-
     def get_current_tab_manager(self):
         """Get the widget with the TabWidget attribute."""
         return self
@@ -1170,7 +1164,6 @@ def remove_from_data(self, index):
         self.data.pop(index)
         self.tabs.blockSignals(False)
         self.update_actions()
-        self.update_fileswitcher_dlg()
 
     def __modified_readonly_title(self, title, is_modified, is_readonly):
         if is_modified is not None and is_modified:
@@ -1218,7 +1211,6 @@ def add_to_data(self, finfo, set_current):
             self.set_stack_index(index)
             self.current_changed(index)
         self.update_actions()
-        self.update_fileswitcher_dlg()
 
     def __repopulate_stack(self):
         self.tabs.blockSignals(True)
@@ -1234,7 +1226,6 @@ def __repopulate_stack(self):
             index = self.tabs.addTab(finfo.editor, tab_text)
             self.tabs.setTabToolTip(index, tab_tip)
         self.tabs.blockSignals(False)
-        self.update_fileswitcher_dlg()
 
     def rename_in_data(self, index, new_filename):
         finfo = self.data[index]
diff --git a/spyder/widgets/fileswitcher.py b/spyder/widgets/fileswitcher.py
--- a/spyder/widgets/fileswitcher.py
+++ b/spyder/widgets/fileswitcher.py
@@ -770,6 +770,14 @@ def setup(self):
         # Set position according to size
         self.set_dialog_position()
 
+    def show(self):
+        """
+        Override Qt method to force an update of the fileswitcher before
+        showing it. See Issue #5317 and PR #5389.
+        """
+        self.setup()
+        super(FileSwitcher, self).show()
+
     def add_plugin(self, plugin, tabs, data, icon):
         """Add a plugin to display its files."""
         self.plugins_tabs.append((tabs, plugin))


Test patch: