#! /usr/bin/env python3
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 7.6f
#  in conjunction with Tcl version 8.6
#    Oct 25, 2022 07:48:49 PM PDT  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 ttiphack4_support

_bgcolor = '#d9d9d9'  # X11 color: 'gray85'
_fgcolor = '#000000'  # X11 color: 'black'
_compcolor = 'gray40' # X11 color: #666666
_ana1color = '#c3c3c3' # Closest X11 color: 'gray76'
_ana2color = 'beige' # X11 color: #f5f5dc
_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
    style = ttk.Style()
    if sys.platform == "win32":
       style.theme_use('winnative')
    style.configure('.',background=_bgcolor)
    style.configure('.',foreground=_fgcolor)
    style.configure('.',font='TkDefaultFont')
    style.map('.',background =
       [('selected', _compcolor), ('active',_ana2color)])
    if _bgmode == 'dark':
       style.map('.',foreground =
         [('selected', 'white'), ('active','white')])
    else:
       style.map('.',foreground =
         [('selected', 'black'), ('active','black')])
    style.configure('Vertical.TScrollbar',  background=_bgcolor,
        arrowcolor= _fgcolor)
    style.configure('Horizontal.TScrollbar',  background=_bgcolor,
        arrowcolor= _fgcolor)
    _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("600x598+808+34")
        top.minsize(1, 1)
        top.maxsize(4225, 1410)
        top.resizable(0,  0)
        top.title("Tooltip Hack")
        top.configure(highlightbackground="wheat")
        top.configure(highlightcolor="black")

        self.top = top
        self.bkgnd = tk.StringVar()
        self.frgnd = tk.StringVar()
        self.FontData = tk.StringVar()
        self.PadxData = tk.StringVar()
        self.PadyData = tk.StringVar()
        self.ReliefData = tk.StringVar()
        self.JustifyData = tk.StringVar()
        self.BorderwidthData = tk.StringVar()

        self.Button1 = tk.Button(self.top)
        self.Button1.place(x=190, y=70, height=33, width=183)
        self.Button1.configure(activebackground="beige")
        self.Button1.configure(borderwidth="2")
        self.Button1.configure(compound='left')
        self.Button1.configure(disabledforeground="#b8a786")
        self.Button1.configure(highlightbackground="wheat")
        self.Button1.configure(text='''Button''')
        self.Button1_tooltip = \
        ToolTip(self.Button1, '''This is the Tooltop!''')

        self.Entry1 = tk.Entry(self.top)
        self.Entry1.place(x=175, y=170, height=23, width=156)
        self.Entry1.configure(background="white")
        self.Entry1.configure(disabledforeground="#b8a786")
        self.Entry1.configure(font="TkFixedFont")
        self.Entry1.configure(highlightbackground="wheat")
        self.Entry1.configure(selectbackground="#c4c4c4")
        self.Entry1.configure(textvariable=self.bkgnd)
        self.Entry2 = tk.Entry(self.top)
        self.Entry2.place(x=175, y=210, height=23, width=156)
        self.Entry2.configure(background="white")
        self.Entry2.configure(disabledforeground="#b8a786")
        self.Entry2.configure(font="TkFixedFont")
        self.Entry2.configure(highlightbackground="wheat")
        self.Entry2.configure(selectbackground="#c4c4c4")
        self.Entry2.configure(textvariable=self.frgnd)
        self.Label1 = tk.Label(self.top)
        self.Label1.place(x=20, y=170, height=21, width=149)
        self.Label1.configure(activebackground="#f9f9f9")
        self.Label1.configure(anchor='e')
        self.Label1.configure(compound='left')
        self.Label1.configure(disabledforeground="#b8a786")
        self.Label1.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label1.configure(highlightbackground="wheat")
        self.Label1.configure(text='''Background Color:''')
        self.Label2 = tk.Label(self.top)
        self.Label2.place(x=20, y=210, height=21, width=149)
        self.Label2.configure(activebackground="#f9f9f9")
        self.Label2.configure(anchor='e')
        self.Label2.configure(compound='left')
        self.Label2.configure(disabledforeground="#b8a786")
        self.Label2.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label2.configure(highlightbackground="wheat")
        self.Label2.configure(text='''Foreground Color:''')
        self.btnTryIt = tk.Button(self.top)
        self.btnTryIt.place(x=390, y=190, height=33, width=153)
        self.btnTryIt.configure(activebackground="beige")
        self.btnTryIt.configure(borderwidth="2")
        self.btnTryIt.configure(command=ttiphack4_support.on_btnTryIt)
        self.btnTryIt.configure(compound='left')
        self.btnTryIt.configure(disabledforeground="#b8a786")
        self.btnTryIt.configure(highlightbackground="wheat")
        self.btnTryIt.configure(text='''Try It!''')
        self.btnExit = tk.Button(self.top)
        self.btnExit.place(x=440, y=20, height=33, width=133)
        self.btnExit.configure(activebackground="beige")
        self.btnExit.configure(borderwidth="2")
        self.btnExit.configure(command=ttiphack4_support.on_btnExit)
        self.btnExit.configure(compound='left')
        self.btnExit.configure(disabledforeground="#b8a786")
        self.btnExit.configure(font="-family {DejaVu Sans} -size 12 -weight bold -slant italic")
        self.btnExit.configure(highlightbackground="wheat")
        self.btnExit.configure(text='''Exit''')
        self.Label3 = tk.Label(self.top)
        self.Label3.place(x=20, y=250, height=21, width=149)
        self.Label3.configure(activebackground="#f9f9f9")
        self.Label3.configure(anchor='e')
        self.Label3.configure(compound='left')
        self.Label3.configure(disabledforeground="#b8a786")
        self.Label3.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label3.configure(highlightbackground="wheat")
        self.Label3.configure(text='''Pick a Font:''')
        self.Entry3 = tk.Entry(self.top)
        self.Entry3.place(x=175, y=250, height=23, width=156)
        self.Entry3.configure(background="white")
        self.Entry3.configure(disabledforeground="#b8a786")
        self.Entry3.configure(font="TkFixedFont")
        self.Entry3.configure(highlightbackground="wheat")
        self.Entry3.configure(selectbackground="#c4c4c4")
        self.Entry3.configure(textvariable=self.FontData)
        self.btnGetFont = tk.Button(self.top)
        self.btnGetFont.place(x=330, y=252, height=21, width=23)
        self.btnGetFont.configure(activebackground="beige")
        self.btnGetFont.configure(borderwidth="2")
        self.btnGetFont.configure(command=ttiphack4_support.on_btngetfont)
        self.btnGetFont.configure(compound='left')
        self.btnGetFont.configure(disabledforeground="#b8a786")
        self.btnGetFont.configure(highlightbackground="wheat")
        self.btnGetFont.configure(text='''...''')
        self.Button2 = tk.Button(self.top)
        self.Button2.place(x=330, y=170, height=21, width=23)
        self.Button2.configure(activebackground="beige")
        self.Button2.configure(borderwidth="2")
        self.Button2.configure(command=ttiphack4_support.on_Background_Click)
        self.Button2.configure(compound='left')
        self.Button2.configure(disabledforeground="#b8a786")
        self.Button2.configure(highlightbackground="wheat")
        self.Button2.configure(text='''...''')
        self.Button3 = tk.Button(self.top)
        self.Button3.place(x=330, y=210, height=21, width=23)
        self.Button3.configure(activebackground="beige")
        self.Button3.configure(borderwidth="2")
        self.Button3.configure(command=ttiphack4_support.on_Foreground_Click)
        self.Button3.configure(compound='left')
        self.Button3.configure(disabledforeground="#b8a786")
        self.Button3.configure(highlightbackground="wheat")
        self.Button3.configure(text='''...''')
        self.Entry4 = tk.Entry(self.top)
        self.Entry4.place(x=175, y=290, height=23, width=86)
        self.Entry4.configure(background="white")
        self.Entry4.configure(disabledforeground="#b8a786")
        self.Entry4.configure(font="TkFixedFont")
        self.Entry4.configure(highlightbackground="wheat")
        self.Entry4.configure(selectbackground="#c4c4c4")
        self.Entry4.configure(textvariable=self.PadxData)
        self.Entry5 = tk.Entry(self.top)
        self.Entry5.place(x=175, y=320, height=23, width=86)
        self.Entry5.configure(background="white")
        self.Entry5.configure(disabledforeground="#b8a786")
        self.Entry5.configure(font="TkFixedFont")
        self.Entry5.configure(highlightbackground="wheat")
        self.Entry5.configure(selectbackground="#c4c4c4")
        self.Entry5.configure(textvariable=self.PadyData)
        self.Label4 = tk.Label(self.top)
        self.Label4.place(x=20, y=290, height=21, width=149)
        self.Label4.configure(activebackground="#f9f9f9")
        self.Label4.configure(anchor='e')
        self.Label4.configure(compound='left')
        self.Label4.configure(disabledforeground="#b8a786")
        self.Label4.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label4.configure(highlightbackground="wheat")
        self.Label4.configure(text='''Pad X:''')
        self.Label5 = tk.Label(self.top)
        self.Label5.place(x=20, y=320, height=21, width=149)
        self.Label5.configure(activebackground="#f9f9f9")
        self.Label5.configure(anchor='e')
        self.Label5.configure(compound='left')
        self.Label5.configure(disabledforeground="#b8a786")
        self.Label5.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label5.configure(highlightbackground="wheat")
        self.Label5.configure(text='''Pad Y:''')
        _style_code()
        self.TCombobox1 = ttk.Combobox(self.top)
        self.TCombobox1.place(x=175, y=350, height=21, width=137)
        self.TCombobox1.configure(exportselection="0")
        self.TCombobox1.configure(textvariable=self.ReliefData)
        self.TCombobox1.configure(takefocus="")
        self.Label6 = tk.Label(self.top)
        self.Label6.place(x=20, y=350, height=21, width=149)
        self.Label6.configure(activebackground="#f9f9f9")
        self.Label6.configure(anchor='e')
        self.Label6.configure(compound='left')
        self.Label6.configure(disabledforeground="#b8a786")
        self.Label6.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label6.configure(highlightbackground="wheat")
        self.Label6.configure(text='''Relief:''')
        self.TCombobox2 = ttk.Combobox(self.top)
        self.TCombobox2.place(x=175, y=380, height=21, width=137)
        self.TCombobox2.configure(textvariable=self.JustifyData)
        self.TCombobox2.configure(takefocus="")
        self.Label7 = tk.Label(self.top)
        self.Label7.place(x=20, y=380, height=21, width=149)
        self.Label7.configure(activebackground="#f9f9f9")
        self.Label7.configure(anchor='e')
        self.Label7.configure(compound='left')
        self.Label7.configure(disabledforeground="#b8a786")
        self.Label7.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label7.configure(highlightbackground="wheat")
        self.Label7.configure(text='''Justify:''')
        self.Label8 = tk.Label(self.top)
        self.Label8.place(x=20, y=461, height=21, width=149)
        self.Label8.configure(activebackground="#f9f9f9")
        self.Label8.configure(anchor='e')
        self.Label8.configure(compound='left')
        self.Label8.configure(disabledforeground="#b8a786")
        self.Label8.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label8.configure(highlightbackground="wheat")
        self.Label8.configure(text='''Text:''')
        self.Label9 = tk.Label(self.top)
        self.Label9.place(x=30, y=410, height=21, width=139)
        self.Label9.configure(activebackground="#f9f9f9")
        self.Label9.configure(anchor='e')
        self.Label9.configure(compound='left')
        self.Label9.configure(disabledforeground="#b8a786")
        self.Label9.configure(font="-family {DejaVu Sans} -size 10 -weight bold")
        self.Label9.configure(highlightbackground="wheat")
        self.Label9.configure(text='''Borderwidth:''')
        self.Entry7 = tk.Entry(self.top)
        self.Entry7.place(x=175, y=410, height=23, width=86)
        self.Entry7.configure(background="white")
        self.Entry7.configure(disabledforeground="#b8a786")
        self.Entry7.configure(font="TkFixedFont")
        self.Entry7.configure(highlightbackground="wheat")
        self.Entry7.configure(selectbackground="#c4c4c4")
        self.Entry7.configure(textvariable=self.BorderwidthData)
        self.Scrolledtext1 = ScrolledText(self.top)
        self.Scrolledtext1.place(x=175, y=440, height=121, width=332)
        self.Scrolledtext1.configure(background="white")
        self.Scrolledtext1.configure(font="TkTextFont")
        self.Scrolledtext1.configure(insertborderwidth="3")
        self.Scrolledtext1.configure(selectbackground="#c4c4c4")
        self.Scrolledtext1.configure(wrap="none")

