From a3790305c60e64d0fc727fb49b0c2bfd92cdb6c3 2008-07-17 05:53:27 From: Gael Varoquaux Date: 2008-07-17 05:53:27 Subject: [PATCH] Nice background color for already entered code. Bug fix for code completion. --- diff --git a/IPython/frontend/linefrontendbase.py b/IPython/frontend/linefrontendbase.py index 2cc46a6..462c170 100644 --- a/IPython/frontend/linefrontendbase.py +++ b/IPython/frontend/linefrontendbase.py @@ -105,7 +105,7 @@ class LineFrontEndBase(FrontEndBase): raw_string in the history and starts a new prompt. """ if raw_string is None: - raw_string = string + raw_string = python_string # Create a false result, in case there is an exception self.last_result = dict(number=self.prompt_number) try: diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py index 9ff4bc7..cf86f42 100644 --- a/IPython/frontend/wx/console_widget.py +++ b/IPython/frontend/wx/console_widget.py @@ -44,17 +44,16 @@ _DEFAULT_STYLE = { 'bracebad' : 'fore:#000000,back:#FF0000,bold', # properties for the various Python lexer styles - 'comment' : 'fore:#007F00', - 'number' : 'fore:#007F7F', - 'string' : 'fore:#7F007F,italic', - 'char' : 'fore:#7F007F,italic', - 'keyword' : 'fore:#00007F,bold', - 'triple' : 'fore:#7F0000', - 'tripledouble': 'fore:#7F0000', - 'class' : 'fore:#0000FF,bold,underline', - 'def' : 'fore:#007F7F,bold', - 'operator' : 'bold', - + 'comment' : 'fore:#007F00', + 'number' : 'fore:#007F7F', + 'string' : 'fore:#7F007F,italic', + 'char' : 'fore:#7F007F,italic', + 'keyword' : 'fore:#00007F,bold', + 'triple' : 'fore:#7F0000', + 'tripledouble' : 'fore:#7F0000', + 'class' : 'fore:#0000FF,bold,underline', + 'def' : 'fore:#007F7F,bold', + 'operator' : 'bold' } # new style numbers @@ -190,6 +189,7 @@ class ConsoleWidget(editwindow.EditWindow): self.StyleSetSpec(stc.STC_P_STRING, p['string']) self.StyleSetSpec(stc.STC_P_CHARACTER, p['char']) self.StyleSetSpec(stc.STC_P_WORD, p['keyword']) + self.StyleSetSpec(stc.STC_P_WORD2, p['keyword']) self.StyleSetSpec(stc.STC_P_TRIPLE, p['triple']) self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, p['tripledouble']) self.StyleSetSpec(stc.STC_P_CLASSNAME, p['class']) diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py index c5632a6..64d69bd 100644 --- a/IPython/frontend/wx/wx_frontend.py +++ b/IPython/frontend/wx/wx_frontend.py @@ -23,10 +23,17 @@ __docformat__ = "restructuredtext en" import wx import re +from wx import stc from console_widget import ConsoleWidget from IPython.frontend.prefilterfrontend import PrefilterFrontEnd +#_COMMAND_BG = '#FAFAF1' # Nice green +_RUNNING_BUFFER_BG = '#FDFFBE' # Nice yellow + +_RUNNING_BUFFER_MARKER = 31 + + #------------------------------------------------------------------------------- # Classes to implement the Wx frontend #------------------------------------------------------------------------------- @@ -50,6 +57,11 @@ class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): # Capture Character keys self.Bind(wx.EVT_KEY_DOWN, self._on_key_down) + # Marker for running buffer. + self.MarkerDefine(_RUNNING_BUFFER_MARKER, stc.STC_MARK_BACKGROUND, + background=_RUNNING_BUFFER_BG) + + def do_completion(self, mode=None): """ Do code completion. @@ -57,7 +69,8 @@ class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): """ line = self.get_current_edit_buffer() completions = self.complete(line) - self.write_completion(completions, mode=mode) + if len(completions)>0: + self.write_completion(completions, mode=mode) def update_completion(self): @@ -71,11 +84,17 @@ class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): self.AutoCompSetChooseSingle(choose_single) - def execute(self, *args, **kwargs): + def execute(self, python_string, raw_string=None): self._cursor = wx.BusyCursor() - PrefilterFrontEnd.execute(self, *args, **kwargs) + if raw_string is None: + raw_string = python_string + end_line = self.current_prompt_line \ + + max(1, len(raw_string.split('\n'))-1) + for i in range(self.current_prompt_line, end_line): + self.MarkerAdd(i, 31) + PrefilterFrontEnd.execute(self, python_string, raw_string=raw_string) + - def after_execute(self): PrefilterFrontEnd.after_execute(self) if hasattr(self, '_cursor'): @@ -133,7 +152,7 @@ class IPythonWxController(PrefilterFrontEnd, ConsoleWidget): if event.KeyCode == 59: # Intercepting '.' event.Skip() - self.do_completion(mode='popup') + #self.do_completion(mode='popup') else: ConsoleWidget._on_key_up(self, event, skip=skip)