Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
mape
Level 7

Really modal dialog

Hello. 

In Scene Graph SDK we have a Dialog component. It looks like a modal, but doesn't behave as a modal in the code.
Here is explatation:
    m.top.dialog = m.dialog

    print "after show", m


"after show" outputs to console immediately. 
So, I must to observe a field and catch dialog closing in event-driven style. 

Can I do REALLY modal dialog, that stops other statement execution while dialog shown? Another words, to make and use function like this:
result = askDialog() ' <- dialog invoked here.


Thank you. 
0 Kudos
11 Replies
EnTerr
Level 8

Re: Really modal dialog

It not only looks - it is a modal dialog. The meaning of a modal dialog is blocking the user interface and not code execution.

You want your code execution to block till it gets dismissed? Sure, no problem - somewhere in the main or a task thread you can do this quick&dirty:
           while myScene.dialog <> invalid
               sleep(500)
           end while

Do not do that in the render thread however, since it would block screen redraws. Under no circumstance should you delay event execution in the render thread (those being init(), observer functions, input handlers) for long-running code. No sleeping in the render thread! Your app may get terminated, or worse.
0 Kudos
mape
Level 7

Re: Really modal dialog

No, the dialog isn't real modal because current thread not stopped. 

I had try to make endless for-cycle in the Scene thread and Dialog thread. 
while True
end while


The render process stopped, as you say. 

So, it seems that I need to make this cycle exactly in render thread. Any ideas?
0 Kudos
EnTerr
Level 8

Re: Really modal dialog

You'll have to change the way you think about this. You'll have to break your code in two pieces - the one "after" the dialog put in a different function, which is observing for change of say myScene.dialog field - or onKeyEvent() one

See if https://sdkdocs.roku.com/display/sdkdoc/Dialogs+Markup can be of help.
0 Kudos
mape
Level 7

Re: Really modal dialog

"EnTerr" wrote:
You'll have to change the way you think about this. You'll have to break your code in two pieces - the one "after" the dialog put in a different function, which is observing for change of say myScene.dialog field - or onKeyEvent() one

See if https://sdkdocs.roku.com/display/sdkdoc/Dialogs+Markup can be of help.

That mean that it is impossible to make real modal dialog. 
Pity. 
0 Kudos
mape
Level 7

Re: Really modal dialog

EnTerr
Thank you for the answers. 
0 Kudos
destruk
Level 10

Re: Really modal dialog

For a fake modal dialog have you considered pausing all the other routines when it is displayed?  That way the render thread would simply be running and not changing anything.
0 Kudos
mape
Level 7

Re: Really modal dialog

"destruk" wrote:
For a fake modal dialog have you considered pausing all the other routines when it is displayed?  That way the render thread would simply be running and not changing anything.

Not all, just the current thread. 
This in not a fake modal dialog, but real Smiley Happy
This is standard behaviour for the modal dialog on traditional systems. 
0 Kudos
EnTerr
Level 8

Re: Really modal dialog

"mape" wrote:
Not all, just the current thread. 
This in not a fake modal dialog, but real Smiley Happy
This is standard behaviour for the modal dialog on traditional systems. 

You don't understand - the render thread is not just any old thread. It is THE thread that draws the UI. THOU SHALT NOT hog the render thread, ever. That is (for Dune fans), "the spice must flow!". Everything you do in scene/component functions/events should be fast and return within milliseconds. Think of every call as a hot potato. You need something more long-lived - do it in main or spin off a Task.
0 Kudos
mape
Level 7

Re: Really modal dialog

EnTerr
Thank you for the answer, but you talk about technical specifics. I trust you and don't argue. 
But I speak about TEORETHICAL behaviour of the modal dialog. How it should be.
If you right, that just means, that make REAL modal dialog (that behaves as modal on other systems) on Roku is impossible. 
0 Kudos