#! /usr/bin/env python
#
# Support module generated by PAGE version 4.10
# In conjunction with Tcl version 8.6
#    Mar 06, 2018 03:53:43 PM


import sys, os

try:
    from Tkinter import *
except ImportError:
    from tkinter import *

try:
    import ttk
    py3 = 0
except ImportError:
    import tkinter.ttk as ttk
    py3 = 1


from time import sleep

sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
import action_function


def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top


def change_btm_disable():
    
    w.TB_down.configure(state = 'disabled')
    w.TB_f1.configure(state = 'disabled')
    w.TB_f2.configure(state = 'disabled')
    w.TB_f3.configure(state = 'disabled')
    w.TB_f4.configure(state = 'disabled')
    w.TB_f5.configure(state = 'disabled')
    w.TB_up.configure(state = 'disabled')
    w.TB_look_center.configure(state = 'disabled')
    w.TB_look_left.configure(state = 'disabled')
    w.TB_look_right.configure(state = 'disabled')
    w.TB_pull.configure(state = 'disabled')
    w.TB_push.configure(state = 'disabled')
    w.TB_reset.configure(state = 'disabled')
    w.TB_shake_left.configure(state = 'disabled')
    w.TB_shake_right.configure(state = 'disabled')
    w.TB_up.configure(state = 'disabled')

def change_btm_enable():
    
    w.TB_down.configure(state = 'enable')
    w.TB_f1.configure(state = 'enable')
    w.TB_f2.configure(state = 'enable')
    w.TB_f3.configure(state = 'enable')
    w.TB_f4.configure(state = 'enable')
    w.TB_f5.configure(state = 'enable')
    w.TB_up.configure(state = 'enable')
    w.TB_look_center.configure(state = 'enable')
    w.TB_look_left.configure(state = 'enable')
    w.TB_look_right.configure(state = 'enable')
    w.TB_pull.configure(state = 'enable')
    w.TB_push.configure(state = 'enable')
    w.TB_reset.configure(state = 'enable')
    w.TB_shake_left.configure(state = 'enable')
    w.TB_shake_right.configure(state = 'enable')
    w.TB_up.configure(state = 'enable')

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

def TB_com_key():

    w.Scrolledtext_msg.insert("end" , "正在连接.....\n")
    try:
        action_function.loger()
        action_function.creat_swift()
        if swift:
            t_info = action_function.show_dev_info()  # 显示设备信息
            w.Scrolledtext_msg.insert("end" , "设备连接正常，设备信息：！\n")
            w.Scrolledtext_msg.insert("end" , t_info +"\n")
            w.TLabel_state.configure(text = "设备工作正常！")
            change_btm_enable()

    except ImportError:
        print("没有发现设备，请连接好设备！")
        w.Scrolledtext_msg.insert("end" , "没有发现设备，请检查接线！\n")
        w.TLabel_state.configure(text = "没有发现设备！")

def TB_f1_key():
    w.Scrolledtext_msg.insert("end" , "正在执行F1程序......\n")
    action_function.f1_key()
    w.Scrolledtext_msg.insert("end" , "F1程序执行完毕！\n")

def TB_f2_key():
    w.Scrolledtext_msg.insert("end" , "正在执行F2程序......\n")
    action_function.f2_key()
    w.Scrolledtext_msg.insert("end" , "F1程序执行完毕！\n")

def TB_f3_key():
    w.Scrolledtext_msg.insert("end" , "正在执行F3程序......\n")
    action_function.f3_key()
    w.Scrolledtext_msg.insert("end" , "F1程序执行完毕！\n")

def TB_f4_key():
    w.Scrolledtext_msg.insert("end" , "正在执行F4程序......\n")
    action_function.f4_key()
    w.Scrolledtext_msg.insert("end" , "F1程序执行完毕！\n")

def TB_f5_key():
    w.Scrolledtext_msg.insert("end" , "F5程序没有设置！\n")
    sys.stdout.flush()

def TB_look_center():
    action_function.center_look()

def TB_look_left():
    action_function.left_look()

def TB_look_right():
    action_function.right_look()

def TB_pull_key():
    d = w.TCbox_pull.get()
    action_function.pull(d)
    

def TB_push_key():
    d = w.TCbox_push.get()
    action_function.push(d)

def TB_reset_key():
    action_function.reset()

def TB_shake_left_key():
    d = w.TCbox_shake_angle.get()
    action_function.shake_left(d)

def TB_shake_right():
    d = w.TCbox_shake_angle.get()
    action_function.shake_right(d)

def TB_up_key():
    d = w.TCbox_up.get()
    action_function.up(d)

def TB_down_key():
    d = w.TCbox_down.get()
    action_function.down(d)
    

def about_dialog():
    print('uArmContralFrm_support.about_dialog')
    sys.stdout.flush()

def setup_input_dialog(self):
    print('uArmContralFrm_support.setup_input_dialog')
    sys.stdout.flush()



if __name__ == '__main__':
    import uArmContralFrm
    uArmContralFrm.vp_start_gui()


