Skip to main content

Data Watcher

The Data Watcher class is a PyQt system tray application with three main components:

  • Ability to specify a background task to run (i.e. watchdog observer)
  • Ability to manually upload a file using the context menu of the tray icon.
  • Logging display

Example Usage

Using the watchdog library combined with the FileUploadDialog class, you can create a program that watches a directory for new files and runs any tasks in the parse_file function.

You can use the pyinstaller library to create a frozen exe to distribute.

import logging
import sys
from pathlib import Path

from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer

from data_watcher import DataWatcher, FileUploadDialog

logger = logging.getLogger()
icon_path = Path("icon.png").absolute()
app_name = "Data Logger"


# Main parsing method
def parse_file(path: Path):
    logger.info(path)


class CreatedHandler(FileSystemEventHandler):
    def on_created(self, event):
        if not event.is_directory and ".txt" in event.src_path:
            parse_file(event.src_path)


def init_watcher():
    event_handler = CreatedHandler()
    observer = Observer()
    try:
        observer.schedule(event_handler, path=str(Path.cwd()), recursive=False)
        observer.start()
    except FileNotFoundError:
        logging.error('Directory not found')
    logging.info('Watcher Started')

    return observer


def upload_file():
    FileUploadDialog(
        app_name=app_name,
        on_select=parse_file,
        allowed_files_filter='Text Files (*.txt);;All Files (*)'
    )


app = DataWatcher(
    app_name=app_name,
    icon_path=icon_path,
    background_task=init_watcher,
    upload_callback=upload_file
)

sys.exit(app.start())

Metadata

Release files for data-watcher-tray 0.0.1

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

Built distribution (wheel)

Table of built distributions (wheels) for data-watcher-tray 0.0.1
File Interpreter ABI Platform
data_watcher_tray-0.0.1-py3-none-any.whl Python 3 none any Details

Release files / data_watcher_tray-0.0.1-py3-none-any.whl

Download URL data_watcher_tray-0.0.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
525b00545a81b9cb92fc4fad805454223eeb75f56e196ebd92547faba721e0a6
BLAKE2b-256 checksum
How to use checksums
50f147217e7cb74ff507992220c69fbee4b215ffbcaf9a61c1b818ecd5fbd845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

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