Skip to content

Commit

Permalink
Merge pull request #394 from dalthviz/spyder_issue_10692
Browse files Browse the repository at this point in the history
Prevent completion strip if it refers to a file
  • Loading branch information
ccordoba12 committed Nov 17, 2019
2 parents 47f1500 + ca55cc2 commit c65b692
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
11 changes: 8 additions & 3 deletions qtconsole/completion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self, console_widget):

self._text_edit = text_edit
self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)

Expand Down Expand Up @@ -110,7 +109,12 @@ def show_items(self, cursor, items, prefix_length=0):
for item in items:
list_item = QtGui.QListWidgetItem()
list_item.setData(QtCore.Qt.UserRole, item)
list_item.setText(item.split('.')[-1])
# Check if the item could refer to a file. The replacing of '"'
# is needed for items on Windows
if os.path.isfile(os.path.abspath(item.replace("\"", ""))):
list_item.setText(item)
else:
list_item.setText(item.replace("\"", "").split('.')[-1])
self.addItem(list_item)
height = self.sizeHint().height()
screen_rect = QtGui.QApplication.desktop().availableGeometry(self)
Expand All @@ -119,7 +123,8 @@ def show_items(self, cursor, items, prefix_length=0):
point = text_edit.mapToGlobal(text_edit.cursorRect().topRight())
point.setY(point.y() - height)
w = (self.sizeHintForColumn(0) +
self.verticalScrollBar().sizeHint().width())
self.verticalScrollBar().sizeHint().width() +
2 * self.frameWidth())
self.setGeometry(point.x(), point.y(), w, height)

# Move cursor to start of the prefix to replace it
Expand Down
3 changes: 2 additions & 1 deletion qtconsole/tests/test_00_console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def test_debug(qtconsole, qtbot):
modifier=QtCore.Qt.ShiftModifier)

qtbot.waitUntil(
lambda: control.toPlainText().strip().split()[-1] == "ipdb>")
lambda: control.toPlainText().strip().split()[-1] == "ipdb>",
timeout=SHELL_TIMEOUT)

# We should be able to move the cursor while debugging
qtbot.keyClicks(control, "abd")
Expand Down
22 changes: 15 additions & 7 deletions qtconsole/tests/test_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import unittest

from ipython_genutils.py3compat import PY3
from jupyter_client.blocking.channels import Empty

from qtconsole.manager import QtKernelManager
Expand Down Expand Up @@ -142,13 +143,20 @@ def test_frontend_to_kernel(self):
# Get close
comm.close('close')
msg = self._get_next_msg()
# For some reason ipykernel notifies me that it is closing,
# even though I closed the comm
assert msg['header']['msg_type'] == 'comm_close'
assert comm.comm_id == msg['content']['comm_id']
msg = self._get_next_msg()
assert msg['header']['msg_type'] == 'stream'
assert msg['content']['text'] == 'close\n'

# Received message has a header and parent header. The parent header has
# the info about the close message type in Python 3
if PY3:
assert msg['parent_header']['msg_type'] == 'comm_close'
assert msg['msg_type'] == 'stream'
assert msg['content']['text'] == 'close\n'
else:
# For some reason ipykernel notifies me that it is closing,
# even though I closed the comm
assert msg['header']['msg_type'] == 'comm_close'
assert comm.comm_id == msg['content']['comm_id']
msg = self._get_next_msg()
assert msg['header']['msg_type'] == 'stream'

if __name__ == "__main__":
unittest.main()

0 comments on commit c65b692

Please sign in to comment.