Skip to content

Commit

Permalink
Merge pull request #381 from hmaarrfk/qtpy
Browse files Browse the repository at this point in the history
Use qtpy instead of rolling custom loader
  • Loading branch information
ccordoba12 committed Jan 25, 2020
2 parents 4257d22 + 568210f commit 270330f
Show file tree
Hide file tree
Showing 36 changed files with 222 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: false

env:
global:
- CONDA_DEPENDENCIES='pyqt traitlets ipython_genutils jupyter_core jupyter_client pygments ipykernel pytest pytest-cov mock'
- CONDA_DEPENDENCIES='pyqt qtpy traitlets ipython_genutils jupyter_core jupyter_client pygments ipykernel pytest pytest-cov mock'
- PIP_DEPENDENCIES='coveralls pytest-xvfb pytest-qt'

matrix:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Use Conda to install dependencies and activate the development environment.
```
conda create -n qtdev python=3
conda activate qtdev
conda install pyqt
conda install qtpy pyqt
```

To run after the changes have been made to source (preferred):
Expand Down
1 change: 1 addition & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ dependencies:
- pexpect
- pygments
- pyqt
- qtpy
- sphinx
- sphinx_rtd_theme
2 changes: 1 addition & 1 deletion examples/embed_qtconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
python3 embed_qtconsole.py
"""
import sys
from PyQt5 import QtWidgets
from qtpy import QtWidgets

from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.manager import QtKernelManager
Expand Down
4 changes: 2 additions & 2 deletions examples/inprocess_qtconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""


from qtconsole.qt import QtGui
from qtpy import QtWidgets
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager

Expand All @@ -34,6 +34,6 @@ def show():


if __name__ == "__main__":
app = QtGui.QApplication([])
app = QtWidgets.QApplication([])
show()
app.exec_()
2 changes: 1 addition & 1 deletion qtconsole/ansi_code_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re

# System library imports
from qtconsole.qt import QtGui
from qtpy import QtGui

# Local imports
from ipython_genutils.py3compat import string_types
Expand Down
6 changes: 3 additions & 3 deletions qtconsole/bracket_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""

# System library imports
from qtconsole.qt import QtCore, QtGui
from qtpy import QtCore, QtGui, QtWidgets


class BracketMatcher(QtCore.QObject):
Expand All @@ -22,7 +22,7 @@ def __init__(self, text_edit):
""" Create a call tip manager that is attached to the specified Qt
text edit widget.
"""
assert isinstance(text_edit, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
assert isinstance(text_edit, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit))
super(BracketMatcher, self).__init__()

# The format to apply to matching brackets.
Expand Down Expand Up @@ -72,7 +72,7 @@ def _find_match(self, position):
def _selection_for_character(self, position):
""" Convenience method for selecting a character.
"""
selection = QtGui.QTextEdit.ExtraSelection()
selection = QtWidgets.QTextEdit.ExtraSelection()
cursor = self._text_edit.textCursor()
cursor.setPosition(position)
cursor.movePosition(QtGui.QTextCursor.NextCharacter,
Expand Down
24 changes: 12 additions & 12 deletions qtconsole/call_tip_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from unicodedata import category

# System library imports
from qtconsole.qt import QtCore, QtGui
from qtpy import QtCore, QtGui, QtWidgets


class CallTipWidget(QtGui.QLabel):
class CallTipWidget(QtWidgets.QLabel):
""" Shows call tips by parsing the current text of Q[Plain]TextEdit.
"""

Expand All @@ -18,7 +18,7 @@ def __init__(self, text_edit):
""" Create a call tip manager that is attached to the specified Qt
text edit widget.
"""
assert isinstance(text_edit, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
assert isinstance(text_edit, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit))
super(CallTipWidget, self).__init__(None, QtCore.Qt.ToolTip)

self._hide_timer = QtCore.QBasicTimer()
Expand All @@ -27,15 +27,15 @@ def __init__(self, text_edit):
self.setFont(text_edit.document().defaultFont())
self.setForegroundRole(QtGui.QPalette.ToolTipText)
self.setBackgroundRole(QtGui.QPalette.ToolTipBase)
self.setPalette(QtGui.QToolTip.palette())
self.setPalette(QtWidgets.QToolTip.palette())

self.setAlignment(QtCore.Qt.AlignLeft)
self.setIndent(1)
self.setFrameStyle(QtGui.QFrame.NoFrame)
self.setFrameStyle(QtWidgets.QFrame.NoFrame)
self.setMargin(1 + self.style().pixelMetric(
QtGui.QStyle.PM_ToolTipLabelFrameWidth, None, self))
QtWidgets.QStyle.PM_ToolTipLabelFrameWidth, None, self))
self.setWindowOpacity(self.style().styleHint(
QtGui.QStyle.SH_ToolTipLabel_Opacity, None, self, None) / 255.0)
QtWidgets.QStyle.SH_ToolTipLabel_Opacity, None, self, None) / 255.0)
self.setWordWrap(True)

def eventFilter(self, obj, event):
Expand Down Expand Up @@ -98,10 +98,10 @@ def leaveEvent(self, event):
def paintEvent(self, event):
""" Reimplemented to paint the background panel.
"""
painter = QtGui.QStylePainter(self)
option = QtGui.QStyleOptionFrame()
painter = QtWidgets.QStylePainter(self)
option = QtWidgets.QStyleOptionFrame()
option.initFrom(self)
painter.drawPrimitive(QtGui.QStyle.PE_PanelTipLabel, option)
painter.drawPrimitive(QtWidgets.QStyle.PE_PanelTipLabel, option)
painter.end()

super(CallTipWidget, self).paintEvent(event)
Expand Down Expand Up @@ -155,7 +155,7 @@ def show_tip(self, tip):
# location based trying to minimize the area that goes off-screen.
padding = 3 # Distance in pixels between cursor bounds and tip box.
cursor_rect = text_edit.cursorRect(cursor)
screen_rect = QtGui.qApp.desktop().screenGeometry(text_edit)
screen_rect = QtWidgets.QApp.desktop().screenGeometry(text_edit)
point = text_edit.mapToGlobal(cursor_rect.bottomRight())
point.setY(point.y() + padding)
tip_height = self.size().height()
Expand Down Expand Up @@ -240,7 +240,7 @@ def _leave_event_hide(self):
# If Enter events always came after Leave events, we wouldn't need
# this check. But on Mac OS, it sometimes happens the other way
# around when the tooltip is created.
QtGui.qApp.topLevelAt(QtGui.QCursor.pos()) != self):
QtWidgets.QApp.topLevelAt(QtGui.QCursor.pos()) != self):
self._hide_timer.start(300, self)

def _format_tooltip(self, doc):
Expand Down
2 changes: 1 addition & 1 deletion qtconsole/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from zmq import ZMQError
from zmq.eventloop import ioloop, zmqstream

from qtconsole.qt import QtCore
from qtpy import QtCore

# Local imports
from traitlets import Type, Instance
Expand Down
2 changes: 1 addition & 1 deletion qtconsole/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import uuid

from qtconsole.qt import QtCore
from qtpy import QtCore
from qtconsole.util import MetaQObjectHasTraits, SuperQObject


Expand Down
16 changes: 8 additions & 8 deletions qtconsole/completion_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import ipython_genutils.text as text

from qtconsole.qt import QtCore, QtGui
from qtpy import QtCore, QtGui, QtWidgets

#--------------------------------------------------------------------------
# Return an HTML table with selected item in a special class
Expand Down Expand Up @@ -44,8 +44,8 @@ def html_tableify(item_matrix, select=None, header=None , footer=None) :

class SlidingInterval(object):
"""a bound interval that follows a cursor
internally used to scoll the completion view when the cursor
internally used to scoll the completion view when the cursor
try to go beyond the edges, and show '...' when rows are hidden
"""

Expand All @@ -54,9 +54,9 @@ class SlidingInterval(object):
_current = 0
def __init__(self, maximum=1, width=6, minimum=0, sticky_lenght=1):
"""Create a new bounded interval
any value return by this will be bound between maximum and
minimum. usual width will be 'width', and sticky_length
any value return by this will be bound between maximum and
minimum. usual width will be 'width', and sticky_length
set when the return interval should expand to max and min
"""
self._min = minimum
Expand Down Expand Up @@ -109,7 +109,7 @@ def width(self):
def nth(self):
return self.current - self.start

class CompletionHtml(QtGui.QWidget):
class CompletionHtml(QtWidgets.QWidget):
""" A widget for tab completion, navigable by arrow keys """

#--------------------------------------------------------------------------
Expand All @@ -129,7 +129,7 @@ def __init__(self, console_widget):
""" Create a completion widget that is attached to the specified Qt
text edit widget.
"""
assert isinstance(console_widget._control, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
assert isinstance(console_widget._control, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit))
super(CompletionHtml, self).__init__()

self._text_edit = console_widget._control
Expand Down
6 changes: 3 additions & 3 deletions qtconsole/completion_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from qtconsole.qt import QtCore, QtGui
from qtpy import QtCore, QtGui, QtWidgets
import ipython_genutils.text as text


class CompletionPlain(QtGui.QWidget):
class CompletionPlain(QtWidgets.QWidget):
""" A widget for tab completion, navigable by arrow keys """

#--------------------------------------------------------------------------
Expand All @@ -18,7 +18,7 @@ def __init__(self, console_widget):
""" Create a completion widget that is attached to the specified Qt
text edit widget.
"""
assert isinstance(console_widget._control, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
assert isinstance(console_widget._control, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit))
super(CompletionPlain, self).__init__()

self._text_edit = console_widget._control
Expand Down
24 changes: 12 additions & 12 deletions qtconsole/completion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import os
import sys

from qtconsole.qt import QtCore, QtGui
from qtpy import QtCore, QtGui, QtWidgets


class CompletionWidget(QtGui.QListWidget):
class CompletionWidget(QtWidgets.QListWidget):
""" A widget for GUI tab completion.
"""

Expand All @@ -19,13 +19,13 @@ def __init__(self, console_widget):
text edit widget.
"""
text_edit = console_widget._control
assert isinstance(text_edit, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
assert isinstance(text_edit, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit))
super(CompletionWidget, self).__init__(parent=console_widget)

