Hm, okay. So, the situation is, you have a Cinema app/plugin, but since you use a non-native GUI, you must bridge the gap to your GUI and Cinema native image data.
Please understand that using external UI kits is out of scope of support. Not only because it is a third party library, and because we refuse support for them, but also because we generally do not like it when plugins use other UI tool kits than the native one.
With that being said:
The script I have shown you above would be at least a way to cache command icons. You would have to add a mechanism to avoid having to write all bitmaps to disk every time, and to delete unused ones, because as I explained above, not all commands are static.
For assets I would have to check myself or see some actual code. My base assumption would be that at least bitmap icons of assets can be loaded via BaseBitmap::Init (or InitWith in Python), even when the asset uses an exotic URL such as c4d://[relative:///icon]/5159. Because Python binds to BaseBitmap::Init which expects a cinema::Filename as the first argument, which will be internally converted to a maxon::Url and the Maxon API should then just figure out what you mean with c4d://[relative:///icon]/5159 and load the correct bitmap for you. In asset icons you might also encounter other exotic URL types such as ramdisk urls, zipped urls and more. But in all cases, at least in theory, the unpacking into a BaseBitmap should work from the Python API. For vector icons you will have to wait a bit.
Cheers,
Ferdinand
PS: I am also not sure if serializing to disk is the best way. In C++ it would be for sure not be faster to write everything to disk and then read it back, instead of just converting data in memory. In slow, slow, slow Python, it might actually be faster to write stuff to disk and load it back using the C++ backend, than copying data in Python in memory.
I.e., I mean something like this. But I did it there in the other direction, our GUI wraps alien image data. And not an alien GUI wraps our image data.