Your Digital Media Has Never Looked So Good

 
rsromeo
Topic Author
Posts: 103
Joined: Wed Jun 02, 2010 4:25 pm

Dialog and Closing App

Sun Nov 12, 2017 8:07 am

Hi, just getting started with SG, I'm old school SDK trying to catch up.  I'm trying to launch a dialog and when user clicks OK, it ends the app.  I was trying to use the "dialog example" from Roku.
So what I do is call the below sub which displays the dialog shown in XML file below.  My problem is once user clicks OK, I want to close the app.  Right now, when I click OK, nothing happens because its doing nothing but returning Boolean value.  I'm not sure what I need to call at this point to kill the app.  I tried a roUrlTransfer call but it errors out on the SetUrl property ("http://localhost:8060/keypress/Home").  I assume this type of call won't work in the onKeyEvent so do I need to return focus somehow to the screen so I can close it?
Any help would be appreciated.
sub showChannelSGScreen()
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("DialogExample")
  screen.show()
  while(true)
    msg = wait(0, m.port)
    msgType = type(msg)
    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed()
      end if
    end if
  end while
end sub

XML FILE
<component name = "DialogExample" extends = "Scene" >
  <script type = "text/brightscript" >

    <![CDATA[

sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
      m.top.setFocus(true)
      showdialog()
end sub

    sub showdialog()
      dialog = createObject("roSGNode", "Dialog")
      dialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
      dialog.title = "My title"
      dialog.optionsDialog = true
      dialog.message = "Press * To Dismiss"
      m.top.dialog = dialog
      m.top.setFocus(true)
    end sub

function onKeyEvent(key as String, press as Boolean) as Boolean
  if press then
    if (key = "OK") then
    return true
    end if
end if
return false
end function
    ]]>
  </script>

</component>
 
tim_beynart
Posts: 171
Joined: Wed Jul 15, 2015 8:30 am

Re: Dialog and Closing App

Mon Nov 13, 2017 8:15 am

You need to tell the source/main.brs loop to exit, here's some crude and untested code that might do the trick

m.scene.findNode("myExitDialog").observeField("pleaseExitNow",m.port)
while true
  msg = wait(0, m.port)
  if type(msg) = "roSGNodeEvent"
   if msg.getField() = "pleaseExitNow"
   'close the loop, kill the app
     return
   end if
  end if
end while
 
rsromeo
Topic Author
Posts: 103
Joined: Wed Jun 02, 2010 4:25 pm

Re: Dialog and Closing App

Mon Nov 13, 2017 10:51 am

Thanks, will give it a try but I guess I have to add the node to the diaglogexample.xml file?  How do you do that?

Who is online

Users browsing this forum: No registered users and 4 guests