Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.10 compatiblity fixes #2856

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ilastik/applets/counting/countingGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _countingColorTable():
colortable = matplotlib_to_qt4_colortable("jet", N=n_gradual, asLong=False)
weights = numpy.tanh(numpy.linspace(0, 1.0, n_gradual))
for w, c in zip(weights, colortable):
c.setAlpha(w * 255)
c.setAlpha(int(w * 255))
colortable = [c.rgba() for c in colortable]

return [*colortable, *[colortable[-1]] * (n_total - n_gradual)]
Expand Down
2 changes: 1 addition & 1 deletion ilastik/applets/counting/countingGuiBoxesInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
def setOpacity(self, float):
logger.debug("Resetting Opacity {}".format(float))

self._normalColor.setAlpha(float * 255)
self._normalColor.setAlpha(int(float * 255))

Check warning on line 452 in ilastik/applets/counting/countingGuiBoxesInterface.py

View check run for this annotation

Codecov / codecov/patch

ilastik/applets/counting/countingGuiBoxesInterface.py#L452

Added line #L452 was not covered by tests

self.updateColor()

Expand Down
2 changes: 1 addition & 1 deletion ilastik/shell/gui/ilastikShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def show(self):
self.updateShellProjectDisplay()
# Default to a 50-50 split
totalSplitterHeight = sum(self.sideSplitter.sizes())
self.sideSplitter.setSizes([totalSplitterHeight / 2, totalSplitterHeight / 2])
self.sideSplitter.setSizes([totalSplitterHeight // 2, totalSplitterHeight // 2])

@threadRouted
def updateShellProjectDisplay(self):
Expand Down
31 changes: 7 additions & 24 deletions ilastik/widgets/featureTableWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# http://ilastik.org/license.html
###############################################################################
import enum
from past.utils import old_div
from PyQt5.QtGui import QBrush, QColor, QFont, QIcon, QImage, QPainter, QPen, QPixmap, QPolygon, QKeyEvent
from PyQt5.QtGui import QBrush, QColor, QFont, QIcon, QPainter, QPen, QPixmap, QPolygon, QKeyEvent
from PyQt5.QtWidgets import (
QAbstractItemView,
QHeaderView,
Expand Down Expand Up @@ -173,8 +172,8 @@
painter.setBrush(brush)
painter.drawEllipse(
QRect(
old_div(self.pixmapSize.width(), 2) - old_div(self.brushSize, 2),
old_div(self.pixmapSize.height(), 2) - old_div(self.brushSize, 2),
self.pixmapSize.width() // 2 - self.brushSize // 2,
self.pixmapSize.height() // 2 - self.brushSize // 2,
self.brushSize,
self.brushSize,
)
Expand Down Expand Up @@ -297,8 +296,8 @@
painter.drawRect(QRect(5, 5, width - 10, height - 10))
pen.setWidth(4)
painter.setPen(pen)
painter.drawLine(width / 2 - 5, height / 2, width / 2, height - 10)
painter.drawLine(width / 2, height - 10, width / 2 + 10, 2)
painter.drawLine(width // 2 - 5, height // 2, width // 2, height - 10)
painter.drawLine(width // 2, height - 10, width // 2 + 10, 2)
painter.end()

def drawPixmapForPartiallyChecked(self, painter: QPainter, width: int, height: int) -> None:
Expand All @@ -310,8 +309,8 @@
pen.setWidth(4)
pen.setColor(QColor(139, 137, 137))
painter.setPen(pen)
painter.drawLine(width / 2 - 5, height / 2, width / 2, height - 10)
painter.drawLine(width / 2, height - 10, width / 2 + 10, 2)
painter.drawLine(width // 2 - 5, height // 2, width // 2, height - 10)
painter.drawLine(width // 2, height - 10, width // 2 + 10, 2)

Check warning on line 313 in ilastik/widgets/featureTableWidget.py

View check run for this annotation

Codecov / codecov/patch

ilastik/widgets/featureTableWidget.py#L312-L313

Added lines #L312 - L313 were not covered by tests
painter.end()

def paint(self, painter, option, index):
Expand Down Expand Up @@ -351,22 +350,6 @@
painter.fillRect(option.rect.adjusted(5, 5, -5, -5), QColor(0, 250, 154))
painter.drawPixmap(option.rect, self.getPixmap(self.Role.CHECKED, option.rect.size()))

def adjustRectForImage(self, option):
if self.itemWidth > self.itemHeight:
return option.rect.adjusted(
old_div((self.itemWidth - self.itemHeight), 2) + 5,
5,
-(old_div((self.itemWidth - self.itemHeight), 2)) - 5,
-5,
)
else:
return option.rect.adjusted(
5,
old_div((self.itemHeight - self.itemWidth), 2) + 5,
-(old_div((self.itemHeight - self.itemWidth), 2)) - 5,
-5,
)


# ==============================================================================
# FeatureTableWidget2d
Expand Down
22 changes: 7 additions & 15 deletions ilastik/widgets/preView.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division

###############################################################################
# ilastik: interactive learning and segmentation toolkit
#
Expand All @@ -20,25 +18,23 @@
# on the ilastik web site at:
# http://ilastik.org/license.html
###############################################################################
from past.utils import old_div
from PyQt5.QtGui import QPixmap, QPainter, QBrush, QPen, QPalette, QColor
from PyQt5.QtGui import QPixmap, QPainter, QBrush, QPen, QPalette
from PyQt5.QtWidgets import QGraphicsView, QVBoxLayout, QLabel, QGraphicsScene
from PyQt5.QtCore import Qt, QRect, QSize, QEvent


# ===============================================================================
# PreView
# ===============================================================================
class PreView(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)

self.zoom = 2
self.zoom: int = 2
self.scale(self.zoom, self.zoom)
self.lastSize = 0
self.lastSize: int = 0

self.setDragMode(QGraphicsView.ScrollHandDrag)
# self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.installEventFilter(self)

self.hudLayout = QVBoxLayout(self)
Expand All @@ -64,7 +60,7 @@
def sizeHint(self):
return QSize(200, 200)

def updateFilledCircle(self, s):
def updateFilledCircle(self, s: int):
size = s * self.zoom
pixmap = QPixmap(self.width(), self.height())
pixmap.fill(Qt.transparent)
Expand All @@ -76,9 +72,7 @@
brush = QBrush(p.link().color())
painter.setBrush(brush)
painter.setOpacity(0.4)
painter.drawEllipse(
QRect(old_div(self.width(), 2) - old_div(size, 2), old_div(self.height(), 2) - old_div(size, 2), size, size)
)
painter.drawEllipse(QRect(self.width() // 2 - size // 2, self.height() // 2 - size // 2, size, size))

Check warning on line 75 in ilastik/widgets/preView.py

View check run for this annotation

Codecov / codecov/patch

ilastik/widgets/preView.py#L75

Added line #L75 was not covered by tests
painter.end()
# painter ellipse 2
painter2 = QPainter()
Expand All @@ -87,9 +81,7 @@
pen2 = QPen(Qt.green)
pen2.setWidth(1)
painter2.setPen(pen2)
painter2.drawEllipse(
QRect(old_div(self.width(), 2) - old_div(size, 2), old_div(self.height(), 2) - old_div(size, 2), size, size)
)
painter2.drawEllipse(QRect(self.width() // 2 - size // 2, self.height() // 2 - size // 2, size, size))

Check warning on line 84 in ilastik/widgets/preView.py

View check run for this annotation

Codecov / codecov/patch

ilastik/widgets/preView.py#L84

Added line #L84 was not covered by tests
painter2.end()

self.ellipseLabel.setPixmap(QPixmap(pixmap))
Expand Down
6 changes: 3 additions & 3 deletions lazyflow/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
assert self._executionCount > 0, "BUG: Can't decrement the execution count below zero!"
with self._condition:
self._executionCount -= 1
self._condition.notifyAll()
self._condition.notify_all()

def propagateDirty(self, slot, subindex, roi):
"""This method is called when an output of another operator on
Expand Down Expand Up @@ -473,7 +473,7 @@
return func(self, *args, **kwargs)
finally:
self._settingUp = False
self._condition.notifyAll()
self._condition.notify_all()

Check warning on line 476 in lazyflow/operator.py

View check run for this annotation

Codecov / codecov/patch

lazyflow/operator.py#L476

Added line #L476 was not covered by tests

wrapper.__wrapped__ = func # Emulate python 3 behavior of @wraps
return wrapper
Expand All @@ -499,7 +499,7 @@
self._setup_count += 1

self._settingUp = False
self._condition.notifyAll()
self._condition.notify_all()

try:
# Determine new "ready" flags
Expand Down
4 changes: 2 additions & 2 deletions lazyflow/operators/cacheMemoryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def setRefreshInterval(self, t):
"""
with self._condition:
self._refresh_interval = t
self._condition.notifyAll()
self._condition.notify_all()

def disable(self):
"""
Expand All @@ -274,7 +274,7 @@ def enable(self):
with self._disable_lock:
self._disabled = False
with self._condition:
self._condition.notifyAll()
self._condition.notify_all()


_cache_memory_manager = _CacheMemoryManager()
Expand Down