Jump to content

Create a dynamic dialog


---
 Share

Recommended Posts

Hello all ,

 Is it possible to create a dynamic dialog? The number of widgets (columns and rows) depends on the user (project)?

Defined by "gom.script.sys.create_user_defined_dialog" only allows to enter a specific number of items, eg checkbox.

Is it possible to edit the dialog window content after its definition (adding more widgets, editing the number of columns and rows) - change the dialog box format?

Link to comment
Share on other sites

It's possible.

For general information about dialog handling (dynamic and static) please have a look at: https://connect.gom.com/x/DZ-VAg

You must define the dialog with parameter "Extendable break dialog" to enable dynamic behavior by the dialog-event-handler.

image.png.b553d7762d2c8764ccafc0bfffc7957f.png

This code just shows a simple example for reference:

import gom

DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \
' <title>Test Dialog</title>' \
' <style></style>' \
' <control id="OkCancel"/>' \
' <position></position>' \
' <embedding></embedding>' \
' <sizemode></sizemode>' \
' <size width="198" height="191"/>' \
' <content columns="1" rows="4">' \
'  <widget columnspan="1" type="input::checkbox" rowspan="1" row="0" column="0">' \
'   <name>checkbox1</name>' \
'   <tooltip></tooltip>' \
'   <value>true</value>' \
'   <title>Checkbox 1</title>' \
'  </widget>' \
'  <widget columnspan="1" type="input::checkbox" rowspan="1" row="1" column="0">' \
'   <name>checkbox2</name>' \
'   <tooltip></tooltip>' \
'   <value>true</value>' \
'   <title>Checkbox 2</title>' \
'  </widget>' \
'  <widget columnspan="1" type="label" rowspan="1" row="2" column="0">' \
'   <name>text1</name>' \
'   <tooltip></tooltip>' \
'   <text>Text 1</text>' \
'   <word_wrap>false</word_wrap>' \
'  </widget>' \
'  <widget columnspan="1" type="input::string" rowspan="1" row="3" column="0">' \
'   <name>text2</name>' \
'   <tooltip></tooltip>' \
'   <value>Text 2</value>' \
'   <read_only>false</read_only>' \
'   <password>false</password>' \
'  </widget>' \
' </content>' \
'</dialog>')

#
# Event handler function called if anything happens inside of the dialog
#
def dialog_event_handler (widget):
	DIALOG.text1.visible = DIALOG.checkbox1.value
	DIALOG.text2.enabled = DIALOG.checkbox2.value

DIALOG.handler = dialog_event_handler

RESULT=gom.script.sys.show_user_defined_dialog (dialog=DIALOG)

For more information about every single dialog widget you can also use the Python-__doc__-shortcut.

image.png.42b84614eb2042c80c87e18a084b0250.png

Link to comment
Share on other sites

  • 2 years later...
---

Hi everyone,

I need some help with a script I'm working on in GOM Inspect. I'm trying to let the user select an STL file via a custom dialog box, and then import that file into the project. The file path seems to be correctly selected, but the file is not imported, and I keep getting the message: "Dialog canceled or no file selected.".

If anyone could point out what I'm doing wrong or missing, that would be much appreciated!

Here is the code:

 

# 2. Display the user-defined dialog

DIALOG = gom.script.sys.create_user_defined_dialog(dialog={
    "content": [
        [
            {
                "columns": 1,
                "name": "label",
                "rows": 1,
                "text": {
                    "id": "",
                    "text": "Add the STL file before cutting the HMU BLOCK",
                    "translatable": True
                },
                "tooltip": {
                    "id": "",
                    "text": "",
                    "translatable": True
                },
                "type": "label",
                "word_wrap": False
            }
        ],
        [
            {
                "columns": 1,
                "default": "",
                "file_types": [
                    {
                        "description": "All files",
                        "name": "*.stl*"
                    }
                ],
                "file_types_default": "*.stl*",
                "limited": True,
                "name": "file",
                "rows": 1,
                "selection_type": "file",
                "title": {
                    "id": "",
                    "text": "Choose a file",
                    "translatable": True
                },
                "tooltip": {
                    "id": "",
                    "text": "",
                    "translatable": True
                },
                "type": "input::file"
            }
        ]
    ],
    "control": {
        "id": "OkCancel"
    },
    "embedding": "",
    "position": "",
    "size": {
        "height": 163,
        "width": 375
    },
    "sizemode": "",
    "style": "",
    "title": {
        "id": "",
        "text": "Dialog title",
        "translatable": True
    }
})

# Event handler function (currently unused)

def dialog_event_handler(widget):
    pass

DIALOG.handler = dialog_event_handler

RESULT = gom.script.sys.show_user_defined_dialog(dialog=DIALOG)

print("Dialog result:", RESULT)

# 4. Retrieve the 'file' field value
if RESULT == 'ok':
    stl_nominal_path = RESULT.result['file'].value

    # 5. Import the selected STL file
    gom.script.sys.import_stl(
        bgr_coding=True,
        body_split='no_color',
        files=[stl_nominal_path],
        geometry_based_refining=False,
        import_mode='clipboard',
        length_unit='mm',
        stl_color_bit_set=False,
        target_type='cad_body'
    )
else:
    print("Dialog canceled or no file selected.")


Thanks in advance for your help! Let me know if I need to share more of the code.

Edited
Link to comment
Share on other sites

---

Please sign in to view this quote.

try changing to check if name is blank or not selected, your print of RESULT shows it never returns OK

print("Dialog result:", RESULT)

# 4. Retrieve the 'file' field value

if RESULT.file != '':

 

Also change to stl_nominal_path = RESULT.file

  • Like! 1
Link to comment
Share on other sites

  • 1 month later...

Hi Erik,

the old connect is down, please refer to the App Development Documentation (top of forum -> Links). This should be covered in the section for dialogs.

Link to comment
Share on other sites

Thanks Nanno.

What I've basically learned is:

1. Don't store the dialog externally, but make sure it's embedded in the script.

3. The dialog is stored as a JSON-like list (of lists) of dictionaries.

2. Replace the static dictionary values, typically str, int, etc. literals, with your own variable references.

This works well. The only (minor) drawback is that the dialog editor can't open a dialog modified this way.

 

Edited
Link to comment
Share on other sites

 Share

×
×
  • Create New...