Back to Gambas
- 1 Hotkeys
- 2 KDE panel applet ?
- 3 Listview
- 4 Variables
- 5 Project Building
- 6 Application Startup
- 7 Window Geometry
If you want to use some hotkeys for a project, you might code something like this:
Public sub Form_KeyPress () If key.code = ... then Something happens
Unfortunately this only works, if the form has no buttons and other controls. If the form has other controls and one of the controls has the focus, then it does not work.
There is no interface in the QT component to globally intercept key events yet, but there is a trick:
If you have a menu in your form, its keyboard shortcuts are globally managed. So you can add an hidden menu to your form to solve your problem.
KDE panel applet ?
Is it possible to write a KDE panel applet with Gambas?
No, currently it is not possible to do that. KDE panel applets are implemented as shared libraries with specific interfaces.
How can I add a listview item after an existing one, when there is an item missing:
Wrong: Listview.add("Key","Name",,"Key2") -- Error: Comma missing.
You have to pass NULL as picture argument. You cannot "jump" arguments when you call a function in Gambas.
Does gambas support structured data types?
In some versions of basic, it is possible to create structured data types using by using type definitions as follows:
' This will not work in gambas TYPE rhubarbstructure foo AS STRING * 32 bar AS INTEGER END TYPE
PUBLIC rhubarb AS rhubarbstructure
Does gambas support include files?
Does gambas support conditional compilation directives?
Making the application startup from a main routine
In gambas, to make an application startup from a main routine:
- Create a new module called MMain
- In the MMain module, create a public sub called Main as follows:
PUBLIC SUB Main() ' This is the start of the program END
- Right click the MMain module, then select Startup class from the context menu
Obtaining the command line parameters
PUBLIC SUB main() ' This reads and displays the command line parameters DIM l AS Integer DIM numparms AS Integer DIM parm AS String numparms = Application.Args.Count FOR l = 0 TO numparms - 1 parm = Application.Args[l] PRINT l; " : "; parm NEXT END SUB
Determining the maximum window size
In gambas, the trick to determining the maximum window size that will fit on the screen is to create a form that is maximized and then query its dimensions from within a Form_Resize() event. Note that the form can be invisible during this process, and typically we would use the main modal window (FMain in this example).
Creating the form
From with the project create a form (FMain) with the following properties set:
FMain.Maximized = True FMain.Visible = False ' The form can be invisible
From within the project view, rightclick the FMain form and select Edit class from the contextmenu. This will display a form class file (FMain.class) as follows:
PUBLIC SUB _new()
PUBLIC SUB Form_Open()
We can now add a Form_Resize() event to the class file with the necessary code to obtain the screen dimensions as follows:
PUBLIC SUB Form_Resize() PRINT "The maximum window size that can be used is "; FMain.Width; " x "; FMain.Height END