from time import time, localtime, strftime
class ToolTip(tk.Toplevel):
    """ Provides a ToolTip widget for Tkinter. """
    def __init__(self, wdgt, msg=None, msgFunc=None, delay=0.5,
                 follow=True):
        self.wdgt = wdgt
        self.parent = self.wdgt.master
        tk.Toplevel.__init__(self, self.parent, bg='black', padx=1, pady=1)
        self.withdraw()
        self.overrideredirect(True)
        self.msgVar = tk.StringVar()
        if msg is None:
            self.msgVar.set('No message provided')
        else:
            self.msgVar.set(msg)
        self.msgFunc = msgFunc
        self.delay = delay
        self.follow = follow
        self.visible = 0
        self.lastMotion = 0
        self.msg = tk.Message(self, textvariable=self.msgVar, bg=_bgcolor,
                   fg=_fgcolor, font="TkDefaultFont",
                   aspect=1000)
        self.msg.grid()
        self.wdgt.bind('<Enter>', self.spawn, '+')
        self.wdgt.bind('<Leave>', self.hide, '+')
        self.wdgt.bind('<Motion>', self.move, '+')
    def spawn(self, event=None):
        self.visible = 1
        self.after(int(self.delay * 1000), self.show)
    def show(self):
        if self.visible == 1 and time() - self.lastMotion > self.delay:
            self.visible = 2
        if self.visible == 2:
            self.deiconify()
    def move(self, event):
        self.lastMotion = time()
        if self.follow is False:
            self.withdraw()
            self.visible = 1
        self.geometry('+%i+%i' % (event.x_root + 20, event.y_root - 10))
        try:
            self.msgVar.set(self.msgFunc())
        except:
            pass
        self.after(int(self.delay * 1000), self.show)
    def hide(self, event=None):
        self.visible = 0
        self.withdraw()
    def update(self, msg):
        self.msgVar.set(msg)
    def configure(self, **kwargs):
        backgroundset = False
        foregroundset = False
        # Get the current tooltip text just in case the user doesn't provide any.
        current_text = self.msgVar.get()
        # to clear the tooltip text, use the .update method
        if 'debug' in kwargs.keys():
            debug = kwargs.pop('debug', False)
            if debug:
                for key, value in kwargs.items():
                    print(f'key: {key} - value: {value}')
        if 'background' in kwargs.keys():
            background = kwargs.pop('background')
            backgroundset = True
        if 'bg' in kwargs.keys():
            background = kwargs.pop('bg')
            backgroundset = True
        if 'foreground' in kwargs.keys():
            foreground = kwargs.pop('foreground')
            foregroundset = True
        if 'fg' in kwargs.keys():
            foreground = kwargs.pop('fg')
            foregroundset = True

        fontd = kwargs.pop('font', None)
        # print(f'Font: {fontd}')
        # text = kwargs.pop('text', None)
        if 'text' in kwargs.keys():
            text = kwargs.pop('text')
            if (text == '') or (text == "\n"):
                text = current_text
            else:
                self.msgVar.set(text)
        reliefd = kwargs.pop('relief', 'flat')
        justifyd = kwargs.pop('justify', 'left')
        padxd = kwargs.pop('padx', 1)
        padyd = kwargs.pop('pady', 1)
        borderwidthd = kwargs.pop('borderwidth', 2)
        wid = self.msg      # The message widget which is the actual tooltip
        if backgroundset:
            wid.config(bg=background)
        if foregroundset:
            wid.config(fg=foreground)
        wid.config(font=fontd)
        wid.config(borderwidth=borderwidthd)
        wid.config(relief=reliefd)
        wid.config(justify=justifyd)
        wid.config(padx=padxd)
        wid.config(pady=padyd)
#                   End of Class ToolTip

# 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 ScrolledText(AutoScroll, tk.Text):
    '''A standard Tkinter Text widget with scrollbars that will
    automatically show/hide as needed.'''
    @_create_container
    def __init__(self, master, **kw):
        tk.Text.__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():
    ttiphack4_support.main()

if __name__ == '__main__':
    ttiphack4_support.main()




