#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.23a
#  in conjunction with Tcl version 8.6
#    Jul 03, 2019 01:12:37 PM -03  platform: Windows NT

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import views.abm_medicos_support as abm_medicos_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    abm_medicos_support.set_Tk_var()
    top = abmMedicos (root)
    abm_medicos_support.init(root, top)
    root.mainloop()

w = None
def create_abmMedicos(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt, top
    rt = root
    w = tk.Toplevel (root)
    abm_medicos_support.set_Tk_var()
    top = abmMedicos (w)
    abm_medicos_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_abmMedicos():
    global w
    w.destroy()
    w = None

class abmMedicos:
    def __init__(self, top=None):
        self.medicos = []
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _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'
        font9 = "-family {Segoe UI} -size 18 -weight normal -slant "  \
            "roman -underline 0 -overstrike 0"
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.',background=_bgcolor)
        self.style.configure('.',foreground=_fgcolor)
        self.style.configure('.',font="TkDefaultFont")
        self.style.map('.',background=
            [('selected', _compcolor), ('active',_ana2color)])

        top.geometry("757x530+320+131")
        top.title("Medicos")
        top.configure(borderwidth="1")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")
        top.configure(padx="10")
        top.configure(pady="10")

        self.Message1 = tk.Message(top)
        self.Message1.place(relx=0.053, rely=0.038, relheight=0.1
                , relwidth=0.911)
        self.Message1.configure(background="#5466d8")
        self.Message1.configure(borderwidth="10")
        self.Message1.configure(font=font9)
        self.Message1.configure(foreground="#000000")
        self.Message1.configure(highlightbackground="#d9d9d9")
        self.Message1.configure(highlightcolor="black")
        self.Message1.configure(text='''ABM Médicos''')
        self.Message1.configure(width=690)

        self.apellidoLabel = ttk.Label(top)
        self.apellidoLabel.place(relx=0.092, rely=0.17, height=19, width=86)
        self.apellidoLabel.configure(background="#d9d9d9")
        self.apellidoLabel.configure(foreground="#000000")
        self.apellidoLabel.configure(font="TkDefaultFont")
        self.apellidoLabel.configure(relief="flat")
        self.apellidoLabel.configure(text='''Apellido''')
        self.apellidoLabel.configure(width=100)

        self.nombreLabel = ttk.Label(top)
        self.nombreLabel.place(relx=0.555, rely=0.17, height=19, width=58)
        self.nombreLabel.configure(background="#d9d9d9")
        self.nombreLabel.configure(foreground="#000000")
        self.nombreLabel.configure(font="TkDefaultFont")
        self.nombreLabel.configure(relief="flat")
        self.nombreLabel.configure(text='''Nombre''')
        self.nombreLabel.configure(width=58)

        self.TLabel1_2 = ttk.Label(top)
        self.TLabel1_2.place(relx=0.033, rely=0.434, height=1, width=36)
        self.TLabel1_2.configure(background="#d9d9d9")
        self.TLabel1_2.configure(foreground="#000000")
        self.TLabel1_2.configure(font="TkDefaultFont")
        self.TLabel1_2.configure(relief="flat")
        self.TLabel1_2.configure(text='''Tlabel''')

        self.especialidadLabel = ttk.Label(top)
        self.especialidadLabel.place(relx=0.092, rely=0.245, height=19, width=76)

        self.especialidadLabel.configure(background="#d9d9d9")
        self.especialidadLabel.configure(foreground="#000000")
        self.especialidadLabel.configure(font="TkDefaultFont")
        self.especialidadLabel.configure(relief="flat")
        self.especialidadLabel.configure(text='''Especialidad''')
        self.especialidadLabel.configure(width=76)

        self.matriculaLabel = ttk.Label(top)
        self.matriculaLabel.place(relx=0.555, rely=0.245, height=19, width=70)
        self.matriculaLabel.configure(background="#d9d9d9")
        self.matriculaLabel.configure(foreground="#000000")
        self.matriculaLabel.configure(font="TkDefaultFont")
        self.matriculaLabel.configure(relief="flat")
        self.matriculaLabel.configure(text='''Matrícula''')
        self.matriculaLabel.configure(width=70)

        self.apelldoInput = ttk.Entry(top)
        self.apelldoInput.place(relx=0.211, rely=0.17, relheight=0.04
                , relwidth=0.272)
        self.apelldoInput.configure(textvariable=abm_medicos_support.medicoApellido)
        self.apelldoInput.configure(width=206)
        self.apelldoInput.configure(takefocus="")

        self.nombreInput = ttk.Entry(top)
        self.nombreInput.place(relx=0.647, rely=0.151, relheight=0.04
                , relwidth=0.272)
        self.nombreInput.configure(textvariable=abm_medicos_support.medicoNombre)
        self.nombreInput.configure(width=206)
        self.nombreInput.configure(takefocus="")
        

        self.especialidadInput = ttk.Entry(top)
        self.especialidadInput.place(relx=0.211, rely=0.245, relheight=0.04
                , relwidth=0.272)
        self.especialidadInput.configure(textvariable=abm_medicos_support.especialidad)
        self.especialidadInput.configure(width=206)
        self.especialidadInput.configure(takefocus="")
        

        self.matriculaInput = ttk.Entry(top)
        self.matriculaInput.place(relx=0.647, rely=0.245, relheight=0.04
                , relwidth=0.127)
        self.matriculaInput.configure(textvariable=abm_medicos_support.matricula)
        self.matriculaInput.configure(width=96)
        self.matriculaInput.configure(takefocus="")
        

        self.grabarButton = ttk.Button(top)
        self.grabarButton.place(relx=0.515, rely=0.811, height=25, width=76)
        self.grabarButton.configure(takefocus="")
        self.grabarButton.configure(text='''Grabar''')
        self.grabarButton.configure(command=abm_medicos_support.nuevoMedico)

        self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        top.configure(menu = self.menubar)

        self.salirButton = ttk.Button(top)
        self.salirButton.place(relx=0.674, rely=0.811, height=25, width=76)
        self.salirButton.configure(command=abm_medicos_support.destroy_window)
        self.salirButton.configure(takefocus="")
        self.salirButton.configure(text='''Salir''')

        self.medicoList = ScrolledListBox(top)
        self.medicoList.place(relx=0.053, rely=0.321, relheight=0.406
                , relwidth=0.9)
        self.medicoList.configure(background="white")
        self.medicoList.configure(disabledforeground="#a3a3a3")
        self.medicoList.configure(font="TkFixedFont")
        self.medicoList.configure(foreground="black")
        self.medicoList.configure(highlightbackground="#d9d9d9")
        self.medicoList.configure(highlightcolor="#d9d9d9")
        self.medicoList.configure(selectbackground="#c4c4c4")
        self.medicoList.configure(selectforeground="black")
        self.medicoList.configure(width=10)

        self.actualizar()

        self.nuevoButton = ttk.Button(top)
        self.nuevoButton.place(relx=0.198, rely=0.811, height=25, width=76)
        self.nuevoButton.configure(takefocus="")
        self.nuevoButton.configure(text='''Nuevo''')

        self.editButton = ttk.Button(top)
        self.editButton.place(relx=0.357, rely=0.811, height=25, width=76)
        self.editButton.configure(takefocus="")
        self.editButton.configure(text='''Editar''')

    def actualizar(self):
        self.medicos = abm_medicos_support.getAll()
        for item in self.medicos:
            self.medicoList.insert(tk.END,"{}, {}, {}".format(item.apellido,item.nombre,item.especialidad))
    
    def insertarUltimo(self,item):
        self.medicoList.insert(tk.END,"{}, {}, {}".format(item.apellido,item.nombre,item.especialidad))

    def clear(self):
        abm_medicos_support.medicoNombre.set("")
        abm_medicos_support.medicoApellido.set("")
        abm_medicos_support.especialidad.set("")
        abm_medicos_support.matricula.set("")


# 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)

        #self.configure(yscrollcommand=_autoscroll(vsb),
        #    xscrollcommand=_autoscroll(hsb))
        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)
        if py3:
            methods = tk.Pack.__dict__.keys() | tk.Grid.__dict__.keys() \
                  | tk.Place.__dict__.keys()
        else:
            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 ScrolledListBox(AutoScroll, tk.Listbox):
    '''A standard Tkinter Text widget with scrollbars that will
    automatically show/hide as needed.'''
    @_create_container
    def __init__(self, master, **kw):
        tk.Listbox.__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')

if __name__ == '__main__':
    vp_start_gui()





