#! /usr/bin/env python3
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 8.0v
#  in conjunction with Tcl version 8.6
#    Aug 09, 2023 11:02:11 AM CDT  platform: Linux

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

_script = sys.argv[0]
_location = os.path.dirname(_script)

import colourchart23_support

_bgcolor = "#d9d9d9"  # X11 color: 'gray85'
_fgcolor = "#000000"  # X11 color: 'black'
_compcolor = "#d9d9d9"  # X11 color: 'gray85'
_ana1color = "#d9d9d9"  # X11 color: 'gray85'
_ana2color = "#ececec"  # Closest X11 color: 'gray92'
_tabfg1 = "black"
_tabfg2 = "black"
_tabbg1 = "grey75"
_tabbg2 = "grey89"
_bgmode = "light"

_style_code_ran = 0


def _style_code():
    global _style_code_ran
    if _style_code_ran:
        return
    try:
        colourchart23_support.root.tk.call("source", "./themes/notsodark.tcl")
    except:
        pass
    style = ttk.Style()
    style.theme_use("notsodark")
    style.configure(".", font="TkDefaultFont")
    global _fgcolor, _bgcolor, _hcolor
    _fgcolor = style.lookup(".", "foreground")
    _bgcolor = style.lookup(".", "background")
    _hcolor = style.lookup(".", "highlightcolor")
    style.configure("Vertical.TScrollbar", background=_bgcolor, arrowcolor=_fgcolor)
    style.configure("Horizontal.TScrollbar", background=_bgcolor, arrowcolor=_fgcolor)
    _fgcolor = style.lookup(".", "foreground")
    _bgcolor = style.lookup(".", "background")
    _hcolor = style.lookup(".", "focuscolor")
    colourchart23_support.root.tk_setPalette(
        background=_bgcolor,
        foreground=_fgcolor,
        highlightColor=_hcolor,
    )
    _style_code_ran = 1


class Toplevel1:
    def __init__(self, top=None):
        """This class configures and populates the toplevel window.
        top is the toplevel containing window."""

        top.geometry("1423x995+453+118")
        top.minsize(1, 1)
        # top.maxsize(3585, 1450)
        top.maxsize(1425, 1242)
        top.resizable(1, 1)
        top.title("New Toplevel")
        top.configure(highlightbackground="#919191")
        top.configure(highlightcolor="black")

        self.top = top

        self.Frame1 = tk.Frame(self.top)
        self.Frame1.place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0)
        self.Frame1.configure(relief="groove")
        self.Frame1.configure(borderwidth="2")
        self.Frame1.configure(relief="groove")
        _style_code()
        self.Scrolledwindow1 = ScrolledWindow(self.Frame1)
        self.Scrolledwindow1.place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0)
        self.Scrolledwindow1.configure(borderwidth="2")
        self.Scrolledwindow1.configure(relief="groove")
        self.Scrolledwindow1.configure(selectbackground="#d9d9d9")
        self.color = self.Scrolledwindow1.cget("background")
        self.Scrolledwindow1_f = tk.Frame(self.Scrolledwindow1, background=self.color)
        self.Scrolledwindow1.create_window(
            0, 0, anchor="nw", window=self.Scrolledwindow1_f
        )


