<commit_before># -*- coding: utf-8 -*- 

import wx
import wx.dataview as dv
import wx.lib.newevent
import logging
import thread
import time
import random
from os import path
from os.path import expanduser
from wx.lib.wordwrap import wordwrap
from watchdog.observers import Observer
# from watchdog.events import LoggingEventHandler
from watchdog.events import FileSystemEventHandler


__author__ = "<NAME>"
__application__ = "The Watcher"
__version__ = "1.0 (Beta)"

IS_OSX = wx.Platform == "__WXMAC__"
IS_WIN = wx.Platform == "__WXMSW__"

# This creates a new Event class and a EVT binder function
(UpdateLogEvent, EVT_UPDATE_LOG) = wx.lib.newevent.NewEvent()


class LogEventHandler(FileSystemEventHandler):
    def __init__(self, win):
        self.win = win

    def on_created(self, event):
        super(LogEventHandler, self).on_created(event)

        what= 'Directory' if event.is_directory else 'File'
        msg = UpdateLogEvent(logmsg="%s ... created %s" % (what, event.src_path))
        wx.PostEvent(self.win, msg)


################################################################################
## Class Watcher
################################################################################

class Watcher:
    def __init__(self, win, watchpath):
        self.win = win
        self.path = watchpath
        self.event_handler = LogEventHandler(self.win)
        self.observer = Observer()
        self.observer.schedule(self.event_handler, self.path, recursive=True)
        # print "Watcher created ", self.win, self.path


    def Start(self):
        self.keepGoing = self.running = True
        thread.start_new_thread(self.observer.start, ())
        # self.observer.start()
        print "Thread Started..."


    def Stop(self):
        self.keepGoing = False
        self.running = False
<commit_msg>Updated watchdog custom event Handler<commit_after># -*- coding: utf-8 -*- 

import wx
import wx.dataview as dv
import wx.lib.newevent
import logging
import thread
import time
import random
from os import path
from os.path import expanduser
from wx.lib.wordwrap import wordwrap
from watchdog.observers import Observer
# from watchdog.events import LoggingEventHandler
# from watchdog.events import FileSystemEventHandler
from watchdog.events import PatternMatchingEventHandler

__author__ = "<NAME>"
__application__ = "The Watcher"
__version__ = "1.0 (Beta)"

IS_OSX = wx.Platform == "__WXMAC__"
IS_WIN = wx.Platform == "__WXMSW__"

# This creates a new Event class and a EVT binder function
(UpdateLogEvent, EVT_UPDATE_LOG) = wx.lib.newevent.NewEvent()


class wxLogEventHandler(PatternMatchingEventHandler):
    def __init__(self, win, patterns=None, ignore_patterns=None, 
                 ignore_directories=False, case_sensitive=False,
                 create=True, modify=True, delete=False, rename=False):
        self._case_sensitive = case_sensitive
        self._ignore_patterns = ignore_patterns
        self._patterns = patterns
        self._ignore_directories = ignore_directories
        self.win = win
        self.evt_onCreated = create
        self.evt_onModified = modify
        self.evt_onDeleted = delete
        self.evt_onRenamed = rename

    def process(self, event):
        # print event.src_path, ">", event.event_type, type(event)
        what = 'Directory' if event.is_directory else 'File'
        msg=None
        if event.event_type == 'created' and self.evt_onCreated:
            # print what, "Created! |", event.src_path
            msg = UpdateLogEvent(logmsg="Created! | %s" % event.src_path)
        elif event.event_type == 'modified' and self.evt_onModified:
            # print what, "Modified! |", event.src_path
            msg = UpdateLogEvent(logmsg="Modified! | %s" % event.src_path)
        elif event.event_type == 'deleted' and self.evt_onDeleted:
            # print what, "Deleted! |", event.src_path
            msg = UpdateLogEvent(logmsg="Deleted! | %s" % event.src_path)
        elif event.event_type == 'moved' and self.evt_onRenamed:
            # print what, "Moved! |", event.src_path, event.dest_path
            msg = UpdateLogEvent(logmsg="Moved! | %s to %s" % 
                                 (event.src_path, event.dest_path))
        if msg != None:
            wx.PostEvent(self.win, msg)

    def on_moved(self, event):
        self.process(event)

    def on_created(self, event):
        self.process(event)

    def on_deleted(self, event):
        self.process(event)

    def on_modified(self, event):
        self.process(event)


################################################################################
## Class Watcher
################################################################################

class Watcher:
    def __init__(self, win, watchpath, patterns=None, ignore_patterns=None, 
                 ignore_directories=False, case_sensitive=False,
                 create=True, modify=True, delete=False, rename=False):
        self.win = win
        self.path = watchpath
        self.event_handler = wxLogEventHandler(self.win, patterns, 
                                ignore_patterns, ignore_directories, 
                                case_sensitive, create, modify, delete, rename)
        self.observer = Observer()
        self.observer.schedule(self.event_handler, self.path, recursive=True)
        # print "Watcher created ", self.win, self.path


    def Start(self):
        self.keepGoing = self.running = True
        thread.start_new_thread(self.observer.start, ())
        # self.observer.start()
        print "Thread Started..."


    def Stop(self):
        self.keepGoing = False
        self.running = False

{'fraction_non_alphanumeric': 0.15126347411203392, 'fraction_numerical': 0.0010602579961123874, 'mean_word_length': 3.063173007896626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6089294', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1597, 'n_words': 394}