diff --git a/IPython/Magic.py b/IPython/Magic.py index 896601e..f1c0162 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -2728,8 +2728,7 @@ Defaulting color scheme to 'NoColor'""" os.chdir(os.path.expanduser(ps)) if self.shell.rc.term_title: #print 'set term title:',self.shell.rc.term_title # dbg - ttitle = 'IPy ' + abbrev_cwd() - platutils.set_term_title(ttitle) + platutils.set_term_title('IPy ' + abbrev_cwd()) except OSError: print sys.exc_info()[1] else: diff --git a/IPython/platutils.py b/IPython/platutils.py index 839e1b8..7f84769 100644 --- a/IPython/platutils.py +++ b/IPython/platutils.py @@ -3,13 +3,8 @@ Importing this module should give you the implementations that are correct for your operation system, from platutils_PLATFORMNAME module. - -$Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $ - - """ - #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez # @@ -21,15 +16,32 @@ from IPython import Release __author__ = '%s <%s>' % Release.authors['Ville'] __license__ = Release.license -import os,sys +import os +import sys +# Import the platform-specific implementations if os.name == 'posix': - from platutils_posix import * + import platutils_posix as _platutils elif sys.platform == 'win32': - from platutils_win32 import * + import platutils_win32 as _platutils else: - from platutils_dummy import * + import platutils_dummy as _platutils import warnings warnings.warn("Platutils not available for platform '%s', some features may be missing" % os.name) del warnings + + +# Functionality that's logically common to all platforms goes here, each +# platform-specific module only provides the bits that are OS-dependent. + +def freeze_term_title(): + _platutils.ignore_termtitle = True + + +def set_term_title(title): + """Set terminal title using the necessary platform-dependent calls.""" + + if _platutils.ignore_termtitle: + return + _platutils.set_term_title(title) diff --git a/IPython/platutils_dummy.py b/IPython/platutils_dummy.py index 149acb9..86dc990 100644 --- a/IPython/platutils_dummy.py +++ b/IPython/platutils_dummy.py @@ -3,13 +3,8 @@ This has empty implementation of the platutils functions, used for unsupported operating systems. - -$Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $ - - """ - #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez # @@ -21,9 +16,9 @@ from IPython import Release __author__ = '%s <%s>' % Release.authors['Ville'] __license__ = Release.license +# This variable is part of the expected API of the module: +ignore_termtitle = True -def _dummy(*args,**kw): +def set_term_title(*args,**kw): + """Dummy no-op.""" pass - -set_term_title = _dummy - diff --git a/IPython/platutils_posix.py b/IPython/platutils_posix.py index fa46ce8..d0dbc0a 100644 --- a/IPython/platutils_posix.py +++ b/IPython/platutils_posix.py @@ -3,12 +3,8 @@ Importing this module directly is not portable - rather, import platutils to use these functions in platform agnostic fashion. - -$Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $ - """ - #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez # @@ -31,9 +27,6 @@ def _dummy_op(*a, **b): def _set_term_title_xterm(title): """ Change virtual terminal title in xterm-workalikes """ - if ignore_termtitle: - return - sys.stdout.write('\033]%d;%s\007' % (0,title)) @@ -41,7 +34,3 @@ if os.environ.get('TERM','') == 'xterm': set_term_title = _set_term_title_xterm else: set_term_title = _dummy_op - -def freeze_term_title(): - global ignore_termtitle - ignore_termtitle = True diff --git a/IPython/platutils_win32.py b/IPython/platutils_win32.py index 76e5333..630a9ca 100644 --- a/IPython/platutils_win32.py +++ b/IPython/platutils_win32.py @@ -3,12 +3,8 @@ Importing this module directly is not portable - rather, import platutils to use these functions in platform agnostic fashion. - -$Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $ - """ - #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez # @@ -22,35 +18,30 @@ __license__ = Release.license import os -ignore_termtitle = 0 +ignore_termtitle = False try: import ctypes - SetConsoleTitleW=ctypes.windll.kernel32.SetConsoleTitleW - SetConsoleTitleW.argtypes=[ctypes.c_wchar_p] - def _set_term_title(title): - """ Set terminal title using the ctypes""" + + SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW + SetConsoleTitleW.argtypes = [ctypes.c_wchar_p] + + def set_term_title(title): + """Set terminal title using ctypes to access the Win32 APIs.""" SetConsoleTitleW(title) except ImportError: - def _set_term_title(title): - """ Set terminal title using the 'title' command """ - curr=os.getcwd() - os.chdir("C:") #Cannot be on network share when issuing system commands - ret = os.system("title " + title) - os.chdir(curr) + def set_term_title(title): + """Set terminal title using the 'title' command.""" + global ignore_termtitle + + try: + # Cannot be on network share when issuing system commands + curr = os.getcwd() + os.chdir("C:") + ret = os.system("title " + title) + finally: + os.chdir(curr) if ret: - ignore_termtitle = 1 - -def set_term_title(title): - """ Set terminal title using the 'title' command """ - global ignore_termtitle - - if ignore_termtitle: - return - _set_term_title(title) - -def freeze_term_title(): - global ignore_termtitle - ignore_termtitle = 1 - + # non-zero return code signals error, don't try again + ignore_termtitle = True