This change introduces a SettingsDict – a dictionary tied to a list of Setting objects which describe the keys and their types. The extension is now defined as:
# Store is subclass of Extensible
class MyStore(Store, name="my"):
extension_desc = "My custom store. It limits number the queries."
extension_settings = [
Setting("url", "string", desc="Connection URL),
Setting("query_limit", "integer", desc="Max number of rows returned", default=1000),
]
url: str
query_limit: int
def __init__(self, url: str, query_limit: int):
self.url = url
self.query_limit = query_limit
The extension can be initialized by two ways:
create_with_dict(mapping: Mapping[str, Any]) – accepts any kind of mapping, the values are coalesced/cast to the appropriate setting value types. This method is unlikely to be overriden by subclasses.
create_with_settings(settings: SettingsDict) – creates an instance of the extension using already well typed dictionary of setting values. This method might be overriden by subclasses to customize conversion of values that need to be passed to the __init__() method if they differ from advertised settings.
One can see all the details of extensions by running: slicer extension TYPE NAME. To list all extensions: slicer extension TYPE or just slicer extension.
This change introduces a
SettingsDict
– a dictionary tied to a list ofSetting
objects which describe the keys and their types. The extension is now defined as:The extension can be initialized by two ways:
create_with_dict(mapping: Mapping[str, Any])
– accepts any kind of mapping, the values are coalesced/cast to the appropriate setting value types. This method is unlikely to be overriden by subclasses.create_with_settings(settings: SettingsDict)
– creates an instance of the extension using already well typed dictionary of setting values. This method might be overriden by subclasses to customize conversion of values that need to be passed to the__init__()
method if they differ from advertised settings.One can see all the details of extensions by running:
slicer extension TYPE NAME
. To list all extensions:slicer extension TYPE
or justslicer extension
.