##// END OF EJS Templates
Make set_term_title() default to no-op, as it can cause problems....
Fernando Perez -
Show More
@@ -1,47 +1,70 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ Proxy module for accessing platform specific utility functions.
2 """ Proxy module for accessing platform specific utility functions.
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 """
6 """
7
7
8 #*****************************************************************************
8 #*****************************************************************************
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #*****************************************************************************
13 #*****************************************************************************
14
14
15 from IPython import Release
16 __author__ = '%s <%s>' % Release.authors['Ville']
17 __license__ = Release.license
18
19 import os
15 import os
20 import sys
16 import sys
21
17
22 # Import the platform-specific implementations
18 # Import the platform-specific implementations
23 if os.name == 'posix':
19 if os.name == 'posix':
24 import platutils_posix as _platutils
20 import platutils_posix as _platutils
25 elif sys.platform == 'win32':
21 elif sys.platform == 'win32':
26 import platutils_win32 as _platutils
22 import platutils_win32 as _platutils
27 else:
23 else:
28 import platutils_dummy as _platutils
24 import platutils_dummy as _platutils
29 import warnings
25 import warnings
30 warnings.warn("Platutils not available for platform '%s', some features may be missing" %
26 warnings.warn("Platutils not available for platform '%s', some features may be missing" %
31 os.name)
27 os.name)
32 del warnings
28 del warnings
33
29
34
30
35 # Functionality that's logically common to all platforms goes here, each
31 # Functionality that's logically common to all platforms goes here, each
36 # platform-specific module only provides the bits that are OS-dependent.
32 # platform-specific module only provides the bits that are OS-dependent.
37
33
38 def freeze_term_title():
34 # XXX - I'm still not happy with a module global for this, but at least now
39 _platutils.ignore_termtitle = True
35 # there is a public, cross-platform way of toggling the term title control on
36 # and off. We should make this a stateful object later on so that each user
37 # can have its own instance if needed.
38 def toggle_set_term_title(val):
39 """Control whether set_term_title is active or not.
40
41 set_term_title() allows writing to the console titlebar. In embedded
42 widgets this can cause problems, so this call can be used to toggle it on
43 or off as needed.
44
45 The default state of the module is for the function to be disabled.
46
47 Parameters
48 ----------
49 val : bool
50 If True, set_term_title() actually writes to the terminal (using the
51 appropriate platform-specific module). If False, it is a no-op.
52 """
53 _platutils.ignore_termtitle = not(val)
40
54
41
55
42 def set_term_title(title):
56 def set_term_title(title):
43 """Set terminal title using the necessary platform-dependent calls."""
57 """Set terminal title using the necessary platform-dependent calls."""
44
58
45 if _platutils.ignore_termtitle:
59 if _platutils.ignore_termtitle:
46 return
60 return
47 _platutils.set_term_title(title)
61 _platutils.set_term_title(title)
62
63
64 #-----------------------------------------------------------------------------
65 # Deprecated functions
66 #-----------------------------------------------------------------------------
67 def freeze_term_title():
68 warnings.warn("This function is deprecated, use toggle_set_term_title()")
69 _platutils.ignore_termtitle = True
70
@@ -1,36 +1,32 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ Platform specific utility functions, posix version
2 """ Platform specific utility functions, posix version
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 """
6 """
7
7
8 #*****************************************************************************
8 #*****************************************************************************
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #*****************************************************************************
13 #*****************************************************************************
14
14
15 from IPython import Release
16 __author__ = '%s <%s>' % Release.authors['Ville']
17 __license__ = Release.license
18
19 import sys
15 import sys
20 import os
16 import os
21
17
22 ignore_termtitle = False
18 ignore_termtitle = True
23
19
24 def _dummy_op(*a, **b):
20 def _dummy_op(*a, **b):
25 """ A no-op function """
21 """ A no-op function """
26
22
27 def _set_term_title_xterm(title):
23 def _set_term_title_xterm(title):
28 """ Change virtual terminal title in xterm-workalikes """
24 """ Change virtual terminal title in xterm-workalikes """
29
25
30 sys.stdout.write('\033]%d;%s\007' % (0,title))
26 sys.stdout.write('\033]0;%s\007' % title)
31
27
32
28
33 if os.environ.get('TERM','') == 'xterm':
29 if os.environ.get('TERM','') == 'xterm':
34 set_term_title = _set_term_title_xterm
30 set_term_title = _set_term_title_xterm
35 else:
31 else:
36 set_term_title = _dummy_op
32 set_term_title = _dummy_op
@@ -1,47 +1,44 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ Platform specific utility functions, win32 version
2 """ Platform specific utility functions, win32 version
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 """
6 """
7
7
8 #*****************************************************************************
8 #*****************************************************************************
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #*****************************************************************************
13 #*****************************************************************************
14
14
15 from IPython import Release
16 __author__ = '%s <%s>' % Release.authors['Ville']
17 __license__ = Release.license
18
15
19 import os
16 import os
20
17
21 ignore_termtitle = False
18 ignore_termtitle = True
22
19
23 try:
20 try:
24 import ctypes
21 import ctypes
25
22
26 SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
23 SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
27 SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]
24 SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]
28
25
29 def set_term_title(title):
26 def set_term_title(title):
30 """Set terminal title using ctypes to access the Win32 APIs."""
27 """Set terminal title using ctypes to access the Win32 APIs."""
31 SetConsoleTitleW(title)
28 SetConsoleTitleW(title)
32
29
33 except ImportError:
30 except ImportError:
34 def set_term_title(title):
31 def set_term_title(title):
35 """Set terminal title using the 'title' command."""
32 """Set terminal title using the 'title' command."""
36 global ignore_termtitle
33 global ignore_termtitle
37
34
38 try:
35 try:
39 # Cannot be on network share when issuing system commands
36 # Cannot be on network share when issuing system commands
40 curr = os.getcwd()
37 curr = os.getcwd()
41 os.chdir("C:")
38 os.chdir("C:")
42 ret = os.system("title " + title)
39 ret = os.system("title " + title)
43 finally:
40 finally:
44 os.chdir(curr)
41 os.chdir(curr)
45 if ret:
42 if ret:
46 # non-zero return code signals error, don't try again
43 # non-zero return code signals error, don't try again
47 ignore_termtitle = True
44 ignore_termtitle = True
General Comments 0
You need to be logged in to leave comments. Login now