Widgets and other classes to interact with tested application¶
The Object base class¶
-
class
funq.models.
Object
[source]¶ Allow to manipulate a QObject or derived.
Variables: - client – client for the communication with libFunq
[type:
funq.client.FunqClient
] - oid – ID of the managed C++ instance. [type: long]
- path – complete path to the object [type: str]
- classes – list of class names of the managed C++ instance, in inheritance order (ie ‘QObject’ is last) [type : list(str)]
-
properties
()[source]¶ Returns a dict of availables properties for this object with associated values.
Example:
enabled = object.properties()["enabled"]
-
set_properties
(**properties)[source]¶ Define some properties on this object.
Example:
object.set_properties(text="My beautiful text")
-
set_property
(name, value)[source]¶ Define one property on this object.
Example:
object.set_property('text', "My beautiful text")
-
wait_for_properties
(props, timeout=10.0, timeout_interval=0.1)[source]¶ Wait for the properties to have the given values.
Example:
self.wait_for_properties({'enabled': True, 'visible': True})
-
call_slot
(slot_name, params={})[source]¶ CAUTION; This methods allows to call a slot (written on the tested application). The slot must take a QVariant and returns a QVariant.
This is not really recommended to use this method, as it will trigger code in the tested application in an unusual way.
The methods returns what the slot returned, decoded as python object.
Parameters: - slot_name – name of the slot
- params – parameters (must be json serialisable) that will be send to the tested application as a QVariant.
- client – client for the communication with libFunq
[type:
The Widget base class¶
A Widget is often obtained with funq.client.FunqClient.widget()
.
Example:
my_widget = self.funq.widget('my_widget')
-
class
funq.models.
Widget
[source]¶ Allow to manipulate a QWidget or derived.
-
click
(wait_for_enabled=10.0)[source]¶ Click on the widget. If wait_for_enabled is > 0 (default), it will wait until the widget become active (enabled and visible) before sending click.
-
dclick
(wait_for_enabled=10.0)[source]¶ Double click on the widget. If wait_for_enabled is > 0 (default), it will wait until the widget become active (enabled and visible) before sending click.
-
keyclick
(text)[source]¶ Simulate keypress and keyrelease events for every character in the given text. Example:
widget.keyclick("my text")
-
shortcut
(key_sequence)[source]¶ Send a shortcut on the widget, defined with a text sequence. See the QKeySequence::fromString to see the documentation of the format needed for the text sequence.
Parameters: text – text sequence of the shortcut (see QKeySequence::fromString documentation)
-
drag_n_drop
(src_pos=None, dest_widget=None, dest_pos=None)[source]¶ Do a drag and drop from this widget.
Parameters: - src_pos – starting position of the drag. Must be a tuple (x, y) in widget coordinates or None (the center of the widget will then be used)
- dest_widget – destination widget. If None, src_widget will be used.
- dest_pos – ending position (the drop). Must be a tuple (x, y) in widget coordinates or None (the center of the dest widget will then be used)
-
Interacting with the data of QT Model/View framework¶
To interact with items in QAbstractTableModel, it is needed to get the
associated view (QAbstractItemView). The returned instance will be of type
AbstractItemView
and the data will then be retrievable with
the AbstractItemView.model_items()
method.
Example:
view = self.funq.widget('my_tableview')
assert isinstance(view, AbstractItemView)
model_items = view.model_items()
item = model_items.item_by_named_path(['item1'])
item.dclick()
-
class
funq.models.
AbstractItemView
[source]¶ Specific Widget to manipulate QAbstractItemView or derived.
-
model_items
()[source]¶ Returns an instance of
ModelItems
based on the model associated to the view.
-
current_editor
(editor_class_name=None)[source]¶ Returns the editor actually opened on this view. One item must be in editing mode, by using
ModelItem.dclick()
orModelItem.edit()
for example.Currently these editor types are handled: ‘QLineEdit’, ‘QComboBox’, ‘QSpinBox’ and ‘QDoubleSpinBox’.
Parameters: editor_class_name – name of the editor type. If None, every type of editor will be tested (this may actually be very slow)
-
-
class
funq.models.
TableView
[source]¶ Specific widget to manipulate a QTableView widget.
-
horizontal_header
(timeout=2.0, timeout_interval=0.1, wait_active=True)[source]¶ Return the horizontal
HeaderView
associated to this tableview.Each optionnal parameter is passed to
funq.client.FunqClient.widget()
.
-
vertical_header
(timeout=2.0, timeout_interval=0.1, wait_active=True)[source]¶ Return the vertical
HeaderView
associated to this tableview.Each optionnal parameter is passed to
funq.client.FunqClient.widget()
.
-
-
class
funq.models.
TreeView
[source]¶ Specific widget to manipulate a QTreeView widget.
-
header
(timeout=2.0, timeout_interval=0.1, wait_active=True)[source]¶ Return the
HeaderView
associated to this treeview.Each optionnal parameter is passed to
funq.client.FunqClient.widget()
.
-
-
class
funq.models.
ModelItems
[source]¶ Allow to manipulate all modelitems in a QAbstractModelItem or derived.
Variables: items – list of ModelItem
-
iter
()¶ Allow to iterate on every items recursively.
Example:
for item in items.iter(): print item
-
item_by_named_path
(named_path, match_column=0, sep='/', column=0)[source]¶ Returns the item (
ModelItem
) that match the arborescence defined by named_path and in the given column.Note
The arguments are the same as for
row_by_named_path()
, with the addition of column.Parameters: column – the column of the desired item
-
row_by_named_path
(named_path, match_column=0, sep='/')[source]¶ Returns the item list of
ModelItem
that match the arborescence defined by named_path, or None if the path does not exists.Important
Use unicode characters in named_path to match elements with non-ascii characters.
Example:
model_items.row_by_named_path([u'TG/CBO/AP (AUT 1)', u'Paramètres tranche', u'TG', u'DANGER'])
Parameters: - named_path – path for the interesting ModelIndex. May be defined with a list of str or with a single str that will be splitted on sep.
- match_column – column used to check`named_path` is a string.
-
-
class
funq.models.
ModelItem
[source]¶ Allow to manipulate a modelitem in a QAbstractModelItem or derived.
Variables: - viewid – ID of the view attached to the model containing this item [type: long]
- row – item row number [type: int]
- column – item column number [type: int]
- value – item text value [type: unicode]
- check_state – item text value of the check state, or None
- itempath – Internal ID to localize this item [type: str ou None]
- items – list of subitems [type:
ModelItem
]
-
click
(origin='center', offset_x=0, offset_y=0)[source]¶ Click on this item.
Parameters: - origin – Origin of the cursor coordinates of the ModelItem object. Availables values: “center”, “left” or “right”.
- offset_x – x position relative to the origin. Negative value allowed.
- offset_y – y position relative to the origin. Negative value allowed.
-
dclick
(origin='center', offset_x=0, offset_y=0)[source]¶ Double click on this item.
Parameters: - origin – Origin of the cursor coordinates of the ModelItem object.
- offset_x – x position relative to the origin. Negative value allowed.
- offset_y – y position relative to the origin. Negative value allowed.
Interacting with the data of QT Graphics View framework¶
Handling QGraphicsItems data is quite similar to handling data of the Models/Views framework.
It requires the associated view (an instance of QGraphicsView). In funq
the widget will be an instance of GraphicsView
and the data will
be available with the GraphicsView.gitems()
method.
Example:
gview = self.funq.widget('my_gview')
gitems = gview.gitems()
for item in gitems.iter():
# do something with item
-
class
funq.models.
GraphicsView
[source]¶ Allow to manipulate an instance of QGraphicsView.
-
class
funq.models.
GItems
[source]¶ Allow to manipulate a group of QGraphicsItems.
Variables: items – list of GItem
that are on top of the scene (and not subitems)-
iter
()¶ Allow to iterate on every items recursively.
Example:
for item in items.iter(): print item
-
-
class
funq.models.
GItem
[source]¶ Allow to manipulate a QGraphicsItem.
Variables: - viewid – ID of the view attached to the model containing this item [type: long]
- gid – Internal gitem ID [type: unsigned long long]
- objectname – value of the “objectName” property if it inherits from QObject. [type: unicode or None]
- classes – list of names of class inheritance if it inherits from QObject. [type: list(str) or None]
- items – list of subitems [type:
GItem
]
Interacting with QtQuick objects¶
New in version 1.2.0.
If funq-server is built uppon Qt5 with QtQuick enabled, you can manipulate QtQuickItems.
Example:
from funq.models import QuickWindow, QuickItem
# first get the quick view
quick_view = self.funq.active_widget()
assert isinstance(quick_view, QuickWindow)
# get an item, click on it and print its color property
my_rect = quick_view.item(id='rect')
assert isinstance(my_rect, QuickItem)
my_rect.click()
print(my_rect.properties()["color"])
-
class
funq.models.
QuickWindow
[source]¶ Represent a QQuickWindow or QQuickView.
If your application is a qml app with one window, you can easily get the
QuickWindow
withfunq.FunqClient.active_widget()
.Example:
quick_window = self.funq.active_widget()
-
item
(alias=None, path=None, id=None)[source]¶ Search for a
funq.models.QuickItem
and returns it.An item can be identified by its id, using an alias or using a raw path. The preferred way is using an id (defined in the qml file) - this takes precedence over other methods.
For example, with the following qml code:
import QtQuick 2.0 Item { id: root width: 320 height: 480 Rectangle { id: rect color: "#272822" width: 320 height: 480 } }
You can use the following statements:
# using id root = quick_window.item(id='root') rect = quick_window.item(id='root.rect') # or just 'rect' # using alias # you must have something like the following line in your alias file: # my_rect = QQuickView::QQuickItem::QQuickRectangle rect = quick_window.item(alias='my_rect') # using raw path - note the path is relative to the quick window rect = quick_window.item(path='QQuickItem::QQuickRectangle')
Parameters: - alias – alias defined in the aliases file that points to the item.
- path – path of the item, relative to the view (do not pass the full path)
- id – id of the qml item.
-