Confusion about GUI source code

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
rslaav
Posts: 25
Last visit: Sat Oct 01, 2022 6:11 am
Has voted: 2 times

Confusion about GUI source code

Post by rslaav »

Product, version and build: DevOps suite
Operating system: Windows 10
PowerShell version(s): Latest

I am curious about the source code when creating GUIs using powershell Studio. I decided to try making a Menu Form, and the default items that show up are File, Edit, Help. I had a look at the script in Powershell Studio, and there's nothing in it that shows me these items. So I decided to add a new element in the Menu called "testing", such that it would be File, Edit, Help, Testing. Yet again, the source I was viewing in Powershell remained the same.

I got a little upset, so I opened the PSF using notepad, and noticed the script is preceded by a bunch of XML, one of which is <FORM> followed by a bunch of stuff </FORM>. I can't make the slightest sense of what's inside those XML tags, and It basically leaves me without the ability to programmatically modify the menu items. Let's say I were to use a different program in the future to modify a snippet of code related to the menu, it would become impossible.

I am wondering what that stuff is, and what I can use to actually work with that code, apart from the visual-designer in Powershell Studio. Another issue would be if someone else needed to review my code, and they don't have a copy of Powershell Studio, it would just look like gobbledygook to them.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Confusion about GUI source code

Post by Alexander Riedel »

No reason to be upset. There is, for one, a misunderstand how this works. And secondly slight misplaced expectations :D
The form data is store in the PSF as XML, yes. Has to be that way because the .NET framework designer does not understand PowerShell. It understands objects and those are just simply best serialized and de-serialized in XML. There is nothing nefarious about this. Simply put, you should never have any reason to look at a PSF in text mode. More on that later.
When you run a GUI script or package a GUI script, PowerShell Studio is generating the code from the xml alongside your custom code, e.g. event handlers into a final PS1 and runs or packages that.
You can always export your script as a PS1 and see the actual code. So you can use that if someone really needs to review your entire code (custom and generated)
Just to be clear, you can not re-import any modified exported script after making changes there. It doesn't work that way.

Now for the mismatched expectations. If you would use XAML in the future to design your UI, you would have to put up with the "gobbledygook", as you call it, of the XML that is XAML. Us ancient C/C++ developers use resource files to save GUI specifications and that is not even remotely C or C++. If you were to use Microsoft Visual Studio, you would not expect to be able to re-use your solution and project files in a third party IDE sometime in the future. Even using Microsoft Word documents in anything else but Microsoft Word is somewhat hit and miss, open standards be damned.
Just like you would not look at a .docx file in Notepad, you should not look at a .PSF file in Notepad. It serves no purpose.
Yes, if you decide to collaborate with someone on a PowerShell GUI project, they should have the same software. That is true for virtually all software development north of command line tools.
Alexander Riedel
SAPIEN Technologies, Inc.
rslaav
Posts: 25
Last visit: Sat Oct 01, 2022 6:11 am
Has voted: 2 times

Re: Confusion about GUI source code

Post by rslaav »

I see, thank you for that response. So if I were to make my stuff open-source and available freely on a public git repo, I would essentially have to export everything to PS1 for the GUI to be modifiable by anyone else? And at that point I wouldn't be able to convert it back to PSF, which kind of forces anyone who wishes to modify my code to have a license of Powershell Studio. I wish you guys had a community edition for this purpose. I love supporting SAPIEN, you guys make cool products, but I am still trying to figure out a way to share my work with people who might find it useful and have the ability to provide some suggestions and input.

I am gonna try to write my code such that if someone is running it from a powershell-only server, it will not attempt to load a GUI, but otherwise do so. It's gonna be interesting trying to come up with a menu in a poweshell-only mode with no GUI. Anyone have any resources on that? Thank you kindly. :)
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Confusion about GUI source code

Post by Alexander Riedel »

For open source you would have to use the exported PS1, yes. I mean you can include the PSF of course. And yes you need a PowerShell Studio license to use that.
You should probably make sure that the code you wrote is clearly marked as the 'modifiable' part.
As for non GUI menu code, I think there was a module for that purpose I have seen somewhere. I do not recall the name, only that something exists. Sorry.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.