[Gambas-user] Showing the Form's Gui
Caveat
Gambas at ...1950...
Wed Apr 14 13:09:47 CEST 2010
Hi Jorge,
While we wait to see if Ricardo wants to share his open forms method
(I'm also interested to see it), here's some code I have used before
(see attachment) where the opening/closing of forms is handled by a
module, which I've called RunController.
The module is set as the Startup Class (normally that's by default the
first Form you declare I think) and must have a Main() method.
Right-clicking on the module brings up a context menu where you can
click on the Startup Class checkbox.
You can see that the RunController module can decide when it opens each
form (so you could have some long-running data extraction go on in the
background), and handles events raised by the forms (in conjunction with
Attach, making sure RunController actually gets the events).
One of the first things RunController does is to decide "should I first
open up the settings form (no Dragons defined yet)?" or "should I show
the main form already (at least one Dragon exists in settings)?":
IF theSettings.getDragonCount() = 0 THEN
settingsFrm = NEW SettingsForm
settingsFrm.Show
Object.Attach(settingsFrm, ME, "SettingsFrm")
ELSE
Logger.logMessage("RunController.Main() dragon found, so starting
Remote Control", FALSE)
remC = NEW RemoteControl
remC.Show
Object.Attach(remC, ME, "Remote")
tCop = NEW TrafficCop
tCop.show
Object.Attach(tCop, ME, "Cop")
END IF
One limitation of my approach is that you need to explicitly declare
each form you're going to use up-front, so I'm interested to see if
Ricardo's approach avoids that.
Regards,
Caveat
On Wed, 2010-04-14 at 11:59 +0200, Jorge Carrión wrote:
> Ricardo:
> Could you post a example of your open forms method? I'm very interested on
> it. It sound like something I have searching for a long time.
>
> Gracias
>
> Jorge
>
>
> 2010/4/13 Ricardo Díaz Martín <oceanosoftlapalma at ...626...>
>
> > If It can help to someone, this is I always do:
> >
> > When I'm going to open a form, I always call my own OpenForm(FormName as
> > String, Parameters as String) sub. This sub is not inside the form I'm
> > going
> > to open. It's a public sub that's is inside a utilities module.
> >
> > OpenForm() sub create new object with the form (f.e. FRMMain) and put its
> > reference inside a public collection called OpenedForms. Before to show
> > form
> > to the user, I show other form with a progress bar and a label showing
> > "Loading..." and I'm going executing SQL, show/hid controls, etc... with no
> > show anything. If there thrownare a fixed steps to data load, I updated progress
> > bar and when load process finish I show the form.
> >
> > I use this in all my apps (since lot of years when I never eared about
> > gambas and I was programing in VB, Access, Java, etc...) and for me is the
> > best option. For sure there is a lot of ways to do this.
> >
> > Regards,
> > Ricardo Díaz
> >
> >
> >
> > 2010/4/13 Doriano Blengino <doriano.blengino at ...1909...>
> >
> > > Fabien Bodard ha scritto:
> > > > 2010/4/13 Doriano Blengino <doriano.blengino at ...1909...>:
> > > >
> > > >> Fabien Bodard ha scritto:
> > > >>
> > > >>> just remember to put a flag to say when the data are loaded !
> > > >>>
> > > >>>
> > > >> What would be the reason for this flag?
> > > >>
> > > > if the form is showed and the data not accessible ?
> > > >
> > > Really, there could be a problem if the user clicks a button 50 ms after
> > > the button (and the whole form) is visible. A remote possibility, and
> > > application-dependent. But I know users enough to imagine that someone
> > > could do it... :-)
> > >
> > > Reducing the interval of the one-shot timer can help, but does not solve
> > > (interval=0 could?). The better way is to disable actions the user could
> > > do with invalid data (application dependent: who says that the form is
> > > intended to receive clicks?), and perhaps add a nice label stating
> > > "Loading data, please wait..." and so on.
> > >
> > > Anyway, the flag is the worse solution. Supposing you use a flag, and
> > > the user clicks or types too fast, what would you do? A
> > > Message.Info("You clicked too fast. Go to have a coffee and come back
> > > later.")? :-) Better to disable some controls, so the user is informed
> > > before; in addition, controls are already "global variables" which carry
> > > informations with them. Well, this is my opinion - I hate to duplicate
> > > informations around, but someone else on this list, time ago, said
> > > "never use the GUI to store information". The problem with global (or
> > > class) variables is that you can forget them more easily than some
> > > property of a visible control.
> > >
> > > Regards,
> > > Doriano
> > >
> > >
> > >
> > >
> > ------------------------------------------------------------------------------
> > > Download Intel® Parallel Studio Eval
> > > Try the new software tools for yourself. Speed compiling, find bugs
> > > proactively, and fine-tune applications for parallel performance.
> > > See why Intel Parallel Studio got high marks during beta.
> > > http://p.sf.net/sfu/intel-sw-dev
> > > _______________________________________________
> > > Gambas-user mailing list
> > > Gambas-user at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> >
> > ------------------------------------------------------------------------------
> > Download Intel® Parallel Studio Eval
> > Try the new software tools for yourself. Speed compiling, find bugs
> > proactively, and fine-tune applications for parallel performance.
> > See why Intel Parallel Studio got high marks during beta.
> > http://p.sf.net/sfu/intel-sw-dev
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
-------------- next part --------------
' Gambas module file
CONST VERSION AS String = "v.0.9.9"
' Forms used in this App
PRIVATE settingsFrm AS SettingsForm
PRIVATE shoutCastFrm AS ShoutCast
PRIVATE remC AS RemoteControl
PRIVATE streamerFrm AS Streamer
PRIVATE tCop AS TrafficCop
' AllSettings is the master settings holder, contains last window size and position for the main App,
' as well as a collection of DragonSettings objects for each Dragon that's been defined
PRIVATE theSettings AS AllSettings
PUBLIC SUB Main()
Logger.setDebugMode(Logger.DEBUG_LOG_AND_PRINT)
Logger.logMessage("RunController.Main() The beginning of it all!! **************", FALSE)
theSettings = NEW AllSettings
IF theSettings.getDragonCount() = 0 THEN
settingsFrm = NEW SettingsForm
settingsFrm.Show
Object.Attach(settingsFrm, ME, "SettingsFrm")
ELSE
Logger.logMessage("RunController.Main() dragon found, so starting Remote Control", FALSE)
remC = NEW RemoteControl
remC.Show
Object.Attach(remC, ME, "Remote")
tCop = NEW TrafficCop
tCop.show
Object.Attach(tCop, ME, "Cop")
END IF
END
PUBLIC SUB SettingsFrm_OK_Clicked()
Logger.logMessage("RunController.SettingsFrm_OK_Clicked EVENT Caught!", FALSE)
theSettings.save()
object.Detach(settingsFrm)
settingsFrm.Close()
remC = NEW RemoteControl
Logger.logMessage("RunController.SettingsFrm_OK_Clicked() created new RemoteControl instance", FALSE)
remC.Show
Object.Attach(remC, ME, "Remote")
END
PUBLIC SUB Remote_changeSettings()
Logger.logMessage("RunController.Remote_changeSettings EVENT Caught!", FALSE)
object.Detach(remC)
remC.Close()
remC = NULL
settingsFrm = NEW SettingsForm
settingsFrm.Show
Object.Attach(settingsFrm, ME, "SettingsFrm")
END
PUBLIC SUB Remote_changeShoutCast()
Logger.logMessage("RunController.Remote_changeShoutCast EVENT Caught!", FALSE)
object.Detach(remC)
remC.Close()
shoutCastFrm = NEW ShoutCast
shoutCastFrm.Show
Object.Attach(shoutCastFrm, ME, "ShoutCastFrm")
END
PUBLIC SUB Remote_changeStreaming()
Logger.logMessage("RunController.Remote_changeStreaming EVENT Caught!", FALSE)
object.Detach(remC)
remC.Close()
streamerFrm = NEW Streamer
streamerFrm.Show
Object.Attach(streamerFrm, ME, "StreamerFrm")
END
PUBLIC SUB Remote_logChanged(newValue AS Boolean)
Logger.logMessage("RunController.Remote_logChanged EVENT Caught!", FALSE)
Logger.logMessage("RunController.Remote_logChanged new value: " & Utils.booleanToString(newValue), FALSE)
IF newValue THEN
Logger.setDebugMode(Logger.DEBUG_LOG_AND_PRINT)
ELSE
Logger.setDebugMode(Logger.NO_DEBUG)
END IF
Settings["Dragon/ShowLog"] = newValue
END
PUBLIC SUB Remote_showLogChanged(newValue AS Boolean)
Logger.logMessage("RunController.Remote_showLogChanged EVENT Caught!", FALSE)
Logger.logMessage("RunController.Remote_showLogChanged new value: " & Utils.booleanToString(newValue), FALSE)
IF newValue THEN
IF tCop = NULL THEN
tCop = NEW TrafficCop
Object.Attach(tCop, ME, "Cop")
END IF
tCop.Show
ELSE
IF tCop = NULL THEN
RETURN
ELSE
tCop.Hide
END IF
END IF
Settings["Dragon/ShowLog"] = newValue
END
PUBLIC SUB Remote_shoutyChanged(newValue AS Boolean)
Logger.logMessage("RunController.Remote_shoutyChanged EVENT Caught!", FALSE)
Logger.logMessage("RunController.Remote_shoutyChanged new value: " & Utils.booleanToString(newValue), FALSE)
Settings["Dragon/Shouty"] = newValue
END
PUBLIC SUB Remote_requestSent(requestData AS String)
Logger.logMessage("RunController.Remote_requestSent EVENT Caught!", FALSE)
Logger.logMessage("RunController.Remote_requestSent request data: " & requestData, FALSE)
IF tCop = NULL THEN
RETURN
END IF
tCop.requestSent(requestData)
tCop.Refresh
END
PUBLIC SUB Remote_responseReceived(requestData AS String, responseData AS String)
Logger.logMessage("RunController.Remote_responseReceived EVENT Caught!", FALSE)
Logger.logMessage("RunController.Remote_responseReceived request data: " & requestData, FALSE)
Logger.logMessage("RunController.Remote_responseReceived response data: " & responseData, FALSE)
IF tCop = NULL THEN
RETURN
END IF
tCop.responseReceived(responseData)
tCop.Refresh
END
PUBLIC SUB Remote_Move()
getSettings(FALSE).setXCoord(remC.X)
getSettings(FALSE).setYCoord(remC.Y)
END
PUBLIC SUB Remote_Close()
Logger.logMessage("RunController.Remote_Close() EVENT Caught!", FALSE)
theSettings.save()
QUIT
END
PUBLIC SUB Cop_Close()
Logger.logMessage("RunController.Cop_Close() EVENT Caught!", FALSE)
'Remote_showLogChanged(FALSE)
IF remC <> NULL THEN
remC.setShowLog(FALSE)
END IF
tCop = NULL
END
PUBLIC SUB Remote_Resize()
getSettings(FALSE).setWidth(remC.Width)
getSettings(FALSE).setHeight(remC.Height)
remC.Form_Resize
END
PUBLIC FUNCTION getSettings(refresh AS Boolean) AS AllSettings
IF theSettings = NULL OR refresh THEN
theSettings = NEW AllSettings
END IF
RETURN theSettings
END
More information about the User
mailing list