Skip to main content

Introduction

The QtAlchemy library is a collection of Qt Model-View classes and helper functions to aid in rapid development of desktop database applications. It aims to provide a strong API for exposing foreign key relationships in elegant and immediate ways to the user of applications. Context menus, searches and combo-boxes and tabbed interfaces are all utilized. The use of SQLAlchemy makes it possible that these features are supported on a variety of database backends with virtually no code changes.

The Command class gives a way to construct menus and toolbars from decorated python functions. The power of this becomes more evident when bound to a view where the command function can then receive the identifier of the selected item of the view. This provides a flexible way to link commands to any sqlalchemy query generated views.

Documentation is available at http://qtalchemy.org .

QtAlchemy is currently being developed with Python 2.7.x, SQLAlchemy 0.8.x and PySide 1.2.x. Testing has been done on Python 3.3.2 and 2.7.5. SQLAlchemy tested versions include 0.8.2 and 0.9-pre. Testing includes linux and Windows targets.

As of QtAlchemy version 0.8.x, QtAlchemy uses PySide. See licensing comments at the bottom of this file. To use PyQt4 instead of PySide, you must install from the source in the bitbucket repository rather than PyPI since you need to convert the source before running the install script. Install in the following way:

python qtbindings.py --platform=PyQt4
python setup.py build
sudo python setup.py install

Example

In the interests of being concise, the example given here does not reference a database.

The UserAttr property class provides yet another type defined python property. The purpose of reinventing this was to ensure that we could interact with our models sufficiently and provide a uniform experience for SQLAlchemy column properties and UserAttr properties.

>>> from qtalchemy import UserAttr
>>> import datetime
>>> class Person(object):
...     name=UserAttr(str,"Name")
...     birth_date=UserAttr(datetime.date,"Birth Date")
...     age=UserAttr(int,"Age (days)",readonly=True)
...
...     @age.on_get
...     def age_getter(self):
...         return (datetime.date.today()-self.birth_date).days

With this declaration, we can declare a person and compute their age:

>>> me = Person()
>>> me.name = "Joel"
>>> me.birth_date = datetime.date(1979,1,9)
>>> me.age  #depends on today! -- #doctest: +SKIP
11746
>>> me.age-(datetime.date.today()-datetime.date(2011,1,9)).days  # on birthday 1<<5
11688

We can create a dialog showing the name & birth-date. The main magic happens in the addBoundForm call which obtains labels from the UserAttr classes and places the correct edit widgets on screen.

>>> from PySide import QtCore, QtGui
>>> from qtalchemy import MapperMixin, LayoutLayout, ButtonBoxButton, LayoutWidget
>>>
>>> class PersonEdit(QtGui.QDialog,MapperMixin):
...     def __init__(self,parent,person):
...         QtGui.QDialog.__init__(self,parent)
...         MapperMixin.__init__(self)
...
...         self.person = person
...
...         vbox = QtGui.QVBoxLayout(self)
...         mm = self.mapClass(Person)
...         mm.addBoundForm(vbox,["name","birth_date"])
...         mm.connect_instance(self.person)
...
...         buttons = LayoutWidget(vbox,QtGui.QDialogButtonBox())
...         self.close_button = ButtonBoxButton(buttons,QtGui.QDialogButtonBox.Ok)
...         buttons.accepted.connect(self.btnClose)
...
...     def btnClose(self):
...         self.submit() # changes descend to model on focus-change; ensure receiving the current focus
...         self.close()

And, now, we only need some app code to actually kick this off

>>> app = QtGui.QApplication([])
>>> sam = Person()
>>> sam.name = "Samuel"
>>> d = PersonEdit(None,sam)
>>> d.exec_()  # gui interaction -- #doctest: +SKIP
0
>>> sam.age    # assumes selection of yesterday in the gui -- #doctest: +SKIP
1

Development

QtAlchemy is still in heavy core development as schedule allows. Major new emphases include:

  • abstracting query building for lists allowing user sorting and additional columns

  • html generation for use with the QtWebKit bridge

  • qml view for queries

Changelog

0.8.3:

  • Python 3 support! No 2to3 or other gotchas.

  • SQLAlchemy 0.9x compatibility fixes

0.8.2:

  • sqlalchemy 0.8x compatibility fixes

  • more PySide fixes

0.8.1:

  • mainly bugfixes for PySide support

0.8.0:

  • Change to PySide as default imports

  • Relax license from GPL to LGPL

  • Improve yoke change handling

  • Create new PopupKeyListing for foreign key entry

