Your Digital Media Has Never Looked So Good

 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Really modal dialog

Mon Mar 27, 2017 1:41 am

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. 
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Really modal dialog

Mon Mar 27, 2017 12:20 pm

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.
 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Re: Really modal dialog

Tue Mar 28, 2017 3:41 am

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?
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Really modal dialog

Tue Mar 28, 2017 8:24 pm

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.
 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Re: Really modal dialog

Wed Mar 29, 2017 12:36 am

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. 
 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Re: Really modal dialog

Wed Mar 29, 2017 12:37 am

EnTerr
Thank you for the answers. 
 
destruk
Posts: 2720
Joined: Sat Dec 18, 2010 4:58 pm

Re: Really modal dialog

Wed Mar 29, 2017 8:35 am

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.
 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Re: Really modal dialog

Thu Mar 30, 2017 4:40 am

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 :)
This is standard behaviour for the modal dialog on traditional systems. 
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Really modal dialog

Thu Mar 30, 2017 11:01 am

mape wrote:
Not all, just the current thread. 
This in not a fake modal dialog, but real :)
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.
 
User avatar
mape
Topic Author
Posts: 17
Joined: Mon Mar 13, 2017 12:53 am

Re: Really modal dialog

Fri Mar 31, 2017 12:32 am

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. 
 
belltown
Posts: 1465
Joined: Thu Dec 09, 2010 1:43 pm
Contact:

Re: Really modal dialog

Fri Mar 31, 2017 9:54 am

The defining characteristic of a modal dialog is that it prevents user interaction with the rest of the UI until the dialog is dismissed. And if the user REALLY can't interact with the rest of the UI until the dialog is dismissed then you have a 'REALLY modal dialog'. The Scene Graph Dialog component provides a 'REALLY modal dialog'.

You need to understand a fundamental principle of Scene Graph architecture: The render thread is completely, 100% event-driven. The init() function registers event handlers. The rest of the code in a component defines the event handlers, which get called in response to specific events. This is not the type of architecture where you have a main program loop that waits for user-input, processes the input, then goes back to waiting for the next input, etc. Your program code never waits (nor executes) until the system detects an event that it needs to handle (e.g. a button-click), then calls the appropriate event-handling function, which handles the event, then exits. If you understand that already, then great. If not, you have some more studying to do.

JavaScript browser applications work exactly the same way -- with one exception: They allow functions such as prompt() and alert() to block the render thread while waiting for user input. It sounds to me like the question you're really asking is: "Can a Scene Graph render thread block while waiting for user input?" The answer to that question is unequivocally, NO. The reason is that Roku chose not to allow it, whereas the JavaScript creators did choose to allow it. There may be any number of reasons for their respective decisions, but that's just the way it is. REALLY.
https://github.com/belltown/
 
User avatar
RokuNB
Posts: 465
Joined: Fri Mar 31, 2017 2:22 pm

Re: Really modal dialog

Fri Mar 31, 2017 5:45 pm

^^^ What he said :)

Who is online

Users browsing this forum: No registered users and 8 guests