Repository: spyder-ide/spyder

Issue:
Console tabs are too big because they display the full filename
_From [andreasn...@googlemail.com](https://code.google.com/u/106330885117898830116/) on 2012-10-04T15:20:39Z_

The console tabs of running or run programs are quite big, because they display the complete filename including path, e.g.:

"Console - /home/user/python/myproject/util/module.py"

On some Spyder window setups, this big tab uses much space and thus leaves very little space for the other views tabs, I have put in the same pane. These other tabs then often show only one letter and it is somehow unpleasing to the eye.

Not so long ago, only the filename ("Console - module.py") was displayed in these tabs. Can we have an option for choosing between long and short filenames in the console tabs?

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1165_



Discussion:
_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2012-10-08T09:58:26Z_

We certainly can have this! I've also being bothered by this but haven't found time to fix it. I'll try to do it during the 2.2 cycle.

Thanks for reporting.

**Summary:** Console tabs are too big because they display the full filename  
  **Status:** Accepted  
  **Labels:** MS-v2.2 Cat-Console  

_From [jed.lud...@gmail.com](https://code.google.com/u/114333776555678317161/) on 2013-04-29T14:27:24Z_

**Labels:** -MS-v2.2 MS-v2.3  

_From [pierre.raybaut](https://code.google.com/u/pierre.raybaut/) on 2013-05-11T05:53:28Z_

**Labels:** -MS-v2.3 MS-v2.4  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-09-27T05:20:41Z_

To solve this you need to look in plugins/externalconsole.py, for the method called "start", and the arg called "fname", which you can redefine to contain only the file name instead of the full path.

**Labels:** Easy  

Consoles now show the filename on the tab, and the full path in the title of the dockwidget. I don't know when it was fixed, but it is !

@Nodd, the idea is **not** to show the full path, but only the filename :-)

yes, that's what they do ?

Not at the moment. That's why the console title can be too wide, and the idea is to fix that ;-)

Are we speaking about the same thing ?
I see the full path in the console title (and I think it's fine), and I see the filename only in the tab (and that's fine too). The title width does not limit the dockwidget's size (I tested by making it floating instead of docked).
![spydertabs](https://cloud.githubusercontent.com/assets/506348/7475999/3383b046-f34b-11e4-9b81-f6dc540be3e5.png)

Sorry for not being clear enough :-)

When our Python Console is tabbed next to other panes (e.g. History Log or IPython Console), then it's tab title is too big because it uses the full filename path. The idea is to use a shorter title ;-)

Ooooooh, the title of the dockwidget is used for the dockwidget's tab title ! Now I get it.
I need to update my telepathy package !

Well... I have access to the tabs now since the dockwidget tab reordering PR, so I could just make sure it is always a fixed value :-)

Even better!! Thanks :-)

@malliwi88, please work on this one.

@malliwi88, I hope to see your PR for this on Monday or Tuesday. It's an easy fix :-)
Okay, we're talking about this, right?

This is the problem
![seleccion_012](https://cloud.githubusercontent.com/assets/5307894/20856168/ae2fe178-b8d6-11e6-9cac-2929618cdb08.png)

This is the result of PR #3780 
![seleccion_013](https://cloud.githubusercontent.com/assets/5307894/20856175/ee38ab9c-b8d6-11e6-9020-77b8ed8caa53.png)

Thanks @ccordoba12 


@dalthviz, please work on this one.

Resolving patch:
diff --git a/spyder/plugins/externalconsole.py b/spyder/plugins/externalconsole.py
--- a/spyder/plugins/externalconsole.py
+++ b/spyder/plugins/externalconsole.py
@@ -27,7 +27,7 @@
 from spyder import dependencies
 from spyder.config.base import _, SCIENTIFIC_STARTUP
 from spyder.config.main import CONF
-from spyder.utils import encoding, programs
+from spyder.utils import encoding, programs, sourcecode
 from spyder.utils import icon_manager as ima
 from spyder.utils.misc import (get_error_match, get_python_executable,
                                is_python_script, remove_backslashes)
@@ -371,6 +371,7 @@ def close_console(self, index=None):
         self.shellwidgets.pop(index)
         self.icons.pop(index)
         self.update_plugin_title.emit()
+        self.update_tabs_text()
 
     def set_variableexplorer(self, variableexplorer):
         """Set variable explorer plugin"""
@@ -637,8 +638,11 @@ def start(self, fname, wdir=None, args='', interact=False, debug=False,
                 tab_name = "Python %d" % self.python_count
                 tab_icon1 = ima.icon('python')
                 tab_icon2 = ima.icon('python_t')
+                self.filenames.insert(index, fname)
             else:
-                tab_name = osp.basename(fname)
+                self.filenames.insert(index, fname)
+                tab_name = self.get_tab_text(fname)
+                self.update_tabs_text()
                 tab_icon1 = ima.icon('run')
                 tab_icon2 = ima.icon('terminated')
         else:
@@ -651,8 +655,8 @@ def start(self, fname, wdir=None, args='', interact=False, debug=False,
             tab_name += (" %d" % self.terminal_count)
             tab_icon1 = ima.icon('cmdprompt')
             tab_icon2 = ima.icon('cmdprompt_t')
+            self.filenames.insert(index, fname)
         self.shellwidgets.insert(index, shellwidget)
-        self.filenames.insert(index, fname)
         self.icons.insert(index, (tab_icon1, tab_icon2))
         if index is None:
             index = self.tabwidget.addTab(shellwidget, tab_name)
@@ -680,7 +684,19 @@ def open_file_in_spyder(self, fname, lineno):
         self.main.editor.activateWindow()
         self.main.editor.raise_()
         self.main.editor.load(fname, lineno)
-        
+
+    def get_tab_text(self, fname):
+        """Get tab text without ambiguation."""
+        files_path_list = [filename for filename in self.filenames
+                           if filename is not None]
+        return sourcecode.get_file_title(files_path_list, fname)
+
+    def update_tabs_text(self):
+        """Update the text from the tabs."""
+        for index, fname in enumerate(self.filenames):
+            if fname is not None:
+                self.tabwidget.setTabText(index, self.get_tab_text(fname))
+
     #------ Private API -------------------------------------------------------
     def process_started(self, shell_id):
         index = self.get_shell_index_from_id(shell_id)
@@ -707,30 +723,22 @@ def process_finished(self, shell_id):
     def get_plugin_title(self):
         """Return widget title"""
         title = _('Python console')
-        if self.filenames:
-            index = self.tabwidget.currentIndex()
-            fname = self.filenames[index]
-            if fname:
-                title += ' - ' + to_text_string(fname)
         return title
-    
+
     def get_plugin_icon(self):
-        """Return widget icon"""
+        """Return widget icon."""
         return ima.icon('console')
     
     def get_focus_widget(self):
-        """
-        Return the widget to give focus to when
-        this plugin's dockwidget is raised on top-level
-        """
+        """Return the widget to give focus to."""
         return self.tabwidget.currentWidget()
         
     def get_plugin_actions(self):
         """Return a list of actions related to plugin"""
         interpreter_action = create_action(self,
-                            _("Open a &Python console"), None,
-                            ima.icon('python'),
-                            triggered=self.open_interpreter)
+                                           _("Open a &Python console"), None,
+                                           ima.icon('python'),
+                                           triggered=self.open_interpreter)
         if os.name == 'nt':
             text = _("Open &command prompt")
             tip = _("Open a Windows command prompt")


Test patch: