We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Crash when trying to run a Python file in a project from the explorer pane - Spyder 4.0.1
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [y] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ y] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ y] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [n/a ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ y] Tried basic troubleshooting (if a bug/error)
    * [y ] Restarted Spyder
    * [ n] Reset preferences with ``spyder --reset`` I reinstalled everything from scratch using `Anaconda3-2019.10-Windows-x86_64`
    * [y ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/) updated following: https://docs.anaconda.com/anaconda/install/update-version/ 
    * [n/a] Tried the other applicable steps from the Troubleshooting Guide
* [y ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Crash when trying to run a Python file in a project
Same as in: https://github.com/spyder-ide/spyder/issues/10590


### What steps reproduce the problem?
1. right click on a python file in the left pane
2. choose "run" from the context menu

### What is the expected output? What do you see instead?
file should execute but instead I get an error message


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py37\lib\site-packages\spyder\plugins\explorer\plugin.py", line 100, in <lambda>
    False, True))
TypeError: run_script() missing 1 required positional argument: 'console_namespace'

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.1
* Python version:  3.7.6 
* Qt version:  5.12.5
* PyQt version: 5.12.3 
* Operating System name/version: Windows 10

__N.B. In practice I am using a  py37 (python 3.7.6) virtual environment selected from the Anaconda Navigator, and with Spyder launched from there.__

