Often there is a desire to pass on a Gambas program. Two approaches are possible:
Gambas provides suitable export dialogs for both variants in the IDE. This → chapter 11.10 explains how to generate an installation package for a target distribution.
The description of how to put together an installation package and install it on a target computer is based on a concrete objective with narrowly defined boundary conditions - implemented in the StructDB project. In my opinion, the note is necessary because there will be no general, promising description for every Linux distribution and for every (stable) version of Gambas.
Figure 220.127.116.11.1: GUI for the program StructDB
These previews are the result of many attempts to successfully compile an installation package and reflect the experience with the wizard for generating an installation package (? packer wizard). Success is considered successful if the installation package can be installed by user B with root privileges on the target computer without any problems and user B can use the installed program as specified in the program specification.
As soon as you create the project whose program you want to pass on, you should be sure about the type of project and the options to be selected, and choose the type and the appropriate options. For programs with a GUI, you can choose:
If you select 'Graphical application', the component gb.gui will be loaded at development time and the Packer Wizard will load both the gb.gtk packages and the gb.qt4 packages to the dependencies list. As a result, you will find 3 different *.deb files in the package:
and leads to the question: Which Debian package is used on the target machine?
You can install the StructDB_gtk_1.2.12-0ubuntu1_all.deb package or the StructDB_qt4_1.2.12-0ubuntu1_all.deb package, or both. However, since these two packages depend on the Debian package StructDB_1.2.12-0ubuntu1_all.deb, which is the project without GUI dependencies, the StructDB_1.2.12-0ubuntu1_all.deb package is also installed in any case.
(F1) Defining program configurations (configuration file)
(F2) Multilingual application
(F3) Using a program help ( → function key F1)
(F4) Sharing of files that can only be read by all users
(F5) Sharing of files that require a user's write and read rights
(F6) Starting the program with and without argument
(F7) Creating your own MIME type for program-specific data files
The following sections and further chapters describe how to successfully implement the above requirements using the StructDB project as an example. At suitable places, some extracts from the source code of the project support the description.
The component gb.settings is used to define program configurations in a configuration file (→ Chapter 19.1). The window coordinates of the program window are stored in the configuration file in the standard path in the StructDB project.
Only at the first start the program window is centered. The values that were saved in the configuration file when the program window was closed then apply:
Public Sub Form_Open() … If IsNull(structSettings["Window/Top"]) And IsNull(structSettings["Window/Left"]) Then FMain.Center Else FMain.Top = structSettings["Window/Top", FMain.Top] FMain.Left = structSettings["Window/Left", FMain.Left] Endif … End ' Form_Open() Public Sub Form_Close() structSettings["Window/Top"] = FMain.Top structSettings["Window/Left"] = FMain.Left If FHelp.Closed = False Then FHelp.Close End ' Form_Close()
In the Options tab of the project settings, the default language English (UK) is selected in the Options tab after the Project can be translated question has been answered with Yes. Further information on the internationalization (I18N) of a project can be found in? chapter 20.1.3 Message and I18N and in? chapter 11.11 Project I18N.
The quickest way to start the translation of the individual texts into the German language is to use CTRL+T or start it in the menu under Project> Translate - you only have to translate it yourself.
Give the program StructDB and all future users a program help. The help in the main program is called with the function key F1 and the event Form_KeyPress() is evaluated in the main program. In response, a further form - FHelp in this case - is displayed with the help text which is closed with the escape key (ESC):
Public Sub Form_KeyPress() If Key.Code = Key.F1 Then FHelp.Show Endif If Key.Code = Key.ESC And FHelp.Closed = False Then FHelp.Delete Endif End ' Form_KeyPress() Public Sub Form_Show() FHelp.Border = 1 FHelp.Arrangement = Arrange.Fill TextArea1.Background = &H00FFFFDF& TextArea1.Text = File.Load("help.txt") ' → Relative path! End ' Form_Show()
The help text is only read from a file help.txt, since it does not have to be changed for the current program version. The help file is located in the IDE in the logical folder “Data”, which corresponds to the physical project folder.
Note: All files in the physical project directory are included in the “Gambas executable” when the StructDB.gambas executable file is generated. You can't find them anywhere in the file system of the target computer; but you can't reach them under “Application. Path” either! Details about this freely selected classification of folders (logical/physical) in a Gambas project can be found in the next paragraph.
The following explanations are generally necessary - also for understanding the transfer of files in the installation project:
On a data carrier, which will often be the computer hard disk, the Gambas project StructDB is located in a certain directory structure. If you switch on the display of hidden files/folders in your file browser, you will see some hidden folders that Gambas uses for control files as well as files and folders (marked red) that you have copied or created into the project directory.
Figure 18.104.22.168.7.1: Directory structure project directory (file browser)
If you edit the StructDB project in the Gambas IDE, you will surely notice the difference to the directory structure in → figure 22.214.171.124.1:
Figure 126.96.36.199.7.2: Directory Structure (Project Folder) Gambas IDE
If you also want to use the installation package to install files system-wide on the target computer, but to protect files from writing access by regular (non-root) users, then copy these files to the physical folder. hidden at the time of development or create them in the logical folder “Project” in the IDE, for example!
Figure 188.8.131.52.8.1: Files in hidden folder.hidden
User-specific files, on the other hand, are stored in user B's home directory on the target computer. Here, the content can only be read and edited by user B, unlike all other users. These user-specific files must be located in the IDE folder structure in the logical folder “Data” - that is, in the physical project folder. Such a file is in the project StructDB example. sdb (→ Figure 184.108.40.206.1), which is given to the program StructDB as a sample database and requires read and write permissions from user B. This file is called StructDB example. sdb (→ Figure 220.127.116.11.1).
But pay attention: You cannot install the user-specific file example.sdb with a Debian package, because the Debian Installer will always start as root and cannot recognize that you are, for example, the system user B with the sonorous name gambanix. Therefore, when the program is started for the first time, the selected user-specific file example. sdb is copied to the StructDB folder in user B's home directory. The folder whose name you can freely choose will be created if it does not exist - which is to be checked:
Public Sub Form_Open() … If Not Exist(User.Home &/ "StructDB") Then Try Mkdir User.Home &/ "StructDB" If Error Then Message.Error(Subst$(("Couldn't create the directory &1"), User.Home &/ "StructDB" & Error.Code)) Quit Else Try Copy "example.sdb" To User.Home &/ "StructDB/example.sdb" If Error Then Message.Error(Subst$(("Couldn't copy the file &1"), User.Home &/ "StructDB/example.sdb")) Endif Wait Endif Endif ' Not Exist(User.Home &/ "StructDB") … End ' Form_Open()
The program start of StructDB on a target computer (Mint 17.1 with German language package) is done either via the menu or by a created starter on the desktop or by calling it in the console - in the first case without argument:
hans@linuxmint:~$ /usr/bin/StructDB hans@linuxmint:~$ StructDB
Figure 18.104.22.168.1: Program start without argument
In the second case, the (pseudo) database file example.sdb is passed as argument at program startup:
hans@linuxmint:~$ StructDB -- ~/Kursdaten/example.sdb
Figure 22.214.171.124.10.2: Program start with file as argument
In the source code there is a small section in the procedure Form_Open(), which opens the program safely with and without argument when starting the program:
Public sOpenProjectPath As String Dim sArgsString As String Dim bOpenByArgs As Boolean Args.Begin() Args.End() For Each sArgsString In Args.End() If Not IsNull(sArgsString) Then sOpenProjectPath = sArgsString Import(sOpenProjectPath) tlblRecords.Foreground = Color.Red bOpenByArgs = True Endif Next If bOpenByArgs = False Then cmbDWC1.Text = cmbDWC1.Text cmbDWC2.Text = cmbDWC2.Text tlblRecords.Visible = False tlblRecords.Foreground = Color.Red Status(False) btnUpdate.Enabled = False btnSave.Enabled = False txbLastname.SetFocus Endif ' bOpenByArgs = False ?
2 methods of the component gb.args are used. A detailed description of this component can be found in chapter 5.8.0 Gambas programs with options and arguments.
More elegant would be the possibility that after double-clicking on a *.sdb file, the database program StructDB opens, the records from the selected *.sdb file are read and displayed. To achieve this, you must