How do I structure a program with a lot of windows (forms)?

You need some new stunning features ? Tell us here.
OgreVorbis
User
User
Posts: 77
Joined: Thu Jan 16, 2020 10:47 pm

How do I structure a program with a lot of windows (forms)?

Post by OgreVorbis »

So I have a few years experience in PB, but I have not yet made a program that has many windows until now. I have my event loop for the main window in my main source file; in this same file is where I put all my functions. I use the form designer to make new windows, but it tells me not to place the code/events in the same .pbf file because it will get overwritten when the form changes (I confirmed this to be true). So, I end up putting my event loops for the other windows in my main source file. Now my main event loop has expanded and contains sub "Select" commands and cases. I can see that as this project expands, it will become bloated. But then what do I do? Make two files for every window; one with events/functions and another with the auto-generated form code? This seems junky, but I guess it's passable.

So how do you structure your large window based projects?

Also PB, WHY do you delete code put at the end of the window? Can't the compiler be a little smarter than that? It allows me to manually edit the form generation code, so why not just leave anything at the bottom of the file intact?
My blog/software site: http://dosaidsoft.com/
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: How do I structure a program with a lot of windows (forms)?

Post by Fangbeast »

My old project has 40 windows currently and it will end up being 70. Currently is around 80,000 lines of code and may get to over 100,00 which is huge for an old bloke like me.

I like PB's form designer but I use purevision which builds form and constants cone into two separate files. "projectname_constants.pb" and "projectname_windows.pb". "projectname is just an example here.

You can tell it to output the event loop code and it produces "projectname.pb" which you can then tell it to NOT do it the next time it exports the constants and windows files so it doesn't overwrite the main file.

The constants and windows pb files contain ALL the constants and windows code for ALL of your windows, gadgets etc and there is never any need to edit that.

You do all your work tying them together in the "projectname.pb" file. The checkbox for this main file is off by default so that you don't accidentally overwrite your main file. You should not have to export it again unless you make huge changes to your code (like I do!!) but then manually add in all the other gadgets/events to it.
Amateur Radio, D-STAR/VK3HAF
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: How do I structure a program with a lot of windows (forms)?

Post by Joris »

Why not using MDIGadget() ?
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How do I structure a program with a lot of windows (forms)?

Post by mk-soft »

I also use the FormDesigner for many windows. But I switch off #PB_Any and the 'Generate event procedure'.
Then I write the event management myself by hand.

To save myself the work, I have written an EventDesigner that creates all the necessary procedures and event management from many form files. It also adapts to subsequent changes and extensions.

See signature.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
OgreVorbis
User
User
Posts: 77
Joined: Thu Jan 16, 2020 10:47 pm

Re: How do I structure a program with a lot of windows (forms)?

Post by OgreVorbis »

mk-soft wrote: Sun Mar 27, 2022 2:59 pm I also use the FormDesigner for many windows. But I switch off #PB_Any and the 'Generate event procedure'.
Then I write the event management myself by hand.
Are you saying that if you do that it will allow you to write the event loop in that .pbf file? Cause that would be the most intuitive for me.
This may be a stupid question, but if I make an enumeration for the gadget numbers, can they be the same numbers as other forms? My guess is no. In that case, does that mean I need to make one enumeration for every gadget on every window so they are all unique? Are enumerations global?

In your opinion, how many lines in one file is too much? Is 1000-2000 reasonable?

I will check out your event designer.
My blog/software site: http://dosaidsoft.com/
OgreVorbis
User
User
Posts: 77
Joined: Thu Jan 16, 2020 10:47 pm

Re: How do I structure a program with a lot of windows (forms)?

Post by OgreVorbis »

:twisted: I just realized something that is probably unkosher?
I figured out that IncludeFile pulls other code files into the same scope as the main file. When I first started this program, I didn't plan on it getting large, so I just used variables on the fly without declaring them. I don't normally do that. But anyway, I thought this means that separating my code for different windows into other files would make a lot of the variables and procedures go out of scope, but it DOESN'T.

So I could just IncludeFile in my Select Case for the separate windows and it would just work haha.

How bad is that?
My blog/software site: http://dosaidsoft.com/
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How do I structure a program with a lot of windows (forms)?

Post by mk-soft »

No, do not write anything yourself in the form file, as this is always overwritten.

The FormDesigner uses named enumeration for constants. This prevents the window and gadget numbers from overlapping.
Unfortunately, the FormDesigner is not quite perfect here and always uses the same number for Menu and StatusBar.

This is corrected in the EventDesigner and creates a common form file (GuiCommonFile.pb) from the form files.

To process the events from the individual forms, move the query to Procedure and call the procedures in the event loop. THERE MAY ONLY BE ONE WaitWindoEvent().

Since the constants are consecutive numbers, I use virtual tables in the EventDesigner to call the correct procedure for the event.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: How do I structure a program with a lot of windows (forms)?

Post by ChrisR »

You can have a look at the little demo of my GUI Designer: how to create an application with several windows.

For the name of the controls, there is an option to add the window name to the variables or constants names and thus distinguish them more easily if you have several windows. Also have different constant names for the menu, toolbar or StatusBar.
And with the options "Bind All Gadget Events" and "Bind Events in an Include File", the events will be written in a separate source file for each window, for a better organization, structure.
Also you can use the "Add Compiler IsMainFile" option to keep only the event loop of your main window.
You can test it in the demo version (link in 1st post), limited to 16 Gadgets, to get a better idea of all the possibilities.
zikitrake
Addict
Addict
Posts: 833
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: How do I structure a program with a lot of windows (forms)?

Post by zikitrake »

Fangbeast wrote: Sun Mar 27, 2022 5:24 am...but I use purevision which builds form and constants cone into two separate files...
I'm in a similar situation, Purevision has been my "salvation" for the last few years.

Being able to open a forms project and work with multiple windows without having a .PBI for each of them is what makes me keep using it ahead of the great IceDesigner by @ChrisR (of which I have my paid copy but, personally, I find it very uncomfortable to have a file for each window).
Post Reply