Skip to main content

PyQt/PySide interface to handle logging data to file particularly well suited for multithreaded programs.

Project description

https://img.shields.io/pypi/v/dvg-pyqt-filelogger https://img.shields.io/pypi/pyversions/dvg-pyqt-filelogger https://github.com/Dennis-van-Gils/python-dvg-pyqt-filelogger/actions/workflows/python-package.yml/badge.svg https://coveralls.io/repos/github/Dennis-van-Gils/python-dvg-pyqt-filelogger/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/License-MIT-purple.svg

DvG_PyQt_FileLogger

Provides a PyQt interface to handle logging data to a file particularly well suited for multithreaded programs.

Supports PyQt5, PyQt6, PySide2 and PySide6.

Installation:

pip install dvg-pyqt-filelogger

Example usage

The following are snippets of code, not a full program.

from qtpy import QtWidgets as QtWid
from dvg_pyqt_filelogger import FileLogger

# Main/GUI thread
# ---------------

class MainWindow(QtWid.QWidget):
    def __init__(
        self,
        log: FileLogger,
        parent=None,
        **kwargs
    ):
        super().__init__(parent, **kwargs)

        # Create a record button
        self.record_button = QtWid.QPushButton("Click to start recording to file")
        self.record_button.setCheckable(True)
        self.record_button.clicked.connect(lambda state: log.record(state))

class YourDataGeneratingDevice:
    reading_1 = 0.0

device = YourDataGeneratingDevice()

def write_header_to_log():
    log.write("elapsed [s]\treading_1\n")

def write_data_to_log():
    log.write(f"{log.elapsed():.3f}\t{device.reading_1:.4f}\n")

log = FileLogger(
    write_header_function=write_header_to_log,
    write_data_function=write_data_to_log
)

log.signal_recording_started.connect(
    lambda filepath: window.record_button.setText(
        f"Recording to file: {filepath}"
    )
)
log.signal_recording_stopped.connect(
    lambda: window.record_button.setText(
        "Click to start recording to file"
    )
)

window = MainWindow(log)

# Data acquisition and/or logging thread
# --------------------------------------

# New data got acquired
device.reading_1 = 20.3

# Must be called whenever new data has become available
log.update()

API

Class FileLogger

FileLogger(
    write_header_function: Callable | None = None,
    write_data_function: Callable | None = None,
    encoding: str = "utf-8",
)

Changelog

1.4.0 (2024-06-24)

  • Using qtpy library instead of my own Qt5/6 mechanism

  • Support for Numpy 2.0

  • Extended API and docstrings

  • Added argument encoding, defaulting to “utf-8”

  • Added type hints

  • Added method get_filepath()

1.3.0 (2023-02-27)

  • Raise ImportError instead of general Exception

1.2.0 (2022-09-13)

  • Added support for PyQt5, PyQt6, PySide2 and PySide6

1.1.0 (2021-05-13)

  • Added support for numpy.savetxt()

1.0.0 (2020-08-11)

  • First release on PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dvg_pyqt_filelogger-1.4.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

dvg_pyqt_filelogger-1.4.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file dvg_pyqt_filelogger-1.4.0.tar.gz.

File metadata

  • Download URL: dvg_pyqt_filelogger-1.4.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for dvg_pyqt_filelogger-1.4.0.tar.gz
Algorithm Hash digest
SHA256 5245742f95ce9a571584fe2d5f046993e9553ccb9067de2d6752d3579d6f3f3d
MD5 eb7a89382ceccd586128928ccfe899a7
BLAKE2b-256 0a625c892c03d0606040b46628b12b4b5ea1f77443f1ef0640f8e5dc09a961ab

See more details on using hashes here.

File details

Details for the file dvg_pyqt_filelogger-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dvg_pyqt_filelogger-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fac1d8cc9b79668c9a5dddb8e50f26dfffb270d38aef8138652c18d4bc50326
MD5 d696139af0578ce21407fdad490e6bfe
BLAKE2b-256 25cee47b5801ac516a5b4743f22f01b0831b847627cf0fa200c1f6ba87da7322

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page