Coder Social home page Coder Social logo

Comments (5)

marcsyp avatar marcsyp commented on July 23, 2024

Incidentally, one big improvement in the meantime is to do a check on whether the index of the list exists so that there is no exception and all the other element_id values get set properly anyway -- the user would just have to manually change the script to the one desired. As it stands, the exception of an index higher than the script list item count causes no values to be set, which is rough. Thanks.

from config-presets.

marcsyp avatar marcsyp commented on July 23, 2024

Working Example:

'def config_preset_dropdown_change(dropdown_value, *components_value):
config_preset = config_presets[dropdown_value]
print(f"[Config-Presets] Changed to: {dropdown_value}")

                        # update component values with user preset
                        current_components = dict(zip(component_map.keys(), components_value))
                        #print("Components before:", current_components)
                        current_components.update(config_preset)

                        # transform necessary components from index to value
                        for component_name, component_value in current_components.items():
                            #print(component_name, component_value)
                            if component_name in index_type_components and type(component_value) == int:
                                    if (component_value < len(component_map[component_name].choices)):        # <--------------
                                        current_components[component_name] = component_map[component_name].choices[component_value]

                        #print("Components after :", current_components)
                        
                        return list(current_components.values())'

from config-presets.

wywywywy avatar wywywywy commented on July 23, 2024

Sorry how do you mean? You can already specify the script name. It does have to be a number.

{
    "Ultimate SD Upscale": {
        "script_list": "Ultimate SD upscale"
    }
}

from config-presets.

marcsyp avatar marcsyp commented on July 23, 2024

Yes, exactly -- currently it is stored as an int (index position of the script in the list when the configuration was saved), but if it were stored as the name of the script, as you have demonstrated, the CP logic would need a special IF block to handle the script_list field and search for the name of the script in the list of choices and convert that to the index position, then passing that to the component if an index was found.

from config-presets.

wywywywy avatar wywywywy commented on July 23, 2024

I meant to say it does NOT have to be a number. Setting it to a name already works (though bear in mind it's case sensitive).

This line handles it already.

current_components.update(config_preset)

from config-presets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.