// Script function: Switching light or changing status from red to green.

// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined 
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html

Class GlobalSionDialog : UIFrame
   {
      image EMGreenLight(object MyObject) 
        {                                                             
        RGBImage EMGreenLight=RGBImage("", 4,22,22) 
        EMGreenLight=RGB(250,250,250)
        EMGreenLight=tert(iradius<15, RGB(0,250-(iradius*10), 0),EMGreenLight) 
        EMGreenLight=tert(iradius>8 && iradius<11, RGB(0,0,0),EMGreenLight)
        return EMGreenLight
        }
        
       image EMRedLight (object MyObject)
       {                                                                             
       RGBImage EMRedLight=RGBImage("",4,22,22)
       EMRedLight=RGB(250,250,250)
       EMRedLight=tert(iradius<10, RGB(250-(iradius*10), 0, 0), EMRedLight)
       EMRedLight=tert(iradius>7 && iradius<10, RGB(0,0,0),EMRedLight)
       return EMRedLight
       }
                                      
                               
       void EMResetRed(object MyObject, number EMResetX) 
       {
       image EMRedSign 
       if(EMResetX) EMRedSign=MyObject.EMRedLight()
       else EMRedSign=MyObject.EMGreenLight()
       taggroup MyLightStatus=MyObject.LookupElement("EMRedLight")
       MyObject.LookupElement("EMRedLight").DLGGetElement(0).DLGBitmapData(EMRedSign) 
       }              
                
       void EMPushButton(object MyObject) 
       {
       MyObject.EMResetRed(0)
       taggroup MyLightStatus=MyObject.LookupElement("EMRedLight")
       MyObject.LookupElement("EMRedLight").DLGGetElement(0).DLGBitmapData(MyObject.EMGreenLight())
       MyObject.validateview()
       
       return
       }
               
TagGroup GlobalSionCreatedDialog( object MyObject )
       {
       TagGroup EMDialog = DLGCreateDialog("Switch Test") 
                                
       taggroup EMControlBox, EMStartButton
       taggroup MyControlBox=DLGCreateBox("",EMControlBox).DLGInternalPadding(25,5)
       EMStartButton=DLGCreatePushButton("Switch to Green", "EMPushButton").DLGIdentifier("EMStartButton")
       
       taggroup EMRedLight=DLGCreateGraphic(20,20).DLGIdentifier("EMRedLight")
       image EMGraphic:=RGBImage("",4,22,22)
       EMGraphic=MyObject.EMRedLight()
 
       taggroup EMBitMap=DLGCreateBitmap(EMGraphic)
       DLGAddBitmap(EMRedLight, EMBitMap)
    
       taggroup EMGroup=DLGGroupItems(EMStartButton, EMRedLight).DLGTableLayout(2,1,0)
       EMControlBox.DLGAddElement(EMGroup)
       EMDialog.DLGAddElement(MyControlBox)
       return EMDialog
       }

GlobalSionDialog( object MyObject )
       {
        MyObject.init( MyObject.GlobalSionCreatedDialog() )
       }
 }
               
 if ( alloc( GlobalSionDialog).Pose() ) exit (0)
 
 