diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 9b64009..2b8ad2d 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -802,19 +802,41 @@ class ConsoleWidget(QtGui.QWidget): cursor.movePosition(QtGui.QTextCursor.End) return cursor + def _get_input_buffer_cursor_column(self): + """ Returns the column of the cursor in the input buffer, excluding the + contribution by the prompt, or -1 if there is no such column. + """ + prompt = self._get_input_buffer_cursor_prompt() + if prompt is None: + return -1 + else: + cursor = self._control.textCursor() + return cursor.columnNumber() - len(prompt) + def _get_input_buffer_cursor_line(self): - """ The text in the line of the input buffer in which the user's cursor - rests. Returns a string if there is such a line; otherwise, None. + """ Returns line of the input buffer that contains the cursor, or None + if there is no such line. + """ + prompt = self._get_input_buffer_cursor_prompt() + if prompt is None: + return None + else: + cursor = self._control.textCursor() + text = self._get_block_plain_text(cursor.block()) + return text[len(prompt):] + + def _get_input_buffer_cursor_prompt(self): + """ Returns the (plain text) prompt for line of the input buffer that + contains the cursor, or None if there is no such line. """ if self._executing: return None cursor = self._control.textCursor() if cursor.position() >= self._prompt_pos: - text = self._get_block_plain_text(cursor.block()) if cursor.blockNumber() == self._get_prompt_cursor().blockNumber(): - return text[len(self._prompt):] + return self._prompt else: - return text[len(self._continuation_prompt):] + return self._continuation_prompt else: return None diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index 1521860..f177b15 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -292,16 +292,11 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): return False # Send the completion request to the kernel - text = '.'.join(context) - - # FIXME - Evan: we need the position of the cursor in the current input - # buffer. I tried this line below but the numbers I get are bogus. - - # Not sure what to do. fperez. - cursor_pos = self._get_cursor().position() - self._complete_id = self.kernel_manager.xreq_channel.complete( - text, self._get_input_buffer_cursor_line(), cursor_pos, - self.input_buffer) + '.'.join(context), # text + self._get_input_buffer_cursor_line(), # line + self._get_input_buffer_cursor_column(), # cursor_pos + self.input_buffer) # block self._complete_pos = self._get_cursor().position() return True diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index e6e5334..aa88055 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -109,11 +109,9 @@ class IPythonWidget(FrontendWidget): """ Reimplemented for IPython-style traceback formatting. """ content = msg['content'] - - traceback = '\n'.join(content['traceback']) - - if 0: - # FIXME: for now, tracebacks come as plain text, so we can't use + traceback = '\n'.join(content['traceback']) + '\n' + if False: + # FIXME: For now, tracebacks come as plain text, so we can't use # the html renderer yet. Once we refactor ultratb to produce # properly styled tracebacks, this branch should be the default traceback = traceback.replace(' ', ' ') diff --git a/IPython/frontend/qt/console/scripts/ipythonqt.py b/IPython/frontend/qt/console/scripts/ipythonqt.py index 1a8033c..f4409aa 100755 --- a/IPython/frontend/qt/console/scripts/ipythonqt.py +++ b/IPython/frontend/qt/console/scripts/ipythonqt.py @@ -61,11 +61,7 @@ def main(): kernel_manager.start_kernel() kernel_manager.start_channels() - # FIXME: this is a hack, set colors to lightbg by default in qt terminal - # unconditionally, regardless of user settings in config files. - kernel_manager.xreq_channel.execute("%colors lightbg") - - # Launch the application. + # Create the widget. app = QtGui.QApplication([]) if args.pure: kind = 'rich' if args.rich else 'plain' @@ -77,6 +73,12 @@ def main(): widget.kernel_manager = kernel_manager widget.setWindowTitle('Python' if args.pure else 'IPython') widget.show() + + # FIXME: This is a hack: set colors to lightbg by default in qt terminal + # unconditionally, regardless of user settings in config files. + widget.execute("%colors lightbg", hidden=True) + + # Start the application main loop. app.exec_() diff --git a/IPython/zmq/kernelmanager.py b/IPython/zmq/kernelmanager.py index 929f5f9..375e3fc 100644 --- a/IPython/zmq/kernelmanager.py +++ b/IPython/zmq/kernelmanager.py @@ -183,7 +183,7 @@ class XReqSocketChannel(ZmqSocketChannel): return msg['header']['msg_id'] def complete(self, text, line, cursor_pos, block=None): - """Tab complete text, line, block in the kernel's namespace. + """Tab complete text in the kernel's namespace. Parameters ---------- @@ -192,7 +192,10 @@ class XReqSocketChannel(ZmqSocketChannel): line : str The full line of text that is the surrounding context for the text to complete. - block : str + cursor_pos : int + The position of the cursor in the line where the completion was + requested. + block : str, optional The full block of code in which the completion is being requested. Returns