I have created a simple GUI for use in my RPi. When it opens, a countdown from 10 begins and when reaching 0 it should run the shutdown command:
Code: Select all
Run("/usr/sbin/shutdown", "-h now")
Code: Select all
Run("gimp", "")
Any Linux guru here that can help me?
My crontat -l:
Code: Select all
30 01 * * * DISPLAY=:0.0 /home/pi/Desktop/shutdowngui
Code: Select all
@REQUIRE "RapaGUI", {Link = True}
@DISPLAY {Width = 320, Height = 200, FillStyle = #FILLCOLOR, Color = #GRAY}
timeLeft$ = "10" ;Countdown start
Function p_EventFunc(msg)
Switch msg.Class
Case "Button": ;This is the only class for events, but just in case...
Switch msg.Attribute
Case "Pressed":
Switch msg.ID ;Check which button was pressed
Case "btn_Cancel": ;"Cancel" button was pressed
End() ;End program and cancel shutdown
EndSwitch
EndSwitch
EndSwitch
EndFunction
/*******************
* Main function *
*******************/
Function p_CountDown()
timeLeft$ = timeLeft$ - 1 ;Reduce countdown time
Cls() ;Clear display
TextOut(#CENTER, #CENTER, timeLeft$) ;Display new time
If timeLeft$ = 0 ;If countdown ends...
Run("/usr/sbin/shutdown", "-h now") ;Shutdown system
End() ;End program
EndIf
EndFunction
InstallEventHandler({RapaGUI = p_EventFunc})
moai.CreateApp( ;Create GUI from file
[[<?xml version="1.0" encoding="utf-8"?>
<application>
<window title="ShutdownGUI">
<vgroup>
<label align = "Left">Raspberry will shutdown in:</label>
<hollywood display="1"/>
<hgroup>
<rectangle/>
<button id = "btn_Cancel">Cancel</button>
<rectangle/>
</hgroup>
</vgroup>
</window>
</application>
]]
)
SetFont(#SANS,56)
SetFontStyle(#ANTIALIAS)
TextOut(#CENTER, #CENTER, timeLeft$) ;Display initial countdown time
SetInterval(1, p_Countdown, 1000) ;Run countdown with 1 second interval
Repeat
WaitEvent()
Forever