<commit_before>#!/usr/bin/env python

from tkinter import font, ttk, filedialog
import tkinter as tk
from appdirs import AppDirs
import configparser
import os
import time
import logging
from fsevents import Observer, Stream
from dirsync import sync

DEBUG=True
def debug(*args):
    if DEBUG:
        print(args)


class AppConfig():

    def __init__(self):
        self.dirs = None
        self.app_title = ''
        self.config = None

    def config_setup(self, app_title):
        self.dirs = AppDirs(app_title, "Author")
        if not os.path.exists(self.dirs.user_config_dir):
            os.makedirs(self.dirs.user_config_dir)
        if not os.path.exists(self.dirs.user_log_dir):
            os.makedirs(self.dirs.user_log_dir)
        self.app_title = app_title
        self.read_config()
        self.configure_gui()

    def get_config_path(self):
        return os.path.join(
            self.dirs.user_config_dir,
            '{}.conf'.format(self.app_title)
        )

    def get_default_config(self):
        return {'section': {'key': 'value'}}

    def read_config(self):
        self.config = configparser.ConfigParser()
        self.config.read(
            self.get_config_path()
        )
        dc = self.get_default_config()
        anychange = False
        for section, default_values  in dc.items():
            if section not in self.config.sections():
                self.config[section] = default_values
                anychange = True
        if anychange:
            self.write_config()

    def write_config(self):
        with open(
                self.get_config_path(), 'w'
        ) as cf:
            self.config.write(cf)

    def purge_config(self):
        os.unlink(self.get_config_path())

    def configure_gui(self):
        pass

