Page 1 of 1
Form Designer & multiple windows.
Posted: Mon Nov 03, 2014 8:54 pm
by jassing
I had been using PureForm and enjoyed that; but figured it's time to start using the new built in form designer.
The problem I seem to have is that when I follow the help; I end up with two waitwindowevent() loops.
so I have to go in and delete the openwindow & repeat loops out of all form source files before building...
what am I missing?
Re: Form Designer & multiple windows.
Posted: Tue Nov 04, 2014 5:43 pm
by Polo
Disabling the event loop generation in your purebasic preferences should do the trick!
Re: Form Designer & multiple windows.
Posted: Fri Nov 07, 2014 5:43 pm
by jassing
Polo wrote:Disabling the event loop generation in your purebasic preferences should do the trick!
sadly, it did not..
Re: Form Designer & multiple windows.
Posted: Fri Nov 07, 2014 5:46 pm
by Polo
Here an empty form generates this code, without any event loop.
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Global Window_0
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Re: Form Designer & multiple windows.
Posted: Mon Nov 10, 2014 12:57 am
by jassing
Here's what happens for me (pb 5.31 x64)
if I delete the openwindow and loop; it just re-appears later.
Re: Form Designer & multiple windows.
Posted: Mon Nov 10, 2014 6:33 am
by Teddy Rogers
Something like this maybe?
In your .pb file...
Code: Select all
; The main event loop.
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case MainWindow
MainWindow_Events(Event)
EndSelect
Until Event = #PB_Event_CloseWindow
...and in the .pbf file...
Code: Select all
Procedure MainWindow_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Checkbox_Lee
Lee_Factor(EventType())
Case #TrackBar_Current
Arcing_Current(EventType())
Case #Button_Calculate
Arcing_Current(EventType())
Case #Combo_Equipment
Arcing_Current(EventType())
Case #Combo_Grounding
Arcing_Current(EventType())
Case #Checkbox_Joules
JoulesToCal(EventType())
Case #Checkbox_Distance
Distance_Factor(EventType())
Case #Combo_Equipment_Type
Equipment_Type(EventType())
Case #TrackBar_Integer
Arcing_Current(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
I just posted some code using the Form Designer, hopefully you may find it helpful...
http://www.purebasic.fr/english/viewtop ... 12&t=60934
Ted.
Re: Form Designer & multiple windows.
Posted: Mon Nov 10, 2014 7:35 am
by TI-994A
jassing wrote:Here's what happens for me (pb 5.31 x64)

Hi jassing. In the properties window, you're only disabling the
events procedure. To disable the
event loop, you'd have to go to the
File > Preferences > Form menu, and disable the
Generate event loop option.

Re: Form Designer & multiple windows.
Posted: Mon Nov 10, 2014 4:03 pm
by mestnyi
Code: Select all
; The main event loop.
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case MainWindow
MainWindow_Events(Event)
EndSelect
Until Event = #PB_Event_CloseWindow
I think it will be better to do the following ,
that would separately handle the window closing event for each window , and yet, you can specify one of the window as the main window.
Code: Select all
Global Window_0, Window_1
Procedure OpenWindow_0(x = 0, y = 0, width = 400, height = 200)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "main window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ProcedureReturn Window_0
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Procedure OpenWindow_1(x = 0, y = 0, width = 400, height = 200)
Window_1 = OpenWindow(#PB_Any, x, y, width, height, "window1", #PB_Window_SystemMenu)
ProcedureReturn Window_1
EndProcedure
Procedure Window_1_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
OpenWindow_1()
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
CloseWindow(EventWindow())
If GetActiveWindow() =-1 Or EventWindow() = Window_0
End
EndIf
EndSelect
Select EventWindow()
Case Window_0
Window_0_Events(Event)
Case Window_1
Window_1_Events(Event)
EndSelect
ForEver
Re: Form Designer & multiple windows.
Posted: Mon Nov 10, 2014 8:23 pm
by Polo
TI994 described what I meant much more efficiently than I

Re: Form Designer & multiple windows.
Posted: Mon Jan 26, 2015 6:07 pm
by mestnyi
What do you think?
Code: Select all
CompilerIf Not Defined(IsCloseWindow, #PB_Function) And
Not Defined(IsCloseWindow, #PB_Procedure)
EnableExplicit
CompilerIf Not Defined(PB_Object_Count, #PB_Function) And
Not Defined(PB_Object_Count, #PB_Procedure) And
Not Defined(CountWindow, #PB_Function) And
Not Defined(CountWindow, #PB_Procedure)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
CompilerElse
ImportC ""
CompilerEndIf
PB_Object_Count( Objects )
PB_Window_Objects.l
EndImport
CompilerEndIf
ProcedureDLL IsCloseWindow2( Window = #PB_All)
If Window ! #PB_All
If ((Not IsWindow( EventWindow() )) And EventWindow() = Window )
ProcedureReturn #True
EndIf
Else
If Not PB_Object_Count( PB_Window_Objects )
ProcedureReturn #True
EndIf
EndIf
EndProcedure
ProcedureDLL IsCloseWindow( ) ;Returns TRUE is window close
ProcedureReturn IsCloseWindow2( #PB_All )
EndProcedure
Macro IsCloseWindow( Window = #PB_All) ;Returns TRUE is window close
IsCloseWindow2( Window )
EndMacro
DisableExplicit
CompilerEndIf
CompilerIf Not Defined(WindowClose, #PB_Function) And
Not Defined(WindowClose, #PB_Procedure)
ProcedureDLL WindowClose5(Event,MainWindow =-1,Message =-1,Text$="Вы уверены,"+#CRLF$+"что хотите выйти?",Title$="")
Protected Window = EventWindow()
If Event = #PB_Event_CloseWindow
If IsWindow(Window) And Title$ = ""
Title$ = GetWindowTitle(Window)
EndIf
If MainWindow = Window :Window = -1 :EndIf
;If MainWindow =-1 And Message =-1 :Message = Window :EndIf
Select Message
Case Window
If MessageRequester( Title$, Text$, #PB_MessageRequester_YesNo ) ! #PB_MessageRequester_Yes
ProcedureReturn #False
EndIf
EndSelect
CloseWindow( Window )
If IsCloseWindow( MainWindow )
ProcedureReturn #True
EndIf
EndIf
EndProcedure
ProcedureDLL WindowClose4(Event,MainWindow,Message,Text$)
ProcedureReturn WindowClose5(Event,MainWindow,Message,Text$,"")
EndProcedure
ProcedureDLL WindowClose3(Event,MainWindow,Message)
ProcedureReturn WindowClose4(Event,MainWindow,Message,"Вы уверены,"+#CRLF$+"что хотите выйти?")
EndProcedure
ProcedureDLL WindowClose2(Event,MainWindow)
ProcedureReturn WindowClose3(Event,MainWindow,#PB_All)
EndProcedure
ProcedureDLL WindowClose(Event)
ProcedureReturn WindowClose2(Event,#PB_Any)
EndProcedure
Macro WindowClose(Event,MainWindow =-1,Message =-1,Text="Вы уверены,"+#CRLF$+"что хотите выйти?",Title="") ;Returns TRUE is window close
WindowClose5(Event,MainWindow,Message,Text,Title)
EndMacro
CompilerEndIf
;-----------------------
Global Window_0, Window_1
Procedure OpenWindow_0(x = 0, y = 0, width = 400, height = 200)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "main window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ProcedureReturn Window_0
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Procedure OpenWindow_1(x = 0, y = 0, width = 400, height = 200)
Window_1 = OpenWindow(#PB_Any, x, y, width, height, "window1", #PB_Window_SystemMenu)
ProcedureReturn Window_1
EndProcedure
Procedure Window_1_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
OpenWindow_1()
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case Window_0
Window_0_Events(Event)
Case Window_1
Window_1_Events(Event)
EndSelect
Until WindowClose(Event,Window_0)