Skip to content

Commit

Permalink
Merge pull request #169 from markotoplak/pyqt6-compat
Browse files Browse the repository at this point in the history
PyQt6 compatibility
  • Loading branch information
janezd committed Mar 3, 2023
2 parents 4e72ff9 + 4c5e19b commit a65b9b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
40 changes: 25 additions & 15 deletions orangecontrib/geo/widgets/owchoropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from AnyQt.QtCore import Qt, QObject, QSize, QRectF, pyqtSignal as Signal, \
QPointF
from AnyQt.QtGui import QPen, QBrush, QColor, QPolygonF, QPainter, QStaticText
from AnyQt.QtGui import QPen, QBrush, QColor, QPolygonF, QPainter, QStaticText, QPalette
from AnyQt.QtWidgets import QApplication, QToolTip, QGraphicsTextItem, \
QGraphicsRectItem

Expand Down Expand Up @@ -229,35 +229,45 @@ def _create_legend(self, anchor):

def _create_drag_tooltip(self, scene):
tip_parts = [
(Qt.ShiftModifier, "Shift: Add group"),
(Qt.ShiftModifier + Qt.ControlModifier,
"Shift-{}: Append to group".
(Qt.ControlModifier,
"{}: Append to group".
format("Cmd" if sys.platform == "darwin" else "Ctrl")),
(Qt.ShiftModifier, "Shift: Add group"),
(Qt.AltModifier, "Alt: Remove")
]
all_parts = ", ".join(part for _, part in tip_parts)
all_parts = "<center>" + \
", ".join(part for _, part in tip_parts) + \
"</center>"
self.tiptexts = {
int(modifier): all_parts.replace(part, "<b>{}</b>".format(part))
modifier: all_parts.replace(part, "<b>{}</b>".format(part))
for modifier, part in tip_parts
}
self.tiptexts[0] = all_parts
self.tiptexts[Qt.NoModifier] = all_parts

self.tip_textitem = text = QGraphicsTextItem()
# Set to the longest text
text.setHtml(self.tiptexts[Qt.ShiftModifier + Qt.ControlModifier])
text.setHtml(self.tiptexts[Qt.ControlModifier])
text.setPos(4, 2)
r = text.boundingRect()
text.setTextWidth(r.width())
rect = QGraphicsRectItem(0, 0, r.width() + 8, r.height() + 4)
rect.setBrush(QColor(224, 224, 224, 212))
color = self.plot_widget.palette().color(QPalette.Disabled, QPalette.Window)
color.setAlpha(212)
rect.setBrush(color)
rect.setPen(QPen(Qt.NoPen))
self.update_tooltip()

scene.drag_tooltip = scene.createItemGroup([rect, text])
scene.drag_tooltip.hide()

def update_tooltip(self, modifiers=Qt.NoModifier):
modifiers &= Qt.ShiftModifier + Qt.ControlModifier + Qt.AltModifier
text = self.tiptexts.get(int(modifiers), self.tiptexts[0])
text = self.tiptexts[Qt.NoModifier]
for mod in [Qt.ControlModifier,
Qt.ShiftModifier,
Qt.AltModifier]:
if modifiers & mod:
text = self.tiptexts.get(mod)
break
self.tip_textitem.setHtml(text)

def clear(self):
Expand Down Expand Up @@ -475,12 +485,12 @@ def select_by_indices(self, indices):
if self.selection is None:
self.selection = np.zeros(self.n_ids, dtype=np.uint8)
keys = QApplication.keyboardModifiers()
if keys & Qt.AltModifier:
self.selection_remove(indices)
elif keys & Qt.ShiftModifier and keys & Qt.ControlModifier:
if keys & Qt.ControlModifier:
self.selection_append(indices)
elif keys & Qt.ShiftModifier:
self.selection_new_group(indices)
elif keys & Qt.AltModifier:
self.selection_remove(indices)
else:
self.selection_select(indices)

Expand Down Expand Up @@ -584,7 +594,7 @@ def update_choropleth(self):
'Sum': AggDesc("sum", False, False),
'Mean': AggDesc("mean", False, True),
'Median': AggDesc("median", False, True),
'Mode': AggDesc(lambda x: stats.mode(x, nan_policy='omit').mode[0],
'Mode': AggDesc(lambda x: stats.mode(x, nan_policy='omit', keepdims=True).mode[0],
True, True),
'Maximal': AggDesc("max", False, True),
'Minimal': AggDesc("min", False, True),
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/geo/widgets/owgeocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _radioChanged():
selectionMode=gui.TableView.NoSelection,
editTriggers=gui.TableView.AllEditTriggers)
view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
view.verticalHeader().setSectionResizeMode(0)
view.verticalHeader().setSectionResizeMode(QHeaderView.Interactive)
view.setMinimumWidth(500)
view.setModel(model)

Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/geo/widgets/plotutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def zoom():
self.match_zoom(rect.center())

if self.graph.state == ZOOMING \
and ev.button() & (Qt.LeftButton | Qt.MidButton) \
and ev.button() & (Qt.LeftButton | Qt.MiddleButton) \
and self.state['mouseMode'] == ViewBox.RectMode \
and ev.isFinish():
zoom()
Expand Down
12 changes: 5 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ setenv =
deps =
{env:PYQT_PYPI_NAME:PyQt5}=={env:PYQT_PYPI_VERSION:5.15.*}
{env:WEBENGINE_PYPI_NAME:PyQtWebEngine}=={env:WEBENGINE_PYPI_VERSION:5.15.*}
oldest: scikit-learn~=0.22.0
oldest: orange3==3.25.0
# Use newer canvas-core and widget-base to avoid segfaults on windows
oldest: orange-canvas-core==0.1.9 ; sys_platform != 'win32'
oldest: orange-canvas-core==0.1.15 ; sys_platform == 'win32'
oldest: orange-widget-base==4.5.0 ; sys_platform != 'win32'
oldest: orange-widget-base==4.9.0 ; sys_platform == 'win32'
oldest: scikit-learn~=0.23.1
oldest: numpy~=1.21.0 # some older version
oldest: orange3==3.31.0
oldest: orange-canvas-core==0.1.24
oldest: orange-widget-base==4.16.1
latest: https://github.com/biolab/orange3/archive/refs/heads/master.zip#egg=orange3
latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core
latest: https://github.com/biolab/orange-widget-base/archive/refs/heads/master.zip#egg=orange-widget-base
Expand Down

0 comments on commit a65b9b8

Please sign in to comment.