NimarkoGram Docs
RU
Docs/Plugin settings

Plugin settings

Build switches and inputs, and persist user preferences.

On this pageAdd a switchChoose a rowWrite from code

Add a switch

Return a list of rows from create_settings(). Each stored value needs a stable key. Use the same key and default in the settings row and in the code that reads the preference.

Python
from ui.settings import Switch

# Methods of your BasePlugin subclass
def create_settings(self):
    return [Switch(key="show_hint", text="Show hint", default=True)]

def hints_enabled(self):
    return self.get_setting("show_hint", True)

Choose a row

Class from ui.settings Purpose
Header(text) Names a group of settings.
Switch(key, text, default) Stores a boolean.
Selector(key, text, default, items) Selects a list item by its zero-based index.
Input(key, text, default) Stores text.
Text(text, on_click=...) Runs an action. Its callback receives an Android View.
Divider(text) Separates rows, with optional explanatory text.

Write from code

self.set_setting("show_hint", False, reload_settings=True) saves the value and requests a refresh of the plugin settings. When a refresh is unnecessary, use the first two arguments alone.