diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py index ebc50d7..21778ec 100644 --- a/IPython/frontend/wx/console_widget.py +++ b/IPython/frontend/wx/console_widget.py @@ -25,6 +25,8 @@ import wx.stc as stc from wx.py import editwindow import time import sys +import string + LINESEP = '\n' if sys.platform == 'win32': LINESEP = '\n\r' @@ -45,6 +47,7 @@ if sys.platform == 'darwin': _DEFAULT_SIZE = 12 _DEFAULT_STYLE = { + #background definition 'stdout' : 'fore:#0000FF', 'stderr' : 'fore:#007f00', 'trace' : 'fore:#FF0000', @@ -118,15 +121,6 @@ class ConsoleWidget(editwindow.EditWindow): '1;34': [12, 'LIGHT BLUE'], '1;35': [13, 'MEDIUM VIOLET RED'], '1;36': [14, 'LIGHT STEEL BLUE'], '1;37': [15, 'YELLOW']} - # The color of the carret (call _apply_style() after setting) - carret_color = 'BLACK' - - _COMPLETE_BUFFER_BG = '#FAFAF1' # Nice green - _INPUT_BUFFER_BG = '#FDFFD3' # Nice yellow - _ERROR_BG = '#FFF1F1' # Nice red - - background_color = 'WHITE' - #we define platform specific fonts if wx.Platform == '__WXMSW__': faces = { 'times': 'Times New Roman', @@ -163,7 +157,7 @@ class ConsoleWidget(editwindow.EditWindow): def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.WANTS_CHARS, ): editwindow.EditWindow.__init__(self, parent, id, pos, size, style) - self._configure_scintilla() + self.configure_scintilla() self.enter_catched = False #this var track if 'enter' key as ever been processed #thus it will only be reallowed until key goes up self.current_prompt_pos = 0 @@ -270,24 +264,36 @@ class ConsoleWidget(editwindow.EditWindow): # Styling API #-------------------------------------------------------------------------- - def set_new_style(self): - """ call this method with new style and ansi_style to change colors of the console """ - self._configure_scintilla() - - #-------------------------------------------------------------------------- - # Private API - #-------------------------------------------------------------------------- - - def _configure_scintilla(self): + def configure_scintilla(self): + + p = self.style + + #First we define the special background colors + if '_COMPLETE_BUFFER_BG' in p: + _COMPLETE_BUFFER_BG = p['_COMPLETE_BUFFER_BG'] + else: + _COMPLETE_BUFFER_BG = '#FAFAF1' # Nice green + + if '_INPUT_BUFFER_BG' in p: + _INPUT_BUFFER_BG = p['_INPUT_BUFFER_BG'] + else: + _INPUT_BUFFER_BG = '#FDFFD3' # Nice yellow + + if '_ERROR_BG' in p: + _ERROR_BG = p['_ERROR_BG'] + else: + _ERROR_BG = '#FFF1F1' # Nice red + # Marker for complete buffer. self.MarkerDefine(_COMPLETE_BUFFER_MARKER, stc.STC_MARK_BACKGROUND, - background = self._COMPLETE_BUFFER_BG) + background = _COMPLETE_BUFFER_BG) + # Marker for current input buffer. self.MarkerDefine(_INPUT_MARKER, stc.STC_MARK_BACKGROUND, - background = self._INPUT_BUFFER_BG) + background = _INPUT_BUFFER_BG) # Marker for tracebacks. self.MarkerDefine(_ERROR_MARKER, stc.STC_MARK_BACKGROUND, - background = self._ERROR_BG) + background = _ERROR_BG) self.SetEOLMode(stc.STC_EOL_LF) @@ -331,25 +337,34 @@ class ConsoleWidget(editwindow.EditWindow): self.SetMarginWidth(1, 0) self.SetMarginWidth(2, 0) - #self._apply_style() - self.SetCaretForeground(self.carret_color) - # Xterm escape sequences self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?') self.title_pat = re.compile('\x1b]0;(.*?)\x07') - #self.SetEdgeMode(stc.STC_EDGE_LINE) - #self.SetEdgeColumn(80) - - # styles - p = self.style + if 'carret_color' in p: + self.SetCaretForeground(p['carret_color']) + else: + self.SetCaretForeground('BLACK') + + if 'background_color' in p: + background_color = p['background_color'] + else: + background_color = 'WHITE' + if 'default' in p: + if 'back' not in p['default']: + p['default']+=',back:%s' % background_color + if 'size' not in p['default']: + p['default']+=',size:%s' % self.faces['size'] + if 'face' not in p['default']: + p['default']+=',face:%s' % self.faces['mono'] + self.StyleSetSpec(stc.STC_STYLE_DEFAULT, p['default']) else: self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "fore:%s,back:%s,size:%d,face:%s" - % (self.ANSI_STYLES['0;30'][1], self.background_color, + % (self.ANSI_STYLES['0;30'][1], background_color, self.faces['size'], self.faces['mono'])) #all styles = default one @@ -359,6 +374,22 @@ class ConsoleWidget(editwindow.EditWindow): #for style in self.ANSI_STYLES.values(): # self.StyleSetSpec(style[0], "bold,fore:%s" % style[1]) + #prompt definition + if 'prompt_in1' in p: + self.prompt_in1 = p['prompt_in1'] + else: + self.prompt_in1 = \ + '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02' + + if 'prompt_out' in p: + self.prompt_out = p['prompt_out'] + else: + self.prompt_out = \ + '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' + + self.output_prompt_template = string.Template(self.prompt_out) + self.input_prompt_template = string.Template(self.prompt_in1) + if 'stdout' in p: self.StyleSetSpec(_STDOUT_STYLE, p['stdout']) if 'stderr' in p: @@ -394,6 +425,10 @@ class ConsoleWidget(editwindow.EditWindow): if 'comment' in p: self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, p['comment']) + #-------------------------------------------------------------------------- + # Private API + #-------------------------------------------------------------------------- + def _on_key_down(self, event, skip=True): """ Key press callback used for correcting behavior for console-like interfaces: the cursor is constraint to be after @@ -432,7 +467,7 @@ class ConsoleWidget(editwindow.EditWindow): if event.KeyCode in (13, wx.WXK_NUMPAD_ENTER) and \ event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN): catched = True - if(not self.enter_catched): + if not self.enter_catched: self.CallTipCancel() self.write('\n', refresh=False) # Under windows scintilla seems to be doing funny stuff to the diff --git a/IPython/frontend/wx/ipythonx.py b/IPython/frontend/wx/ipythonx.py index e25e197..5fc1027 100644 --- a/IPython/frontend/wx/ipythonx.py +++ b/IPython/frontend/wx/ipythonx.py @@ -28,56 +28,17 @@ class IPythonXController(WxController): def __init__(self, *args, **kwargs): - if kwargs['colorset'] == 'black': - self.prompt_in1 = \ - '\n\x01\x1b[0;30m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;30m\x02]: \x01\x1b[0m\x02' - - self.prompt_out = \ - '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' - WxController.__init__(self, *args, **kwargs) self.ipython0.ask_exit = self.do_exit - if kwargs['colorset'] == 'black': - - self.carret_color = 'WHITE' - self.background_color = 'BLACK' + if kwargs['styledef'] is not None: + self.style = kwargs['styledef'] + #we add a vertical line to console widget self.SetEdgeMode(stc.STC_EDGE_LINE) self.SetEdgeColumn(88) - - self.style = { - #'stdout' : '',#fore:#0000FF', - #'stderr' : '',#fore:#007f00', - #'trace' : '',#fore:#FF0000', - - #'bracegood' : 'fore:#0000FF,back:#0000FF,bold', - #'bracebad' : 'fore:#FF0000,back:#0000FF,bold', - 'default' : "fore:%s,back:%s,size:%d,face:%s,bold" - % ("#EEEEEE", self.background_color, - self.faces['size'], self.faces['mono']), - - # properties for the various Python lexer styles - 'comment' : 'fore:#BBBBBB,italic', - 'number' : 'fore:#FF9692', - 'string' : 'fore:#ed9d13,italic', - 'char' : 'fore:#FFFFFF,italic', - 'keyword' : 'fore:#6AB825,bold', - 'triple' : 'fore:#FF7BDD', - 'tripledouble' : 'fore:#FF7BDD', - 'class' : 'fore:#FF00FF,bold,underline', - 'def' : 'fore:#FFFF00,bold', - 'operator' : 'bold' - } - - #we define the background of old inputs - self._COMPLETE_BUFFER_BG = '#000000' # RRGGBB: Black - #we define the background of current input - self._INPUT_BUFFER_BG = '#444444' # RRGGBB: Light black - #we define the background when an error is reported - self._ERROR_BG = '#800000' #'#d22323' #'#AE0021' # RRGGBB: Black - - self.set_new_style() + + self.configure_scintilla() # Scroll to top maxrange = self.GetScrollRange(wx.VERTICAL) @@ -124,10 +85,10 @@ class IPythonX(wx.Frame): """ Main frame of the IPythonX app. """ - def __init__(self, parent, id, title, debug=False, colorset='white'): + def __init__(self, parent, id, title, debug=False, style=None): wx.Frame.__init__(self, parent, id, title, size=(300,250)) self._sizer = wx.BoxSizer(wx.VERTICAL) - self.shell = IPythonXController(self, debug=debug, colorset=colorset) + self.shell = IPythonXController(self, debug=debug, styledef=style) self._sizer.Add(self.shell, 1, wx.EXPAND) self.SetSizer(self._sizer) self.SetAutoLayout(1) @@ -163,8 +124,51 @@ Simple graphical frontend to IPython, using WxWidgets.""" import sys sys.argv = sys.argv[:1] + style = None + + if options.colorset == 'black': + style = { + 'carret_color' : 'WHITE', + 'background_color' : 'BLACK', + + #prompt + 'prompt_in1' : \ + '\n\x01\x1b[0;30m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;30m\x02]: \x01\x1b[0m\x02', + + 'prompt_out' : \ + '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02', + + #we define the background of old inputs + '_COMPLETE_BUFFER_BG' : '#000000', # RRGGBB: Black + #we define the background of current input + '_INPUT_BUFFER_BG' : '#444444', # RRGGBB: Light black + #we define the background when an error is reported + '_ERROR_BG' : '#800000', # RRGGBB: Light Red + + #'stdout' : '',#fore:#0000FF', + #'stderr' : '',#fore:#007f00', + #'trace' : '',#fore:#FF0000', + + #'bracegood' : 'fore:#0000FF,back:#0000FF,bold', + #'bracebad' : 'fore:#FF0000,back:#0000FF,bold', + 'default' : "fore:%s,bold" % ("#EEEEEE"), + + # properties for the various Python lexer styles + 'comment' : 'fore:#BBBBBB,italic', + 'number' : 'fore:#FF9692', + 'string' : 'fore:#ed9d13,italic', + 'char' : 'fore:#FFFFFF,italic', + 'keyword' : 'fore:#6AB825,bold', + 'triple' : 'fore:#FF7BDD', + 'tripledouble' : 'fore:#FF7BDD', + 'class' : 'fore:#FF00FF,bold,underline', + 'def' : 'fore:#FFFF00,bold', + 'operator' : 'bold' + } + + app = wx.PySimpleApp() - frame = IPythonX(None, wx.ID_ANY, 'IPythonX', debug=options.debug, colorset=options.colorset) + frame = IPythonX(None, wx.ID_ANY, 'IPythonX', debug=options.debug, style=style) frame.shell.SetFocus() frame.shell.app = app frame.SetSize((680, 460)) diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py index adb9481..3d9e793 100644 --- a/IPython/frontend/wx/wx_frontend.py +++ b/IPython/frontend/wx/wx_frontend.py @@ -55,12 +55,7 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): This class inherits from ConsoleWidget, that provides a console-like widget to provide a text-rendering widget suitable for a terminal. """ - prompt_in1 = \ - '\n\x01\x1b[0;34m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;34m\x02]: \x01\x1b[0m\x02' - - prompt_out = \ - '\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' - + # Print debug info on what is happening to the console. debug = False @@ -131,8 +126,6 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): *args, **kwds): """ Create Shell instance. """ - self.load_prompt() - ConsoleWidget.__init__(self, parent, id, pos, size, style) PrefilterFrontEnd.__init__(self, **kwds) @@ -153,12 +146,6 @@ class WxController(ConsoleWidget, PrefilterFrontEnd): self.shell.user_ns['self'] = self # Inject our own raw_input in namespace self.shell.user_ns['raw_input'] = self.raw_input - - def load_prompt(self): - self.output_prompt_template = string.Template(self.prompt_out) - - self.input_prompt_template = string.Template(self.prompt_in1) - def raw_input(self, prompt=''): """ A replacement from python's raw_input.