Show More
@@ -1,47 +1,70 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ Proxy module for accessing platform specific utility functions. |
|
3 | 3 | |
|
4 | 4 | Importing this module should give you the implementations that are correct |
|
5 | 5 | for your operation system, from platutils_PLATFORMNAME module. |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #***************************************************************************** |
|
9 | 9 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 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 | 15 | import os |
|
20 | 16 | import sys |
|
21 | 17 | |
|
22 | 18 | # Import the platform-specific implementations |
|
23 | 19 | if os.name == 'posix': |
|
24 | 20 | import platutils_posix as _platutils |
|
25 | 21 | elif sys.platform == 'win32': |
|
26 | 22 | import platutils_win32 as _platutils |
|
27 | 23 | else: |
|
28 | 24 | import platutils_dummy as _platutils |
|
29 | 25 | import warnings |
|
30 | 26 | warnings.warn("Platutils not available for platform '%s', some features may be missing" % |
|
31 | 27 | os.name) |
|
32 | 28 | del warnings |
|
33 | 29 | |
|
34 | 30 | |
|
35 | 31 | # Functionality that's logically common to all platforms goes here, each |
|
36 | 32 | # platform-specific module only provides the bits that are OS-dependent. |
|
37 | 33 | |
|
38 | def freeze_term_title(): | |
|
39 | _platutils.ignore_termtitle = True | |
|
34 | # XXX - I'm still not happy with a module global for this, but at least now | |
|
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 | 56 | def set_term_title(title): |
|
43 | 57 | """Set terminal title using the necessary platform-dependent calls.""" |
|
44 | 58 | |
|
45 | 59 | if _platutils.ignore_termtitle: |
|
46 | 60 | return |
|
47 | 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 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ Platform specific utility functions, posix version |
|
3 | 3 | |
|
4 | 4 | Importing this module directly is not portable - rather, import platutils |
|
5 | 5 | to use these functions in platform agnostic fashion. |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #***************************************************************************** |
|
9 | 9 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 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 | 15 | import sys |
|
20 | 16 | import os |
|
21 | 17 | |
|
22 |
ignore_termtitle = |
|
|
18 | ignore_termtitle = True | |
|
23 | 19 | |
|
24 | 20 | def _dummy_op(*a, **b): |
|
25 | 21 | """ A no-op function """ |
|
26 | 22 | |
|
27 | 23 | def _set_term_title_xterm(title): |
|
28 | 24 | """ Change virtual terminal title in xterm-workalikes """ |
|
29 | 25 | |
|
30 |
sys.stdout.write('\033] |
|
|
26 | sys.stdout.write('\033]0;%s\007' % title) | |
|
31 | 27 | |
|
32 | 28 | |
|
33 | 29 | if os.environ.get('TERM','') == 'xterm': |
|
34 | 30 | set_term_title = _set_term_title_xterm |
|
35 | 31 | else: |
|
36 | 32 | set_term_title = _dummy_op |
@@ -1,47 +1,44 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ Platform specific utility functions, win32 version |
|
3 | 3 | |
|
4 | 4 | Importing this module directly is not portable - rather, import platutils |
|
5 | 5 | to use these functions in platform agnostic fashion. |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #***************************************************************************** |
|
9 | 9 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 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 | 16 | import os |
|
20 | 17 | |
|
21 |
ignore_termtitle = |
|
|
18 | ignore_termtitle = True | |
|
22 | 19 | |
|
23 | 20 | try: |
|
24 | 21 | import ctypes |
|
25 | 22 | |
|
26 | 23 | SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW |
|
27 | 24 | SetConsoleTitleW.argtypes = [ctypes.c_wchar_p] |
|
28 | 25 | |
|
29 | 26 | def set_term_title(title): |
|
30 | 27 | """Set terminal title using ctypes to access the Win32 APIs.""" |
|
31 | 28 | SetConsoleTitleW(title) |
|
32 | 29 | |
|
33 | 30 | except ImportError: |
|
34 | 31 | def set_term_title(title): |
|
35 | 32 | """Set terminal title using the 'title' command.""" |
|
36 | 33 | global ignore_termtitle |
|
37 | 34 | |
|
38 | 35 | try: |
|
39 | 36 | # Cannot be on network share when issuing system commands |
|
40 | 37 | curr = os.getcwd() |
|
41 | 38 | os.chdir("C:") |
|
42 | 39 | ret = os.system("title " + title) |
|
43 | 40 | finally: |
|
44 | 41 | os.chdir(curr) |
|
45 | 42 | if ret: |
|
46 | 43 | # non-zero return code signals error, don't try again |
|
47 | 44 | ignore_termtitle = True |
General Comments 0
You need to be logged in to leave comments.
Login now