0

I have a dictionary with information :

Facets = {
    'Entity'        : {'facet_type': 'Entity'        , 'facet_parameters': ['IFC Class'   , 'Predefined Type']},
    'Attribute'     : {'facet_type': 'Attribute'     , 'facet_parameters': ['Name'        , 'Value']},
    'Classification': {'facet_type': 'Classification', 'facet_parameters': ['System'      , 'Value']},
    'Property'      : {'facet_type': 'Property'      , 'facet_parameters': ['Property Set', 'Name', 'Value']},
    'Material'      : {'facet_type': 'Material'      , 'facet_parameters': ['Value']},
    'Parts'         : {'facet_type': 'Parts'         , 'facet_parameters': ['Entity'      , 'Relationship']}
}

I want to create an (IDS) editor using pySimpleGUI. People should select the facet_type and then be able to enter the facet_parameters themself.

so in layout the following allow them to select the correct facet_type :

layout = [[sg.Text('All elements of'), 
           sg.Combo(sorted(Facets.keys()),key='-FACET-', enable_events=True)]]

And then in the while loop I want that for each parameter in the facet parameters, it gives an imput box but I cant do it

window = sg.Window('IDS', layout,resizable=True)

while True:
    event, values = window.read()
    
    if event == sg.WINDOW_CLOSED:
        break
    elif event == '-FACET-':
        selected_facet = values['-FACET-']
        facet_parameters = Facets[selected_facet]['facet_parameters']

So far I am stuck here and can't produce any piece of code that would update the layout to add something like that (screenshot to explain) :

Screenshot showing the desired result

Thank you for your time.

1 Answer 1

2

If the values for dict Facets are fixed, you can build the layout for all elements when initial, just set only which one visible.

import PySimpleGUI as sg

def column_layout(category):
    items = Facets[category]['facet_parameters']
    layout = [[sg.Text(item), sg.Push(), sg.Input(key=(category, item))] for item in items]
    return layout

Facets = {
    'Entity'        : {'facet_type': 'Entity'        , 'facet_parameters': ['IFC Class'   , 'Predefined Type']},
    'Attribute'     : {'facet_type': 'Attribute'     , 'facet_parameters': ['Name'        , 'Value']},
    'Classification': {'facet_type': 'Classification', 'facet_parameters': ['System'      , 'Value']},
    'Property'      : {'facet_type': 'Property'      , 'facet_parameters': ['Property Set', 'Name', 'Value']},
    'Material'      : {'facet_type': 'Material'      , 'facet_parameters': ['Value']},
    'Parts'         : {'facet_type': 'Parts'         , 'facet_parameters': ['Entity'      , 'Relationship']}
}

categories = sorted(Facets.keys())
category = categories[0]

sg.set_options(font=("Courier New", 12))
sub_column = [[sg.Column(column_layout(category), visible=(i==0), key=category) for i, category in enumerate(categories)]]
layout = [
    [sg.Push(),
     sg.Text('All elements of'),
     sg.Combo(categories, default_value=category, enable_events=True, key='-FACET-'),
     sg.Push()],
    [sg.Column(sub_column)],
]
window = sg.Window('Title', layout)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    elif event == '-FACET-':
        window[category].update(visible=False)
        category = values[event]
        window[category].update(visible=True)
        window.refresh()
        window.move_to_center()

window.close()

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, I was also trying to display a default value of None, and was wondering with this code how would you hide the sub_column then ?
Also, do you use sorted(Facets.keys()) to get a list list from the dict keys easily ? And if so, are there other methods to do this (let's say without changing the order of display)
You can add one more Column element with empty layout into sub_column, like category = "None"; sub_column = [[sg.Column([], key="None")] + [sg.Column(column_layout(category), visible=False, key=category) for i, category in enumerate(categories)]].
To get the list from dict keys without changing the order of display, you can do it by `list(Facets.keys()).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.