Skip to content

Instantly share code, notes, and snippets.

"""
Utilities for building concurrent PyQt5 applications.
"""
from __future__ import absolute_import
import threading
import weakref
import logging
import warnings
@ales-erjavec
ales-erjavec / python-framework-reloc.sh
Last active June 23, 2023 08:56
Fetch, extract and layout a macOS relocatable Python framework
#!/usr/bin/env bash
usage() {
echo "$0 [ --version VERSION ] FRAMEWORKPATH
Fetch, extract and layout a macOS relocatable Python framework at FRAMEWORKPATH
Options:
--version VERSION Python version (default ${VERSION})
--macos MACOSVER Minimum supported macOS version (as of 3.6.5 and
@ales-erjavec
ales-erjavec / qcheckcombobox.py
Last active June 20, 2023 09:45
A QComboBox supporting multiple item selection
"""
Check Combo Box
---------------
A QComboBox subclass designed for multiple item selection.
The combo box popup allows the user to check/uncheck multiple items at
once.
"""
"""
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
@ales-erjavec
ales-erjavec / numpy_openblas_config.py
Last active December 31, 2021 08:46
Inspect/config numpy-linked OpenBLAS
"""
Inspect/config numpy-linked OpenBLAS
"""
import re
import ctypes
import numpy.core
"""
Utilities for inspecting/modifying widget geometry state as returned/set by
`QWidget.saveGeometry` and `QWidget.restoreGeometry`
"""
import struct
from collections import namedtuple
#: Parsed geometry state (version 1; Qt < 5.4)
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.
"""
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
@ales-erjavec
ales-erjavec / qvariant_cast.py
Last active March 10, 2021 13:52
qvariant_cast "like" in PyQt5/PySide2
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",)
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: