This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An experiment to fix PyQt QObject.tr context override | |
https://www.riverbankcomputing.com/static/Docs/PyQt5/i18n.html#differences-between-pyqt5-and-qt | |
.. note:: | |
Known deficiencies: | |
* No support for @property, @pyQtSlot, etc. decorators |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import singledispatch | |
def singledispatch_next(f): | |
""" | |
Decorate a `singledispatch` function f with a `next` method. | |
`f.next(__class__)` dispatches to the 'base' or next implementation in | |
the __class__'s mro chain. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Read the IDX file format as described by http://yann.lecun.com/exdb/mnist/ | |
""" | |
import os | |
import io | |
import struct | |
import mmap | |
from functools import reduce | |
from typing import IO, Tuple, Union |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import overload, Union, Type, TypeVar, Any | |
from functools import lru_cache | |
from PyQt5.QtCore import QObject, pyqtProperty as Property | |
@lru_cache(maxsize=200) | |
def _converter(type_: Union[type, str]): | |
class Obj(QObject): | |
__slots__ = ("field",) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtCore import QObject, pyqtProperty | |
class Q_Property(pyqtProperty): | |
""" | |
A descriptor that more closely resembles the Q_PROPERTY macro. | |
Encourage a coding style which is consistent with Qt. | |
Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
DataType | |
-------- | |
A NamedTuple like class except it also defines strict type dependent | |
__eq__, __ne__ and __hash__. This ensures that instances can be compared, | |
hashed in dict, sets, ... I.e. | |
Example | |
------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable | |
from PyQt5.QtWidgets import QListView, QLineEdit | |
from PyQt5.QtGui import QResizeEvent | |
from PyQt5.QtCore import ( | |
Qt, QAbstractItemModel, QModelIndex, QSortFilterProxyModel, QItemSelection | |
) | |
class FilterListView(QListView): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from types import SimpleNamespace | |
from threading import Event | |
from concurrent.futures.thread import ThreadPoolExecutor | |
from PyQt5.QtCore import ( | |
Qt, QObject, QCoreApplication, QTimer, QEventLoop, pyqtSignal | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
from PyQt5.QtCore import Qt, QPointF, QRectF | |
from PyQt5.QtGui import QStaticText, QFont, QPalette, QPainter, QTransform | |
from PyQt5.QtWidgets import QGraphicsObject, QWidget, QStyleOptionGraphicsItem | |
class StaticTextItem(QGraphicsObject): | |
""" | |
A text graphics object for displaying text in a QGraphicsScene. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
#include <assert.h> | |
int mod(int a, int b) { | |
int res; | |
if (b < 0) { | |
// because -INT_MIN == INT_MIN | |
if (b > INT_MIN) { | |
return -mod(-a, -b); |
NewerOlder