Modify value in `SlicerLauncherSettings.ini` from application

Hi,

Is it possible to set value to SlicerLauncherSettings.ini from application?
For example:

slicer.app.setEnvironmentVariable("SLICER_HOME", "/my/path")

will modify SLICER_HOME env var but it doesn’t change the value in SlicerLauncherSettings.ini.

You can access/modify the SlicerLauncherSettings.ini file at multiple levels:

  • as any other text file, using standard file read/write functions
  • as a Qt settings file (QSettings settings(fileName, QSettings::IniFormat);)
  • as a CTK launcher settings ini file, using CTKApLauncherLib’s ctkAppLauncherSettings class
1 Like

Thank you for the response,

First I tried to use ctkAppLauncherSettings as it is done in qSlicerCoreApplication but then I understood that ctkAppLauncherSettings doesn’t privide API to overwrite values in file. To do that I would need to work with settings as with usual textual file.

I decided to use userSettings (QSettings class) for now:

QSettings* settings = app->userSettings();
settings->setValue("MyKey", "FALSE");

By the way I don’t know should this work or not but it doesn’t:

settings=qt.QSettings(slicer.app.launcherSettingsFilePath, 1)  # 1 is QSettings::IniFormat I could not find this enum in python

I expected that settings retrieves information from slicer.app.launcherSettingsFilePath .ini file and I could work with it as with QSettings.

But settings.allKeys() returns empty list.

And settings.fileName() shows
'/home/kerim/.config/home/kerim/Documents/Colada/Colada-0.1.0-2022-04-17-linux-amd64/bin/ColadaLauncherSettings.ini/1.conf'

While slicer.app.launcherSettingsFilePath returns
'/home/kerim/Documents/Colada/Colada-0.1.0-2022-04-17-linux-amd64/bin/../bin/ColadaLauncherSettings.ini'

As you can see settings.fileName() adds /1.conf at the end.
Am I misunderstanding something?

As I understand there is a constructor QSettings(const QString & fileName , QSettings::Format format , QObject * parent = nullptr) but it works somehow strange

It works for me perfectly if I use the proper Qt constant:

>>> settings=qt.QSettings(slicer.app.launcherSettingsFilePath, qt.QSettings.IniFormat)
>>> settings.allKeys()
('Application/arguments', 'Application/name', 'Application/organizationDomain', 'Application/organizationName', 'Application/path', 'Application/revision', 'Environment/additionalPathVariables', 'EnvironmentVariables/ITK_AUTOLOAD_PATH', 'EnvironmentVariables/PIP_REQUIRE_VIRTUALENV', 'EnvironmentVariables/PYTHONHOME', 'EnvironmentVariables/PYTHONNOUSERSITE', ...
1 Like

Thank you very much!

Your approach works
I didn’t know that there might be a difference between passing the value 1 and qt.QSettings.IniFormat.