1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-22 14:41:39 +00:00

Format all files with black correcting line length

This commit is contained in:
2021-08-15 04:10:18 -05:00
parent 9446f37fad
commit ffe6b7047c
80 changed files with 517 additions and 970 deletions

View File

@@ -2,15 +2,24 @@
# which should be included with this package. The terms are also available at
# http://www.gnu.org/licenses/gpl-3.0.html
from PyQt5.QtCore import (
QObject, Qt, QSize, QRectF, QPointF, QPoint, pyqtSlot, pyqtSignal, QEvent)
from PyQt5.QtCore import QObject, Qt, QSize, QRectF, QPointF, QPoint, pyqtSlot, pyqtSignal, QEvent
from PyQt5.QtGui import QPixmap, QPainter, QPalette, QCursor, QIcon, QKeySequence
from PyQt5.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsPixmapItem,
QToolBar, QToolButton, QAction, QWidget, QScrollArea,
QApplication, QAbstractScrollArea, QStyle)
QGraphicsView,
QGraphicsScene,
QGraphicsPixmapItem,
QToolBar,
QToolButton,
QAction,
QWidget,
QScrollArea,
QApplication,
QAbstractScrollArea,
QStyle,
)
from hscommon.trans import trget
from hscommon.plat import ISLINUX
tr = trget("ui")
MAX_SCALE = 12.0
@@ -50,8 +59,7 @@ class ViewerToolBar(QToolBar):
"actionZoomIn",
QKeySequence.ZoomIn,
QIcon.fromTheme("zoom-in")
if ISLINUX
and not self.parent.app.prefs.details_dialog_override_theme_icons
if ISLINUX and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "zoom_in")),
tr("Increase zoom"),
controller.zoomIn,
@@ -60,8 +68,7 @@ class ViewerToolBar(QToolBar):
"actionZoomOut",
QKeySequence.ZoomOut,
QIcon.fromTheme("zoom-out")
if ISLINUX
and not self.parent.app.prefs.details_dialog_override_theme_icons
if ISLINUX and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "zoom_out")),
tr("Decrease zoom"),
controller.zoomOut,
@@ -70,8 +77,7 @@ class ViewerToolBar(QToolBar):
"actionNormalSize",
tr("Ctrl+/"),
QIcon.fromTheme("zoom-original")
if ISLINUX
and not self.parent.app.prefs.details_dialog_override_theme_icons
if ISLINUX and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "zoom_original")),
tr("Normal size"),
controller.zoomNormalSize,
@@ -80,12 +86,11 @@ class ViewerToolBar(QToolBar):
"actionBestFit",
tr("Ctrl+*"),
QIcon.fromTheme("zoom-best-fit")
if ISLINUX
and not self.parent.app.prefs.details_dialog_override_theme_icons
if ISLINUX and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "zoom_best_fit")),
tr("Best fit"),
controller.zoomBestFit,
)
),
]
# TODO try with QWidgetAction() instead in order to have
# the popup menu work in the toolbar (if resized below minimum height)
@@ -95,13 +100,12 @@ class ViewerToolBar(QToolBar):
self.buttonImgSwap = QToolButton(self)
self.buttonImgSwap.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.buttonImgSwap.setIcon(
QIcon.fromTheme('view-refresh',
self.style().standardIcon(QStyle.SP_BrowserReload))
if ISLINUX
and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "exchange")))
self.buttonImgSwap.setText('Swap images')
self.buttonImgSwap.setToolTip('Swap images')
QIcon.fromTheme("view-refresh", self.style().standardIcon(QStyle.SP_BrowserReload))
if ISLINUX and not self.parent.app.prefs.details_dialog_override_theme_icons
else QIcon(QPixmap(":/" + "exchange"))
)
self.buttonImgSwap.setText("Swap images")
self.buttonImgSwap.setToolTip("Swap images")
self.buttonImgSwap.pressed.connect(self.controller.swapImages)
self.buttonImgSwap.released.connect(self.controller.swapImages)
@@ -207,11 +211,11 @@ class BaseController(QObject):
# than the ReferenceImageViewer by one pixel, which distorts the
# scaled down pixmap for the reference, hence we'll reuse its size here.
selected_size = self._updateImage(
self.selectedPixmap, self.scaledSelectedPixmap,
self.selectedViewer, None, same_group)
self.selectedPixmap, self.scaledSelectedPixmap, self.selectedViewer, None, same_group
)
self._updateImage(
self.referencePixmap, self.scaledReferencePixmap,
self.referenceViewer, selected_size, same_group)
self.referencePixmap, self.scaledReferencePixmap, self.referenceViewer, selected_size, same_group
)
if ignore_update:
self.selectedViewer.ignore_signal = False
@@ -229,12 +233,10 @@ class BaseController(QObject):
return target_size
# zoomed in state, expand
# only if not same_group, we need full update
scaledpixmap = pixmap.scaled(
target_size, Qt.KeepAspectRatioByExpanding, Qt.FastTransformation)
scaledpixmap = pixmap.scaled(target_size, Qt.KeepAspectRatioByExpanding, Qt.FastTransformation)
else:
# best fit, keep ratio always
scaledpixmap = pixmap.scaled(
target_size, Qt.KeepAspectRatio, Qt.FastTransformation)
scaledpixmap = pixmap.scaled(target_size, Qt.KeepAspectRatio, Qt.FastTransformation)
viewer.setImage(scaledpixmap)
return target_size
@@ -347,12 +349,8 @@ class BaseController(QObject):
self.selectedViewer.resetCenter()
self.referenceViewer.resetCenter()
target_size = self._updateImage(
self.selectedPixmap, self.scaledSelectedPixmap,
self.selectedViewer, None, True)
self._updateImage(
self.referencePixmap, self.scaledReferencePixmap,
self.referenceViewer, target_size, True)
target_size = self._updateImage(self.selectedPixmap, self.scaledSelectedPixmap, self.selectedViewer, None, True)
self._updateImage(self.referencePixmap, self.scaledReferencePixmap, self.referenceViewer, target_size, True)
self.centerViews()
self.parent.verticalToolBar.buttonZoomIn.setEnabled(False)
@@ -402,6 +400,7 @@ class BaseController(QObject):
class QWidgetController(BaseController):
"""Specialized version for QWidget-based viewers."""
def __init__(self, parent):
super().__init__(parent)
@@ -430,6 +429,7 @@ class QWidgetController(BaseController):
class ScrollAreaController(BaseController):
"""Specialized version fro QLabel-based viewers."""
def __init__(self, parent):
super().__init__(parent)
@@ -442,10 +442,8 @@ class ScrollAreaController(BaseController):
super().updateBothImages(same_group)
if not self.referenceViewer.isEnabled():
return
self.referenceViewer._horizontalScrollBar.setValue(
self.selectedViewer._horizontalScrollBar.value())
self.referenceViewer._verticalScrollBar.setValue(
self.selectedViewer._verticalScrollBar.value())
self.referenceViewer._horizontalScrollBar.setValue(self.selectedViewer._horizontalScrollBar.value())
self.referenceViewer._verticalScrollBar.setValue(self.selectedViewer._verticalScrollBar.value())
@pyqtSlot(QPoint)
def onDraggedMouse(self, delta):
@@ -518,6 +516,7 @@ class ScrollAreaController(BaseController):
class GraphicsViewController(BaseController):
"""Specialized version fro QGraphicsView-based viewers."""
def __init__(self, parent):
super().__init__(parent)
@@ -625,10 +624,8 @@ class GraphicsViewController(BaseController):
if ignore_update:
self.selectedViewer.ignore_signal = True
self._updateFitImage(
self.selectedPixmap, self.selectedViewer)
self._updateFitImage(
self.referencePixmap, self.referenceViewer)
self._updateFitImage(self.selectedPixmap, self.selectedViewer)
self._updateFitImage(self.referencePixmap, self.referenceViewer)
if ignore_update:
self.selectedViewer.ignore_signal = False
@@ -699,6 +696,7 @@ class GraphicsViewController(BaseController):
class QWidgetImageViewer(QWidget):
"""Use a QPixmap, but no scrollbars and no keyboard key sequence for navigation."""
# FIXME: panning while zoomed-in is broken (due to delta not interpolated right?
mouseDragged = pyqtSignal(QPointF)
mouseWheeled = pyqtSignal(float)
@@ -720,15 +718,13 @@ class QWidgetImageViewer(QWidget):
self.setMouseTracking(False)
def __repr__(self):
return f'{self._instance_name}'
return f"{self._instance_name}"
def connectMouseSignals(self):
if not self._dragConnection:
self._dragConnection = self.mouseDragged.connect(
self.controller.onDraggedMouse)
self._dragConnection = self.mouseDragged.connect(self.controller.onDraggedMouse)
if not self._wheelConnection:
self._wheelConnection = self.mouseWheeled.connect(
self.controller.scaleImagesBy)
self._wheelConnection = self.mouseWheeled.connect(self.controller.scaleImagesBy)
def disconnectMouseSignals(self):
if self._dragConnection:
@@ -746,7 +742,7 @@ class QWidgetImageViewer(QWidget):
painter.drawPixmap(self._rect.topLeft(), self._pixmap)
def resetCenter(self):
""" Resets origin """
"""Resets origin"""
# Make sure we are not still panning around
self._mousePanningDelta = QPointF()
self.update()
@@ -783,8 +779,7 @@ class QWidgetImageViewer(QWidget):
event.ignore()
return
self._mousePanningDelta += (
event.pos() - self._lastMouseClickPoint) * 1.0 / self.current_scale
self._mousePanningDelta += (event.pos() - self._lastMouseClickPoint) * 1.0 / self.current_scale
self._lastMouseClickPoint = event.pos()
if self._drag:
self.mouseDragged.emit(self._mousePanningDelta)
@@ -860,6 +855,7 @@ class QWidgetImageViewer(QWidget):
class ScalablePixmap(QWidget):
"""Container for a pixmap that scales up very fast, used in ScrollAreaImageViewer."""
def __init__(self, parent):
super().__init__(parent)
self._pixmap = QPixmap()
@@ -881,6 +877,7 @@ class ScalablePixmap(QWidget):
class ScrollAreaImageViewer(QScrollArea):
"""Implementation using a pixmap container in a simple scroll area."""
mouseDragged = pyqtSignal(QPoint)
mouseWheeled = pyqtSignal(float, QPointF)
@@ -921,7 +918,7 @@ class ScrollAreaImageViewer(QScrollArea):
self.setVisible(True)
def __repr__(self):
return f'{self._instance_name}'
return f"{self._instance_name}"
def toggleScrollBars(self, forceOn=False):
if not self.prefs.details_dialog_viewers_show_scrollbars:
@@ -938,11 +935,9 @@ class ScrollAreaImageViewer(QScrollArea):
def connectMouseSignals(self):
if not self._dragConnection:
self._dragConnection = self.mouseDragged.connect(
self.controller.onDraggedMouse)
self._dragConnection = self.mouseDragged.connect(self.controller.onDraggedMouse)
if not self._wheelConnection:
self._wheelConnection = self.mouseWheeled.connect(
self.controller.onMouseWheel)
self._wheelConnection = self.mouseWheeled.connect(self.controller.onMouseWheel)
def disconnectMouseSignals(self):
if self._dragConnection:
@@ -955,10 +950,8 @@ class ScrollAreaImageViewer(QScrollArea):
def connectScrollBars(self):
"""Only call once controller is connected."""
# Cyclic connections are handled by Qt
self._verticalScrollBar.valueChanged.connect(
self.controller.onVScrollBarChanged, Qt.UniqueConnection)
self._horizontalScrollBar.valueChanged.connect(
self.controller.onHScrollBarChanged, Qt.UniqueConnection)
self._verticalScrollBar.valueChanged.connect(self.controller.onVScrollBarChanged, Qt.UniqueConnection)
self._horizontalScrollBar.valueChanged.connect(self.controller.onHScrollBarChanged, Qt.UniqueConnection)
def contextMenuEvent(self, event):
"""Block parent's (main window) context menu on right click."""
@@ -987,7 +980,7 @@ class ScrollAreaImageViewer(QScrollArea):
event.ignore()
return
if self._drag:
delta = (event.pos() - self._lastMouseClickPoint)
delta = event.pos() - self._lastMouseClickPoint
self._lastMouseClickPoint = event.pos()
self.mouseDragged.emit(delta)
super().mouseMoveEvent(event)
@@ -1064,35 +1057,29 @@ class ScrollAreaImageViewer(QScrollArea):
"""After scaling, no mouse position, default to center."""
# scrollBar.setMaximum(scrollBar.maximum() - scrollBar.minimum() + scrollBar.pageStep())
self._horizontalScrollBar.setValue(
int(factor * self._horizontalScrollBar.value()
+ ((factor - 1) * self._horizontalScrollBar.pageStep() / 2)))
int(factor * self._horizontalScrollBar.value() + ((factor - 1) * self._horizontalScrollBar.pageStep() / 2))
)
self._verticalScrollBar.setValue(
int(factor * self._verticalScrollBar.value()
+ ((factor - 1) * self._verticalScrollBar.pageStep() / 2)))
int(factor * self._verticalScrollBar.value() + ((factor - 1) * self._verticalScrollBar.pageStep() / 2))
)
def adjustScrollBarsScaled(self, delta):
"""After scaling with the mouse, update relative to mouse position."""
self._horizontalScrollBar.setValue(
self._horizontalScrollBar.value() + delta.x())
self._verticalScrollBar.setValue(
self._verticalScrollBar.value() + delta.y())
self._horizontalScrollBar.setValue(self._horizontalScrollBar.value() + delta.x())
self._verticalScrollBar.setValue(self._verticalScrollBar.value() + delta.y())
def adjustScrollBarsAuto(self):
"""After panning, update accordingly."""
self.horizontalScrollBar().setValue(
self.horizontalScrollBar().value() - self._mousePanningDelta.x())
self.verticalScrollBar().setValue(
self.verticalScrollBar().value() - self._mousePanningDelta.y())
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - self._mousePanningDelta.x())
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - self._mousePanningDelta.y())
def adjustScrollBarCentered(self):
"""Just center in the middle."""
self._horizontalScrollBar.setValue(
int(self._horizontalScrollBar.maximum() / 2))
self._verticalScrollBar.setValue(
int(self._verticalScrollBar.maximum() / 2))
self._horizontalScrollBar.setValue(int(self._horizontalScrollBar.maximum() / 2))
self._verticalScrollBar.setValue(int(self._verticalScrollBar.maximum() / 2))
def resetCenter(self):
""" Resets origin """
"""Resets origin"""
self._mousePanningDelta = QPoint()
self.current_scale = 1.0
# self.scaleAt(1.0)
@@ -1127,6 +1114,7 @@ class ScrollAreaImageViewer(QScrollArea):
class GraphicsViewViewer(QGraphicsView):
"""Re-Implementation a full-fledged GraphicsView but is a bit buggy."""
mouseDragged = pyqtSignal()
mouseWheeled = pyqtSignal(float, QPointF)
@@ -1178,11 +1166,9 @@ class GraphicsViewViewer(QGraphicsView):
def connectMouseSignals(self):
if not self._dragConnection:
self._dragConnection = self.mouseDragged.connect(
self.controller.syncCenters)
self._dragConnection = self.mouseDragged.connect(self.controller.syncCenters)
if not self._wheelConnection:
self._wheelConnection = self.mouseWheeled.connect(
self.controller.onMouseWheel)
self._wheelConnection = self.mouseWheeled.connect(self.controller.onMouseWheel)
def disconnectMouseSignals(self):
if self._dragConnection:
@@ -1195,10 +1181,8 @@ class GraphicsViewViewer(QGraphicsView):
def connectScrollBars(self):
"""Only call once controller is connected."""
# Cyclic connections are handled by Qt
self._verticalScrollBar.valueChanged.connect(
self.controller.onVScrollBarChanged, Qt.UniqueConnection)
self._horizontalScrollBar.valueChanged.connect(
self.controller.onHScrollBarChanged, Qt.UniqueConnection)
self._verticalScrollBar.valueChanged.connect(self.controller.onVScrollBarChanged, Qt.UniqueConnection)
self._horizontalScrollBar.valueChanged.connect(self.controller.onHScrollBarChanged, Qt.UniqueConnection)
def toggleScrollBars(self, forceOn=False):
if not self.prefs.details_dialog_viewers_show_scrollbars:
@@ -1298,7 +1282,7 @@ class GraphicsViewViewer(QGraphicsView):
self.centerOn(self._centerPoint)
def resetCenter(self):
""" Resets origin """
"""Resets origin"""
self._mousePanningDelta = QPointF()
self.current_scale = 1.0
@@ -1345,10 +1329,8 @@ class GraphicsViewViewer(QGraphicsView):
def adjustScrollBarsScaled(self, delta):
"""After scaling with the mouse, update relative to mouse position."""
self._horizontalScrollBar.setValue(
self._horizontalScrollBar.value() + delta.x())
self._verticalScrollBar.setValue(
self._verticalScrollBar.value() + delta.y())
self._horizontalScrollBar.setValue(self._horizontalScrollBar.value() + delta.x())
self._verticalScrollBar.setValue(self._verticalScrollBar.value() + delta.y())
def sizeHint(self):
return self.viewport().rect().size()
@@ -1356,15 +1338,13 @@ class GraphicsViewViewer(QGraphicsView):
def adjustScrollBarsFactor(self, factor):
"""After scaling, no mouse position, default to center."""
self._horizontalScrollBar.setValue(
int(factor * self._horizontalScrollBar.value()
+ ((factor - 1) * self._horizontalScrollBar.pageStep() / 2)))
int(factor * self._horizontalScrollBar.value() + ((factor - 1) * self._horizontalScrollBar.pageStep() / 2))
)
self._verticalScrollBar.setValue(
int(factor * self._verticalScrollBar.value()
+ ((factor - 1) * self._verticalScrollBar.pageStep() / 2)))
int(factor * self._verticalScrollBar.value() + ((factor - 1) * self._verticalScrollBar.pageStep() / 2))
)
def adjustScrollBarsAuto(self):
"""After panning, update accordingly."""
self.horizontalScrollBar().setValue(
self.horizontalScrollBar().value() - self._mousePanningDelta.x())
self.verticalScrollBar().setValue(
self.verticalScrollBar().value() - self._mousePanningDelta.y())
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - self._mousePanningDelta.x())
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - self._mousePanningDelta.y())