System tray app and task runner used for watching files
Project description
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())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file data_watcher_tray-0.0.1-py3-none-any.whl.
File metadata
- Download URL: data_watcher_tray-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
525b00545a81b9cb92fc4fad805454223eeb75f56e196ebd92547faba721e0a6
|
|
| MD5 |
e2a12dba4d2af098dbbaf2a9a6a354a9
|
|
| BLAKE2b-256 |
50f147217e7cb74ff507992220c69fbee4b215ffbcaf9a61c1b818ecd5fbd845
|