#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 7g
#  in conjunction with Tcl version 8.6
#    Jun 12, 2021 08:39:17 AM PDT  platform: Linux

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

import clone

colors = ['white', 'gold', 'cyan', 'salmon', 'wheat', 'pale green',
          'dodger blue', 'pink', 'burlywood1',]
cc = -1

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 _top34, _w34
    _top34 = root
    _w34 = clone.Main(_top34)
    root.mainloop()

def create_clone(*args):
    ''' Callback function for the create button in any of the Called windows.
    It lines up the new windows along the left edge of the screen.'''
    global instance
    instance += 1
    cl = len(colors)
    global cc
    cc += 1
    if cc == cl - 1:
        cc = 0
    color = colors[cc]
    geom = "+0+%s" % str(65 + (cc * 100))
    # Build a dynamic block of code and then execute it to create and
    # configure the clone.
    build_window = '''
global _top{i}, _w{i}
_top{i} = tk.Toplevel(root)
_w{i} = clone.Called(_top{i})
configure_called(_top{i}, _w{i}, color, instance, geom)'''.format(i=instance)
    exec(build_window)

def open_two(*args):
    '''Callback function that creates two copies of the Called toplevel
       widget and then disales the create button in the main window.'''
    global instance
    # Creates a toplevel widget.
    global _top35, _w35
    _top35 = tk.Toplevel(root)
    _w35 = clone.Called(_top35)
    configure_called(_top35, _w35, 'orange', 1, "+375+450")
    # Creates a toplevel widget.
    global _top36, _w36
    _top36 = tk.Toplevel(root)
    _w36 = clone.Called(_top36)
    configure_called(_top36, _w36, 'plum', 2, "+750+450")
    _w34.Button1.configure(state='disable')
    instance = 2

def configure_called(top_level, w, color, instance, geom):
    ''' Configures the background color of the toplevel and child widgets
    of a Called window to be 'color' and sets the geometry of the toplevel.'''
    top_level.configure(background=color)
    top_level.geometry(geom)
    w.btnCreateClone.configure(background=color)
    w.btnClose.configure(background=color)
    w.btnQuit.configure(background=color)
    w.Label2.configure(background=color)
    w.Label2.configure(text="instance {}".format(instance))

def quit(*args):
    ''' Callback function called from any of the Quit buttons.'''
    sys.exit()

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




