# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""
    Kubernetes
    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)  # noqa: E501
    The version of the OpenAPI document: release-1.16
    by: https://openapi-generator.tech
"""

import sys,os
import tkinter as tk
from tkinter import messagebox, Menu, filedialog
import tkinter.ttk as ttk
from ttkthemes import ThemedStyle
import time
from threading import Thread
import threading
from MergeHandler import *
from PIL import ImageTk

class Application(tk.Frame):
    """ This class provides functions for graphical user interface and ConvertHandler object creation """

    def __init__(self, master):
        """This function handles the creation of graphical user interface object"""
        super().__init__(master)
        self.pack()

         # Adds progressbar object to the graphical user interface
        self.progress = ttk.Progressbar(root, length = 100, mode = 'indeterminate')
        self.progress.place(x = 0, y = 40, height = 15, width = 620)
        self.progress['maximum'] = 100

        # Adds button object to the graphical user interface
        self.w = ttk.Button(text ="Merge", command = self.thread_start)
        self.w.place(x = 629, y = 0, height = 35)

        # Adds entry object to the graphical user interface
        self.entrythingy = ttk.Entry(font = "Calibri 12")
        self.entrythingy.place(x = 0, y = 0, height = 35, width = 620)
        self.entrythingy.insert(0, "Select folder")
        self.entrythingy.configure(state="DISABLED")

        # Binds events for the input object
        self.contents = tk.StringVar()
        self.entrythingy.bind('<Button-1>', self.on_click)
        self.entrythingy.bind('<Button-3>', self.on_click)
        self.entrythingy["textvariable"] = self.contents

    def on_click(self, master):
        """Deletes placeholder for input"""
        self.entrythingy.delete(0, "")
        current_directory = filedialog.askdirectory().replace('/','\\')
        self.entrythingy.insert(0, current_directory)

    def thread_start(self):
        """Starts the ConvertHandler class in a new thread"""
        path = self.entrythingy.get()
        thread_object = threading.Thread(self.create_object())
        thread_object.start()
        thread_object.join()

    def create_object(self):
        path = self.entrythingy.get()
        object = MergeHandler(self, path, self.progress)

    def exitProgram(self):
        """The function turns off the program"""
        sys.exit()

# Application entry point
if __name__ == "__main__":
    root = tk.Tk()
    root.title("Map To PDF © Philip Wingemo")
    root.geometry("700x60")
    photo = ImageTk.PhotoImage(file = "ico-1.jpg")
    root.iconphoto(False, photo)
    style = ThemedStyle(root)
    style.set_theme("plastik")
    myapp = Application(root)
    myapp.mainloop()