class Application(tk.Frame, AppConfig):

    def __init__(self, master=None):
        super().__init__()
        tk.Frame.__init__(self, master)
        top = self.winfo_toplevel()
        top.protocol("WM_DELETE_WINDOW", self.stop_observer)
        top.createcommand("tk::mac::Quit", self.stop_observer)
        self.menuBar = tk.Menu(top)
        top['menu'] = self.menuBar
        self.grid(padx=12, pady=12)
        self.wfs_dir = tk.StringVar()
        self.sfs_dir = tk.StringVar()
        self.active = tk.IntVar()
        self.progress = tk.IntVar()
        self.action = tk.StringVar()
        self.action.set('No activity')
        self.action_id = None
        self.activate_id = None
        self.ticker_id = None
        self.observer = None
        self.stream = None
        self.app_icon = None
        self.app_icons = [
            tk.PhotoImage(file='icon/icon_{}.gif'.format(n))
            for n in range(1,5)
        ]
        self.create_widgets()

    def get_default_config(self):
        return {
            'state': {
                'wfs_dir': '',
                'sfs_dir': '',
                'active': False,
            }
        }

    def configure_gui(self):
        self.wfs_dir.set(self.config['state']['wfs_dir'])
        self.sfs_dir.set(self.config['state']['sfs_dir'])
        self.active.set(int(self.config.getboolean('state', 'active')))
        self.toggle_activate()

    def tick_app_icon(self):
        debug('tick', self.app_icons)
        self.app_icons.insert(0, self.app_icons.pop())
        self.app_icon.configure(image=self.app_icons[0])

    def ticking(self):
        self.tick_app_icon()
        self.ticker_id = self.after(100, self.ticking)

    def stop_ticking(self):
        self.after_cancel(self.ticker_id)
        self.ticker_id = None

    def create_widgets(self):
        headfont = font.Font(family="Avenir Next", size=54)
        messagefont = font.Font(family="Avenir Next", size=18)
        labelfont = font.Font(family="Avenir Next", size=18, weight='bold')
        helpfont = font.Font(family="Avenir Next", size=12)
        rowcursor = 1
        self.app_icon = tk.Label(
            self,
            image=self.app_icons[0],
        )
        self.app_icon.grid(
            row=rowcursor,
            column=0,
            sticky=tk.E,
        )
        heading = tk.Label(
            self,
            text="EasySync",<commit_msg>Prevent endless ticking<commit_after>#!/usr/bin/env python

from tkinter import font, ttk, filedialog
import tkinter as tk
from appdirs import AppDirs
import configparser
import os
import time
import logging
from fsevents import Observer, Stream
from dirsync import sync

DEBUG=True
def debug(*args):
    if DEBUG:
        print(args)


class AppConfig():

    def __init__(self):
        self.dirs = None
        self.app_title = ''
        self.config = None

    def config_setup(self, app_title):
        self.dirs = AppDirs(app_title, "Author")
        if not os.path.exists(self.dirs.user_config_dir):
            os.makedirs(self.dirs.user_config_dir)
        if not os.path.exists(self.dirs.user_log_dir):
            os.makedirs(self.dirs.user_log_dir)
        self.app_title = app_title
        self.read_config()
        self.configure_gui()

    def get_config_path(self):
        return os.path.join(
            self.dirs.user_config_dir,
            '{}.conf'.format(self.app_title)
        )

    def get_default_config(self):
        return {'section': {'key': 'value'}}

    def read_config(self):
        self.config = configparser.ConfigParser()
        self.config.read(
            self.get_config_path()
        )
        dc = self.get_default_config()
        anychange = False
        for section, default_values  in dc.items():
            if section not in self.config.sections():
                self.config[section] = default_values
                anychange = True
        if anychange:
            self.write_config()

    def write_config(self):
        with open(
                self.get_config_path(), 'w'
        ) as cf:
            self.config.write(cf)

    def purge_config(self):
        os.unlink(self.get_config_path())

    def configure_gui(self):
        pass

class Application(tk.Frame, AppConfig):

    def __init__(self, master=None):
        super().__init__()
        tk.Frame.__init__(self, master)
        top = self.winfo_toplevel()
        top.protocol("WM_DELETE_WINDOW", self.stop_observer)
        top.createcommand("tk::mac::Quit", self.stop_observer)
        self.menuBar = tk.Menu(top)
        top['menu'] = self.menuBar
        self.grid(padx=12, pady=12)
        self.wfs_dir = tk.StringVar()
        self.sfs_dir = tk.StringVar()
        self.active = tk.IntVar()
        self.progress = tk.IntVar()
        self.action = tk.StringVar()
        self.action.set('No activity')
        self.action_id = None
        self.activate_id = None
        self.ticker_id = None
        self.observer = None
        self.stream = None
        self.app_icon = None
        self.app_icons = [
            tk.PhotoImage(file='icon/icon_{}.gif'.format(n))
            for n in range(1,5)
        ]
        self.create_widgets()

    def get_default_config(self):
        return {
            'state': {
                'wfs_dir': '',
                'sfs_dir': '',
                'active': False,
            }
        }

    def configure_gui(self):
        self.wfs_dir.set(self.config['state']['wfs_dir'])
        self.sfs_dir.set(self.config['state']['sfs_dir'])
        self.active.set(int(self.config.getboolean('state', 'active')))
        self.toggle_activate()

    def tick_app_icon(self):
        debug('tick', self.app_icons)
        self.app_icons.insert(0, self.app_icons.pop())
        self.app_icon.configure(image=self.app_icons[0])

    def ticking(self):
        # prevent ticking loops if it is triggered multiple times in succession
        self.stop_ticking()
        self.tick_app_icon()
        self.ticker_id = self.after(100, self.ticking)

    def stop_ticking(self):
        if self.ticker_id is not None:
            self.after_cancel(self.ticker_id)
            self.ticker_id = None

    def create_widgets(self):
        headfont = font.Font(family="Avenir Next", size=54)
        messagefont = font.Font(family="Avenir Next", size=18)
        labelfont = font.Font(family="Avenir Next", size=18, weight='bold')
        helpfont = font.Font(family="Avenir Next", size=12)
        rowcursor = 1
        self.app_icon = tk.Label(
            self,
            image=self.app_icons[0],
        )
        self.app_icon.grid(
            row=rowcursor,
            column=0,
            sticky=tk.E,
        )
        heading = tk.Label(
            self,
            text="EasySync",
{'fraction_non_alphanumeric': 0.11683607898118939, 'fraction_numerical': 0.005140787475172333, 'mean_word_length': 2.051693404634581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5764255', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2673, 'n_words': 494}