Metadata-Version: 2.1
Name: data-watcher-tray
Version: 0.0.1
Summary: System tray app and task runner used for watching files
Home-page: https://github.com/techstormpc/data-watcher-tray
Author: TechStorm PC
Author-email: nathan@techstormpc.com
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Description-Content-Type: text/markdown
Requires-Dist: PyQt6 (==6.3.1)

# 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](https://pypi.org/project/watchdog/))
- 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.

```python
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())
```

