This package provides a set of taurus wiget utilities like color management, configuration, actions.
A class decorator intended to be used in a Qt.QWidget to make its UI loadable from a predefined QtDesigner UI file. This decorator will add a
loadUi()method to the decorated class and optionaly a property with a name given by with_ui parameter.
The folowing example assumes the existence of the ui file
<my_widget_dir>/ui/MyWidget.uiwhich is a QWidget panel with at least a QPushButton with objectName my_button
from taurus.external.qt import Qt from taurus.qt.qtgui.util.ui import UILoadable @UILoadable class MyWidget(Qt.QWidget): def __init__(self, parent=None): Qt.QWidget.__init__(self, parent) self.loadUi() self.my_button.setText("This is MY button")
Another example using a
superUI.uifile in the same directory as the widget. The widget UI components can be accessed through the widget member _ui
import os.path from taurus.external.qt import Qt from taurus.qt.qtgui.util.ui import UILoadable @UILoadable(with_ui="_ui") class MyWidget(Qt.QWidget): def __init__(self, parent=None): Qt.QWidget.__init__(self, parent) self.loadUi(filename="superUI.ui", path=os.path.dirname(__file__)) self._ui.my_button.setText("This is MY button")
with_ui (str) – assigns a member to the decorated class from which you can access all UI components [default: None, meaning no member is created]
the current implementation (Jul14) doesn’t prevent Qt from overloading any members you might have defined previously by the widget object names from the UI file. This happens even if with_ui parameter is given. For example, if the UI contains a QPushButton with objectName my_button:
@UILoadable(with_ui="_ui") class MyWidget(Qt.QWidget): def __init__(self, parent=None): Qt.QWidget.__init__(self, parent) self.my_button = "hello" self.loadUi() widget = MyWidget() print widget.my_button <PyQt4.QtGui.QPushButton object at 0x159e2f8>
This little problem should be solved in the next taurus version.
Returns all widgets in a hierarchy of a certain type
widget (Qt.QWidget) – the widget to be inspected
class-or-type-or-tuple (type class or a tuple of type classes) – type to be checked
a sequence containning all widgets in the hierarchy that match the given type
- Return type
grabWidget(widget, fileName, period=None)¶
Grabs the given widget into the given image filename. If period is not given (or given with None) means grab immediately once and return. If period is given and >0 means grab the image every period seconds
loadUi(obj, filename=None, path=None, with_ui=None)¶
Loads a QtDesigner .ui file into the given widget. If no filename is given, it tries to load from a file name which is the widget class name plus the extension “.ui” (example: if your widget class is called MyWidget it tries to find a MyWidget.ui). If path is not given it uses the directory where the python file which defines the widget is located plus a ui directory (example: if your widget is defined in a file /home/homer/workspace/taurusgui/my_widget.py then it uses the path /home/homer/workspace/taurusgui/ui)
filename (str) – the QtDesigner .ui file name [default: None, meaning calculate file name with the algorithm explained before]
path (str) – directory where the QtDesigner .ui file is located [default: None, meaning calculate path with algorithm explained before]
with_ui (bool) – if True, the objects defined in the ui file will be accessible as submembers of an ui member of the widget. If False, such objects will directly be members of the widget.