Need to get the objects attached to a dialog

88 views
Skip to first unread message

Frédéric VARASTET

unread,
Jun 22, 2023, 10:57:17 AM6/22/23
to DroidScript
Dear all,
I'm desperatly looking for a way
- either to get all the controls attached to the top-level layout of a dialog, knowing the dialog's id,
- or to get the dialog id of a control (if any), knowing the control's id.

The purpose is to know if a control is currently being displayed on the screen.
Indeed, the property IsVisible does not fully cover that need.
And I found a (stupid by efficient) way to know which dialog is visible, if any.

Of course, you might have guessed that I don't want to modify the script that creates the controls in the dialogs' layouts. In fact I cannot ;)

Can someone help please?
Thanks guys
Fred

Alan Hendry

unread,
Jun 22, 2023, 4:46:12 PM6/22/23
to DroidScript
HI,
To loop thru all objects
    var objs = app.GetObjects();
    for( var i in objs )
    {... }
In the loop get the parent of each object
and compare to the layout for the dialog
Regards, ah

Frédéric VARASTET

unread,
Jun 22, 2023, 4:50:51 PM6/22/23
to DroidScript
Thanks Alan, but...
How can I get the layout of the dialog ?

(Another way would be to get the dialog of a layout?)

Thx
Fred

Alan Hendry

unread,
Jun 23, 2023, 5:40:55 AM6/23/23
to DroidScript
Hi,
The example for creating a dialog is below
the controls are children of layDlg
Regards, ah
function OnStart()
{
    dlg = app.CreateDialog( "Custom Dialog" );

    layDlg = app.CreateLayout( "linear", "VCenter,FillXY" );
    layDlg.SetSize( 0.7, 0.3 );
    dlg.AddLayout( layDlg );

    chk = app.CreateCheckBox( "Check Box" );
    chk.SetMargins( 0, 0.02, 0, 0.02 );
    layDlg.AddChild( chk );

    btnDlg = app.CreateButton( "Close Dialog", 0.6, 0.1 );
    btnDlg.SetOnTouch( btnDlg_OnTouch );
    layDlg.AddChild( btnDlg );

    dlg.Show();
}

function btnDlg_OnTouch()
{
    dlg.Dismiss();
}

Frédéric VARASTET

unread,
Jun 23, 2023, 6:01:00 AM6/23/23
to DroidScript
Thanks again Alan,
Creating a dialog is not an issue.
I need to make the link between the control and the dialog outside of the script creating the dialog.

Based on your example, let us suppose we have stored chk and dlg, how can we know that chk is in dlg?
The problem with GetParent is that chk.GetParent() returns the id of the layout layDlg, but layDlg.GetParent() returns null, with no link to dlg or its id.
How are managed dialogs and layouts, inside DS ?

(For your info, my app is a kind of spy of my other existing apps, and I would like to know when a control is displayed or not, knowing when its dialog is displayed or not)

Thank you
Fred

Alan Hendry

unread,
Jun 23, 2023, 6:50:27 AM6/23/23
to DroidScript
HI,
Presuming you have the source code ...
layDlg references the layout,
so use GetObjects to loop thru all objects and check if the objects parent is layDlg.
You may need to make layDlg a global variable.
If you are trying to write a general purpose tool, 
you've gotta find the dialog(s) first, (you can check if they are visible)
Not sure why layDlg.GetParent is null, that'll require the official/technical team.
I don't see a method to get the child layouts of a dialog.
Also not sure why dialogs have GetParent.
Regards, ah
Reply all
Reply to author
Forward
0 new messages