#coding=utf-8
#import libs 
import sys
import os
from   os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import RadioButtonExamples_cmd
import RadioButtonExamples_sty
import Fun
import EXUIControl
EXUIControl.FunLib = Fun
EXUIControl.G_ExeDir = Fun.G_ExeDir
EXUIControl.G_ResDir = Fun.G_ResDir
import tkinter
from   tkinter import *
import tkinter.ttk
import tkinter.font
from   PIL import Image,ImageTk

#Add your Varial Here: (Keep This Line of comments)
#Define UI Class
class  RadioButtonExamples:
    def __init__(self,root,isTKroot = True,params=None):
        uiName = Fun.GetUIName(root,self.__class__.__name__)
        self.uiName = uiName
        Fun.Register(uiName,'UIClass',self)
        self.root = root
        self.configure_event = None
        self.isTKroot = isTKroot
        self.firstRun = True
        self.rootZoomed = False
        Fun.G_UIParamsDictionary[uiName]=params
        Fun.G_UICommandDictionary[uiName]=RadioButtonExamples_cmd
        Fun.Register(uiName,'root',root)
        style = RadioButtonExamples_sty.SetupStyle(isTKroot)
        self.UIJsonString = '{"Version": "1.0.0", "UIName": "RadioButtonExamples", "Description": "", "WindowSize": [960, 640], "WindowPosition": "Center", "WindowHide": false, "WindowResizable": true, "WindowTitle": "RadioButtonExamples", "DarkMode": false, "BorderWidth": 0, "BorderColor": "#ffffff", "DropTitle": false, "DragWindow": false, "MinSize": [0, 0], "ResolutionScaling": true, "PopupDebugDialog": false, "TransparentColor": null, "RootTransparency": 255, "ICOFile": null, "WinState": 1, "WinTopMost": false, "BGColor": "#EFEFEF", "GroupList": {"Group_1": "0", "Group_2": "4", "Group_3": "0"}, "WidgetList": [{"Type": "Form", "Index": 1, "AliasName": "Form_1", "BGColor": "#EFEFEF", "Size": [960, 640], "PlaceInfo": null, "EventList": {"Load": "Form_1_onLoad"}}, {"Type": "Label", "Index": 2, "AliasName": "Label_1", "ParentName": "Form_1", "PlaceInfo": [174, 37, 582, 48, "nw", true, false], "Visible": true, "Size": [582, 48], "BGColor": "#EFEFEF", "Text": "RadioButton的简单应用", "FGColor": "#000000"}, {"Type": "Label", "Index": 14, "AliasName": "Label_2", "ParentName": "Form_1", "PlaceInfo": [268, 204, 313, 132, "nw", true, false], "Visible": true, "Size": [313, 132], "BGColor": "#EFEFEF", "Text": "", "FGColor": "#000000", "AutoWrap": true}, {"Type": "RadioButton", "Index": 3, "AliasName": "RadioButton_1", "ParentName": "Form_1", "PlaceInfo": [48, 122, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 1, "Value": 0, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat", "EventList": {"Command": "RadioButton_1_onCommand"}}, {"Type": "RadioButton", "Index": 4, "AliasName": "RadioButton_2", "ParentName": "Form_1", "PlaceInfo": [48, 192, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 1, "Value": 1, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 5, "AliasName": "RadioButton_3", "ParentName": "Form_1", "PlaceInfo": [48, 270, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 1, "Value": 2, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 6, "AliasName": "RadioButton_4", "ParentName": "Form_1", "PlaceInfo": [48, 347, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 1, "Value": 3, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 7, "AliasName": "RadioButton_5", "ParentName": "Form_1", "PlaceInfo": [48, 424, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 1, "Value": 4, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 8, "AliasName": "RadioButton_6", "ParentName": "Form_1", "PlaceInfo": [635, 122, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 2, "Value": 0, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 9, "AliasName": "RadioButton_7", "ParentName": "Form_1", "PlaceInfo": [635, 198, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 2, "Value": 1, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 10, "AliasName": "RadioButton_8", "ParentName": "Form_1", "PlaceInfo": [635, 275, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 2, "Value": 2, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 11, "AliasName": "RadioButton_9", "ParentName": "Form_1", "PlaceInfo": [635, 347, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 2, "Value": 3, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat"}, {"Type": "RadioButton", "Index": 12, "AliasName": "RadioButton_10", "ParentName": "Form_1", "PlaceInfo": [635, 424, 160, 40, "nw", true, false], "Visible": true, "Size": [160, 40], "GroupID": 2, "Value": 4, "BGColor": "#EFEFEF", "ActiveBGColor": "#EFEFEF", "Text": "RadioButton", "FGColor": "#000000", "Anchor": "w", "SelectColor": "#EFEFEF", "SelectBGColor": "#EFEFEF", "SelectFGColor": "#000000", "Relief": "flat", "EventList": {"Command": "RadioButton_10_onCommand"}}, {"Type": "Button", "Index": 13, "AliasName": "Button_1", "ParentName": "Form_1", "PlaceInfo": [294, 567, 241, 48, "nw", true, false], "Visible": true, "Size": [241, 48], "BGColor": "#EFEFEF", "Text": "获取选中的RdioButton", "FGColor": "#000000", "Relief": "raised", "EventList": {"Command": "Button_1_onCommand"}}, {"Type": "Button", "Index": 15, "AliasName": "Button_2", "ParentName": "Form_1", "PlaceInfo": [10, 481, 258, 48, "nw", true, false], "Visible": true, "Size": [258, 48], "BGColor": "#EFEFEF", "Text": "设置RadioButtion选中状态", "FGColor": "#000000", "Relief": "raised", "EventList": {"Command": "Button_2_onCommand"}}, {"Type": "Button", "Index": 16, "AliasName": "Button_3", "ParentName": "Form_1", "PlaceInfo": [586, 481, 258, 48, "nw", true, false], "Visible": true, "Size": [258, 48], "BGColor": "#EFEFEF", "Text": "设置RadioButtion选中状态", "FGColor": "#000000", "Relief": "raised", "EventList": {"Command": "Button_3_onCommand"}}]}'
        Form_1 = Fun.CreateUIFormJson(uiName,root,isTKroot,style,self.UIJsonString)
        #Inital all element's Data 
        Fun.InitElementData(uiName)
        #Call Form_1's OnLoad Function
        Fun.RunForm1_CallBack(uiName,"Load",RadioButtonExamples_cmd.Form_1_onLoad)
        #Add Some Logic Code Here: (Keep This Line of comments)



        #Exit Application: (Keep This Line of comments)
        if self.isTKroot == True and Fun.GetElement(self.uiName,"root"):
            self.root.protocol('WM_DELETE_WINDOW', self.Exit)
            self.root.bind('<Configure>', self.Configure)
            if self.rootZoomed == True and isinstance(self.root,tkinter.Tk) == True:
                self.root.state("zoomed")
                Fun.SetUIState(uiName,"zoomed")
                self.rootZoomed = False
            
    def GetRootSize(self):
        return Fun.GetUIRootSize(self.uiName)
    def GetAllElement(self):
        return Fun.G_UIElementDictionary[self.uiName]
    def Escape(self,event):
        if Fun.AskBox('提示','确定退出程序？') == True:
            self.Exit()
    def Exit(self):
        if self.isTKroot == True:
            Fun.DestroyUI(self.uiName,0,'')

    def Configure(self,event):
        Form_1 = Fun.GetElement(self.uiName,'Form_1')
        if Form_1 == event.widget:
            Fun.ReDrawCanvasRecord(self.uiName)
        if self.root == event.widget and (self.configure_event is None or self.configure_event[2]!= event.width or self.configure_event[3]!= event.height):
            uiName = self.uiName
            self.configure_event = [event.x,event.y,event.width,event.height]
            Fun.ResizeRoot(self.uiName,self.root,event)
            Fun.ResizeAllChart(self.uiName)
            pass
#Create the root of tkinter 
if  __name__ == '__main__':
    Fun.RunApplication(RadioButtonExamples)