![image](https://user-images.githubusercontent.com/7424763/74289367-17973600-4cec-11ea-9ea3-0fa3beb2b220.png)

![image](https://user-images.githubusercontent.com/7424763/74289341-064e2980-4cec-11ea-86fe-9a83f0c139b9.png)

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.12.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.4 (OK)
sphinx >=0.6.6               :  2.4.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  None (NOK)
matplotlib >=2.0.0           :  3.1.3 (OK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  1.0.1 (OK)
scipy >=0.17.0               :  1.4.1 (OK)
sympy >=0.7.3                :  None (NOK)

```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `spyder/plugins/explorer/plugin.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright © Spyder Project Contributors
4 # Licensed under the terms of the MIT License
5 # (see spyder/__init__.py for details)
6 
7 """Files and Directories Explorer Plugin"""
8 
9 # pylint: disable=C0103
10 # pylint: disable=R0903
11 # pylint: disable=R0911
12 # pylint: disable=R0201
13 
14 # Standard library imports
15 import os.path as osp
16 
17 # Third party imports
18 from qtpy.QtWidgets import QVBoxLayout
19 
20 # Local imports
21 from spyder.config.base import _
22 from spyder.api.plugins import SpyderPluginWidget
23 from spyder.plugins.explorer.widgets.explorer import ExplorerWidget
24 from spyder.plugins.explorer.confpage import ExplorerConfigPage
25 
26 
27 class Explorer(SpyderPluginWidget):
28     """File and Directories Explorer DockWidget."""
29 
30     CONF_SECTION = 'explorer'
31     CONFIGWIDGET_CLASS = ExplorerConfigPage
32     CONF_FILE = False
33 
34     def __init__(self, parent=None):
35         """Initialization."""
36         SpyderPluginWidget.__init__(self, parent)
37 
38         visible_columns = self.get_option('visible_columns',
39                                           default=[0, 3])  # Name & Last Mod
40         self.fileexplorer = ExplorerWidget(
41             self,
42             name_filters=self.get_option('name_filters'),
43             show_all=self.get_option('show_all'),
44             show_icontext=self.get_option('show_icontext'),
45             options_button=self.options_button,
46             single_click_to_open=self.get_option('single_click_to_open'),
47             file_associations=self.get_option('file_associations',
48                                               default={}),
49             visible_columns=visible_columns,
50         )
51         layout = QVBoxLayout()
52         layout.addWidget(self.fileexplorer)
53         self.setLayout(layout)
54         self.fileexplorer.sig_option_changed.connect(
55             self._update_config_options)
56 
57     def _update_config_options(self, option, value):
58         """Update the config options of the explorer to make them permanent."""
59         self.set_option(option, value)
60 
61     #------ SpyderPluginWidget API ---------------------------------------------
62     def get_plugin_title(self):
63         """Return widget title"""
64         return _("Files")
65     
66     def get_focus_widget(self):
67         """
68         Return the widget to give focus to when
69         this plugin's dockwidget is raised on top-level
70         """
71         return self.fileexplorer.treewidget
72     
73     def get_plugin_actions(self):
74         """Return a list of actions related to plugin"""
75         return self.fileexplorer.treewidget.common_actions
76     
77     def register_plugin(self):
78         """Register plugin in Spyder's main window"""
79         ipyconsole = self.main.ipyconsole
80         treewidget = self.fileexplorer.treewidget
81 
82         self.add_dockwidget()
83         self.fileexplorer.sig_open_file.connect(self.main.open_file)
84         self.register_widget_shortcuts(treewidget)
85 
86         treewidget.sig_edit.connect(self.main.editor.load)
87         treewidget.sig_removed.connect(self.main.editor.removed)
88         treewidget.sig_removed_tree.connect(self.main.editor.removed_tree)
89         treewidget.sig_renamed.connect(self.main.editor.renamed)
90         treewidget.sig_renamed_tree.connect(self.main.editor.renamed_tree)
91         treewidget.sig_create_module.connect(self.main.editor.new)
92         treewidget.sig_new_file.connect(lambda t: self.main.editor.new(text=t))
93         treewidget.sig_open_interpreter.connect(
94             ipyconsole.create_client_from_path)
95         treewidget.redirect_stdio.connect(
96             self.main.redirect_internalshell_stdio)
97         treewidget.sig_run.connect(
98             lambda fname:
99             ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,
100                                   False, True))
101         treewidget.sig_open_dir.connect(
102             lambda dirname:
103             self.main.workingdirectory.chdir(dirname,
104                                              refresh_explorer=False,
105                                              refresh_console=True))
106 
107         self.main.editor.open_dir.connect(self.chdir)
108 
109         # Signal "set_explorer_cwd(QString)" will refresh only the
110         # contents of path passed by the signal in explorer:
111         self.main.workingdirectory.set_explorer_cwd.connect(
112                      lambda directory: self.refresh_plugin(new_path=directory,
113                                                            force_current=True))
114 
115     def refresh_plugin(self, new_path=None, force_current=True):
116         """Refresh explorer widget"""
117         self.fileexplorer.treewidget.update_history(new_path)
118         self.fileexplorer.treewidget.refresh(new_path,
119                                              force_current=force_current)
120 
121     def on_first_registration(self):
122         """Action to be performed on first plugin registration."""
123         # TODO: Remove this for spyder 5
124         # self.tabify(self.main.projects)
125         self.tabify(self.main.variableexplorer)
126 
127     def apply_plugin_settings(self, options):
128         """Handle preference options update."""
129         method_map = {
130             'file_associations':
131                 self.fileexplorer.treewidget.set_file_associations,
132             'single_click_to_open':
133                 self.fileexplorer.treewidget.set_single_click_to_open,
134             'name_filters':
135                 self.fileexplorer.treewidget.set_name_filters,
136             'show_all':
137                 self.fileexplorer.treewidget.toggle_all,
138             'show_icontext':
139                 self.fileexplorer.toggle_icontext,
140         }
141         for option in options:
142             if option in method_map:
143                 value = self.get_option(option)
144                 method = method_map.get(option)
145                 method(value)
146         self.fileexplorer.treewidget.update_common_actions()
147 
148     #------ Public API ---------------------------------------------------------
149     def chdir(self, directory):
150         """Set working directory"""
151         self.fileexplorer.treewidget.chdir(directory)
152
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/spyder/plugins/explorer/plugin.py b/spyder/plugins/explorer/plugin.py
--- a/spyder/plugins/explorer/plugin.py
+++ b/spyder/plugins/explorer/plugin.py
@@ -97,7 +97,7 @@
         treewidget.sig_run.connect(
             lambda fname:
             ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,
-                                  False, True))
+                                  False, True, False))
         treewidget.sig_open_dir.connect(
             lambda dirname:
             self.main.workingdirectory.chdir(dirname,

{"golden_diff": "diff --git a/spyder/plugins/explorer/plugin.py b/spyder/plugins/explorer/plugin.py\n--- a/spyder/plugins/explorer/plugin.py\n+++ b/spyder/plugins/explorer/plugin.py\n@@ -97,7 +97,7 @@\n         treewidget.sig_run.connect(\r\n             lambda fname:\r\n             ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,\r\n-                                  False, True))\r\n+                                  False, True, False))\r\n         treewidget.sig_open_dir.connect(\r\n             lambda dirname:\r\n             self.main.workingdirectory.chdir(dirname,\n", "issue": "Crash when trying to run a Python file in a project from the explorer pane - Spyder 4.0.1\n<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->\r\n\r\n### Issue Report Checklist\r\n\r\n* [y] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports\r\n* [ y] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice\r\n* [ y] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)\r\n* [n/a ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)\r\n* [ y] Tried basic troubleshooting (if a bug/error)\r\n    * [y ] Restarted Spyder\r\n    * [ n] Reset preferences with ``spyder --reset`` I reinstalled everything from scratch using `Anaconda3-2019.10-Windows-x86_64`\r\n    * [y ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/) updated following: https://docs.anaconda.com/anaconda/install/update-version/ \r\n    * [n/a] Tried the other applicable steps from the Troubleshooting Guide\r\n* [y ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below\r\n\r\n\r\n## Problem Description\r\nCrash when trying to run a Python file in a project\r\nSame as in: https://github.com/spyder-ide/spyder/issues/10590\r\n\r\n\r\n### What steps reproduce the problem?\r\n1. right click on a python file in the left pane\r\n2. choose \"run\" from the context menu\r\n\r\n### What is the expected output? What do you see instead?\r\nfile should execute but instead I get an error message\r\n\r\n\r\n### Paste Traceback/Error Below (if applicable)\r\n<!--- Copy from error dialog or View > Panes > Internal Console --->\r\n\r\n```python-traceback\r\n\r\n  File \"C:\\Users\\...\\AppData\\Local\\Continuum\\anaconda3\\envs\\py37\\lib\\site-packages\\spyder\\plugins\\explorer\\plugin.py\", line 100, in <lambda>\r\n    False, True))\r\nTypeError: run_script() missing 1 required positional argument: 'console_namespace'\r\n\r\n```\r\n\r\n## Versions\r\n<!--- You can get this information from Help > About Spyder...\r\nor (if Spyder won't launch) the \"conda list\" command\r\nfrom the Anaconda Prompt/Terminal/command line. --->\r\n\r\n* Spyder version: 4.0.1\r\n* Python version:  3.7.6 \r\n* Qt version:  5.12.5\r\n* PyQt version: 5.12.3 \r\n* Operating System name/version: Windows 10\r\n\r\n__N.B. In practice I am using a  py37 (python 3.7.6) virtual environment selected from the Anaconda Navigator, and with Spyder launched from there.__\r\n\r\n![image](https://user-images.githubusercontent.com/7424763/74289367-17973600-4cec-11ea-9ea3-0fa3beb2b220.png)\r\n\r\n![image](https://user-images.githubusercontent.com/7424763/74289341-064e2980-4cec-11ea-86fe-9a83f0c139b9.png)\r\n\r\n### Dependencies\r\n<!--- Please go to the menu entry Help > Dependencies,\r\npress the Copy to clipboard button and paste below --->\r\n\r\n```\r\natomicwrites >=1.2.0         :  1.3.0 (OK)\r\nchardet >=2.0.0              :  3.0.4 (OK)\r\ncloudpickle >=0.5.0          :  1.2.2 (OK)\r\ndiff_match_patch >=20181111  :  20181111 (OK)\r\nintervaltree                 :  None (OK)\r\nIPython >=4.0                :  7.12.0 (OK)\r\njedi =0.14.1                 :  0.14.1 (OK)\r\nnbconvert >=4.0              :  5.6.1 (OK)\r\nnumpydoc >=0.6.0             :  0.9.2 (OK)\r\npexpect >=4.4.0              :  4.8.0 (OK)\r\npickleshare >=0.4            :  0.7.5 (OK)\r\npsutil >=0.3                 :  5.6.7 (OK)\r\npygments >=2.0               :  2.5.2 (OK)\r\npylint >=0.25                :  2.4.4 (OK)\r\npyls >=0.31.2;<0.32.0        :  0.31.7 (OK)\r\nzmq >=17                     :  18.1.1 (OK)\r\nqdarkstyle >=2.7             :  2.8 (OK)\r\nqtawesome >=0.5.7            :  0.6.1 (OK)\r\nqtconsole >=4.6.0            :  4.6.0 (OK)\r\nqtpy >=1.5.0                 :  1.9.0 (OK)\r\nrtree >=0.8.3                :  0.9.4 (OK)\r\nsphinx >=0.6.6               :  2.4.0 (OK)\r\nspyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)\r\nwatchdog                     :  None (OK)\r\ncython >=0.21                :  None (NOK)\r\nmatplotlib >=2.0.0           :  3.1.3 (OK)\r\nnumpy >=1.7                  :  1.18.1 (OK)\r\npandas >=0.13.1              :  1.0.1 (OK)\r\nscipy >=0.17.0               :  1.4.1 (OK)\r\nsympy >=0.7.3                :  None (NOK)\r\n\r\n```\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\r\n#\r\n# Copyright \u00a9 Spyder Project Contributors\r\n# Licensed under the terms of the MIT License\r\n# (see spyder/__init__.py for details)\r\n\r\n\"\"\"Files and Directories Explorer Plugin\"\"\"\r\n\r\n# pylint: disable=C0103\r\n# pylint: disable=R0903\r\n# pylint: disable=R0911\r\n# pylint: disable=R0201\r\n\r\n# Standard library imports\r\nimport os.path as osp\r\n\r\n# Third party imports\r\nfrom qtpy.QtWidgets import QVBoxLayout\r\n\r\n# Local imports\r\nfrom spyder.config.base import _\r\nfrom spyder.api.plugins import SpyderPluginWidget\r\nfrom spyder.plugins.explorer.widgets.explorer import ExplorerWidget\r\nfrom spyder.plugins.explorer.confpage import ExplorerConfigPage\r\n\r\n\r\nclass Explorer(SpyderPluginWidget):\r\n    \"\"\"File and Directories Explorer DockWidget.\"\"\"\r\n\r\n    CONF_SECTION = 'explorer'\r\n    CONFIGWIDGET_CLASS = ExplorerConfigPage\r\n    CONF_FILE = False\r\n\r\n    def __init__(self, parent=None):\r\n        \"\"\"Initialization.\"\"\"\r\n        SpyderPluginWidget.__init__(self, parent)\r\n\r\n        visible_columns = self.get_option('visible_columns',\r\n                                          default=[0, 3])  # Name & Last Mod\r\n        self.fileexplorer = ExplorerWidget(\r\n            self,\r\n            name_filters=self.get_option('name_filters'),\r\n            show_all=self.get_option('show_all'),\r\n            show_icontext=self.get_option('show_icontext'),\r\n            options_button=self.options_button,\r\n            single_click_to_open=self.get_option('single_click_to_open'),\r\n            file_associations=self.get_option('file_associations',\r\n                                              default={}),\r\n            visible_columns=visible_columns,\r\n        )\r\n        layout = QVBoxLayout()\r\n        layout.addWidget(self.fileexplorer)\r\n        self.setLayout(layout)\r\n        self.fileexplorer.sig_option_changed.connect(\r\n            self._update_config_options)\r\n\r\n    def _update_config_options(self, option, value):\r\n        \"\"\"Update the config options of the explorer to make them permanent.\"\"\"\r\n        self.set_option(option, value)\r\n\r\n    #------ SpyderPluginWidget API ---------------------------------------------\r\n    def get_plugin_title(self):\r\n        \"\"\"Return widget title\"\"\"\r\n        return _(\"Files\")\r\n    \r\n    def get_focus_widget(self):\r\n        \"\"\"\r\n        Return the widget to give focus to when\r\n        this plugin's dockwidget is raised on top-level\r\n        \"\"\"\r\n        return self.fileexplorer.treewidget\r\n    \r\n    def get_plugin_actions(self):\r\n        \"\"\"Return a list of actions related to plugin\"\"\"\r\n        return self.fileexplorer.treewidget.common_actions\r\n    \r\n    def register_plugin(self):\r\n        \"\"\"Register plugin in Spyder's main window\"\"\"\r\n        ipyconsole = self.main.ipyconsole\r\n        treewidget = self.fileexplorer.treewidget\r\n\r\n        self.add_dockwidget()\r\n        self.fileexplorer.sig_open_file.connect(self.main.open_file)\r\n        self.register_widget_shortcuts(treewidget)\r\n\r\n        treewidget.sig_edit.connect(self.main.editor.load)\r\n        treewidget.sig_removed.connect(self.main.editor.removed)\r\n        treewidget.sig_removed_tree.connect(self.main.editor.removed_tree)\r\n        treewidget.sig_renamed.connect(self.main.editor.renamed)\r\n        treewidget.sig_renamed_tree.connect(self.main.editor.renamed_tree)\r\n        treewidget.sig_create_module.connect(self.main.editor.new)\r\n        treewidget.sig_new_file.connect(lambda t: self.main.editor.new(text=t))\r\n        treewidget.sig_open_interpreter.connect(\r\n            ipyconsole.create_client_from_path)\r\n        treewidget.redirect_stdio.connect(\r\n            self.main.redirect_internalshell_stdio)\r\n        treewidget.sig_run.connect(\r\n            lambda fname:\r\n            ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,\r\n                                  False, True))\r\n        treewidget.sig_open_dir.connect(\r\n            lambda dirname:\r\n            self.main.workingdirectory.chdir(dirname,\r\n                                             refresh_explorer=False,\r\n                                             refresh_console=True))\r\n\r\n        self.main.editor.open_dir.connect(self.chdir)\r\n\r\n        # Signal \"set_explorer_cwd(QString)\" will refresh only the\r\n        # contents of path passed by the signal in explorer:\r\n        self.main.workingdirectory.set_explorer_cwd.connect(\r\n                     lambda directory: self.refresh_plugin(new_path=directory,\r\n                                                           force_current=True))\r\n\r\n    def refresh_plugin(self, new_path=None, force_current=True):\r\n        \"\"\"Refresh explorer widget\"\"\"\r\n        self.fileexplorer.treewidget.update_history(new_path)\r\n        self.fileexplorer.treewidget.refresh(new_path,\r\n                                             force_current=force_current)\r\n\r\n    def on_first_registration(self):\r\n        \"\"\"Action to be performed on first plugin registration.\"\"\"\r\n        # TODO: Remove this for spyder 5\r\n        # self.tabify(self.main.projects)\r\n        self.tabify(self.main.variableexplorer)\r\n\r\n    def apply_plugin_settings(self, options):\r\n        \"\"\"Handle preference options update.\"\"\"\r\n        method_map = {\r\n            'file_associations':\r\n                self.fileexplorer.treewidget.set_file_associations,\r\n            'single_click_to_open':\r\n                self.fileexplorer.treewidget.set_single_click_to_open,\r\n            'name_filters':\r\n                self.fileexplorer.treewidget.set_name_filters,\r\n            'show_all':\r\n                self.fileexplorer.treewidget.toggle_all,\r\n            'show_icontext':\r\n                self.fileexplorer.toggle_icontext,\r\n        }\r\n        for option in options:\r\n            if option in method_map:\r\n                value = self.get_option(option)\r\n                method = method_map.get(option)\r\n                method(value)\r\n        self.fileexplorer.treewidget.update_common_actions()\r\n\r\n    #------ Public API ---------------------------------------------------------\r\n    def chdir(self, directory):\r\n        \"\"\"Set working directory\"\"\"\r\n        self.fileexplorer.treewidget.chdir(directory)\r\n", "path": "spyder/plugins/explorer/plugin.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\r\n#\r\n# Copyright \u00a9 Spyder Project Contributors\r\n# Licensed under the terms of the MIT License\r\n# (see spyder/__init__.py for details)\r\n\r\n\"\"\"Files and Directories Explorer Plugin\"\"\"\r\n\r\n# pylint: disable=C0103\r\n# pylint: disable=R0903\r\n# pylint: disable=R0911\r\n# pylint: disable=R0201\r\n\r\n# Standard library imports\r\nimport os.path as osp\r\n\r\n# Third party imports\r\nfrom qtpy.QtWidgets import QVBoxLayout\r\n\r\n# Local imports\r\nfrom spyder.config.base import _\r\nfrom spyder.api.plugins import SpyderPluginWidget\r\nfrom spyder.plugins.explorer.widgets.explorer import ExplorerWidget\r\nfrom spyder.plugins.explorer.confpage import ExplorerConfigPage\r\n\r\n\r\nclass Explorer(SpyderPluginWidget):\r\n    \"\"\"File and Directories Explorer DockWidget.\"\"\"\r\n\r\n    CONF_SECTION = 'explorer'\r\n    CONFIGWIDGET_CLASS = ExplorerConfigPage\r\n    CONF_FILE = False\r\n\r\n    def __init__(self, parent=None):\r\n        \"\"\"Initialization.\"\"\"\r\n        SpyderPluginWidget.__init__(self, parent)\r\n\r\n        visible_columns = self.get_option('visible_columns',\r\n                                          default=[0, 3])  # Name & Last Mod\r\n        self.fileexplorer = ExplorerWidget(\r\n            self,\r\n            name_filters=self.get_option('name_filters'),\r\n            show_all=self.get_option('show_all'),\r\n            show_icontext=self.get_option('show_icontext'),\r\n            options_button=self.options_button,\r\n            single_click_to_open=self.get_option('single_click_to_open'),\r\n            file_associations=self.get_option('file_associations',\r\n                                              default={}),\r\n            visible_columns=visible_columns,\r\n        )\r\n        layout = QVBoxLayout()\r\n        layout.addWidget(self.fileexplorer)\r\n        self.setLayout(layout)\r\n        self.fileexplorer.sig_option_changed.connect(\r\n            self._update_config_options)\r\n\r\n    def _update_config_options(self, option, value):\r\n        \"\"\"Update the config options of the explorer to make them permanent.\"\"\"\r\n        self.set_option(option, value)\r\n\r\n    #------ SpyderPluginWidget API ---------------------------------------------\r\n    def get_plugin_title(self):\r\n        \"\"\"Return widget title\"\"\"\r\n        return _(\"Files\")\r\n    \r\n    def get_focus_widget(self):\r\n        \"\"\"\r\n        Return the widget to give focus to when\r\n        this plugin's dockwidget is raised on top-level\r\n        \"\"\"\r\n        return self.fileexplorer.treewidget\r\n    \r\n    def get_plugin_actions(self):\r\n        \"\"\"Return a list of actions related to plugin\"\"\"\r\n        return self.fileexplorer.treewidget.common_actions\r\n    \r\n    def register_plugin(self):\r\n        \"\"\"Register plugin in Spyder's main window\"\"\"\r\n        ipyconsole = self.main.ipyconsole\r\n        treewidget = self.fileexplorer.treewidget\r\n\r\n        self.add_dockwidget()\r\n        self.fileexplorer.sig_open_file.connect(self.main.open_file)\r\n        self.register_widget_shortcuts(treewidget)\r\n\r\n        treewidget.sig_edit.connect(self.main.editor.load)\r\n        treewidget.sig_removed.connect(self.main.editor.removed)\r\n        treewidget.sig_removed_tree.connect(self.main.editor.removed_tree)\r\n        treewidget.sig_renamed.connect(self.main.editor.renamed)\r\n        treewidget.sig_renamed_tree.connect(self.main.editor.renamed_tree)\r\n        treewidget.sig_create_module.connect(self.main.editor.new)\r\n        treewidget.sig_new_file.connect(lambda t: self.main.editor.new(text=t))\r\n        treewidget.sig_open_interpreter.connect(\r\n            ipyconsole.create_client_from_path)\r\n        treewidget.redirect_stdio.connect(\r\n            self.main.redirect_internalshell_stdio)\r\n        treewidget.sig_run.connect(\r\n            lambda fname:\r\n            ipyconsole.run_script(fname, osp.dirname(fname), '', False, False,\r\n                                  False, True, False))\r\n        treewidget.sig_open_dir.connect(\r\n            lambda dirname:\r\n            self.main.workingdirectory.chdir(dirname,\r\n                                             refresh_explorer=False,\r\n                                             refresh_console=True))\r\n\r\n        self.main.editor.open_dir.connect(self.chdir)\r\n\r\n        # Signal \"set_explorer_cwd(QString)\" will refresh only the\r\n        # contents of path passed by the signal in explorer:\r\n        self.main.workingdirectory.set_explorer_cwd.connect(\r\n                     lambda directory: self.refresh_plugin(new_path=directory,\r\n                                                           force_current=True))\r\n\r\n    def refresh_plugin(self, new_path=None, force_current=True):\r\n        \"\"\"Refresh explorer widget\"\"\"\r\n        self.fileexplorer.treewidget.update_history(new_path)\r\n        self.fileexplorer.treewidget.refresh(new_path,\r\n                                             force_current=force_current)\r\n\r\n    def on_first_registration(self):\r\n        \"\"\"Action to be performed on first plugin registration.\"\"\"\r\n        # TODO: Remove this for spyder 5\r\n        # self.tabify(self.main.projects)\r\n        self.tabify(self.main.variableexplorer)\r\n\r\n    def apply_plugin_settings(self, options):\r\n        \"\"\"Handle preference options update.\"\"\"\r\n        method_map = {\r\n            'file_associations':\r\n                self.fileexplorer.treewidget.set_file_associations,\r\n            'single_click_to_open':\r\n                self.fileexplorer.treewidget.set_single_click_to_open,\r\n            'name_filters':\r\n                self.fileexplorer.treewidget.set_name_filters,\r\n            'show_all':\r\n                self.fileexplorer.treewidget.toggle_all,\r\n            'show_icontext':\r\n                self.fileexplorer.toggle_icontext,\r\n        }\r\n        for option in options:\r\n            if option in method_map:\r\n                value = self.get_option(option)\r\n                method = method_map.get(option)\r\n                method(value)\r\n        self.fileexplorer.treewidget.update_common_actions()\r\n\r\n    #------ Public API ---------------------------------------------------------\r\n    def chdir(self, directory):\r\n        \"\"\"Set working directory\"\"\"\r\n        self.fileexplorer.treewidget.chdir(directory)\r\n", "path": "spyder/plugins/explorer/plugin.py"}]}