#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 7m
#  in conjunction with Tcl version 8.6
#    Aug 09, 2021 07:11:37 AM PDT  platform: Linux

import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import *

import two
import time

def main(*args):
    '''Main entry point for the application.'''
    global root
    root = tk.Tk()
    root.protocol( 'WM_DELETE_WINDOW' , root.destroy)
    # Creates a toplevel widget.
    global _top44, _w44
    _top44 = root
    _w44 = two.Main(_top44)
    # Creates a toplevel widget.
    global _top45, _w45
    _top45 = tk.Toplevel(root)
    _w45 = two.Progress_Bar(_top45)
    init(_top44, _w44)
    root.mainloop()

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top
    global _top45
    _top45.withdraw()  # Hides the toplevel containing the window.


def advance(*args):
    print('two_support.advance')
    sys.stdout.flush()
    create_Progress_Bar()
    global prog_var
    # prog_var is created in the Progress_Bar class so we use _w45
    # which references that class.
    bar_value = _w45.prog_var.get() / float(100)
    _top45.deiconify()        # Be sure progress bar is visible.
    if bar_value < 1.0:
        bar_value += 0.2
        print ("Value to display: %f" % bar_value)
        _w45.prog_var.set(int(bar_value*100))
        root.update() # This updates Tk for both this and the progress_bar.
    print (sys._getframe().f_code.co_name, f': {bar_value = }')   # Rozen dpr
    if bar_value >= 1.0:
        time.sleep(1)        # Wait one second and then hide the progress bar
        _top45.withdraw()
        _w45.prog_var.set(0)

def create_Progress_Bar():
    global _top45, _w45
    if _top45 == None:
        _top45 = tk.Toplevel(root)
        _w45 = two.Progress_Bar(_top45)


def quit(*args):
    print('two_support.quit')
    sys.stdout.flush()
    sys.exit()

if __name__ == '__main__':
    two.start_up()




