Table of Contents
Version 0.0.2
Abstract
KNODA, or more exactly the hk_classes library, has an integrated Python interpreter. For further information about Python see http://www.python.org.
This documentation describes version 0.8 of the hk_classes Python interface.
Table of Contents
List of Figures
List of Examples
Table of Contents
Below you see the structure of hk_classes. There are classes that handle the contact to the database (see the left side of the graphic), while others handle the interaction with the user (we have already seen the hk_visible class in the previous section).
The following global variables are defined
hk_this: represents the current object, of which this function is called
hk_thisform: represents the form which contains the current object
hk_thisreport: represents the report which contains the current object
You can use hk_classes within Python. You can write your own Python applications using all the elements of hk_classes or interactively explore your data.
Example 1.1. Using hk_classes as a Python module
horst@horstnotebook:~> python Python 2.2.2 (#1, Mar 17 2003, 15:17:58) [GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from hk_classes import * >>> dr=hk_drivermanager() >>> con=dr.new_connection("mysql") >>> con.set_password("mypassword") >>> con.connect() 1 >>> db=con.new_database("exampledb") >>> mytable=db.new_table("authors") >>> mytable.enable()
Table of Contents
Inherits from hk_data. In contrary to Result Queries (queries with a SELECT - SQL-statement) action queries manipulate data like ALTER TABLE or INSERT INTO. There is no resulting data. Such a query is either successful or fails.
- set_sql(sqlstatement [,convertdelimiter])
sets the SQL statement. If convertdelimiter is False (the default) the identifier delimiters and text delimiters have to fit your SQL backend definitions. If set to True, hk_classes will fix the delimiters if the backend needs non-standard delimiters. (Remember: ANSI SQL identifier delimiter is a double quote ", and the ANSI SQL text delimiter is a single quote ').
- sql()
returns the used SQL statement
- length()
the length in bytes of the SQL statement
- execute()
executes the SQL statement and returns True if successful.
Represents a button in a form. If set_is_togglebutton(True) was called, this button toggles, otherwise it will go to non-pushed state after being clicked
Inherits from hk_dsvisible.
. when the button is pushed the action will be executed on the object Allowed actions are:
open_form
close_form
open_table
open_query
preview_report
print_report
goto_firstrow
goto_lastrow
goto_nextrow
goto_previousrow
insert_row
delete_row
store_row
action_query
The parameter 'object' is the name of the used object e.g. a form name (if you want to open a form).
The parameter 'showmaximized': if true show the window maximized else show the new window in its origin or default size.
The parameter 'registerchange': if this button is part of a form and any registerchange is true, the changes will be stored when you close the window
Example: to open the form "test" use
. The same as the function above, except that 'action' is anumeric value. Allowed values are:
0: open_form
1: close_form
2: open_table
3: open_query
4: preview_report
5: print_report
6: goto_firstrow
7: goto_lastrow
8: goto_nextrow
9: goto_previousrow
10: insert_row
11: delete_row
12: store_row
13: action_query
returns the set object name.
returns the set action number. For a detailled list see set_action
returns wether the used object will be displayed maximized. This value is set with set_object()
At least a database object of type hk_database has to be set to be able to automatically load forms etc.
returns the set hk_database object.
if istoggle is True, the button will remain in its pushed or non-pushed state after clicking, else it will always switch back to non-pushed state
returns whether or not this is a toggle button
if this is a togglebutton you can set its default state. If ispushed is True it will start as a pushed button
returns whether or not this togglebutton is in pushed state. If this button is not a togglebutton the result is undefined.
hk_class is the basic class for all other defined classes.
- show_warningmessage(message)
Prints a warning message by using a dialog window. If none is set the message will be print to standard error (cerr). (Info: if you use it in KNODA, such a dialog window is set)
- hk_translate(text)
tries to translate the message t by using implemented translatingfunction of the underlying OS.
- show_yesnodialog(question, default_value)
prints a question. The user has either to answer the question with yes or no.
Parameter 'question': the shown question
Parameter 'default_value': if hk_classes should not show nerving questions (can be set in KNODA's preferences dialog), the default_value will be returned without asking.
- show_stringvaluedialog(question)
prints the question 'question' and returns the user input. The user has to answer the question by entering a string (i.e. a filename).
Parameter 'question': the shown question
returns the string the user gave as an answer
- hk_string show_filedialog( default_filename,operation_mode)
prints a file dialog. The user adds a file name that will be returned as a string.
Parameter 'default_filename': a preset filename
Parameter 'operation_mode': either file_open (default) or file_save.
- hk_string show_directorydialog( default_directory)
prints a directory selection dialog. The user selects a directory that will be returned as a string.
Parameter 'default_directory': a preset directory
- save_preferences()
This function stores all preferences of the hk_classes library in the file ~/.hk_classes/preferences
represents a RGB-colour.
Inherits from hk_class.
Figure 2.1. hk_colour methods
- hk_colour( red, green, blue)
Constructor. Creates a new hk_colour object and sets the RGB values of the colour
- set_colour( red, green, blue)
sets the RGB colour. Valid values are in the range 0 to 255. returns True if successful, False if the colour could not be set (out of range).
- red()
returns the RGB red value
- green()
returns the RGB green value
- blue()
returns the RGB blue value
Figure 2.2. Predefined colour names
hk_aqua
hk_beige
hk_black
hk_blue
hk_brown
hk_fuchsia
hk_darkgrey
hk_green
hk_grey
hk_lightgrey
hk_lime
hk_maroon
hk_navy
hk_olive
hk_orange
hk_pink
hk_purple
hk_red
hk_silver
hk_teal
hk_white
hk_yellow
Represents one column of a datasource. The data of the current row (set in hk_datasource) can be modified by using the functions set_asstring(), set_asbool(),set_asdouble, set_asinteger and set_asbinary(). and read by using the functions asstring(), asbool(), asdouble(), asinteger() and asbinary().
If the the datasource is in alter or create mode you can change the column definition by using the following functions: set_name(), set_columntype(), set_size(), set_notnull(), set_primary()
Inherits from hk_class.
Figure 2.3. hk_column data methods
- set_asstring(value)
lets you set a new value for this object
- asstring()
returns the current value as a string value
- set_asdouble(value)
lets you set a new value for this object
- asdouble()
returns the current value as a double value
- set_asinteger(value)
lets you set a new value for this object
- asinteger()
returns the current value as a integer value
- is_readonly()
returns true if this column is read-only; if data can be changed it returns false
- find(from_rownumber,to_rownumber,searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found
- find(searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found. This version searches all rows of a datasource.
- datasource()
returns the hk_datasource object, to which this hk_column belongs to.
- count()
returns the number of rows that contain 'Not NULL' values
- count(from,to)
returns the number of rows that contain 'Not NULL' values, starting at position 'from' and counting to position 'to'
- sum()
returns the sum of all rows
- sum(from,to)
returns the sum of all rows, starting at position 'from' and counting to position 'to'
Example 2.3. Read data
col=hk_this.datasource().column_by_name("name") hk_this.show_warningmessage(col.asstring())
Example 2.4. Write data
col=hk_this.datasource().column_by_name("name") col.set_asstring("my new value")
This changes the value of the current column. The data is saved either when
the row position changes (e.g. by calling hk_datasource.goto_row())
the datasource is disabled (e.g. by calling hk_datasource.disable())
the changes are manually stored by calling hk_datasource.store_changed_data()
Example 2.5. Search data
col=hk_this.datasource().column_by_name("name") result=col.find("Schiller") if result > hk_this.datasource().max_rows(): hk_this.show_warningmessage("value not found") else: hk_this.show_warningmessage("Value found at row position: "+str(result))
Figure 2.4. hk_column type methods
- name()
returns the name of this column
- set_name(name)
sets the column name
- set_columntype(type)
sets the type of the column
Possible values are
textcolumn
auto_inccolumn
smallintegercolumn
integercolumn
smallfloatingcolumn
floatingcolumn
datecolumn
datetimecolumn
timecolumn
timestampcolumn
binarycolumn
memocolumn
boolcolumn
othercolumn
- columntype()
returns the type of the column.
- set_size()
sets the column size (e.g. if this column was should be a textcolumn with 10 characters set the type with set_type and the size with this function)
- size()
returns the column size (e.g. if this column was created as CHAR(10) it will return 10)
- set_primary(primary)
if 'primary' is true the column will be part of the primary key (primary index). Can only be edited if the datasource is in the mode ALTER or CREATE.
- is_primary()
returns true if this column is part of a primary key
- set_notnull(notnull)
if 'notnull' true the column needs a value
- is_notnull()
returns True if this column has to have a value
hk_connection connects to the SQL Server. The most important functions are set_host(), set_user(), set_password() and connect().
Inherits from hk_class.
- set_host(hostname)
sets the host name or host IP number
- host()
returns the host name
- set_user(username )
sets the user name used on the host
- user()
returns the user name
- set_password(password)
sets the password for the user
- set_tcp_port(port)
sets the TCP port
- tcp_port()
returns the TCP port
- default_tcp_port()
returns the default TCP port for this database server
- connect([interactive])
connects to the server using the user, host and TCP data. Returns True if connecting was successful, else False.
Parameter 'interactive': if set to interactive and the connection fails, a login dialog appears. Possible values
hk_class.noninteractive
hk_class.interactive
- disconnect()
disconnects from the server
- is_connected()
returns true if this connection is connected to the server
- dblist()
returns a list of all existing databases in this connection
- new_database([name])
creates a new hk_database object
- delete_database(databasename)
deletes an exisiting database
- database_exists(databasename)
returns true if the database "databasename" exists
- mimetype()
returns the mimetype of a local database format, if it is not a local database format it returns an empty string
Internal base class for hk_datasource and hk_actionquery.
Inherits from hk_class.
- set_name(name)
sets the name of the datasource
- name()
returns the name of this datasource
- type()
returns the type of this datasource. Possible values are:
ds_table
ds_query
ds_actionquery
ds_unknown
Represents a particular existing database on the SQL Server. To use it set the name of an existing database with set_name(). To create a new database use hk_connection.create_database().
Inherits from hk_class.
- tablelist()
returns a list of all existing tables in this database
- querylist()
returns a list of all existing queries in this database
- formlist()
returns a list of all existing forms in this database
- reportlist()
returns a list of all existing reports in this database
- new_table([name[,presentation]])
returns a new table object of type hk_datasource (read and write)
Parameter 'name': the name of the table
Parameter 'presentation': a presentation object (either a form or a report) that administers this table. In most cases you don't have to set this parameter.
- new_resultquery([presentation])
returns a new resultquery object of type hk_datasource (readonly)
Parameter 'presentation': a presentation object (either a form or a report) that administers this query. In most cases you don't have to set this parameter.
- new_actionquery()
returns a hk_actionquery object. It can execute SQL statements that don't return data and are only successful or not successful (e.g. CREATE TABLE)
- load_datasource(name[,query [,presentation]])
a convenience function for new_table and new_resultquery, that loads an existing datasource
- delete_table(tablename [,interactive])
deletes a table. Returns True if successful.
Parameter 'tablename': the name of the table
Parameter 'interactive': if set to interactive and the function fails, warning message appears. Possible values
hk_class.noninteractive
hk_class.interactive
- table_exists(tablename)
returns true if the table 'tablename' exists
- query_exists(queryname)
returns true if the query 'queryname' exists
- new_formvisible()
returns a new form object for the current GUI. If you want to display a new form within the GUI, use this function. If the application is a MDI application, the form will be embedded within the main application window.
- new_dialogformvisible()
nearly the same as the above function, but the form will not be embedded in the main application window. Such a form can be used as a dialog in combination with hk_form's show_asdialog() method.
- new_reportvisible()
returns a new report object for the current GUI. If you want to display a new report within the GUI, use this function. If the application is a MDI application, the report will be embedded within the main application window.
- new_tablevisible()
returns a new table object for the current GUI. If you want to display a new table within the GUI, use this function. If the application is a MDI application, the table will be embedded within the main application window.
- new_queryvisible()
returns a new query object for the current GUI. If you want to display a new query within the GUI, use this function. If the application is a MDI application, the query will be embedded within the main application window.
- copy_table(fromdatasource,[schema_and_data[,replacetable[,ask]]])
creates a new table and uses an existing datasource as a template
fromdatasource the datasource object of type hk_datasource which is used as a template
schema_and_data if true the table will be created and the data copied, if false the data will be not copied
replacetable see parameter ask for details
ask ask=true and replacetable=true => you will be warned before overwriting an old table
ask=true and replacetable=false => a new name will be asked
ask=false and replacetable=true => an old table will be overwritten without warning
ask=false and replacetable=false => copy_table immediately stops and returns false, if a table already exists
hk_datasource is the basic class which represents a resultquery or a table of a database. Never create this table directly. Use the hk_database.new_table() method instead.
Inherits from hk_data.
Two types of this class can be distinguished. Tables and resultqueries.
Resultqueries are queries with a SELECT - SQL-statement. The resulting data is readonly.
Tables are a special form of resultqueries. The SQL-statement is fixed ("SELECT * FROM <tablename>), but the resulting dataset can be edited. To reduce the number of rows you can use the function set_filter() and set_temporaryfilter(). To order the rows use the functions set_sorting() and set_temporarysorting().
A datasource manages hk_column objects, which allows you to modify the data of the datasource. See function column_by_name() for more information.
The datasource can be enabled with enable() and disabled by calling disable().
Figure 2.5. hk_datasource data methods
- set_name(n)
sets the name of the datasource
- name()
returns the name of the datasource
- set_sql(statement [,rawsql [,registerchange]])
set your own SQL statement, that will be executed when you enable the datasource. If this datasource is of type "table" the SQL statement will be automatically created. Parameters:
's' is the sql statement, 'rawsql': if true the sql statement will used unmodified (otherwise it may be changed,e.g identifier delimiters, text delimiters etc. ), 'registerchange': if this class is part of a hk_presentation object (i.e. a form or a report) and registerchange is true, then the changes will be stored when the hk_presentation object is closed. sorting, filtering or depending on statements). So it is possible to execute driver specific Returns true, if it is a valid SQL-Select statement and false if it is a query which does not contain the "SELECT" statement, i.e. SHOW FIELDS in Mysql.
- sql()
returns the name of the datasource
- backendsql()
returns the SQL statement as it is sent to the SQL server
- is_rawsql()
returns true if the SQL statement is used unmodified
- goto_row(rownumber)
moves the row selector (row cursor) to 'rownumber'
- goto_first()
move the row selector to the first row. All depending objects will be informed (visible objects, depending datasources etc) True if success, else False.
- goto_last()
move the row selector to the last row. All depending objects will be informed (visible objects, depending datasources etc) True if success, else False.
- goto_next()
move the row selector to the next row. All depending objects will be informed (visible objects, depending datasources etc) True if success, else False.
- goto_previous()
move the row selector to the previous row. All depending objects will be informed (visible objects, depending datasources etc) True if success, else False.
- row_position()
returns the row number of the current row
- max_rows()
returns the total number of existing rows
- enable()
If hk_connection is connected, this method will enable the datasource. The SQL-Statement in @ref SQL will be executed. If the SQL-statement is ok, the resulting data can be reached via the columns returned by columns(). You can browse the data by using the methods goto_row(), goto_first(), goto_last(), goto_next() and goto_previous(). returns True if enable() was successful.
- disable()
if the datasource is enabled, this function will disable it. The columnlist will be deleted.
- set_enabled(e)
convenience function: if e is true the datasource will be enabled by calling enable() else it will disable the datasource by calling disable().
- is_enabled()
returns True if the datasource is enabled.
- column_by_name(name)
returns an hk_column object of the column with the name 'name'
- store_changed_data()
if the data of the actual row has changed you can manually send the changes to the SQL Server by calling this function. The function will be called automatically before the datasource disables or the row selector will be moved to another row.
- database()
returns the hk_database object, to which this datasource belongs
- datasource_used()
returns True if a hk_visible object or a depending datasource is using this datasource, else returns False
- setmode_insertrow()
brings the datasource in insertmode. To add a new row call this function, set the data of the new row as usual in the columns (i.e.with hk_column::as_string ) and finally call either setmode_normal or store_changed_data.
- setmode_normal()
This is the usual mode, where you can browse the data and if the data is not readonly change the data.
- is_readonly()
Returns True if the datasource is read-only. If data can be written this function returns False.
- set_readonly(r)
If the datasource is of type ds_table you can allow or disallow data changes.
The following example shows how to move between rows in a datasource. For this, create a button in the form and set a datasource. Add the script to the "On click"-action.
How to get a specific hk_column object can be seen in the following example. For what you can do with this object, please see the next chapter.
Figure 2.6. hk_datasource filter and sorting methods
- set_filter(filter[,registerchange])
It is possible to filter only specific rows from a datasource by setting this filter. just add the conditions with this function. The parameter 'filter has the same syntax as a SQL statement in the 'WHERE' section, but without the word 'WHERE'
The parameter 'registerchange' : if this class is part of a hk_presentation object (i.e. a form or a report) and registerchange is True, then the changes will be stored when the hk_presentation object is closed.
Example: SELECT * from addresses WHERE city="Mnchen", so you would call set_filter("city=\"Mnchen\"");
- filter()
returns the filter string set with set_filter()
- set_temporaryfilter(temporaryfilter)
a temporary filter just work like a normal filter (see set_filter() ), but have to be manually activated with set_use_temporaryfilter(). When the datasource is loaded with loaddata() temporaryfilters are deactivated by default.
- temporaryfilter()
returns the temporary filter string
- set_use_temporaryfilter(use)
If 'use' is set to True the temporary filter is used, else it it is not used. Attention: this will be only used next time when the datasource will be enabled. If the datasource is already enabled, first disable() the datasource and then enable() it again.
- use_temporaryfilter()
returns True if the temporary filter is used, else False is returned
- clear_filter([registerchange])
deletes the filter, which was set with set_filter()
- set_sorting(order[,registerchange])
It is possible to sort the datasource. Just add the conditions with this function. 'order' has the same syntax as a SQL statement in the "ORDER BY" section, but without the words "ORDER BY".
'registerchange': if this class is part of a hk_presentation object (i.e. a form or a report) and registerchange is true, then the changes will be stored when the hk_presentation object is closed.
Example: SELECT * from addresses ORDER BY city DESC , so you would call set_sorting("city DESC");
- sorting()
returns the sorting string set with set_sorting()
- set_temporarysorting(temporarysorting)
temporary sorting just works like normal sorting (see set_sorting() ), but has to be manually activated with set_use_temporarysorting().
- temporarysorting()
returns the temporary sorting string set with set_temporarystring()
- set_use_temporarysorting(use)
If 'use' is set to True the temporary sorting string is used, else it it is not used. Attention: this will be only used next time when the datasource will be enabled. If the datasource is already enabled, first disable() the datasource and then enable() it again.
- use_temporarysorting()
returns True if the temporary sorting string is used, else False is returned
- clear_sorting([registerchange])
deletes the sorting order, which was set with set_order()
Figure 2.7. hk_datasource structure definition methods
- setmode_createtable
If you want to create a new table first bring the table in createmode. Define new columns with new_column. Afterwards you can create the table by calling create_table_now
- setmode_altertable
If you want to alter an existing table first bring the table in altermode. Define new columns with new_column. Alter it with alter_column and delete a column by calling alter_column. Afterwards you can alter the table by calling @ref alter_table_now
- new_column
if this datasource is of type "table" and in mode "create" or "alter" you can create a new column to define its parameters.
- alter_column(col [, name=NULL [,hk_column::enum_columntype* newtype=NULL [,long* size=NULL [,const hk_string* defaultvalue=NULL [,const bool* primary=NULL, [const bool* notnull=NULL ]]]]]])
if this datasource is of type "table" and in mode "alter" you can alter an existing column. NULL values mean, that this part will not be changed
- delete_column(col)
if this datasource is of type "table" and in mode "alter" you can delete an existing column.Just enter the name here.
- create_table_now(void);
After defining a new table with setmode_createtable and new_column this function creates physically the table
- alter_table_now()
After altering an existing table with setmode_altertable, new_column ,alter_column and delete_column this function alters physically the table
- mode()
returns the mode in which the datasource is. Valid values are:{mode_normal,mode_createtable,mode_altertable,mode_disabled,mode_insertrow,mode_deleterow,mode_unknown}
To create a table, first get a new table object, set a name and set the mode to "createtable".
After that you can define new columns. First create it with new_column() and then set the type, name etc. When finished, create the table with create_table_now().
Example 2.8. create table
>>> table = db.new_table() >>> table.set_name("my new table") >>> table.setmode_createtable() >>> col=table.new_column() >>> col.set_columntype(hk_column.auto_inccolumn) >>> col.set_name("id") >>> col=table.new_column() >>> col.set_name("name") >>> table.create_table_now() CREATE TABLE `my new table` ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT , BIGINT, PRIMARY KEY ( `id` ) ) Table created 1
Figure 2.8. hk_datasource Index definition methods
- create_index(name [,unique [, list<hk_string>& fields]])
Creates an index of a table. returns true if successful otherwise false. Make sure you have set the tablename first. 'name' is the name of the new index, if 'unique' the index will be a unique index, and finally 'fields' is a string list of the field names, this index uses. Function returns True if successful otherwise False;
- alter_index(name [,unique [,list<hk_string>& fields]])
Alters an existing index by first dropping it with drop_index() and then by trying to recreate it with create_index().
- drop_index(name)
Deletes an index of a table. Returns true if successful otherwise false;
Transforms date and/or time formats to any other format
Inherits from hk_class.
- set_date(day,month,year)
sets the date as numbers
- set_time(hour,minute,second)
sets the time as numbers
- set_datetime(day,month,year,hour,minute,second)
sets the date and the time as numbers
- set_date_asstring(s)
sets the date as a string formatted as set in set_dateformat
- set_time_asstring(s)
sets the time as a string formatted as set in set_timeformat
- set_datetime_asstring(s)
sets the datetime as a string formatted as set in set_datetimeformat
- date_asstring()
returns the date as a string formatted as set in set_dateformat
- datetime_asstring()
returns the datetime as a string formatted as set in set_datetimeformat
- time_asstring()
returns the time as a string formatted as set in set_timeformat
- set_dateformat(f)
Any string is valid. The values have to be separated with at least one character. The variables are
D for the day M for the month Y for the year example : "D.M.Y h:m:s" shows the 4th of November 2001 at noon as 04.11.2001 12:00:00 and "Y-M-D h/m" as 2001-11-04 12/00
- set_timeformat(f)
Any string is valid. The values have to be separated with at least one character. The variables are
h for the hour m for the minute s for the second example : "D.M.Y h:m:s" shows the 4th of November 2001 at noon as 04.11.2001 12:00:00 and "Y-M-D h/m" as 2001-11-04 12/00
- set_datetimeformat(f)
Any string is valid. The values have to be separated with at least one character. The variables are
D for the day M for the month Y for the year h for the hour m for the minute s for the second example : "D.M.Y h:m:s" shows the 4th of November 2001 at noon as 04.11.2001 12:00:00 and "Y-M-D h/m" as 2001-11-04 12/00
- day()
returns the day
- month()
returns the month
- year()
returns the year
- hour()
returns the hour
- minute()
returns the minute
- second()
returns the second
- difference(datetime)
returns the difference in seconds,negative values say that this object is contains a time before 'datetime'
hk_drivermanager handles the database drivers. You need just one object of this type for your whole application.
Inherits from hk_class.
- driverlist()
returns a list of all available database drivers
- new_connection(drivername)
creates a new object of type hk_connection. If 'drivername' is not set a dialog appears to ask for the database driver.
Base class for combobox fields. Just set the datasource and the column (defined in the parent class hk_dsdatavisible). To fill the listbox with values set the datasource which contains the wished values with set_listdatasource. The columnname of the row which should be displayed in the listbox Must be set with set_viewcolumn(). The row which contains the data to be written has to be specified with set_listcolumn().
Inherits from hk_dsdatavisible.
- set_listdatasource(list)
Comboboxes need 2 datasources. One (the normal) datasource is set with set_datasource() and stores the values in a field. The second datasource contains a list of possible values for this field.
'list': the hk_datasource object, which contains the values displayed in the combobox
- listdatasource()
returns the list datasource hk_datasource object.
- set_listpresentationdatasource(list)
if this combobox is part of a hk_presentation object (i.e. a form) you can set the listdatasource by its unique presentation number
- listpresentationdatasource()
returns the unique presentation number.
- set_viewcolumnname()
The column of the listdatasource which will be displayed in the combobox
- viewcolumnname()
returns the view columnname.
- set_listcolumnname()
The column containing the equivalent key to the column set with set_column()
- listcolumnname()
returns the list column name.
- set_mode()
If the comboboxmode is set to 'combo' it reacts like a normal datasource. If set to 'selector' the datasource will be moved to the selected row in the datasource. You then just have to add the listcolumnname
combo
selector
- mode()
returns the mode
- viewcolumn()
returns the hk_column object representing the viewcolumn
- listcolumn()
returns the hk_column object representing the listcolumn
This is the base class for visible widgets that provides access to a specific column and its data. To use visible objects you have to set the datasource with set_datasource() and the column with set_columnname().
Inherits from hk_dsvisible.
- set_columnname(columnname [,registerchange])
column name in the datasource(). If there is no column with this name the widget will not be enabled
Parameter 'column': the wished column
Parameter 'registerchange': If this object will be displayed on a form you can decide whether changing the column name should mark the form as changed (then it will be saved when closed). Default is "true".
- columnname()
returns the column name string
- column()
returns the used hk_column object
- set_defaultvalue(def[,registerchange])
Sets the default value. The default value will be used in insert mode.
Parameter 'def': the new default value
Parameter 'registerchange': if true and this widget is part of a form the new default value will be stored when closing the form. The following variables are available:
%NOW% the actual date, time or datetime, depending on the fieldtype. Default ist datetime
%NOWDATE% the actual date
%NOWTIME% the actual time
%TRUE% the driver specific true value.
%FALSE% the driver specific false value.
- defaultvalue()
returns the default value, but variables are replaced by its values
- raw_defaultvalue()
returns the default value as set with set_defaultvalue, without replacing the variables
- reset_default([registerchange])
resets the default value. After that no default value will be used
- set_numberformat([use_numberseparator[, precision[,registerchange]]])
Sets the definition how to format number strings.
Parameter 'use_numberseparator': True or False. If true, this will use a thousand separator if your locale set defines one. E.g. in Germany the number 3.000,5 means three thousand and a half. The dot is the thousands separator. Of course the used character is depending on your locale definition.
Parameter 'precision': The number of digits used to represent values smaller than 1.
- use_numberseparator()
returns True if the number separator is used
- precision()
returns the number of digits
- value_at(row)
returns the formatted string in the column at row position 'row'
- value()
returns the displayed string (the current value)
- set_value(value)
sets the current value,where 'value' is a string. If a column is set, the datasource will be changed, if not it will be only displayed
- find(from_rownumber,to_rownumber,searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found
- find(searchtext[,wholephrase[,casesensitive[,backwards]]])
searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found. This version searches all rows of a datasource.
base class for widgets which show multi column and multi row data in a grid. Its main task is to manage gridcolumns of type hk_dsgridcolumn objects.
The grid can either automatically handle which gridcolumns should be shown. The exact handling can be defined with set_enablingbehaviour(). If you want to define the gridcolumns yourself use set_hold_rowdefinition(),clear_gridcolumn() and set_gridcolumns().
Inherits from hk_dsvisible.
- gridcolumn(col)
returns the hk_dsgridcolumn object at position number 'col'
- columnscount(void)
returns the number of columns shown in the grid
- set_gridcolumnwidth(column, newwidth)
sets the new width 'newwidth' of gridcolumn number 'column'.
- set_gridcolumns(columnnamelist)
you can manually set the gridcolumn definition. 'columnnamelist' is the new defintion of the gridcolumns, all values in this definition will be used
- clear_gridcolumn()
deletes the gridcolumn definition.
- set_hold_rowdefinition(hold)
If true and you change the row definitions (i.e. column size) after disabling and reenabling your definitions still exist, if false the rows will be newly built. Default is true. See also set_enablingbehaviour().
- set_enablingbehaviour(add_col,del_col)
If set_hold_rowdefinition() is true, this function defines what exactly to do during enabling If 'add_col' if true, columns of the datasource will be added to the grid if no equivalent gridcolumn exists. Default is false. If 'del_col' if true, gridcolumns will be removed if no equivalent columns in the datasource exist. Default is false.
- save_query([name[,ask]])
Saves the datasource and grid definition in a file in directory ~/.hk_classes/DRIVERNAME/HOST/DATABASENAME with the extenstion '.hk_query' and using the name 'name'. If 'ask' is True the user will be asked before overwriting an existing file.
- load_query()
loads the query definition with the name that is defined with set_name()
- save_table([name[,ask]])
Saves the grid definition in a file in directory ~/.hk_classes/DRIVERNAME/HOST/DATABASENAME with the extenstion '.hk_table' and using the name 'name'. If 'ask' is True the user will be asked before overwriting an existing file.
- load_table()
loads the table with the name that is defined with set_name()
- change_columnposition(from,to)
It's possible to change the order of the columns. 'from' is the original position of the gridcolumn, 'to' is the target position.
- set_rowheight(newheight [,registerchange])
Sets the height of all rows in the grid.
- rowheight()
returns the current rowheight.
Represents a column in a hk_dsgrid.
Inherits from hk_dsdatavisible.
the text displayed in the column header. If not set the columnname will be displayed
returns the text displayed in the column header
Sets the gridcolumn type. The following values are possible:
columnedit
columnbool
columncombo
If 'type' is columnedit the celldata will be shown as a string. If 'type' is columnbool the celldata will be shown as a boolean field. If 'type' is columcombo the celldata will be handled in a combobox during edit.
returns the gridcolumntype
sets the displaywidth of the gridcolumn
returns the displaywidth
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
returns True if the listdatasource is a table (and thus read- and writeable)
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
If type() is columncombo the cell will be handled in a combobox. See hk_dscombobox for details.
hk_dsimage is a data-aware image object. It does not store the images in a database. It loads them from a directory. The column contains the name of the image. If the image name contains a full path, this will be used. If it is only the image name the path set with set_path() will be used. If this is empty, the image will be searched in the current directory.
Inherits from hk_dsdatavisible.
Sets the path where the images are stored.
returns the path
Zooms the image in percent. Values of 0 or smaller than 0 means 'fit to size', 100 (%) is the original size
returns the current zoom
Base class for hk_presentation. It handles the modechange from designmode to viewmode.
Inherits from hk_dsvisible.
- set_mode(mode)
If mode is 'designmode' then you can define or alter a presentation else the data will be shown. Possible values are:
designmode
viewmode
- set_designmode()
convenience function for set_mode(hk_dsmodevisible.designmode)
- set_viewmode()
convenience function for set_mode(hk_dsmodevisible.viewmode)
- mode()
returns the current mode
This is the base class for visible widgets which do not need access to the data, but do have to know whether or not a datasource is enabled and which row is the actual one.
Inherits from hk_visible.
- set_datasource(datasource)
Sets the datasource object of type hk_datasource.
- datasource()
return the datasource object of type hk_datasource.
- set_presentationdatasource(number [,registerchange])
presentation objects (either a form or a report) administer all datasources themselves. Datasources then can be identified by a unique number. If this visible object is part of a presentation object, you can set this number with this function
- presentationdatasource()
returns the number of the used presentation datasource, or -1 if none is set.
Represents a font object.
Inherits from hk_class.
- hk_font(fontname,fontsize)
Constructor to create a font object. E.g. myfont=hk_font("Arial",12)
- set_font(fontname,fontsize)
Allows to change the fontdefinition. E.g. myfont.set_font("Courier",16)
- fontname()
returns the font name.
- fontsize()
returns the font size.
- set_bold()
If the font should be displayed in bold you can set it with myfont.set_bold(True)
- bold()
returns True if the font is displayed in bold.
- set_italic()
If the font should be displayed in italic you can set it with myfont.set_italic(True)
- italic()
returns True if the font is displayed in italic.
Hk_form represents a form.
Inherits from hk_presentation.
- load_form([name])
Loads the form from a file, where 'name' is the name of the form
- save_form([name[,ask]])
Saves the form to a file, where 'name' is the name of the file. if 'ask' is true and the form already exists you will be asked before the old form will be overwritten. Returns True if successful else False.
- masterform()
if this is a subform it will return master form it belongs to.
- new_grid()
The form has to be in design mode to use this function! The function will create a new hk_dsgrid in the upper left corner and returns it if successful.
- new_lineedit()
The form has to be in design mode to use this function! The function will create a new hk_dslineedit in the upper left corner and returns it if successful.
- new_bool()
The form has to be in design mode to use this function! The function will create a new hk_dsboolean in the upper left corner and returns it if successful.
- new_combobox()
The form has to be in design mode to use this function! The function will create a new hk_dscombobox in the upper left corner and returns it if successful.
- new_button()
The form has to be in design mode to use this function! The function will create a new hk_button in the upper left corner and returns it if successful.
- new_rowselector()
The form has to be in design mode to use this function! The function will create a new hk_dsrowselector in the upper left corner and returns it if successful.
- new_memo()
The form has to be in design mode to use this function! The function will create a new hk_dsmemo in the upper left corner and returns it if successful.
- new_label()
The form has to be in design mode to use this function! The function will create a new hk_label in the upper left corner and returns it if successful.
- set_designsize(width,height[,registerchange])
Sets the real size of the form. If you designed a form in i.e. 800x600 resolution and want to watch it with 1024x768 resolution, set this to 1024x768. Dynamic sized visible objects will be resized. All objects will be positioned new.
- get_visible(number)
returns an existing visible object of type hk_visible identified by a unique identifier number. You should use get_pyvisible instead, so typecasting is not required any more.
Important
To find this number, click on the object. In the property editor you can see the number in field 'Id'.
To change the hk_visible object to the type you need there are some type casting functions
Figure 2.9. Type casting
hk_button cast_button(hk_visible)
hk_dslineedit cast_dslineedit(hk_visible)
hk_dsmemo cast_dsmemo(hk_visible)
hk_dsgrid cast_dsgrid(hk_visible)
hk_dscombobox cast_dscombobox(hk_visible)
hk_dsboolean cast_dsboolean(hk_visible)
hk_dsvisible cast_dsvisible(hk_visible)
hk_form cast_form(hk_visible)
hk_report cast_report(hk_visible)
- get_visible(name)
returns an existing visible object of type hk_visible identified by a unique text identifier. This is a user-defined unique identifier and can be set in the property editor.You should use get_pyvisible instead, so typecasting is not required any more.
- get_pyvisible(number)
returns an existing visible object identified by a unique identifier number. There is no need for typecasting.
Important
To find this number, click on the object. In the property editor you can see the number in field 'Id'.
- get_pyvisible(name)
returns an existing visible object identified by a unique text identifier. There is no need for typecasting.
- set_focus(widget)
will set the focus to 'widget'
- set_taborder( taborder[,registerchange [, forcesetting]])
sets the tab order (the focus order) of the widgets. 'taborder' is a list of the presentation numbers of the widgets, which should get the focus
- goto_taborder_next()
will move the the focus to the next widget (see set_taborder )
- goto_taborder_previous()
will move the the focus to the previous widget (see set_taborder )
- goto_taborder_first()
will move the the focus to the first widget (see set_taborder )
- goto_taborder_last()
will move the the focus to the last widget (see set_taborder )
- show_asdialog([parentform])
Displays this form as a modal dialog. Use this method only, if this form was created via the hk_database.new_dialogformvisible() method. You can optionally set the parentform on which this form will always stay on top.
- screen_width()
return the screen width
- screen_height()
returns the screen height
The next program shows you how to start a form:
Example 2.9. displaying a form
myform=hk_this.datasource().database().new_formvisible() myform.load_form("authorform") myform.set_mode(myform.viewmode)
base class for a pressed key
Inherits from hk_class.
- keynumber key()
returns the key number. The key codes are compatible to Qt of Trolltech. See the QT documentationfor details.
- int state() const;
the state codes can be combined via 'OR'. It returns whether the Alt or the Ctrl key is pressed. Possible values are state_normal,state_shift,state_ctrl, state_alt
- string text()
if the key represents a printable key it will be returned as text()
- accept_key()
returns whether or not this key will be accepted (and used as input)
- set_accept_key(bool)
if true the key will be accepted, if set to false the key will be ignored
Both forms and reports inherit from hk_presentation. The most import function of hk_presentation to manage all needed datasources. New datasources are created with new_datasource(), existing datasources can be found with get_datasource().
Inherits from hk_dsmodevisible.
sets the database object of type hk_database
Returns the type of the presentation. The following values are possibe:
form
report
sets the name of the presentation
returns the name of the presentation
returns a new hk_datasource object with name 'name'. If 'is_query' is True it is a query object, else a table
gets an existing datasource with the identification number 'number'
gets an existing datasource with the identification name 'name'
returns the unique datasourcename for the datasource with the identification number 'number'
deletes all existing datasource objects in the presentation
This function defines which metric system should be used. Allowed values are:
relative: the visible objects use size values from 0 to 10000 (100.00%), relative to the design size of the presentation.
absolute: the visible objects use absolute size values (either in pixels or in one tenth of a millimeter)
returns the set sizetype
Sets the logic size of the presentation.
returns the design height of the presentation
returns the design width of the presentation
returns whether the definition of this presentation has changed
hk_report represents a report. It is a general report generator, that means it is able to not only print Postscript, hk_report is able to create any kind of text output. See set_reporttype().
A report is split in sections of type hk_reportsection. These sections contain the displayed data of type hk_reportdata. There are predefined sections:
the datasection, which is the only section, that has not a sibling.
the pageheader section and the pagefooter section,
the reportheader section and the reportfooter section.
Self defined sections are grouped in pairs (a header and a footer section), which will be managed by a container object of type hk_reportsectionpair. To create a new sectionpair use new_sectionpair() and new_sectionpair_at().
Inherits from hk_presentation.
returns a hk_reportdata object identified by a unique identifier number
returns a hk_reportdata object identified by a unique text identifier
loads the report definition from a file, where 'name' is the name of the report
Saves the report to a file, where 'name' is the name of the file. if 'ask' is true and the report already exists you will be asked before the old report will be overwritten. Returns True if successful else False.
returns the hk_reportsection object which represents the data section.
returns a new hk_reportsectionpair object which embraces the other sections.
returns a new hk_reportsectionpair object at position 'position. The most outside position is 0.
moves an existing hk_reportsectionpair relative to the other existing hk_reportsectionpair objects. The 'actualposition' is the current position of the sectionpair to be moved Parameter 'steps':positive values move it closer to the datasection, negative values move it away.
returns the page header section of type hk_reportsection. The page header section will be printed once at the beginning of every page.
returns the page footer section of type hk_reportsection. The page footer section will be printed at the end of every page.
returns the report header section of type hk_reportsection. The report header section is printed once at the beginning of the report.
returns the report footer section of type hk_reportsection.The report footer section is printed once at the end of the report.
Set the starting pagenumber if the first page should not start with 1.
returns the first page number.
Sets the filename of the report. It will be used for the output of the report. If you don't give the report a name the report and use_standard_storagepath() is false will be printed at the standard output. See also set_fileextension().
returns the filename
The output filename will be completed with this extension, i.e. '.ps' for postscript files
returns the file extension.
sets the report type 'name'.
returns the set report type
returns a list of all available report types.
Here is how to start a report:
Example 2.10. displaying a report
myreport=hk_this.datasource().database().new_reportvisible() myreport.load_report("complexreport") myreport.set_mode(myreport.viewmode)
A visible object in a report is of type hk_reportdata, which inherits from hk_dsdatavisible. The main methods are
set_data(const hk_string& d)
hk_string data(void)
The data property contains the value that is displayed. See the knodatutorial chapter "The report field" for details.
The following example shows how to print numbers in different colours. For this we use the "onprint" action
Example 2.11. reportdata onprint
value=hk_this.column().asdouble() if value<0: hk_this.set_foregroundcolour(hk_red) else: if value==0: hk_this.set_foregroundcolour(hk_black) else: hk_this.set_foregroundcolour(hk_blue)
Represents the data of a field within a section.
Inherits from hk_dsdatavisible.
- set_data(data [,registerchange])
Sets the data string, that should be printed. Available variables for data:
columnnames delimited by #, eg. #mycolumn#
%XPOS% the absolute value of the x-coordinate
%YPOS% the absolute value of the y-coordinate
%WIDTH% the absolute value of the width
%HEIGHT% the absolute value of the height
%RELXPOS% the relative value of the x-coordinate
%RELYPOS% the relative value of the y-coordinate
%RELWIDTH% the relative value of the width
%RELHEIGHT% the relative value of the height
%PAGENUMBER% the number of the page
%ABSOLUTEPAGENUMBER% physical number of the page in file
%ROWNUMBER% the actual row number of the datasource
If you have set a column with set_columnname() you have additionally the following variable names
%value% the raw value of the column defined with @ref set_columnname
%fieldname% the name of the column not recoded defined with set_columnname
%VALUE% the value of the column defined with @ref set_columnname recoded
%FIELDNAME% the recoded (with @ref hk_report::set_recodefunction ) name of the column
%COUNT% the number of values
%SUM% the sum of all values
%MIN% the minimum value
%MAX% the maximum value
%STDDEV% standard deviation
%STDDEVSAMPLE% standard deviation of a sample
%AVERAGE% the average of all values
- data()
returns the data
- set_beforedata(bdata [,registerchange])
The value that will be printed immediately before the data. That can be escape sequences, delimiters etc. Example: CSV files (comma separated values) usually have the following format: "data1","data2" In this case the '"' would be printed before and after the data, so this would be defined with set_beforedata("\"") and set_afterdata("\""). The "," is set with hk_reportsection.set_betweendata(","). Use this function only if hk_report.reporttype() is set to "Userdefined".
- beforedata()
returns the value that will be printed immedialtely before the data.
- set_afterdata(adata [,registerchange])
The value that will be printed immediately after the data. That can be escape sequences, delimiters etc. Example: CSV files (comma separated values) usually have the following format: "data1","data2" In this case the '"' would be printed before and after the data, so this would be defined with set_beforedata("\"") and set_afterdata("\""). The "," is set with hk_reportsection.set_betweendata(","). Use this function only if hk_report.reporttype() is set to "Userdefined".
- afterdata()
returns the value that will be printed immedialtely after the data.
- actual_string()
returns the printed string. This function shouldn't be called from the user!
- count()
returns the value that should be added to hk_report.offset
- set_runningcount([ do_count,[registerchange]])
The values of the variables %SUM% %COUNT% %AVERAGE% %STDDEV% etc. can be relatively to the section. e.g. if the section is a uniquesection and it changes, all variables can be reset to 0 (default). if 'do_count' is true these variables will change to global variables in the report and are not set to 0 when the section changes.
- runningcount()
returns true if runningcount is set
- set_topline([set_it [,registerchange]])
If 'set_it' is True a line should be painted above the data
- set_bottomline([set_it [,registerchange]])
If 'set_it' is True a line should be painted below the data
- set_leftline([set_it [,registerchange]])
If 'set_it' is True a line should be painted left of the data
- set_rightline([set_it [,registerchange]])
If 'set_it' is True a line should be painted right of the data
- set_diagonalluro([set_it [,registerchange]])
If 'set_it' is true a diagonal will be painted from _l_inks _u_nten to _r_echts _o_ben (left down to right up)
- set_diagonalloru([set_it [,registerchange]])
If 'set_it' is true a diagonal will be painted from _l_inks _o_ben to _r_echts _u_nten (left up to right down)
- topline()
returns true if a line at the top of the data is printed
- bottomline()
returns true if a line at the bottom of the data is printed
- leftline()
returns true if a line at the left of the data is printed
- rightline()
returns true if a line at the right of the data is printed
- diagonalloru()
returns true if a diagonal line from left top to right bottom is printed
- diagonalluro()
returns true if a diagonal line from left bottom to right top is printed
- set_frame(set_it)
convenience function: calls set_leftline(set_it),set_rightline(set_it)set_topline(set_it)set_bottomline(set_it)
- set_wordbreak(set_it)
If 'set_it' is true and the reporttype supports it, text will be written in more than one line if the width of the data field is too small
- wordbreak()
returns true is set_wordbreak() is set
- set_configurefunction(functionname)
internal function
- configurefunctionstring()
returns the name of the configure function
hk_reportsection represents a section in a hk_report element. Within a section you can define the outputdata,use it as headers for your data and so in If it is needed as a section header or footer use set_unique() in combination with set_uniquecolumn() It also can contain subreports.
Usually section come as "twins", a header section and a footer section belonging to each other, see hk_reportsectionpair for details
Example 2.12. Creating a CSV export file based on a report
Example: Defining a CVS output (no first row with columnnames)
p_driver=hk_drivermanager() connect=p_driver.new_connection("mysql") connect.set_user("root") connect.set_host("localhost") connect.set_password("my_password") connect.connect() database=connect.new_database("exampledb") e=hk_report() e.set_reporttype("Userdefined") datasrc =e.new_datasource("authors",True)#loads an existing query e.set_presentationdatasource(datasrc) section=e.datasection() section.set_default_data("\"%VALUE%\"")# define " before and after the value of a column section.set_betweendata(" , ")# a comma separated list section.set_sectionend("\n")# one row per datarow e.execute()
You can use the variables
%PAGENUMBER% the number of the page
%ABSOLUTEPAGENUMBER% physical number of the page in file
Inherits from hk_dsdatavisible.
- set_unique([is_unique[,endsection]])
If the section should be printed just once per block and not for each datarow use this function. If 'unique' true if this section should be printed once. If 'endsection' true if this section should not be printed as a header. Instead it will be printed at the end of the block. Sections created with hk_reportsectionpair are already set correctly.
- unique()
returns True if this is a unique section.
- new_data()
returns a new object of type hk_reportdata.
- data_at(position)
returns an existing object of type hk_reportdata.
- actual_string()
Internal function. Returns the string that will be printed.
- set_sectionbegin(sbegin)
The sectionbegin will be printed as a header of the section (before the data).
- sectionbegin()
returns the section begin string.
- set_sectionend()
The sectionend will be printed as a footer of the section (after the data)
- sectionend()
returns the section end string.
- set_betweendata()
A string that will be printed between two datasegments defined with new_data(). E.g. If you want a comma separated list you would need set_betweendata(" , ").
- betweendata()
returns the value that will be printed between 2 data fields
- new_uniquevalue(justcheck)
returns True if this section is a unique section and this section has to be printed. If 'justcheck' is True no variables(lastvalue) will be changed
- endsection()
Returns True if this section is a unique section and will be printed behind the data.
- set_automatic_create_data(automatic)
If set true and you haven't defined any data with new_data() it will automatically create the data objects.
- set_new_page_after_section(npage)
If 'npage' is True a new page will be started after printing this section. Usually this function should only be used in combination with set_unique() as an endsection.
- new_page_after_section()
returns true if a new page at the end of the section will be started.
- set_subreport(reportname [,before_data])
A complete report can be printed within a section. If 'before_data' is true the subreport will be printed before the data of this section will be printed, else it will be printed after the data.
- subreportname()
returns the name of the subreport
- subreport()
returns the subreport as a object of type hk_report.
- add_depending_fields(thisreport_field,subreport_field)
If you set a subreport with set_subreport() add the fields which are connected between the reports
- clear_depending_fields()
Clears the field definition for subreports.
- depending_on_thisreportfields()
Returns a list of the connected fields of this report, which are connected to the subreport.
- depending_on_subreportfields()
Returns a list of the connected fields of the subreport, which are connected to this report.
- print_subreport_before_data()
returns True if the subreport will be printed before the data.
- reset_count()
Will set all COUNT, SUM, AVERAGE and so on variables to 0, if they are not "running counts" (which mean global for the whole report).See hk_reportdata for details. Usually you dont't have to call this function
- counts_as()
- set_default_reportdata(value)
The 'value' will be used as a default when a new data will be created with new_data() The preset value is @VALUE@.
- default_reportdata()
- set_default_beforereportdata(value)
The 'value' will be used as a default when a new data will be created with new_data()
- default_beforereportdata()
- set_default_afterreportdata()
The 'value' will be used as a default when a new data will be created with new_data()
- default_afterreportdata()
- report()
Returns the hk_report object this section belongs to.
- reportsectionpair()
Returns the hk_reportsectionpair object this section belongs to.
- set_offset(value)
The offset is additional space at the end of the section (totalsectionsize= size needed by reportdata + offset)
- offset()
Returns the offset.
- get_reportdatavisible(number)
Returns a hk_reportdata object identified by a unique identifier number. Searches only within this section.
- get_reportdatavisible(identifier)
Returns a hk_reportdata object identified by a unique text identifier. Searches only within this section.
Contains a header and a footer section.
Inherits from hk_class.
- headersection()
Returns the headersection of type hk_reportsection.
- footersection()
Returns the footersection of type hk_reportsection.
- set_sections([use_headersection[,use_footersection]])
Sets the sections. If 'use_headersection' is true a header section will be created else destroyed. If 'use_footersection' is true a footer section will be created else destroyed.
- init_sections()
Brings the sections into their initial state.
- set_columnname(colname)
The column name that will be set for grouping of the reportsections
- columnname()
returns the grouping column name
- set_ascending_order(ascending)
Sets whether the grouped data should be sorted in ascending or in descending order. If 'ascending' is True it is ascending else descending.
- ascending_order()
returns True if the sorting order is ascending.
Base class for visible widgets. It handles the geometry and the look of the widgets.
Inherits from hk_class.
Figure 2.10. Geometry specific methods
- set_size(x, y,width,height)
lets you to set position and size of an object
- set_size(width,height)
lets you to set size of an object
- set_position(x,y)
lets you to set position of an object
- set_x(x)
lets you to set the horizontal position of an object
- set_y(y)
lets you to set the vertical position of an object
- set_width(width)
see set_size()
- set_height(height)
see set_size()
- x()
returns the x co-ordinate of the object
- y()
returns the y co-ordinate of the object
- width()
returns the width of the object
- height()
returns the height of the object
- key()
returns a object of type hk_key. You can use this during the action_on_key() action. In combination with the hk_keys 'set_accept_key()' method you can handle whether or not this key will be accepted as input.
- action_on_click(void)
triggers the on_click action
- action_on_doubleclick(void)
triggers the on_doubleclick action
- action_on_close(void)
triggers the on_close action
- action_on_open(void)
triggers the on_open action
- action_on_getfocus(void)
triggers the on_getfocus action
- action_on_loosefocus(void)
triggers the on_loosefocus action
- action_on_key(void)
triggers the on_key action
Figure 2.11. Look and Feel methods
- set_font(fontname,size)
sets the font, e.g. set_font("Arial",12)
- set_font(font)
sets the font of type hk_font, e.g.
- hk_font font()
returns a font object of type hk_font
- set_foregroundcolour(colour)
sets the foreground colour. 'colour' is of type hk_colour. The foreground colour will be used for fonts, frames etc
- foregroundcolour()
returns the foreground colour, which is of type hk_colour.
- set_backgroundcolour(colour)
sets the background colour. 'colour' is of type hk_colour. This colour will be used to fill the whole background.
- hk_colour backgroundcolour()
returns the background colour, which is of type hk_colour.
Figure 2.12. Miscelleanous methods
- set_label(labeltext)
Every visible object has a label which will be displayed when necessary, i.e. a button usually needs a label
- label()
returns the label string.
- type()
returns the type of this object. Possible values are:
boolean
button
combobox
grid
image
lineedit
memo
report
reportsection
reportdata
rowselector
textlabel
other
- identifier()
the identifier is a unique name within a presentation (either a form or a report) with which this object can be identified and thus located
- presentation()
returns the parent hk_presentation object (either a form or a report)
- show_widget()
if the object isn't visible yet (hidden with hide_widget()) it will be shown
- hide_widget()
if the object is visible it will be hidden
- close_widget()
The object if possible, otherwise it will be hidden
- set_tooltip(tip[,registerchange[,force_setting]])
sets a little help text that will be shown when the mouse moves over the widget
- tooltip()
returns the tooltip text
- set_enabled(enabled [,registerchange [,force_setting]])
sets the visible oject 'enabled', means that it can accept keyboard commands
- is_enabled()
returns True if the object is enabled
The following example shows how to move the button within the form, how to change the colour and how to display different text on the button.
Example 2.14. Changing colour and position
redcolour =hk_colour(255,0,0) greencolour =hk_colour(0,255,0) if hk_this.foregroundcolour().red()!=255: hk_this.set_foregroundcolour(redcolour) hk_this.set_backgroundcolour(greencolour) hk_this.set_label("green button") else: hk_this.set_foregroundcolour(greencolour) hk_this.set_backgroundcolour(redcolour) hk_this.set_label("red button") hk_this.set_position(hk_this.x()+50,hk_this.y()+10)