self._text_edit = text_edit
self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)

# We need Popup style to ensure correct mouse interaction
# (dialog would dissappear on mouse click with ToolTip style)
Expand All @@ -40,8 +40,8 @@ def __init__(self, console_widget):
# Ensure that the text edit keeps focus when widget is displayed.
self.setFocusProxy(self._text_edit)

self.setFrameShadow(QtGui.QFrame.Plain)
self.setFrameShape(QtGui.QFrame.StyledPanel)
self.setFrameShadow(QtWidgets.QFrame.Plain)
self.setFrameShape(QtWidgets.QFrame.StyledPanel)

self.itemActivated.connect(self._complete_current)

Expand All @@ -52,7 +52,7 @@ def eventFilter(self, obj, event):
if obj is self:
if event.type() == QtCore.QEvent.MouseButtonPress:
pos = self.mapToGlobal(event.pos())
target = QtGui.QApplication.widgetAt(pos)
target = QtWidgets.QApplication.widgetAt(pos)
if (target and self.isAncestorOf(target) or target is self):
return False
else:
Expand All @@ -72,7 +72,7 @@ def keyPressEvent(self, event):
QtCore.Qt.Key_Home, QtCore.Qt.Key_End):
return super(CompletionWidget, self).keyPressEvent(event)
else:
QtGui.QApplication.sendEvent(self._text_edit, event)
QtWidgets.QApplication.sendEvent(self._text_edit, event)

#--------------------------------------------------------------------------
# 'QWidget' interface
Expand Down Expand Up @@ -107,7 +107,7 @@ def show_items(self, cursor, items, prefix_length=0):
point = self._get_top_left_position(cursor)
self.clear()
for item in items:
list_item = QtGui.QListWidgetItem()
list_item = QtWidgets.QListWidgetItem()
list_item.setData(QtCore.Qt.UserRole, item)
# Check if the item could refer to a file. The replacing of '"'
# is needed for items on Windows
Expand All @@ -117,7 +117,7 @@ def show_items(self, cursor, items, prefix_length=0):
list_item.setText(item.replace("\"", "").split('.')[-1])
self.addItem(list_item)
height = self.sizeHint().height()
screen_rect = QtGui.QApplication.desktop().availableGeometry(self)
screen_rect = QtWidgets.QApplication.desktop().availableGeometry(self)
if (screen_rect.size().height() + screen_rect.y() -
point.y() - height < 0):
point = text_edit.mapToGlobal(text_edit.cursorRect().topRight())
Expand Down

0 comments on commit 270330f

Please sign in to comment.