##// END OF EJS Templates
Refactor of platutils for cleanup....
Fernando Perez -
Show More
@@ -2728,8 +2728,7 b' Defaulting color scheme to \'NoColor\'"""'
2728 os.chdir(os.path.expanduser(ps))
2728 os.chdir(os.path.expanduser(ps))
2729 if self.shell.rc.term_title:
2729 if self.shell.rc.term_title:
2730 #print 'set term title:',self.shell.rc.term_title # dbg
2730 #print 'set term title:',self.shell.rc.term_title # dbg
2731 ttitle = 'IPy ' + abbrev_cwd()
2731 platutils.set_term_title('IPy ' + abbrev_cwd())
2732 platutils.set_term_title(ttitle)
2733 except OSError:
2732 except OSError:
2734 print sys.exc_info()[1]
2733 print sys.exc_info()[1]
2735 else:
2734 else:
@@ -3,13 +3,8 b''
3
3
4 Importing this module should give you the implementations that are correct
4 Importing this module should give you the implementations that are correct
5 for your operation system, from platutils_PLATFORMNAME module.
5 for your operation system, from platutils_PLATFORMNAME module.
6
7 $Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $
8
9
10 """
6 """
11
7
12
13 #*****************************************************************************
8 #*****************************************************************************
14 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
15 #
10 #
@@ -21,15 +16,32 b' from IPython import Release'
21 __author__ = '%s <%s>' % Release.authors['Ville']
16 __author__ = '%s <%s>' % Release.authors['Ville']
22 __license__ = Release.license
17 __license__ = Release.license
23
18
24 import os,sys
19 import os
20 import sys
25
21
22 # Import the platform-specific implementations
26 if os.name == 'posix':
23 if os.name == 'posix':
27 from platutils_posix import *
24 import platutils_posix as _platutils
28 elif sys.platform == 'win32':
25 elif sys.platform == 'win32':
29 from platutils_win32 import *
26 import platutils_win32 as _platutils
30 else:
27 else:
31 from platutils_dummy import *
28 import platutils_dummy as _platutils
32 import warnings
29 import warnings
33 warnings.warn("Platutils not available for platform '%s', some features may be missing" %
30 warnings.warn("Platutils not available for platform '%s', some features may be missing" %
34 os.name)
31 os.name)
35 del warnings
32 del warnings
33
34
35 # Functionality that's logically common to all platforms goes here, each
36 # platform-specific module only provides the bits that are OS-dependent.
37
38 def freeze_term_title():
39 _platutils.ignore_termtitle = True
40
41
42 def set_term_title(title):
43 """Set terminal title using the necessary platform-dependent calls."""
44
45 if _platutils.ignore_termtitle:
46 return
47 _platutils.set_term_title(title)
@@ -3,13 +3,8 b''
3
3
4 This has empty implementation of the platutils functions, used for
4 This has empty implementation of the platutils functions, used for
5 unsupported operating systems.
5 unsupported operating systems.
6
7 $Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $
8
9
10 """
6 """
11
7
12
13 #*****************************************************************************
8 #*****************************************************************************
14 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
15 #
10 #
@@ -21,9 +16,9 b' from IPython import Release'
21 __author__ = '%s <%s>' % Release.authors['Ville']
16 __author__ = '%s <%s>' % Release.authors['Ville']
22 __license__ = Release.license
17 __license__ = Release.license
23
18
19 # This variable is part of the expected API of the module:
20 ignore_termtitle = True
24
21
25 def _dummy(*args,**kw):
22 def set_term_title(*args,**kw):
23 """Dummy no-op."""
26 pass
24 pass
27
28 set_term_title = _dummy
29
@@ -3,12 +3,8 b''
3
3
4 Importing this module directly is not portable - rather, import platutils
4 Importing this module directly is not portable - rather, import platutils
5 to use these functions in platform agnostic fashion.
5 to use these functions in platform agnostic fashion.
6
7 $Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $
8
9 """
6 """
10
7
11
12 #*****************************************************************************
8 #*****************************************************************************
13 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
14 #
10 #
@@ -31,9 +27,6 b' def _dummy_op(*a, **b):'
31 def _set_term_title_xterm(title):
27 def _set_term_title_xterm(title):
32 """ Change virtual terminal title in xterm-workalikes """
28 """ Change virtual terminal title in xterm-workalikes """
33
29
34 if ignore_termtitle:
35 return
36
37 sys.stdout.write('\033]%d;%s\007' % (0,title))
30 sys.stdout.write('\033]%d;%s\007' % (0,title))
38
31
39
32
@@ -41,7 +34,3 b" if os.environ.get('TERM','') == 'xterm':"
41 set_term_title = _set_term_title_xterm
34 set_term_title = _set_term_title_xterm
42 else:
35 else:
43 set_term_title = _dummy_op
36 set_term_title = _dummy_op
44
45 def freeze_term_title():
46 global ignore_termtitle
47 ignore_termtitle = True
@@ -3,12 +3,8 b''
3
3
4 Importing this module directly is not portable - rather, import platutils
4 Importing this module directly is not portable - rather, import platutils
5 to use these functions in platform agnostic fashion.
5 to use these functions in platform agnostic fashion.
6
7 $Id: ipstruct.py 1005 2006-01-12 08:39:26Z fperez $
8
9 """
6 """
10
7
11
12 #*****************************************************************************
8 #*****************************************************************************
13 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
14 #
10 #
@@ -22,35 +18,30 b' __license__ = Release.license'
22
18
23 import os
19 import os
24
20
25 ignore_termtitle = 0
21 ignore_termtitle = False
26
22
27 try:
23 try:
28 import ctypes
24 import ctypes
29 SetConsoleTitleW=ctypes.windll.kernel32.SetConsoleTitleW
25
30 SetConsoleTitleW.argtypes=[ctypes.c_wchar_p]
26 SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
31 def _set_term_title(title):
27 SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]
32 """ Set terminal title using the ctypes"""
28
29 def set_term_title(title):
30 """Set terminal title using ctypes to access the Win32 APIs."""
33 SetConsoleTitleW(title)
31 SetConsoleTitleW(title)
34
32
35 except ImportError:
33 except ImportError:
36 def _set_term_title(title):
34 def set_term_title(title):
37 """ Set terminal title using the 'title' command """
35 """Set terminal title using the 'title' command."""
38 curr=os.getcwd()
36 global ignore_termtitle
39 os.chdir("C:") #Cannot be on network share when issuing system commands
37
40 ret = os.system("title " + title)
38 try:
41 os.chdir(curr)
39 # Cannot be on network share when issuing system commands
40 curr = os.getcwd()
41 os.chdir("C:")
42 ret = os.system("title " + title)
43 finally:
44 os.chdir(curr)
42 if ret:
45 if ret:
43 ignore_termtitle = 1
46 # non-zero return code signals error, don't try again
44
47 ignore_termtitle = True
45 def set_term_title(title):
46 """ Set terminal title using the 'title' command """
47 global ignore_termtitle
48
49 if ignore_termtitle:
50 return
51 _set_term_title(title)
52
53 def freeze_term_title():
54 global ignore_termtitle
55 ignore_termtitle = 1
56
General Comments 0
You need to be logged in to leave comments. Login now