Re: Ideas to store add-on state.


Pawel Urbanski
 

Thank you for the suggestion. I decided to go the 'appModule' instance
route. This time, I did it properly with the super method and
inheritance and so on.
Unfortunately Pylance of VS Code kept throwing errors about missing
type when parsing the expression of:
self.appModule.InstanceVariableName
I guess it is due to different capitalization and the fact that
'appModule' with a small 'a' is a runtime property of classes in the
add-on runtime.

All in all, things are working well and I even managed to remove that
code part but still use instance variables for other cases.

I posted about the updated VS Code add-on. Thank you once again.

Best,
Pawel

On 6/21/22, James Scholes <james@...> wrote:
If you have state that only needs to be utilised during the add-on's
runtime, and not persisted, I would just store it on the AppModule or
GlobalPlugin instance:

class AppModule(appModuleHandler.AppModule):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._someStateFlag = False
self._someOtherStateFlag = 14
# or
self._state = {'flag1': False, 'flag2': 14}

Is there a reason why this wouldn't be sufficient?

Regards,

James Scholes

On 21/06/2022 at 11:20, Pawel Urbanski wrote:
Dear Everyone,
Since I still occasionally use Visual Studio Code and nobody followed
up with my request to take over the development, I am working on
updating the add-on.
I am looking for hints and inspiration on how to best keep add-on
state. It does not need to be saved but needs to work when the
application is running. I use it to store some add-on flags and state.
Is there anything in NVDA api like this or maybe you cane up with a
working way to share global state. There is the configuration class
but I don't know if it can be made local to the add-on running
instance in the scope of the AppModule class - please treat this
example as explanatory not in terms of working code.

Thank you for any hints...
Pawel








Join nvda-addons@nvda-addons.groups.io to automatically receive all group messages.