Page 1 of 1

Large project organization ideas?

Posted: Tue Jan 12, 2010 4:56 pm
by mrjiles
Hey everyone, I'm trying to figure out an efficient way to manage a large project. The project is by no means complicated, but there are many windows & gadgets and it's starting to get mind boggling sorting through everything.

Currently, my organization looks like this:

Code: Select all

Enumeration
	#Window1
	#Window2
	#Gadget1
	#Gadget2
EndEnumeration

OpenWindow1()

Repeat
	Event.l = WaitWindowEvent()
	Select Event.l
		Case #PB_Event_Gadget
			Select EventGadget()
				Case #Gadget1
					; code here
				Case #Gadget2
					; code here
			EndSelect
	EndSelect
Until ;...
End

Procedure OpenWindow1()
	; open #Window1 code here
EndProcedure

Procedure OpenWindow2()
	; open #Window2 code here
EndProcedure
As you can see, each window is split into it's own procedure, but the events for all of the windows and gadgets are blobbed into a large block. I have thought about each window procedure having it's own event loop, but after testing it appears that multiple loops run at the same time. Maybe I'm missing something with this idea.

Personally, I prefer this coding style, but it too becomes confusing, especially in the method to get/pass data between windows. Most of the time this causes a lot more work for me, but it looks much cleaner to me. Note: no enumeration, each procedure/window is entirely self contained:

Code: Select all

OpenWindow1()

Procedure OpenWindow1()
	Protected Window.l
	Window.l = OpenWindow(#PB_Any ;.......)
	If Window.l
		; code here
	Repeat
		Event.l = WaitWindowEvent()
		Select Event.l
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #Gadget1
						; code here
					Case #Gadget2 ;<<<< This gadget is in OpenWindow2()
						; code here
				EndSelect
		EndSelect
	Until ;...
End
	EndIf
EndProcedure

Procedure OpenWindow2()
	Protected Window.l
	Window.l = OpenWindow(#PB_Any ;.......)
	If Window.l
		; code here
	EndIf
EndProcedure
The problem with this 2nd example is it's not as easy to pass data as when you're using Enumeration:EndEnumeration. Yes, I could use make import variables global, but this too looks sloppy and confusing to me.

How do you do it? Is there a better way? Thanks for any tips on this one!

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 6:11 pm
by Rook Zimbabwe
Hi Jiles!

I wrote my POS software (which has MANY windows and gadgets on each!) using enumeration.

I enumerated the windows and gadgets individually though. I used that so I could NAME the gadgets what they were...

Ialso used the eevent loop in the Visual Designer as the basis for coding. It took a small while to get comfortable with it but now I know it and it is easier... plus very little is done in the REPEAT // UNTIL loop... except for intercepting events. So it is not charging down a list of events looking to find what happened... it can respond only to what happened.

PLUS if I use the enumeration I can use NAMES of my controls... I call the MENUITEM buttons MENUITEM1, MENUITEM2... and so on... I can control colro and what hidden and what text is displayed on each button etc.

Little framework:

Code: Select all



Enumeration
  #Window_MAIN
EndEnumeration

Enumeration
  #ListIcon_EVENT
  #Button_SHOWALL
  #Button_HIDEALL
  #Button_HIDE0
  #Button_HIDE1
  #Button_1
  #Button_0
  #Text_MESSAGE
EndEnumeration
; *************************************
; CREATED by the VD to locate gadgets
Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()
; *************************************
;-
Procedure ListIcon_EVENT_Event(Window, Event, Gadget, Type)
  Debug "#ListIcon_EVENT"
  lineclick = GetGadgetState(#ListIcon_EVENT)
  SetGadgetText(#Text_MESSAGE, "You clicked line: "+Str(lineclick))
EndProcedure
;-
Procedure Button_SHOWALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_SHOWALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "A;; buttons now shown...")
  For X = #Button_1 To #Button_0
    HideGadget(X,0)
  Next
EndProcedure

Procedure Button_HIDEALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDEALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "ALL BUTTONS HIDDEN.")
  For X = #Button_1 To #Button_0
    HideGadget(X,1)
  Next
EndProcedure

Procedure Button_HIDE1_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_0,1)
EndProcedure

Procedure Button_HIDE0_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_0,1)
EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 1 PRESSED!")
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 0 PRESSED!")
EndProcedure
;-
; UNLESS YOU NEED TO HANFLE SOMETHING HAPPENING WITH THE TEXT GADGET YOU REALLY DON't NEED THIS EVENT
;Procedure Text_MESSAGE_Event(Window, Event, Gadget, Type)
;  Debug "#Text_MESSAGE"
;EndProcedure

