Page 1 of 1

EventHandler

Posted: Sat Jul 29, 2017 6:46 pm
by r-tea
I wanted to do a small digital clock MUI window. Buttons do nothing. They're just for trying.

Code: Select all

@VERSION 5,2
@REQUIRE "MUIRoyale", {Link = True}
@FILE 1, "Daysleeper.xml"

@APPTITLE "Daysleeper"
@DISPLAY {Hidden = True}

Function p_EventFunc(msg)

   	Switch msg.Class
  		Case "Window":
      		Switch msg.Attribute
      			Case "CloseRequest":
	 				End
      		EndSwitch
   		Case "Button":
      		Switch msg.Attribute
      			Case "Pressed":
	 				Switch msg.ID
	 					Case "bt1":
							x=x+30
						Case "bt2":
							x=x-30
	 				EndSwitch
	  		EndSwitch
		Default:
			;time$ = GetTime(True)
            mui.Set("tx_time", "contents", GetTime(True))
   	EndSwitch
   
EndFunction

InstallEventHandler({MUIRoyale = p_EventFunc})

mui.CreateGUI(ReadString(1))

; main loop!
Repeat
	WaitEvent
Forever 
XML:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application base="DAYSLEEPER">
   <window title="Daysleeper" muiid="MAIN" notify="closerequest">
    <vgroup>
	 <hgroup frame="text">
      <rectangle/>
      <text id="tx_time" preparse="\33c">00:00:00</text>
      <rectangle/>
     </hgroup>
	 <hgroup>
			<button id="bt1" notify="pressed">button1</button>
			<button id="bt2" notify="pressed">button2</button>
	 </hgroup>
    </vgroup>
   </window>
</application>
I put the mui.Set() in the Default case to execute GetTime() at the end when there is no button pressed message and no application close message. I expected mui.Set() simply will update Text gadget with the current time, but it's not. Where should I put the mui.Set() to make it work?

Re: EventHandler

Posted: Sun Jul 30, 2017 12:13 am
by r-tea
After a while of chasing it within Hollywood docs, I discovered SetInterval() function:

Code: Select all

    Function UpdateTime()
		mui.Set("tx_time", "contents", GetTime(True))
    EndFunction 
...
SetInterval(Nil, UpdateTime,500) 
It works and it was really easy :-)

Re: EventHandler

Posted: Sun Jul 30, 2017 7:03 pm
by jPV
Yeah, as far as I can see, the first version would never go to the Default case. MUI events you get from user input are handled before it, and nothing triggers any MUI event automatically.