##// END OF EJS Templates
More work on InteractiveShell and ipmaker. It works!
Brian Granger -
Show More
@@ -213,10 +213,23 b' cl_args = ('
213 213 action='store_true', dest='NOSEP', default=NoDefault,
214 214 help="Eliminate all spacing between prompts.")
215 215 ),
216 (('-term_title',), dict(
217 action='store_true', dest='TERM_TITLE', default=NoDefault,
218 help="Enable auto setting the terminal title.")
219 ),
220 (('-noterm_title',), dict(
221 action='store_false', dest='TERM_TITLE', default=NoDefault,
222 help="Disable auto setting the terminal title.")
223 ),
216 224 (('-xmode',), dict(
217 225 type=str, dest='XMODE', default=NoDefault,
218 226 help="Exception mode ('Plain','Context','Verbose')")
219 227 ),
228 # These are only here to get the proper deprecation warnings
229 (('-pylab','-wthread','-qthread','-q4thread','-gthread'), dict(
230 action='store_true', dest='THREADED_SHELL', default=NoDefault,
231 help="These command line flags are deprecated, see the 'gui' magic.")
232 ),
220 233 )
221 234
222 235
@@ -244,11 +257,9 b' class IPythonApp(Application):'
244 257 if clc.CLASSIC: clc.QUICK = 1
245 258
246 259 # Display the deprecation warnings about threaded shells
247 # if opts_all.pylab == 1: threaded_shell_warning()
248 # if opts_all.wthread == 1: threaded_shell_warning()
249 # if opts_all.qthread == 1: threaded_shell_warning()
250 # if opts_all.q4thread == 1: threaded_shell_warning()
251 # if opts_all.gthread == 1: threaded_shell_warning()
260 if hasattr(clc, 'THREADED_SHELL'):
261 threaded_shell_warning()
262 del clc['THREADED_SHELL']
252 263
253 264 def load_file_config(self):
254 265 if hasattr(self.command_line_config, 'QUICK'):
@@ -276,22 +287,13 b' class IPythonApp(Application):'
276 287 config.XMODE = 'Plain'
277 288
278 289 # All this should be moved to traitlet handlers in InteractiveShell
290 # But, currently InteractiveShell doesn't have support for changing
291 # these values at runtime. Once we support that, this should
292 # be moved there!!!
279 293 if hasattr(config, 'NOSEP'):
280 294 if config.NOSEP:
281 295 config.SEPARATE_IN = config.SEPARATE_OUT = config.SEPARATE_OUT2 = '0'
282 296
283 if hasattr(config, 'SEPARATE_IN'):
284 if config.SEPARATE_IN == '0': config.SEPARATE_IN = ''
285 config.SEPARATE_IN = config.SEPARATE_IN.replace('\\n','\n')
286
287 if hasattr(config, 'SEPARATE_OUT'):
288 if config.SEPARATE_OUT == '0': config.SEPARATE_OUT = ''
289 config.SEPARATE_OUT = config.SEPARATE_OUT.replace('\\n','\n')
290
291 if hasattr(config, 'SEPARATE_OUT'):
292 if config.SEPARATE_OUT2 == '0': config.SEPARATE_OUT2 = ''
293 config.SEPARATE_OUT2 = config.SEPARATE_OUT2.replace('\\n','\n')
294
295 297 def construct(self):
296 298 # I am a little hesitant to put these into InteractiveShell itself.
297 299 # But that might be the place for them
@@ -53,9 +53,10 b' from IPython.utils.ipstruct import Struct'
53 53 from IPython.utils import PyColorize
54 54 from IPython.utils.genutils import *
55 55 from IPython.utils.strdispatch import StrDispatch
56 from IPython.utils.platutils import toggle_set_term_title, set_term_title
56 57
57 58 from IPython.utils.traitlets import (
58 Int, Float, Str, CBool, CaselessStrEnum, Enum
59 Int, Float, Str, CBool, CaselessStrEnum, Enum, List
59 60 )
60 61
61 62 #-----------------------------------------------------------------------------
@@ -170,6 +171,19 b' def get_default_editor():'
170 171 ed = 'notepad' # same in Windows!
171 172 return ed
172 173
174
175 class SeparateStr(Str):
176 """A Str subclass to validate separate_in, separate_out, etc.
177
178 This is a Str based traitlet that converts '0'->'' and '\\n'->'\n'.
179 """
180
181 def validate(self, obj, value):
182 if value == '0': value = ''
183 value = value.replace('\\n','\n')
184 return super(SeparateStr, self).validate(obj, value)
185
186
173 187 #-----------------------------------------------------------------------------
174 188 # Main IPython class
175 189 #-----------------------------------------------------------------------------
@@ -195,12 +209,10 b' def get_default_editor():'
195 209 class InteractiveShell(Component, Magic):
196 210 """An enhanced console for Python."""
197 211
198 alias = []
199 212 autocall = Enum((0,1,2), config_key='AUTOCALL')
200 213 autoedit_syntax = CBool(False, config_key='AUTOEDIT_SYNTAX')
201 214 autoindent = CBool(True, config_key='AUTOINDENT')
202 215 automagic = CBool(True, config_key='AUTOMAGIC')
203 autoexec = []
204 216 display_banner = CBool(True, config_key='DISPLAY_BANNER')
205 217 banner = Str('')
206 218 banner1 = Str(default_banner, config_key='BANNER1')
@@ -212,34 +224,35 b' class InteractiveShell(Component, Magic):'
212 224 colors = CaselessStrEnum(('NoColor','LightBG','Linux'),
213 225 default_value='LightBG', config_key='COLORS')
214 226 confirm_exit = CBool(True, config_key='CONFIRM_EXIT')
215 debug = CBool(False)
227 debug = CBool(False, config_key='DEBUG')
216 228 deep_reload = CBool(False, config_key='DEEP_RELOAD')
217 229 embedded = CBool(False)
218 230 editor = Str(get_default_editor(), config_key='EDITOR')
219 231 filename = Str("<ipython console>")
220 help = CBool(False)
221 interactive = CBool(False)
232 interactive = CBool(False, config_key='INTERACTIVE')
222 233 logstart = CBool(False, config_key='LOGSTART')
223 234 logfile = Str('', config_key='LOGFILE')
224 235 logplay = Str('', config_key='LOGPLAY')
225 multi_line_specials = CBool(True)
226 object_info_string_level = Int(0)
227 pager = Str('less')
236 multi_line_specials = CBool(True, config_key='MULTI_LINE_SPECIALS')
237 object_info_string_level = Enum((0,1,2), default_value=0,
238 config_keys='OBJECT_INFO_STRING_LEVEL')
239 pager = Str('less', config_key='PAGER')
228 240 pdb = CBool(False, config_key='PDB')
229 241 pprint = CBool(True, config_key='PPRINT')
230 242 profile = Str('', config_key='PROFILE')
231 243 prompt_in1 = Str('In [\\#]: ', config_key='PROMPT_IN1')
232 244 prompt_in2 = Str(' .\\D.: ', config_key='PROMPT_IN2')
233 245 prompt_out = Str('Out[\\#]: ', config_key='PROMPT_OUT1')
234 prompts_pad_left = CBool(True)
235 pydb = CBool(False)
236 quiet = CBool(False)
246 prompts_pad_left = CBool(True, config_key='PROMPTS_PAD_LEFT')
247 quiet = CBool(False, config_key='QUIET')
237 248
238 249 readline_use = CBool(True, config_key='READLINE_USE')
239 readline_merge_completions = CBool(True)
240 readline_omit__names = Int(0)
241 readline_remove_delims = '-/~'
242 readline_parse_and_bind = [
250 readline_merge_completions = CBool(True,
251 config_key='READLINE_MERGE_COMPLETIONS')
252 readline_omit__names = Enum((0,1,2), default_value=0,
253 config_key='READLINE_OMIT_NAMES')
254 readline_remove_delims = Str('-/~', config_key='READLINE_REMOVE_DELIMS')
255 readline_parse_and_bind = List([
243 256 'tab: complete',
244 257 '"\C-l": possible-completions',
245 258 'set show-all-if-ambiguous on',
@@ -255,19 +268,25 b' class InteractiveShell(Component, Magic):'
255 268 '"\e[B": history-search-forward',
256 269 '"\C-k": kill-line',
257 270 '"\C-u": unix-line-discard',
258 ]
271 ], allow_none=False, config_key='READLINE_PARSE_AND_BIND'
272 )
259 273
260 274 screen_length = Int(0, config_key='SCREEN_LENGTH')
261 separate_in = Str('\n', config_key='SEPARATE_IN')
262 separate_out = Str('', config_key='SEPARATE_OUT')
263 separate_out2 = Str('', config_key='SEPARATE_OUT2')
264 system_header = Str('IPython system call: ')
265 system_verbose = CBool(False)
266 term_title = CBool(True)
267 wildcards_case_sensitive = CBool(True)
275
276 # Use custom TraitletTypes that convert '0'->'' and '\\n'->'\n'
277 separate_in = SeparateStr('\n', config_key='SEPARATE_IN')
278 separate_out = SeparateStr('', config_key='SEPARATE_OUT')
279 separate_out2 = SeparateStr('', config_key='SEPARATE_OUT2')
280
281 system_header = Str('IPython system call: ', config_key='SYSTEM_HEADER')
282 system_verbose = CBool(False, config_key='SYSTEM_VERBOSE')
283 term_title = CBool(False, config_key='TERM_TITLE')
284 wildcards_case_sensitive = CBool(True, config_key='WILDCARDS_CASE_SENSITIVE')
268 285 xmode = CaselessStrEnum(('Context','Plain', 'Verbose'),
269 286 default_value='Context', config_key='XMODE')
270 magic_docstrings = CBool(False)
287
288 alias = List(allow_none=False, config_key='ALIAS')
289 autoexec = List(allow_none=False)
271 290
272 291 # class attribute to indicate whether the class supports threads or not.
273 292 # Subclasses with thread support should override this as needed.
@@ -285,6 +304,7 b' class InteractiveShell(Component, Magic):'
285 304 super(InteractiveShell, self).__init__(parent, config=config, name=name)
286 305
287 306 self.init_instance_attrs()
307 self.init_term_title()
288 308 self.init_usage(usage)
289 309 self.init_banner(banner1, banner2)
290 310 self.init_embedded(embedded)
@@ -343,6 +363,9 b' class InteractiveShell(Component, Magic):'
343 363 num_lines_bot = self.separate_in.count('\n')+1
344 364 return self.screen_length - num_lines_bot
345 365
366 def _term_title_changed(self, name, new_value):
367 self.init_term_title()
368
346 369 #-------------------------------------------------------------------------
347 370 # init_* methods called by __init__
348 371 #-------------------------------------------------------------------------
@@ -386,6 +409,14 b' class InteractiveShell(Component, Magic):'
386 409 # Indentation management
387 410 self.indent_current_nsp = 0
388 411
412 def init_term_title(self):
413 # Enable or disable the terminal title.
414 if self.term_title:
415 toggle_set_term_title(True)
416 set_term_title('IPython: ' + abbrev_cwd())
417 else:
418 toggle_set_term_title(False)
419
389 420 def init_usage(self, usage=None):
390 421 if usage is None:
391 422 self.usage = interactive_usage
@@ -564,7 +595,7 b' class InteractiveShell(Component, Magic):'
564 595
565 596 # Now the history file
566 597 try:
567 histfname = 'history-%s' % self.config.PROFILE
598 histfname = 'history-%s' % self.profile
568 599 except AttributeError:
569 600 histfname = 'history'
570 601 self.histfile = os.path.join(self.config.IPYTHONDIR, histfname)
@@ -903,8 +934,8 b' class InteractiveShell(Component, Magic):'
903 934 self.call_pdb = self.pdb
904 935
905 936 def init_exec_commands(self):
906 for cmd in self.autoexec:
907 #print "autoexec>",cmd #dbg
937 for cmd in self.config.EXECUTE:
938 print "execute:", cmd
908 939 self.api.runlines(cmd)
909 940
910 941 batchrun = False
@@ -2856,8 +2856,7 b' Defaulting color scheme to \'NoColor\'"""'
2856 2856 try:
2857 2857 os.chdir(os.path.expanduser(ps))
2858 2858 if self.shell.term_title:
2859 #print 'set term title:',self.shell.term_title # dbg
2860 platutils.set_term_title('IPy ' + abbrev_cwd())
2859 platutils.set_term_title('IPython: ' + abbrev_cwd())
2861 2860 except OSError:
2862 2861 print sys.exc_info()[1]
2863 2862 else:
@@ -2870,7 +2869,7 b' Defaulting color scheme to \'NoColor\'"""'
2870 2869 else:
2871 2870 os.chdir(self.shell.home_dir)
2872 2871 if self.shell.term_title:
2873 platutils.set_term_title("IPy ~")
2872 platutils.set_term_title('IPython: ' + '~')
2874 2873 cwd = os.getcwd()
2875 2874 dhist = self.shell.user_ns['_dh']
2876 2875
@@ -54,7 +54,6 b' def toggle_set_term_title(val):'
54 54
55 55 def set_term_title(title):
56 56 """Set terminal title using the necessary platform-dependent calls."""
57
58 57 if _platutils.ignore_termtitle:
59 58 return
60 59 _platutils.set_term_title(title)
@@ -17,17 +17,18 b' import os'
17 17
18 18 ignore_termtitle = True
19 19
20
20 21 def _dummy_op(*a, **b):
21 22 """ A no-op function """
22 23
23 24
24 25 def _set_term_title_xterm(title):
25 26 """ Change virtual terminal title in xterm-workalikes """
26
27 27 sys.stdout.write('\033]0;%s\007' % title)
28 28
29 TERM = os.environ.get('TERM','')
29 30
30 if os.environ.get('TERM','') == 'xterm':
31 if (TERM == 'xterm') or (TERM == 'xterm-color'):
31 32 set_term_title = _set_term_title_xterm
32 33 else:
33 34 set_term_title = _dummy_op
@@ -26,6 +26,7 b' try:'
26 26 """Set terminal title using ctypes to access the Win32 APIs."""
27 27 SetConsoleTitleW(title)
28 28
29
29 30 except ImportError:
30 31 def set_term_title(title):
31 32 """Set terminal title using the 'title' command."""
@@ -52,10 +52,15 b' Authors:'
52 52 import inspect
53 53 import sys
54 54 import types
55 from types import InstanceType, ClassType, FunctionType
55 from types import (
56 InstanceType, ClassType, FunctionType,
57 ListType, TupleType
58 )
56 59
57 60 ClassTypes = (ClassType, type)
58 61
62 SequenceTypes = (ListType, TupleType)
63
59 64 #-----------------------------------------------------------------------------
60 65 # Basic classes
61 66 #-----------------------------------------------------------------------------
@@ -860,7 +865,9 b' class CBool(Bool):'
860 865 except:
861 866 self.error(obj, value)
862 867
868
863 869 class Enum(TraitletType):
870 """An enum that whose value must be in a given sequence."""
864 871
865 872 def __init__(self, values, default_value=None, allow_none=True, **metadata):
866 873 self.values = values
@@ -884,6 +891,7 b' class Enum(TraitletType):'
884 891 return result
885 892
886 893 class CaselessStrEnum(Enum):
894 """An enum of strings that are caseless in validate."""
887 895
888 896 def validate(self, obj, value):
889 897 if value is None:
@@ -897,3 +905,21 b' class CaselessStrEnum(Enum):'
897 905 if v.lower() == value.lower():
898 906 return v
899 907 self.error(obj, value)
908
909
910 class List(Instance):
911 """An instance of a Python list."""
912
913 def __init__(self, default_value=None, allow_none=True, **metadata):
914 """Create a list traitlet type from a list or tuple.
915
916 The default value is created by doing ``list(default_value)``,
917 which creates a copy of the ``default_value``.
918 """
919 if default_value is None:
920 args = ((),)
921 elif isinstance(default_value, SequenceTypes):
922 args = (default_value,)
923
924 super(List,self).__init__(klass=list, args=args,
925 allow_none=allow_none, **metadata)
General Comments 0
You need to be logged in to leave comments. Login now