- John Lennon
#===================================================================================================
# Example Script: Aztec Simple Event Script
# Demonstrates creation of a simple window and timer with event processing. Uses WindowCloseEvent,
# WindowResizeEvent and TimerAlarmEvent.
#===================================================================================================
# Main class that is derived from Thread. VM automatically creates us and executes Run().
class Main from<Thread>
{
method Main()
{
}
method virtual Run()
{
# Create the simple window, a timer and then go into event mode.
CreateWindowAndTimer()
EventMode()
}
method CreateWindowAndTimer()
{
data<TimerInterface> MyTimerInterface = new<TimerInterface>
# Create the UI - a simple resizable Frame window and a single read-only Edit control.
MainFrame = new<Frame(null,0,0,400,180,"Sample Event Script",true)>
MainFrame.AddWindowCloseHandler(MainFrameCloseHandler)
MainFrame.AddWindowResizeHandler(MainFrameResizeHandler)
TimerResultWindow = new<Text(MainFrame,10,55,250,25,"")>
#-------------------------------------------------------------------------------------
# Create the Timer, setup the handler and start it up. The timer alarm event handler
# uses the ITimer interface. We must pass in this "Main" object as ExtraObject.
#-------------------------------------------------------------------------------------
MyTimer = new<Timer()>
MyTimer.AddTimerAlarmHandler(MyTimerInterface,self)
MyTimer.SetAlarm(1000,0)
# Dynamically position the text and then display the window.
UpdateUITextPosition()
MainFrame.Show()
}
method unique MainFrameCloseHandler(WindowCloseEvent MyWindow,Base ExtraObject)
{
# Close the window and shutdown the script.
MainFrame.Close()
exit
}
method unique MainFrameResizeHandler(WindowResizeEvent MyWindow,Base ExtraObject)
{
# Change the vertical position of the single text control based on frame height.
UpdateUITextPosition()
}
method UpdateUITextPosition()
{
data<int> XPos = 10
data<int> YPos
# Calculate Y position of the text control based on frame height and set it.
YPos = (MainFrame.Height() / 2) - 10
TimerResultWindow.SetPos(XPos,YPos)
}
method UpdateAlarmText()
{
data<int> shared Counter
# Increment the shared counter and then update the window.
Counter.Inc()
TimerResultWindow.SetWindowText("Timer alarm event counter is " + Counter.Str())
}
data<Frame> MainFrame
data<Text> TimerResultWindow
data<Timer> MyTimer
}
# Interface class to handle the Timer alarm event.
class TimerInterface from<ITimer>
{
method virtual OnTimerAlarm(TimerAlarmEvent MyEvent,Base ExtraObject)
{
# The "Main" object is passed in as ExtraObject. Convert and update alarm text window.
data<Main> MainObject = ExtraObject as type<Main>
MainObject.UpdateAlarmText()
}
}