EventHandler

Discuss GUI programming with the MUI Royale plugin here
Post Reply
User avatar
r-tea
Posts: 62
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

EventHandler

Post by r-tea » Sat Jul 29, 2017 6:46 pm

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?

User avatar
r-tea
Posts: 62
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: EventHandler

Post by r-tea » Sun Jul 30, 2017 12:13 am

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 :-)

User avatar
jPV
Posts: 134
Joined: Sat Mar 26, 2016 11:44 am
Location: RNO
Contact:

Re: EventHandler

Post by jPV » Sun Jul 30, 2017 7:03 pm

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.

Post Reply