Functions¶
Dialog Functions¶
- dtlibs.qt.question(prompt)¶
Display a question dialog with Yes and No buttons. The return value is True if Yes was selected or False if No was selected.
- dtlibs.qt.message(prompt)¶
Use a QMessageBox to display an information message.
- dtlibs.qt.error(prompt)¶
Use a QMessageBox to display an error message.
- dtlibs.qt.getText(prompt[, default='', validate=None, handle_invalid='confirm'])¶
Requests a text string through a gui prompt.
Parameters: Returns: The value entered, or None if the request was cancelled.
handle_invalid can be any one of the following strings
Value Description ‘confirm’ A confirmation dialog is displayed, asking whether to accept. ‘warn_accept’ A warning dialog is displayed and the value is accepted. ‘warn_deny’ A warning dialog is displayed and the value can be re-entered. ‘cancel’ Nothing is displayed or accepted.
- dtlibs.qt.getOption(prompt, options[, current=0])¶
Display a dropdown list of options.
Parameters: - prompt – Prompt text to display.
- options – A list of strings.
- current – The initially selected index.
Returns: The newly selected index
General UI functions¶
- dtlibs.qt.setUi(uifile[, obj=None])¶
Load the .ui file and set it up for the obj instance.
Parameters: - uifile – The relative filename of the ui file to load.
- obj – A QWidget subclass instance
If the ui file references tango_icons.qrc, then references are updated so that it will be found, regardless of its relative position.
- dtlibs.qt.tangoIcon(name)¶
Return an icon from the Tango icon set.
name follows the freedesktop.org Icon Naming Standards. For example, 'actions/document-new'.
- dtlibs.qt.standardBrush(color_role)¶
Return a brush for a Qt standard color role.
- dtlibs.qt.percentageBrush(percentage[, colour=QtCore.Qt.red])¶
Return a brush with colour faded by percentage. A percentage of 0% has no effect on the colour, and a percentage of 100% results in white.
Application¶
- dtlibs.qt.runApp(mainWindow, name)¶
Creates a new application and runs it, setting the main window and name. This also sets the locale to the current system locale.
Example usage is:
from gui import MainWindow if __name__== '__main': runApp(MainWindow, 'My Application')
Once the application created has been terminated, runApp calls sys.exit, so this should be the final command to be run.
mainWindow can be either a QWidget instance or subclass. If it is a subclass, then an instance is created.
This is implemented by calling the following:
locale.setLocal(locale.LC_ALL, '') QXApplication() win = mainWindow() QXApplication.setApplicationName(name) QXApplication.setMainWindow(win) win.setWindowTitle(name) win.show() sys.exit(QXApplication.exec_())
Utility Functions¶
- @dtlibs.qt.hideproxy¶
This class decorator handles method calls by searching recursively through source models until it finds a matching method, which it uses instead. The following example illustrates usage on a custom model:
@hideproxy class SortModel(QSortFilterProxyModel): ... datamodel = QStandardItemModel() sortmodel = SortModel() sortmodel.setSourceModel(datamodel)
This makes the following two calls identical:
item = sortmodel.itemFromIndex(proxyindex) item = sortmodel.sourceModel().itemFromIndex(sortmodel.mapToSource(proxyindex))
Arguments and return values may be converted if required, e.g. mapping of model indexes. The conversions used are based on annotations in the source model, which should be one of 'row', 'column' or 'index'. The conversions are done by methods in the proxy model mapRowFromSource, mapColumnFromSource, mapFromSource and the corresponding ToSource methods. mapToSource and mapFromSource are defined by PyQt4. If any of the others are not defined by the model then they are dynamically created.
- dtlibs.qt.textHeight(widget[, text])¶
Return the height of text painted by widget. If text is omitted, then the height of a single character is returned.
- dtlibs.qt.textWidth(widget[, text])¶
Return the width of text painted by widget. If text is omitted, the average character width is returned.
- dtlibs.qt.compactSeparators(toolbar)¶
Remove adjacent separators in a QTooBar instance.
Add all actions in a QMenu to a QTooBar.
If toolbar is missing a new QToolBar is created, otherwise toolbar is updated. In either case, the toolbar is returned.
Actions are added in the same order as they were to the QMenu instance. Separators are added to correspond to those in the menu, and submenus are also added to one level, surrounded by separators. Further submenus are added as dropdown menus.
- dtlibs.qt.guessWidget(value)¶
Attempt to guess which widget to provide based on a value.
The return value is a class which implementes QXStdWidgetABC. value is the value the widget should work with. If no suitable widget is found, QXStdTextEdit is returned.