Access perspective theme folder in web dev python endpoint

Hi

I want to get access to the theme folder of perspective web dev, in a python endpoint.
What is the correct URL and syntax for that?
For example, the http://gatewayIP:8088/main/myfile.xxx give me access to the ignition webserver folder but there is no doc for the theme folder.

If you look around the forum for the IgnitionGateway method, you can use it to retrieve the SystemManager, which has a getDataDir() method - that method will give you the start of a tree, which you could walk down to get to the themes directory.

2 Likes

Thanks Paul
Could you please write a short snippet code for me. To show how to import and use it. I’m not java export.

From:

themes = context.systemManager.dataDir.toPath().resolve("modules").resolve("com.inductiveautomation.perspective").resolve("themes")

system.file.readFileAsString(themes.resolve("dark.css").toAbsolutePath())
1 Like

Hi Paul,
I get this error:


I cant get IgnitionGateway object.

This would only be possible executing in gateway scope.

Is console run code in gateway scope?
By the way how about web dev scope? is it gateway scope or not?

WebDev is gateway scope. The console is not (it’s designer, which is like client, but a little different because it’s in the designer).

1 Like

I am able to run this in a Perspective session scope to see the contents of the theme files:

from com.inductiveautomation.ignition.gateway import IgnitionGateway
context = IgnitionGateway.get()
filePath = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/modules/com.inductiveautomation.perspective/themes/dark.css'
return system.file.readFileAsString(filePath)
2 Likes

Did something change since Mar 2021? I'm trying to access the themes directory using this script on a tag event change:

	themes = context.systemManager.dataDir.toPath().resolve("modules").resolve("com.inductiveautomation.perspective").resolve("themes")
	themeFile = system.file.readFileAsString(themes.resolve("dark.css").toAbsolutePath())
	
	system.util.getLogger('ThemesLogger').info("The theme file contents: {}".format(themeFile))

and I get this error in the gateway logs:

I also tried the other method that should be able to be used from a designer script console, but I get an error ImportError: cannot import name IgnitionGateway.

from com.inductiveautomation.ignition.gateway import IgnitionGateway
context = IgnitionGateway.get()
filePath = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/modules/com.inductiveautomation.perspective/themes/dark.css'

print system.file.readFileAsString(filePath)

No, nothing changed.

Your first script is complaining that context isn't defined.

Your second script would never work in the Designer script console, you can't reference gateway-scoped classes from there.

Yeah, that's what the error is telling me... Do I need to instantiate or call context somehow? This is literally a snip from a post in this thread, so I'm not too familiar with the context the OP was working in...

It was probably this:

it would work in a tag event script, but not in the Designer.

Perfect! One last question: I have this script working in the tag event script:

from com.inductiveautomation.ignition.gateway import IgnitionGateway
context = IgnitionGateway.get()
themes = context.systemManager.dataDir.toPath().resolve("modules").resolve("com.inductiveautomation.perspective").resolve("themes")
filePath = "themes: {}, type(themes): {}".format(themes, type(themes))

system.tag.writeBlocking(["[default]themesDS"], filePath)

I'm looking to get the list of themes programmatically, just like there is a list in the designer. Is there a method that will retrieve the files and folders located at \themes, which I'll then check for extensions on?

Look at the Files utility class, full of static methods that accept a Path object like themes in your code:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html

1 Like