How to create presets


My motivation is to get these styles to presets.

Does somebody used presets for styling for an add-on? or knows an add-on that does? So a user can click or select the preset and there is nothing else to be done by the user. Alternatively, there is the possibility to make a user custom settings via add-on config.

I don’t know if there is an add-on that does it, but implementing that functionality is easy. Try the following:

  1. Create presets folder in the root of your add-on, then put some preset files(json) in the folder.
  2. Create, then put the following code into it:
    import pathlib
    import json
    import aqt
    from . import config
    def load_json(path: pathlib.Path):
            with as f:
                return json.load(f)
        except BaseException:
            return None
    def on_preset_selected(path: pathlib.Path):
        preset = load_json(path)
        if preset:
  , preset)
    def create_addon_menu() -> aqt.QMenu:
        addon_menu = aqt.QMenu('Show total review count in main screen',
        preset_menu = addon_menu.addMenu('Choose a preset ...')
        presets_path = pathlib.Path(__file__).resolve().parent / 'presets'
        for file_path in sorted(presets_path.glob('*.json')):
            act = preset_menu.addAction(file_path.stem)
                lambda _, path=file_path: on_preset_selected(path))
        return addon_menu
  3. Import in

Below is a demo video(gif):


Wow, that is far more than I expected. Thank you so much for taking some of your time. I’ll try it out.

No problem, glad if it helped.

1 Like