PureBasic 5.41 Form Designer - multiple forms example wanted

You need some new stunning features ? Tell us here.
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

PureBasic 5.41 Form Designer - multiple forms example wanted

Post by agb2008 »

Hello !
I am just trying to get use to new development environment (PureBasic) switching from B4J because of need to build
native applications without side dependencies... Overall I was able to solve main issue with just main code conversion
but unfortunately i am stack with GUI development procedures. I've checked forums, help files, e.t.c. but so far I am
getting a bit misleading info: either there was some kind of change in the form designer itself that affect code building
procedures or it seems that people prefer to just avoid using designer at all, or (that's also could be the case) I am for
some reason can't find proper tutorial or examples for it.

What I am trying to find is an example (real life example that could be loaded into PureBasic 5.41 for examination) of
demo application that consist of two independent forms, main code file and events files (.pb files with events - one for
each forms - from what i could see that's seems to be the best coding practice - or not ?)

Could anyone please share an example code or manual/tutorial describing steps need to create such configuration ?
Forms could be quite simple - just probably two buttons, string and text gadgets on each of the forms. Main issue is to
understand how to build together such configuration, how to handle events for each of the gadgets from both forms,
what options have to be switched on/off to avoid code corruption (famous generate event loop / generate event procedures)

Could you please advice ? it's much easier to learn by example !

Thank you beforehand !
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by Marc56us »

This is exactly what is in the example of the documentation: :)

Using the form designer in real world projects
'...For example, to build a program which handle two windows, we will have to create two form files and one main file...'

http://purebasic.com/documentation/refe ... _form.html
or hit F1 in IDE and follow: The PureBasic IDE / Form designer
(scroll down to the middle of the page)

:wink:
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by agb2008 »

Marc56us,
That example is actually the reason why I asked this question... To make it work all files from that example have to be included
or referenced not only Main.pb as in an example that you are refer to...
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by agb2008 »

I was able to solve my issue partially by switching off all automatic "event loop" and "event procedure" options in form designer
and as a result I am getting .pbf file content very similar to one manually written one and presented in a very useful post :
"The Basic Anatomy of a PureBasic Program" by TI-994A.
And in my main.pb code module I use XIncludeFile construction to reference my mainwindow.pbf form file, plus using
this construction in it:

Code: Select all

Repeat
  event = WaitWindowEvent()
    window = EventWindow()
      If window = Window_0
        If event = #PB_Event_CloseWindow
          End
        EndIf
        gadget = EventGadget()
          If gadget = Button_0
            SetLabel("Open window №2")
            OpenWindow_1()
          EndIf
          If gadget = Button_1
            CancelButton()
            End
          EndIf
      EndIf
      If window = Window_1
        If event = #PB_Event_CloseWindow
          CloseWindow(Window_1)
        EndIf
        gadget = EventGadget()
          If gadget = Button_3
            Debug event
            CloseWindow(Window_1)
            SetGadgetText(Text_0,"Close window №2")
          EndIf
      EndIf
ForEver
As you could see construction quite similar to the one referenced in the post that I mentioned earlier.
But in this case I just have to set proper logic for selecting correct events - and then use any procedures
or inline code that you want.

Disadvantage of this method is that it seems that general idea of event procedure not used (no need to select
proper procedures in form designer) which might sound as wrong idea - but it is working solution.

What do you think ? Could you please advice ?

P.S. Right now in my case I've got 4 files in my project:

main.pb - main code file where "manual event loop" defined
mainwindow.pbf and secondwindow.pbf - two files with form definition for Window_0 and Window_1
mainwindow_events.pb - that was attempt to move form gadgets procedures (event procedures initially) and then used just as an external
file with procedures definition.
steelx7000
New User
New User
Posts: 4
Joined: Wed Jan 20, 2016 4:10 pm

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by steelx7000 »

@agb2008 this is my sample....
It use 3 files:
event.pb
Win1.pbf (Label : W1_Text1, Button: W1_btnOpen, W1_btnClose)
Win2.pbf(Label: Text_0 --> caption="This is window 2")

Code: Select all

IncludeFile "Win1.pbf"
IncludeFile "Win2.pbf"

Declare W1_btnClose_Click()
Declare W1_btnOpen_Click()

OpenWin1()
DisableGadget(W1_btnClose, #True)

Repeat
  event = WaitWindowEvent()
  eventClose.i = #False
  Select event
    Case #PB_Event_Gadget
      evGadget = EventGadget()
      Select evGadget
        Case W1_btnClose
          W1_btnClose_Click()
        Case W1_btnOpen
          W1_btnOpen_Click()
      EndSelect
    Case #PB_Event_CloseWindow
      If GetActiveWindow() = Win2
        SetGadgetText(W1_Text1, "Close window 2")
        DisableGadget(W1_btnOpen, #False)
        DisableGadget(W1_btnClose, #True)
        CloseWindow(GetActiveWindow())
      ElseIf GetActiveWindow() = Win1
        eventClose = #True
        
      EndIf
      
  EndSelect
  
Until eventClose = #True


Procedure W1_btnOpen_Click()
  SetGadgetText(W1_Text1, "Opening window 2")
  DisableGadget(W1_btnClose, #False)
  DisableGadget(W1_btnOpen, #True)
  OpenWin2()
  
EndProcedure

Procedure W1_btnClose_Click()
  SetGadgetText(W1_Text1, "Close window 2")
  DisableGadget(W1_btnOpen, #False)
  DisableGadget(W1_btnClose, #True)
  CloseWindow(Win2)  
EndProcedure
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by TI-994A »

agb2008 wrote:...it seems that general idea of event procedure not used (no need to select proper procedures in form designer) which might sound as wrong idea - but it is working solution.
The PureBasic Form Designer is a very flexible tool for rapid UI development. However, once the UI has been visually laid out, the program structure is entirely up to you.

If the Generate event procedure and Generate event loop options are disabled in the form preferences, the Form Designer would then act purely as a layout tool. These would then have to be manually coded in a separate module, just as you have done. This is the easiest approach and affords the best control. Furthermore, the auto-generated event loop is only suitable for single-window applications, so that would be unusable to begin with.

On the other hand, the auto-generated event procedures are simply a convenience, lending no advantages whatsoever. It is perfectly valid and safe to create your own procedures to handle the various events, or even execute code directly within the event loop itself; again, just as you've done. It's all a matter of coding style and preference.

In regard to separating the modules, this again is purely a matter of preference. While it is not possible to add anything to the form files, the structures of other source and include files are flexible. It doesn't matter if procedures are in the same file as the event loop, or separated, as long as they are all declared and included properly.

Hope that addresses your concerns.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by agb2008 »

TI-994A:

Thank you very much for reply and comments. It indeed would be very useful if
your tutorial "Events handling with the Form Designer" could be included in
PureBasic online help. And as well comment regarding "event loop" generation
- that it's only for single window application. That could save a lot of time for
people who just start working with PureBasic GUI development.
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by Fred »

The generate "event loop" option will be removed in the next PB version, as it doesn't fit well with the original Form design and confuse new users.
User avatar
newtheogott
Enthusiast
Enthusiast
Posts: 120
Joined: Sat Apr 26, 2003 2:52 pm
Location: Germany, Karlsruhe
Contact:

Re: PureBasic 5.41 Form Designer - multiple forms example wa

Post by newtheogott »

PureBasic now understands Module's.
Could'nt the event handling be generated in a separate "file.pb" so the user could copy and paste snippets from there,
instead of being forced to handcode all event procedures for any control?

Also often Controls need an initialization. This could also be pre-generated.
For somebody who really knows the structure of the language this is not complicated to do,
and anybody using this tool will save a lot of typing work.

Possibly since the code designer was designed, PureBasic got a lot of features that are not yet included in the Design.
Also - like in teh IDE - Printing is currently not possibly?
WHY?
The Vectroprint is available. It will not be a big deal to include that.
Is user-friendlyness for new users no topic?
--Theo Gottwald
-----------------------------------------
http://www.it-berater.org * http://www.fa2.de * http://www.smart-package.com
Post Reply