0.7.1:

  • QueryDataView gained basic ability to requery on column header clicks for sorting

  • a few doc fixes

  • new helper function family for using Geraldo in qtalchemy.ext.reporttools

0.7.0:

  • improved exception error handling and reporting for GUI applications with-out console

  • new yoke supporting a combo box

  • improve yoke documentation

  • add complete examples to front of documentation

  • various model/list improvements including column width defaulting

0.6.12:

  • BoundCommandMenu has slots to be dispatched from html binding entity commands to html viewing forms

  • structured load and save extending the framework in BoundDialog

  • new TreeView exposing the QTreeView

  • tree model support in PBTableModel

  • improved PySide portability and fixed various crash-bugs related to that

0.6.11:

  • context sensitive help and status tips for fields

  • new preCommand/refresh signals with CommandEvent structure allowing aborting by the ambient screen

  • improvements in the generic data import wizard

  • table view improvements (bug fixes, corrected model updates to be more precise)

  • use pywin32 ShellExecute instead of os.system for better windows support

0.6.10:

  • renamed to qtalchemy

  • exposed Qt’s association of icons with commands appearing in menus and toolbars

  • moved qtalchemy.PBTable to qtalchemy.widgets.TableView

  • new qtalchemy.ext module for common dialogs (a data import wizard for now)

0.6.9:

  • wrote a broad outline of documentation

  • added boolean, time, and formatted text input yokes

  • rewrote DialogGeo as WindowGeometry saving and restoring window and splitter geometry for arbitrary windows

  • brand new command structure replacing DomainEntity

0.6.8:

  • color and font control in the python business object layer

  • improved packaging support for windows

  • QGridLayout support in WidgetAttributeMapper

  • extended UserAttr value storage to include attribute paths (e.g. self.sub.sub1.value)

  • new QtAlchemy.xplatform module for cross platform helpers

  • rewrote WidgetAttributeMapper using InputYoke methodology

  • rename PBEventMappedBase to ModelObject

  • additions and corrections to examples

  • event model corrections (more needed)

0.6:

  • new QtAlchemy.widgets sub-module for QLineEdit derived classes (others in the future)

  • new QtAlchemy.dialogs sub-module for auth dialog classes

  • continued tweaks for PySide and nosetests

0.5.1

  • first usable (??) release

License

QtAlchemy is licensed under the LGPL now that it defaults to shipping with PySide imports. I find this to be a rather unique licensing situation that we now have with PyQt4 and PySide. I can write my code for PySide and LGPL it and it is totally legitimate. However, it also seems entirely legitimate for a user of my library to switch the imports from PySide to PyQt4 … but then you will need to consult a lawyer about the license for that amalgamation since depending on PyQt4 requires the library to be GPL.

Metadata

Release files for qtalchemy 0.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qtalchemy 0.8.3
File Size Uploaded
qtalchemy-0.8.3.tar.gz 92.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for qtalchemy 0.8.3
File Interpreter ABI Platform
qtalchemy-0.8.3-py3.3.egg Legacy Egg format - - Details
qtalchemy-0.8.3-py2.7.egg Legacy Egg format - - Details

Total release size: 502.5 kB

Release files / qtalchemy-0.8.3.tar.gz

Download URL qtalchemy-0.8.3.tar.gz
Size 92.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8706f1bdf1af1155eb812ee326c09329e28dfe1677efecb6fbcd6983c24e154c
BLAKE2b-256 checksum
How to use checksums
7194391b8a39cdca24e8299c57dfb36c3c583e0cb8c423b819064c81075f240b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / qtalchemy-0.8.3-py3.3.egg

Download URL qtalchemy-0.8.3-py3.3.egg
Size 215.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
2a3408a362292a42253c5134b8ac88fe9c46124b695f44ed488aa12b57c38b60
BLAKE2b-256 checksum
How to use checksums
a2e75a8967782aa1d2cacd04c26f85f826cc0bf92778a249139b74af2010b534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / qtalchemy-0.8.3-py2.7.egg

Download URL qtalchemy-0.8.3-py2.7.egg
Size 195.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
62aa8f85a270c9cbf94461ea81e7fe784545239a9b478753a2434982281f2e4f
BLAKE2b-256 checksum
How to use checksums
5970dedd5339de603fdb51011eec2d734fd2cb6695394895df2f3c67b2e2019b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.8.3 This release

3 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page