The util module

Small utilities and simple base classes for the qpageview module.

class Rectangular[source]

Bases: object

Defines a Qt-inspired and -based interface for rectangular objects.

The attributes x, y, width and height default to 0 at the class level and can be set and read directly.

For convenience, Qt-styled methods are available to access and modify these attributes.

x = 0
y = 0
width = 0
height = 0
setPos(point)[source]

Set the x and y coordinates from the given QPoint point.

pos()[source]

Return our x and y coordinates as a QPoint(x, y).

setSize(size)[source]

Set the height and width attributes from the given QSize size.

size()[source]

Return the height and width attributes as a QSize(width, height).

setGeometry(rect)[source]

Set our x, y, width and height directly from the given QRect.

geometry()[source]

Return our x, y, width and height as a QRect.

rect()[source]

Return QRect(0, 0, width, height).

class MapToPage(transform)[source]

Bases: object

Simple class wrapping a QTransform to map rect and point to page coordinates.

rect(rect)[source]

Convert QRect or QRectF to a QRect in page coordinates.

point(point)[source]

Convert QPointF or QPoint to a QPoint in page coordinates.

class MapFromPage(transform)[source]

Bases: MapToPage

Simple class wrapping a QTransform to map rect and point from page to original coordinates.

rect(rect)[source]

Convert QRect or QRectF to a QRectF in original coordinates.

point(point)[source]

Convert QPointF or QPoint to a QPointF in original coordinates.

class LongMousePressMixin(*args, **kwargs)[source]

Bases: object

Mixin class to add support for long mouse press to a QWidget.

To handle a long mouse press event, implement longMousePressEvent().

longMousePressEnabled = True

Whether to enable handling of long mouse presses; set to False to disable

longMousePressTolerance = 3

Allow moving some pixels before a long mouse press is considered a drag

longMousePressTime = 800

How long to presse a mouse button (in msec) for a long press

longMousePressEvent(ev)[source]

Implement this to handle a long mouse press event.

timerEvent(ev)[source]

Implemented to check for a long mouse button press.

mousePressEvent(ev)[source]

Reimplemented to check for a long mouse button press.

mouseMoveEvent(ev)[source]

Reimplemented to check for moves during a long press.

mouseReleaseEvent(ev)[source]

Reimplemented to cancel a long press.

class Point(x, y)[source]

Bases: QPoint

An overflow-safe QPoint.

This works around an oversight in PyQt, which does not constrain integer arguments to fixed sizes as used in C++, causing an OverflowError when those limits are exceeded.

setX(self, xpos: int)[source]
setY(self, ypos: int)[source]
rotate(matrix, rotation, width, height, dest=False)[source]

Rotate matrix inside a rectangular area of width x height.

The matrix can be a either a QPainter or a QTransform. The rotation is 0, 1, 2 or 3, etc. (Rotate_0, Rotate_90, etc…). If dest is True, width and height refer to the destination, otherwise to the source.

align(w, h, ow, oh, alignment=<AlignmentFlag.AlignCenter: 132>)[source]

Return (x, y) to align a rect w x h in an outer rectangle ow x oh.

The alignment can be a combination of Qt.AlignmentFlag values. If w > ow, x = -1; and if h > oh, y = -1.

alignrect(rect, point, alignment=<AlignmentFlag.AlignCenter: 132>)[source]

Align rect with point according to the alignment.

The alignment can be a combination of Qt.AlignmentFlag values.

clamp(x, lower, upper)[source]

Return x bounded such that lower <= x <= upper.

clamp_int32(x)[source]

Return x bounded to the range of a 32-bit signed integer.

sign(x)[source]

Return the sign of x: -1 if x < 0, 0 if x == 0, or 1 if x > 0.

signalsBlocked(*objs)[source]

Block the pyqtSignals of the given QObjects during the context.

autoCropRect(image)[source]

Return a QRect specifying the contents of the QImage.

Edges of the image are trimmed if they have the same color.

oversampleFactor(key, pageSize)[source]

Return the optimal scale factor for oversampling.

Oversampling (rendering the image at higher resolution, then downscaling) can help with readability at lower pixel densities.

The pageSize argument specifies the page dimensions in points as returned by page.pageSize().

If this returns 1, render the image directly at your desired size. Otherwise, multiply the page dimensions by the returned value before rendering, then downscale to your desired size.

tempdir()[source]

Return a temporary directory that is erased on app quit.