DBFrames public API reference (BETA)

Classes

G

The global variables class.

Configuration properties
  • dbfilename: SQLite database file name, default 'dbfile.db'.
  • maxrows: maximal number of rows listed in tables, default -1 (no limits).
  • initorder: application objects in the initialization order. 'Parameters' like objects always must be first. Objects joined as 'foreign' to other objects must be initialized first than the objects they joined to.
  • menuorder: application objects in menu and notebook position order.
  • lstr: title and message strings dictionary for localization purposes.
  • actions: tuple of tuples (<Action name>, <Action class>). 'Action' is the non-DBFrame frame, usually ActionDialog class which allows to implement any function you need and will be put in 'Actions' application menu.
  • p: the application parameters.
Runtime properties
  • app_restart: restart application flag.
Runtime readonly properties
  • conn: PySqlite3 connection object.
  • objects: application frames dictionary {<DBFrame class> : <DBFrame object instance>,}.
  • startframe: the application main frame.
  • app: the application object.

DBFrame

The base class for building user defined classes which help to show and edit user's data. It consists of database table definition, database fields definition and their GUI controls description. DBFrame object instance allows access to child ListForm and EditForm GUI objects.

Configuration properties
  • tablename: the database table name.

  • title: the window title.

  • columns: the tuple of dictionaries which defines table columns, e.g. ({"name": "field_name", "type": FIELD_TYPE, "title": u"Column title",},) the column dictionary members:

    Mandatory
    • "name": the field name;
    • "type": the field type (currently supported types: DATE, INTEGER, REAL, TEXT, TIMESTAMP);
    • "title": the column title;
    Optional
    • "foreign": the joined text field as a dictionary of the three value pairs: { "dbframe": <DBFrame_class>, "key_fld": <key_field_name>, "str_fld": <text_field_name>} where:
      • "dbframe": the DBFrame class that corresponds 'LEFT JOIN table' in SQL expression.
      • "key_fld": the key field in dbframe class that corresponds 'field2' in 'LEFT JOIN table ON field1 = field2' SQL expression.
      • "str_fld": the field of the TEXT type in dbframe class that represents joined text with the table column defined in columns.
      • "extra_keys": if you have more than one field to join as defined in "key_fld", define the tuple of extra fields like this: (("this_dbframe_field", "joined_field"),).
    • "readonly": the function which returns True if this field is readonly;
    • "show": True to show the column (default), False to hide the column;
    • "default": the default value for the field;
    • "filter": the function that returns tuple with two values: ('relational_operator', filter_value) where 'relational_operator' is one of ["", "=", "<=", ">=", "<", ">", "like"]; filter_value is a value the field is compared to. If "filter" defined it will also appear in filter dialog called by "F" button on the application's top panel. If the filter function is defined, but return value is None, it will appear in the filter dialog with empty relational operator and conditional value.
    • "choose": (for edit form) the dictionary which means that this field will be displayed as a combo box control with values: {<value>: <displayed text>,};
    • "short": (for edit form) the GUI control for this field will be displayed in 'short' layout: not directly under the previous control, but next to it;
    • "editable": the function that returns True if data in current record are editable (default: True).
  • "readonly": the function that returns True if data in this class are readonly (default: False).

  • "orderby": the function that returns list of tuples [(<field_name>, <order_type>)], where <field_name> is a database table field name, <order_type> is either "asc" or "desc".

  • "total": the database field name for the column values which will be calculated as total sum.

  • "detail": the tuple of two elements (DBFrame_class, "field_name_with_key_from_DBFrame_class"). "detail" allows to bind different DBFrames in master-detail way. The detail DBFrame will always be filtered by "field_name_with_key_from_DBFrame_class" value which is currently selected in parent DBFrame.

  • "initvalues": the tuple of tuples, used to fill up database table directly after table creation in renewstruc() function.

Runtime readonly properties
  • crow_gui: the current row index in ListForm view.
  • crow_db: the current row index (ROWID) in database tables.
  • crow_edit: True if the current record is in editable state.
  • editform: the EditForm object for current DBFrame instance.
  • listform: the ListForm object for current DBFrame instance.
  • masterform: the master frame of detail DBFrame instance in master-detail related frames.
  • sql: the SQL expression currently used.
Methods
  • get_by_value(by_field, by_value, get_field): search table records by field <by_field> for value <by_value> and return found record value of field <get_field>.
  • get_by_values(by_field_value_dict, get_field): search table records by field <by_field> for value <by_value> in dictionary <by_field_value_dict> {<by_field> : <by_value>,} and returns found record value of field <get_field>.
  • get_column(fname): return column dictionary for column with name <fname>.
  • get_curr_value(self, get_field): return value from selected table row for field name <get_field>.
  • get_curr_values( * param): return list of values from selected row of database table only for fields defined in <param> parameter.
  • get_edit(fname): return value from EditForm control for field <fname>.
  • get_edit_value(fname): return value from EditForm control for field <fname>.
  • get_master(): return master DBFrame object from detail DBFrame object.
  • get_master_field(fld): return master DBFrame object's field <fld> value from detail DBFrame object.
  • get_master_key(): return master DBFrame object's current database table ROWID value from detail DBFrame object.
  • get_selected_dict(): return dictionary of <field name>:<value> pairs from the selected row
  • get_selected_list(): return list of values from selected row.
  • refresh_data(): refresh dataset in DBFrame object.
  • refresh_master_filter(): refresh filters for master DBFrame object from detail DBFrame object.
  • set_column(fname, par, val): set column dictionary parameter <par> to value <val> for field <fname>.
  • set_edit_value(fname, val): put value <val> into EditForm control for field <fname>.
  • sum_col(fld_name, format=False, refresh=False): return sum of values for the field <fld_name> as string; if <format> is True then the result value will be left-justified; if <refresh> is True then master DBFrame will be refreshed.
Customizable event handlers
  • on_ok: on OK button pressed.
  • on_cancel: on X button pressed.
  • on_add: on + button pressed.
  • on_delete: on - button pressed.

ListForm

This class represents list view for database table values and not directly customizable by user. List columns for this class are described in 'columns' parameter of the parent DBFrame class. The instance of this class is accessed from listform property of the parent DBFrame object.

Methods
  • fill_with_data(search_pos = None): fill list form with data; if search_pos defined, the row selector will be positioned on row with index search_pos. This method is called automatically from refresh_data method of DBFrame object.

EditForm

This class represents edit view for database table values and not directly customizable by user. GUI controls for this class are described in 'columns' parameter of the parent DBFrame class. The instance of this class is accessed from editform property of the parent DBFrame object. GUI control values may be accessed with get_edit_value and set_edit_value methods from the parent DBFrame object.

Methods
  • refresh(): refresh data in the form controls.

ActionDialog

The base class for Action dialogs -- custom dialogs which can be accessed from 'Actions' menu and defined in actions global variable. It's methods are the same as Dialog methods of PocketPyGui library.

Properties
  • pf: the parent frame, usually StartFrame object.
  • dbconn: the current database connection.
  • objects: the copy of objects property of G class.

StartFrame

The main frame for DBFrames applications. It serve as parent container for DBFrame instance objects. The StartFrame instance object stores in startframe property of G class.

Global methods