Procedure RegisterGadgetEvent(Gadget, *Function)
  
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
    EndIf
  Next
  
EndProcedure
;-
Procedure Open_Window_MAIN()
  
  If OpenWindow(#Window_MAIN, 5, 5, 400, 277, "JILES EXAMPLE 1.0",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    ; If CreateGadgetList(WindowID(#Window_0)) ; removed for pb4.4
    TextGadget(#Text_MESSAGE, 5, 255, 390, 20, "", #PB_Text_Center | #PB_Text_Border)
    ; RegisterGadgetEvent(#Text_MESSAGE, @Text_MESSAGE_Event()) ; not necessary unless something happens when we click it
    ButtonGadget(#Button_0, 5, 10, 120, 30, "Button 0")
    RegisterGadgetEvent(#Button_0, @Button_0_Event())
    ButtonGadget(#Button_1, 5, 45, 120, 30, "Button 1")
    RegisterGadgetEvent(#Button_1, @Button_1_Event())
    ButtonGadget(#Button_HIDE0, 5, 80, 120, 30, "HIDE BUTTON 0")
    RegisterGadgetEvent(#Button_HIDE0, @Button_HIDE0_Event())
    ButtonGadget(#Button_HIDE1, 5, 115, 120, 30, "HIDE BUTTON 1")
    RegisterGadgetEvent(#Button_HIDE1, @Button_HIDE1_Event())
    ButtonGadget(#Button_HIDEALL, 5, 150, 120, 30, "HIDE ALL BUTTONS")
    RegisterGadgetEvent(#Button_HIDEALL, @Button_HIDEALL_Event())
    ButtonGadget(#Button_SHOWALL, 5, 220, 120, 30, "SHOW ALL BUTTONS")
    RegisterGadgetEvent(#Button_SHOWALL, @Button_SHOWALL_Event())
    ListIconGadget(#ListIcon_EVENT, 140, 10, 250, 240, "EVENT", 130, #PB_ListIcon_GridLines)
    RegisterGadgetEvent(#ListIcon_EVENT, @ListIcon_EVENT_Event())
    
    ; EndIf ; ditto removed for 4.4
  EndIf
EndProcedure

Open_Window_MAIN()

SetGadgetText(#Text_MESSAGE, "PROGRAM START")

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
  Case #PB_Event_Gadget
    CallEventFunction(Window, Event, Gadget, Type)
    
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
This is still alittle rough... I could have a procedure to get the message from #Text_MESSAGE and plop it in the listicon and then do my function... save a few lines and modularize the code more...

But for large project organization it HAS helped... Only the even that triggers the gadget gets called... and I have a LOT of gadgets in my rPOS program! :mrgreen:

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 8:32 pm
by Foz
Here is the same thing but using a Prototype instead of CallFunctionFast:

Code: Select all

;{- Event Handler
Prototype ProtoEvents(Window, Event, Gadget, Type)

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.ProtoEvents
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure RegisterGadgetEvent(Gadget, *Function)
 
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
 
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
 
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      EventProcedures()\EventFunction(Window, Event, Gadget, Type)
      Break
    EndIf
  Next
 
EndProcedure
;}

;{- Form Constants
Enumeration
  #Window_MAIN
EndEnumeration

Enumeration
  #ListIcon_EVENT
  #Button_SHOWALL
  #Button_HIDEALL
  #Button_HIDE0
  #Button_HIDE1
  #Button_1
  #Button_0
  #Text_MESSAGE
EndEnumeration
;}

;{- Event Procedures
Procedure ListIcon_EVENT_Event(Window, Event, Gadget, Type)
  Debug "#ListIcon_EVENT"
  lineclick = GetGadgetState(#ListIcon_EVENT)
  SetGadgetText(#Text_MESSAGE, "You clicked line: "+Str(lineclick))
EndProcedure

Procedure Button_SHOWALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_SHOWALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "A;; buttons now shown...")
  For X = #Button_1 To #Button_0
    HideGadget(X,0)
  Next
EndProcedure

Procedure Button_HIDEALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDEALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "ALL BUTTONS HIDDEN.")
  For X = #Button_1 To #Button_0
    HideGadget(X,1)
  Next
EndProcedure

Procedure Button_HIDE1_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_1,1)
EndProcedure

Procedure Button_HIDE0_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_0,1)
EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 1 PRESSED!")
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 0 PRESSED!")
EndProcedure

; UNLESS YOU NEED TO HANFLE SOMETHING HAPPENING WITH THE TEXT GADGET YOU REALLY DON't NEED THIS EVENT
;Procedure Text_MESSAGE_Event(Window, Event, Gadget, Type)
;  Debug "#Text_MESSAGE"
;EndProcedure

;}

;{- Build Form
Procedure Open_Window_MAIN()
 
  If OpenWindow(#Window_MAIN, 5, 5, 400, 277, "JILES EXAMPLE 1.0",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    TextGadget(#Text_MESSAGE, 5, 255, 390, 20, "", #PB_Text_Center | #PB_Text_Border)
    ; RegisterGadgetEvent(#Text_MESSAGE, @Text_MESSAGE_Event()) ; not necessary unless something happens when we click it
    ButtonGadget(#Button_0, 5, 10, 120, 30, "Button 0")
    RegisterGadgetEvent(#Button_0, @Button_0_Event())
    ButtonGadget(#Button_1, 5, 45, 120, 30, "Button 1")
    RegisterGadgetEvent(#Button_1, @Button_1_Event())
    ButtonGadget(#Button_HIDE0, 5, 80, 120, 30, "HIDE BUTTON 0")
    RegisterGadgetEvent(#Button_HIDE0, @Button_HIDE0_Event())
    ButtonGadget(#Button_HIDE1, 5, 115, 120, 30, "HIDE BUTTON 1")
    RegisterGadgetEvent(#Button_HIDE1, @Button_HIDE1_Event())
    ButtonGadget(#Button_HIDEALL, 5, 150, 120, 30, "HIDE ALL BUTTONS")
    RegisterGadgetEvent(#Button_HIDEALL, @Button_HIDEALL_Event())
    ButtonGadget(#Button_SHOWALL, 5, 220, 120, 30, "SHOW ALL BUTTONS")
    RegisterGadgetEvent(#Button_SHOWALL, @Button_SHOWALL_Event())
    ListIconGadget(#ListIcon_EVENT, 140, 10, 250, 240, "EVENT", 130, #PB_ListIcon_GridLines)
    RegisterGadgetEvent(#ListIcon_EVENT, @ListIcon_EVENT_Event())
  EndIf
EndProcedure
;}


;{- Main Program Loop
Open_Window_MAIN()

SetGadgetText(#Text_MESSAGE, "PROGRAM START")

Repeat
 
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
 
  Select Event
  Case #PB_Event_Gadget
    CallEventFunction(Window, Event, Gadget, Type)
   
  EndSelect
 
Until Event = #PB_Event_CloseWindow

End
;}

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 9:16 pm
by ts-soft
Here is the same thing but using a Prototype and Map :wink:
Is a bit shorter and i think it is faster, but not shure.
I have only support the eventtype, the other things useless for a gadget.

Code: Select all

 ;{- Event Handler
Prototype ProtoEvents(Type)

Global NewMap Gadgets()
;}

;{- Form Constants
Enumeration
  #Window_MAIN
EndEnumeration

Enumeration
  #ListIcon_EVENT
  #Button_SHOWALL
  #Button_HIDEALL
  #Button_HIDE0
  #Button_HIDE1
  #Button_1
  #Button_0
  #Text_MESSAGE
EndEnumeration
;}

;{- Event Procedures
Procedure ListIcon_EVENT_Event(Type)
  Debug "#ListIcon_EVENT"
  lineclick = GetGadgetState(#ListIcon_EVENT)
  SetGadgetText(#Text_MESSAGE, "You clicked line: "+Str(lineclick))
EndProcedure

Procedure Button_SHOWALL_Event(Type)
  Debug "#Button_SHOWALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "A;; buttons now shown...")
  For X = #Button_1 To #Button_0
    HideGadget(X,0)
  Next
EndProcedure

Procedure Button_HIDEALL_Event(Type)
  Debug "#Button_HIDEALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "ALL BUTTONS HIDDEN.")
  For X = #Button_1 To #Button_0
    HideGadget(X,1)
  Next
EndProcedure

Procedure Button_HIDE1_Event(Type)
  Debug "#Button_HIDE1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_1,1)
EndProcedure

Procedure Button_HIDE0_Event(Type)
  Debug "#Button_HIDE0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_0,1)
EndProcedure

Procedure Button_1_Event(Type)
  Debug "#Button_1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 1 PRESSED!")
EndProcedure

Procedure Button_0_Event(Type)
  Debug "#Button_0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 0 PRESSED!")
EndProcedure
;}

;{- Build Form
Procedure Open_Window_MAIN()

  If OpenWindow(#Window_MAIN, 5, 5, 400, 277, "JILES EXAMPLE 1.0",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    TextGadget(#Text_MESSAGE, 5, 255, 390, 20, "", #PB_Text_Center | #PB_Text_Border)
    ButtonGadget(#Button_0, 5, 10, 120, 30, "Button 0")
    Gadgets(Str(#Button_0)) = @Button_0_Event()
    ButtonGadget(#Button_1, 5, 45, 120, 30, "Button 1")
    Gadgets(Str(#Button_1)) = @Button_1_Event()
    ButtonGadget(#Button_HIDE0, 5, 80, 120, 30, "HIDE BUTTON 0")
    Gadgets(Str(#Button_HIDE0)) = @Button_HIDE0_Event()
    ButtonGadget(#Button_HIDE1, 5, 115, 120, 30, "HIDE BUTTON 1")
    Gadgets(Str(#Button_HIDE1)) = @Button_HIDE1_Event()
    ButtonGadget(#Button_HIDEALL, 5, 150, 120, 30, "HIDE ALL BUTTONS")
    Gadgets(Str(#Button_HIDEALL)) = @Button_HIDEALL_Event()
    ButtonGadget(#Button_SHOWALL, 5, 220, 120, 30, "SHOW ALL BUTTONS")
    Gadgets(Str(#Button_SHOWALL)) = @Button_SHOWALL_Event()
    ListIconGadget(#ListIcon_EVENT, 140, 10, 250, 240, "EVENT", 130, #PB_ListIcon_GridLines)
    Gadgets(Str(#ListIcon_EVENT)) =  @ListIcon_EVENT_Event()
  EndIf
EndProcedure
;}


;{- Main Program Loop
Open_Window_MAIN()

SetGadgetText(#Text_MESSAGE, "PROGRAM START")

Define EventFunction.ProtoEvents
Repeat

  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()

  Select Event
    Case #PB_Event_Gadget
      EventFunction = Gadgets(Str(Gadget))
      EventFunction(Type)
  EndSelect

Until Event = #PB_Event_CloseWindow

End
;} 
Greetings
Thomas

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 9:34 pm
by Foz
Neat! I can't think of doing it any simpler!

Any takers on making it better?

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 9:48 pm
by ts-soft
Without any global linklist or map you can use SetGadgetData()

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 10:10 pm
by mrjiles
Wow, great ideas! Definitely keeps the code a LOT more organized. I think I will implement ASAP!

Thanks!

Re: Large project organization ideas?

Posted: Tue Jan 12, 2010 11:19 pm
by Rook Zimbabwe
Oh EXCELLENT!!!

I hadn't even thought of PROTOTYPE!!! DOH!! :D nor SETGADGETDATA!!!

Brilliance showers on thems that trys to help too! 8)

Re: Large project organization ideas?

Posted: Thu Feb 04, 2010 9:37 pm
by klaver
My three cents: when EventLoop in my project became too big I separated it by windows using macros:

Code: Select all

Macro Win1Events(Event)
  Select Event
    Case #PB_Event_Gadget
      Debug EventGadget()
    Case #PB_Event_CloseWindow
      HideWindow(#Win1, #True)
  EndSelect
EndMacro

Macro Win2Events(Event)
  Select Event
    Case #PB_Event_Gadget
      Debug EventGadget()
    Case #PB_Event_CloseWindow
      HideWindow(#Win2, #True)
  EndSelect
EndMacro

Macro Win3Events(Event)
  Select Event
    Case #PB_Event_Gadget
      Debug EventGadget()
    Case #PB_Event_CloseWindow
      HideWindow(#Win3, #True)
  EndSelect
EndMacro

Repeat
  Event = WaitWindowEvent()
  Select EventWindow()
    Case #Win1
      Win1Events(Event)
    Case #Win2
      Win2Events(Event)
    Case #Win3
      Win3Events(Event)
  EndSelect
ForEver
I don't want to use procedures because calling them is quite slow. And I don't like the idea of loosing the optimalization as a cost of my personal comfort as a programmer.

Also, what's the purpose of this? I've seen it in many PB sources.

Code: Select all

Event  = WaitWindowEvent()
Gadget = EventGadget()
Type = EventType()
Window = EventWindow()
It looks nice, but it's not used most of the time. But still slows the loop down EACH time it's executed.

Re: Large project organization ideas?

Posted: Thu Feb 04, 2010 10:31 pm
by blueznl
mrjiles, I use the same style as you did originally, with a little twist...

1. I've enumerated all parts
2. I go through all gadgets / windows just like you do
3. I've split up my main loop in two sections, events and actions

4. event handling
4.1 check event
4.2 if it's something simple, do it immediately
4.3 if it's something complex, either set an 'action' or call a procedure (to keep the code out of the loop, so to keep things readable)

5. after checking all events, I then check if there's an 'action' set
5.1 check the action
5.2 if it's simple, do it immediately
5.3 if it's complex, call a procedure

This way totally different events can trigger the same action, i can also trigger actions through command line parameters, chain actions ect.

In pseudocode:

Code: Select all

action.i = none
get commandline parameters
set action.i if needed
repeat
  ;
  ; handle events
  ;
  waitwindowevent()
  select event
  case ...
    do whatever needs to be done
  case #pb_event_closewindow
    action.i = exit
  endselect
  ;
  select action
  case ...
    do what needs to be done :-)
    action.i = none
  case exit
    we're done boss      
  endselect
  ;
until action.i = exit
I typically enumerate 'toolbarbuttons' and 'menu entries' and use those values as 'actions' as well. If a menu, a toolbar button, or a gadget trigger the same action, i just set the 'action' var to the specific value and have it handled further down the loop.

I know to many people this two stage approach may seem to make little sense :-) and in some cases it doesn't :-) but it solved some problems in the past...

Re: Large project organization ideas?

Posted: Fri Jul 16, 2010 3:58 pm
by rsts
Since I'm just starting a new project, I found the information in this topic very useful, particularly the model suggested by ts-soft.

Does anyone see any particular disadvantage or advantage to using an array instead of a map for the gadgets. In my way of thinking, in this particular use, an array would appear to be a better approach, but I'm wondering if I'm missing something.

BTW, Mr soft, many thanks for this model.

cheers

Re: Large project organization ideas?

Posted: Fri Jul 16, 2010 6:35 pm
by Rook Zimbabwe
I originally started with the array idea. It was very attractive and if the #Constants are nunmbered the same ass the ARRAY(index) easy to implement.

But there are downsides. If you got a lot of gadgets/windows... array might get bulky and if you remove a gadget or window you would still have to KEEP the information in the array or they would not point to the same location.

Code: Select all

Psuedocode since I have no compiler here in Vegas!

Enumeration
#Window_MAIN = 0
#Window_SOMETHING = 1
endenumeration

enumeration
#Button_CLOSE = 0
#Button_KILLME = 1
#Button_BITEME = 2
#Button_MAMABOY = 3
#Button_CRYBABY = 4
endenumeration

Dim WindowList(1)
Dim ButtonList(3)

etc...
Then you do what you want... BUT that said... I like Tomas' idea better
AND Foz's :mrgreen:

Re: Large project organization ideas?

Posted: Sat Jul 17, 2010 4:23 am
by skywalk
Thanks for this topic. It was very useful to me also.
I actually prefer Klaver's.
Though debugging is a drag with macros. But I don't see the same lag time in my GUI as opposed to the other approaches. Also, I went with #PB_Any for all gadgets / windows and don't rely much on Enumerations.
My menus and gadgets are auto loaded by data sections containing their respective elements' info.
PB compiles so fast, I can never go back to a Visual Designer again! :)