Skip to main content
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

Metadata

Release files for dvg-pyqt-filelogger 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dvg-pyqt-filelogger 1.4.0
File Size Uploaded
dvg_pyqt_filelogger-1.4.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dvg-pyqt-filelogger 1.4.0
File Interpreter ABI Platform
dvg_pyqt_filelogger-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / dvg_pyqt_filelogger-1.4.0.tar.gz

Download URL dvg_pyqt_filelogger-1.4.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5245742f95ce9a571584fe2d5f046993e9553ccb9067de2d6752d3579d6f3f3d
BLAKE2b-256 checksum
How to use checksums
0a625c892c03d0606040b46628b12b4b5ea1f77443f1ef0640f8e5dc09a961ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / dvg_pyqt_filelogger-1.4.0-py3-none-any.whl

Download URL dvg_pyqt_filelogger-1.4.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fac1d8cc9b79668c9a5dddb8e50f26dfffb270d38aef8138652c18d4bc50326
BLAKE2b-256 checksum
How to use checksums
25cee47b5801ac516a5b4743f22f01b0831b847627cf0fa200c1f6ba87da7322
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page