# The following code is added to facilitate the Scrolled widgets you specified.
class AutoScroll(object):
    """Configure the scrollbars for a widget."""

    def __init__(self, master):
        #  Rozen. Added the try-except clauses so that this class
        #  could be used for scrolled entry widget for which vertical
        #  scrolling is not supported. 5/7/14.
        try:
            vsb = ttk.Scrollbar(master, orient="vertical", command=self.yview)
        except:
            pass
        hsb = ttk.Scrollbar(master, orient="horizontal", command=self.xview)
        try:
            self.configure(yscrollcommand=self._autoscroll(vsb))
        except:
            pass
        self.configure(xscrollcommand=self._autoscroll(hsb))
        self.grid(column=0, row=0, sticky="nsew")
        try:
            vsb.grid(column=1, row=0, sticky="ns")
        except:
            pass
        hsb.grid(column=0, row=1, sticky="ew")
        master.grid_columnconfigure(0, weight=1)
        master.grid_rowconfigure(0, weight=1)
        # Copy geometry methods of master  (taken from ScrolledText.py)
        methods = (
            tk.Pack.__dict__.keys() | tk.Grid.__dict__.keys() | tk.Place.__dict__.keys()
        )
        for meth in methods:
            if meth[0] != "_" and meth not in ("config", "configure"):
                setattr(self, meth, getattr(master, meth))

    @staticmethod
    def _autoscroll(sbar):
        """Hide and show scrollbar as needed."""

        def wrapped(first, last):
            first, last = float(first), float(last)
            if first <= 0 and last >= 1:
                sbar.grid_remove()
            else:
                sbar.grid()
            sbar.set(first, last)

        return wrapped

    def __str__(self):
        return str(self.master)


def _create_container(func):
    """Creates a ttk Frame with a given master, and use this new frame to
    place the scrollbars and the widget."""

    def wrapped(cls, master, **kw):
        container = ttk.Frame(master)
        container.bind("<Enter>", lambda e: _bound_to_mousewheel(e, container))
        container.bind("<Leave>", lambda e: _unbound_to_mousewheel(e, container))
        return func(cls, container, **kw)

    return wrapped


class ScrolledWindow(AutoScroll, tk.Canvas):
    """A standard Tkinter Canvas widget with scrollbars that will
    automatically show/hide as needed."""

    @_create_container
    def __init__(self, master, **kw):
        tk.Canvas.__init__(self, master, **kw)
        AutoScroll.__init__(self, master)


import platform


def _bound_to_mousewheel(event, widget):
    child = widget.winfo_children()[0]
    if platform.system() == "Windows" or platform.system() == "Darwin":
        child.bind_all("<MouseWheel>", lambda e: _on_mousewheel(e, child))
        child.bind_all("<Shift-MouseWheel>", lambda e: _on_shiftmouse(e, child))
    else:
        child.bind_all("<Button-4>", lambda e: _on_mousewheel(e, child))
        child.bind_all("<Button-5>", lambda e: _on_mousewheel(e, child))
        child.bind_all("<Shift-Button-4>", lambda e: _on_shiftmouse(e, child))
        child.bind_all("<Shift-Button-5>", lambda e: _on_shiftmouse(e, child))


def _unbound_to_mousewheel(event, widget):
    if platform.system() == "Windows" or platform.system() == "Darwin":
        widget.unbind_all("<MouseWheel>")
        widget.unbind_all("<Shift-MouseWheel>")
    else:
        widget.unbind_all("<Button-4>")
        widget.unbind_all("<Button-5>")
        widget.unbind_all("<Shift-Button-4>")
        widget.unbind_all("<Shift-Button-5>")


def _on_mousewheel(event, widget):
    if platform.system() == "Windows":
        widget.yview_scroll(-1 * int(event.delta / 120), "units")
    elif platform.system() == "Darwin":
        widget.yview_scroll(-1 * int(event.delta), "units")
    else:
        if event.num == 4:
            widget.yview_scroll(-1, "units")
        elif event.num == 5:
            widget.yview_scroll(1, "units")


def _on_shiftmouse(event, widget):
    if platform.system() == "Windows":
        widget.xview_scroll(-1 * int(event.delta / 120), "units")
    elif platform.system() == "Darwin":
        widget.xview_scroll(-1 * int(event.delta), "units")
    else:
        if event.num == 4:
            widget.xview_scroll(-1, "units")
        elif event.num == 5:
            widget.xview_scroll(1, "units")


def start_up():
    colourchart23_support.main()


if __name__ == "__main__":
    colourchart23_support.main()
