Reference¶
Programmatically accessing the graph¶
-
class
qmxgraph.api.
QmxGraphApi
(graph)¶ Python binding for API used to control underlying JavaScript’s mxGraph graph drawing library.
-
call_api
(fn, *args)¶ Call a function in underlying API provided by JavaScript graph.
- Parameters
fn (str) – A function call available in API.
args (list[Any]) – Positional arguments passed to graph’s JavaScript API call (unfortunately can’t use named arguments with JavaScript). All object passed must be JSON encodable or Variable instances.
- Return type
object
- Returns
Return of API call.
-
dump
()¶ Obtain a representation of the current state of the graph as an XML string. The state can be restored calling
QmxGraphApi.restore()
.- Return type
str
- Returns
A xml string.
-
fit
()¶ Rescale the graph to fit in the container.
-
get_cell_id_at
(x, y)¶ Gets the id of cell at given coordinates.
- Parameters
x (int) – X coordinate in screen coordinates.
y (int) – Y coordinate in screen coordinates.
- Return type
str|None
- Returns
Id of cell if any given position, otherwise returns None.
-
get_cell_type
(cell_id)¶ - Parameters
cell_id (str) – Id of a cell in graph.
- Return type
str
- Returns
Possible returns are:
qmxgraph.constants.CELL_TYPE_VERTEX
for vertices;qmxgraph.constants.CELL_TYPE_EDGE
for edges;qmxgraph.constants.CELL_TYPE_DECORATION
for decorations;qmxgraph.constants.CELL_TYPE_TABLE
for tables;
It raises if none of these types are a match.
-
get_decoration_parent_cell_id
(cell_id)¶ Get the id of the edge that contains the decoration with the given cell id.
- Parameters
cell_id (str) – THe decoration’s id.
- Return type
str
- Returns
Id of the edge containg the given decoration.
-
get_decoration_position
(cell_id)¶ Gets the decoration’s relative position.
- Parameters
cell_id (str) – Id of a decoration in graph.
- Return type
float
- Returns
Returns an a normalized number between [0, 1] representing the position of the decoration along the parent edge.
-
get_edge_terminals
(edge_id)¶ Gets the ids of endpoint vertices of an edge.
- Parameters
edge_id (str) – Id of an edge in graph.
- Return type
list[str]
- Returns
A list with 2 items, first the source vertex id and second the target vertex id.
-
get_edge_terminals_with_ports
(edge_id)¶ Gets the ids of endpoint vertices of an edge and the ports used in the connection.
- Parameters
edge_id (str) – Id of an edge in graph.
- Return type
list[list[str|None]]
- Returns
2 lists with 2 items each:
the source vertex id;
the port’s name used on the source (can be None);
the target vertex id;
the port’s name used on the target (can be None);
-
get_geometry
(cell_id)¶ Gets the geometry of cell in screen coordinates.
- Parameters
cell_id (str) – Id of a cell in graph.
- Return type
list
- Returns
A list with 4 items:
x;
y;
width;
height;
-
get_label
(cell_id)¶ Gets the label of cell.
- Parameters
cell_id (str) – Id of a cell in graph.
- Return type
str
- Returns
Label of cell.
-
get_scale_and_translation
()¶ Get the current scale and translation.
- Return type
Tuple[float, float, float]
- Returns
The values represent:
graph scale;
translation along the x axis;
translation along the y axis;
The three values returned by this function is suitable to be supplied to
QmxGraphApi.set_scale_and_translation()
to set the scale and translation to a previous value.
-
get_selected_cells
()¶ Get the selected cells ids.
- Return type
list[str]
-
get_style
(cell_id)¶ Gets a cell’s style.
- Parameters
cell_id (str) – Id of a cell in graph.
- Return type
str
- Returns
Name of a style or an inline style.
-
get_tag
(cell_id, tag_name)¶ Gets value of a value in cell.
- Parameters
cell_id (str) – Id of a cell in graph.
tag_name (str) – Name of tag.
- Return type
str
- Returns
Value of tag.
-
get_terminal_points
(cell_id)¶ Gets the terminal points of an edge;
- Parameters
cell_id (str) – Id of a edge in graph.
- Return type
list
- Returns
2 lists with 2 items each:
the source x coordinate;
the source y coordinate;
the target x coordinate;
the target y coordinate;
-
get_zoom_scale
()¶ Return the current scale (zoom).
- Return type
float
-
group
()¶ Create a group with currently selected cells in graph. Edges connected between selected vertices are automatically also included in group.
-
has_cell
(cell_id)¶ Indicates if cell exists.
- Parameters
cell_id (str) – Id of a cell in graph.
- Return type
bool
- Returns
True if cell exists.
-
has_port
(cell_id, port_name)¶ Indicates if the port exists.
- Parameters
cell_id (str) – Id of a cell in graph.
port_name (str) – Name of the expected port.
- Return type
bool
- Returns
True if the port exists.
-
has_tag
(cell_id, tag_name)¶ If cell has tag.
- Parameters
cell_id (str) – Id of a cell in graph.
tag_name (str) – Name of tag.
- Return type
bool
- Returns
True if tag exists in cell.
-
insert_decoration
(x, y, width, height, label, style=None, tags=None)¶ Inserts a new decoration over an edge in graph. A decoration is basically an overlay object that is representing some entity over the path of an edge.
Note that x and y must be inside the bounds of an edge, otherwise this call will raise.
- Parameters
x (int) – X coordinate in screen coordinates.
y (int) – Y coordinate in screen coordinates.
width (int) – Width in pixels.
height (int) – Height in pixels.
label (str) – Label of decoration.
style (str|None) – Name of style to be used. Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
- Return type
str
- Returns
Id of new decoration.
-
insert_decoration_on_edge
(edge_id, position, width, height, label, style=None, tags=None)¶ Inserts a new decoration over an edge in graph. A decoration is basically an overlay object that is representing some entity over the path of an edge.
Note that x and y must be inside the bounds of an edge, otherwise this call will raise.
- Parameters
edge_id (str) – Id of an edge in graph.
position (float) – The normalized position in the edge.
width (int) – Width in pixels.
height (int) – Height in pixels.
label (str) – Label of decoration.
style (str|None) – Name of style to be used. Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
- Return type
str
- Returns
Id of new decoration.
-
insert_edge
(source_id, target_id, label, style=None, tags=None, source_port_name=None, target_port_name=None)¶ Inserts a new edge between two vertices in graph.
- Parameters
source_id (str) – Id of source vertex in graph.
target_id (str) – Id of target vertex in graph.
label (str) – Label of edge.
style (str|None) – Name of style to be used. Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
source_port_name (str|None) – The name of the port used to connect to source vertex.
target_port_name (str|None) – The name of the port used to connect to target vertex.
- Return type
str
- Returns
Id of new edge.
-
insert_port
(vertex_id, port_name, x, y, width, height, label=None, style=None, tags=None)¶ Inserts a new port in vertex.
- Parameters
vertex_id (str) – The id of the vertex to witch add this port.
port_name (str) – The name used to refer to the new port.
x (float) – The normalized (0-1) X coordinate for the port (relative to vertex bounds).
y (float) – The normalized (0-1) Y coordinate for the port (relative to vertex bounds).
width (int) – Width of port.
height (int) – Height of port.
label (str|None) – Label of port.
style (str|None) – Name of style to be used. Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
-
insert_table
(x, y, width, contents, title, tags=None, style=None, parent_id=None)¶ Inserts a new table in graph. A table is an object that can be used in graph to display tabular information about other cells, for instance. Tables can’t be connected to other cells like vertices, edges nor decorations.
- Parameters
x (int) – X coordinate in screen coordinates.
y (int) – Y coordinate in screen coordinates.
width (int) – Width in pixels.
contents (qmxgraph.decoration_contents.Table) – The table contents.
title (str) – Title of table.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
style (str|None) – Name of style to be used (Note that the ‘table’ style is always used, options configured with this style have greater precedence). Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
parent_id (str|None) – If not None the created table is placed in a relative position to the cell with id parent_id.
- Return type
str
- Returns
Id of new table.
-
insert_vertex
(x, y, width, height, label, style=None, tags=None)¶ Inserts a new vertex in graph.
- Parameters
x (int) – X coordinate in screen coordinates.
y (int) – Y coordinate in screen coordinates.
width (int) – Width in pixels.
height (int) – Height in pixels.
label (str) – Label of vertex.
style (str|None) – Name of style to be used. Styles available are all default ones provided by mxGraph plus additional ones configured in initialization of this class.
tags (dict[str,str]|None) – Tags are basically custom attributes that may be added to a cell that may be later queried (or even modified), with the objective of allowing better inspection and interaction with cells in a graph.
- Return type
str
- Returns
Id of new vertex.
-
is_connectable
(cell_id)¶ Indicates the cell’s connectivity.
- Parameters
cell_id (str) – Id of a cell in graph.
-
is_port_visible
(cell_id, port_name)¶ Indicates the cell’s visibility.
- Parameters
cell_id (str) – Id of a cell in graph.
port_name (bool) – Name of a port in the cell.
-
is_visible
(cell_id)¶ Indicates the cell’s visibility.
- Parameters
cell_id (str) – Id of a cell in graph.
-
on_cells_added
(handler)¶ Register a handler to event when cells are added from graph.
Requires that a bridge object is first added to JavaScript to work.
- Parameters
handler (str) – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives a QVariantList of added cell ids as only argument.
-
on_cells_removed
(handler)¶ Register a handler to event when cells are removed from graph.
Requires that a bridge object is first added to JavaScript to work.
- Parameters
handler (str) – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives a QVariantList of removed cell ids as only argument.
-
on_label_changed
(handler)¶ Register a handler to event when label of a cell changes in graph.
Requires that a bridge object is first added to JavaScript to work.
- Parameters
handler (str) – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives, respectively, cell id, new label and old label as arguments.
-
on_selection_changed
(handler)¶ Add function to handle selection change events in the graph.
- Parameters
handler – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives an list of str with selected cells ids as only argument.
-
on_terminal_changed
(handler)¶ Add function to handle terminal change events in the graph.
- Parameters
handler – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives, respectively, cell id, boolean indicating if the changed terminal is the source (or target), id of the net terminal, id of the old terminal.
-
on_terminal_with_port_changed
(handler)¶ Add function to handle terminal change with port info events in the graph.
- Parameters
handler – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives, respectively, cell id, boolean indicating if the changed terminal is the source (or target), id of the new terminal, id of the old terminal.
-
on_view_update
(handler)¶ - Add function to handle updates in the graph view.
- param handler
Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives, respectively, graph dump and graph scale and translation.
-
remove_cells
(cell_ids)¶ Remove cells from graph.
- Parameters
cell_ids (list) – Ids of cells that must be removed.
-
remove_port
(vertex_id, port_name)¶ Remove an existing port from a vertex. Any edge connected to the vertex through the port is also removed.
- Parameters
vertex_id (str) – The id of the parent vertex.
port_name (str) – The port’s name to remove.
-
reset_zoom
()¶ Reset graph’s zoom.
-
resize_container
(width, height)¶ Resizes the container of graph drawing widget.
Note that new dimensions have lesser priority than keeping graph big enough to contain all existing vertices and edges. So if new dimensions are too small to contain all parts of graph it will be only resized down to dimensions enough to contain all parts.
- Parameters
width (int) – New width.
height (int) – New height.
-
restore
(state)¶ Restore the graph’s state to one saved with dump.
- Parameters
state (str) – A xml string previously obtained with dump.
-
set_connectable
(cell_id, connectable)¶ Change connectable state of a cell.
- Parameters
cell_id (str) – Id of a cell in graph.
connectable (bool) – If connectable or not.
-
set_decoration_position
(cell_id, position)¶ Gets the decoration’s relative position.
- Parameters
cell_id (str) – Id of a decoration in graph.
position (float) – A normalized number between [0, 1] representing the position of the decoration along the parent edge.
-
set_double_click_handler
(handler)¶ Set the handler used for double click in cells of graph.
Unlike other event handlers, double click is exclusive to a single handler. This follows underlying mxGraph implementation that works in this manner, with the likely intention of enforcing a single side-effect happening when a cell is double clicked.
Requires that a bridge object is first added to JavaScript to work.
- Parameters
handler – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives a str with double clicked cell id as only argument.
-
set_edge_terminal
(edge_id, terminal_type, new_terminal_cell_id, port_name=None)¶ Set an edge’s terminal.
- Parameters
edge_id (str) – The id of a edge in graph.
terminal_type (str) – Indicates if the affect terminal is the source or target for the edge. The valid values are: - QmxGraphApi.SOURCE_TERMINAL_CELL; - QmxGraphApi.TARGET_TERMINAL_CELL;
new_terminal_cell_id – The if of the new terminal for the edge.
port_name (str) – The of the port to use in the connection.
-
set_label
(cell_id, label)¶ Sets the label of a cell.
- Parameters
cell_id (str) – Id of a cell in graph.
label (str) – New label.
Set the handler used for popup menu (i.e. menu triggered by right click) in cells of graph.
Unlike other event handlers, popup menu is exclusive to a single handler. This follows underlying mxGraph implementation that works in this manner, with the likely intention of enforcing a single side-effect happening when a cell is right-clicked.
Requires that a bridge object is first added to JavaScript to work.
- Parameters
handler – Name of signal bound to JavaScript by a bridge object that is going to be used as callback to event. Receives, respectively, id of cell that was right-clicked, X coordinate in screen coordinates and Y coordinate in screen coordinates as its three arguments.
-
set_port_visible
(cell_id, port_name, visible)¶ Change visibility state of cell’s port.
- Parameters
cell_id (str) – Id of a cell in graph.
port_name (str) – Name of a port in the cell.
visible (bool) – If visible or not.
-
set_scale_and_translation
(scale, x, y)¶ Set the scale and translation.
- Parameters
scale (float) – The new graph’s scale (1 = 100%).
x (float) – The new graph’s translation along the X axis (0 = origin).
y (float) – The new graph’s scale along the Y axis (0 = origin}.
-
set_selected_cells
(cell_ids)¶ Select the cells with the given ids.
- Parameters
cell_ids (list[str]) –
-
set_style
(cell_id, style)¶ Sets a cell’s style.
- Parameters
cell_id (str) – Id of a cell in graph.
style (str) – Name of a style or an inline style.
-
set_tag
(cell_id, tag_name, tag_value)¶ Sets a tag in cell.
- Parameters
cell_id (str) – Id of a cell in graph.
tag_name (str) – Name of tag.
tag_value (str) – Value of tag.
-
set_visible
(cell_id, visible)¶ Change visibility state of cell.
- Parameters
cell_id (str) – Id of a cell in graph.
visible (bool) – If visible or not.
-
toggle_grid
()¶ The grid in background of graph helps aligning cells inside graph. It usually starts enabled and can be hidden on demand.
-
toggle_outline
()¶ Outline is a small window that shows an overview of graph. It usually starts disabled and can be shown on demand.
-
toggle_snap
()¶ Snap feature forces vertices to be moved in a way its bounds match grid. It usually starts enabled and can be disabled on demand.
Note that if grid is hidden this feature is also disabled.
-
ungroup
()¶ Ungroup currently selected group.
-
update_table
(table_id, contents, title)¶ Update contents and title of a table in graph.
- Parameters
table_id (str) – Id of a table in graph.
contents (qmxgraph.decoration_contents.Table) – The table contents.
title (str) – Title of table.
-
zoom_in
()¶ Zoom in the graph.
-
zoom_out
()¶ Zoom out the graph.
-
Qt widget¶
-
class
qmxgraph.widget.
QmxGraph
(options=None, styles=None, stencils=(), auto_load=True, parent=None)¶ A graph widget that is actually an web view using as backend mxGraph, a very feature rich JS graph library which is also used as backend to the powerful Google Drive’s draw.io widget.
Tags
Tags don’t have any impact or influence on QmxGraph features. It is just a feature so client code can associate custom data with cells created in a graph.
Tags can be helpful, for instance, to be able to infer an application-specific type of a dragged & dropped new cell. When added cell events are handled, client code can just query tags to know this information. Without tags, it would need to infer based on unreliable heuristics like current style or label.
An important observation is that tag values are always strings. If a value of other type is used it will raise an error.
Debug/Inspection
It is possible to open a web inspector for underlying graph drawing page by typing F12 with widget focused.
-
property
api
¶ - Return type
- Returns
Proxy to API to manipulate graph.
-
blank
()¶ Blanks the graph drawing page, effectively clearing/unloading currently displayed graph.
-
hide_inspector
()¶ Hide web inspector bound to QmxGraph page.
-
inner_web_view
()¶ - Return type
QWebViewWithDragDrop
- Returns
Web view widget showing graph drawing page.
-
is_loaded
()¶ - Return type
bool
- Returns
Is graph page already loaded?
-
load
()¶ Load graph drawing page, if not yet loaded.
-
paintEvent
(paint_event)¶ A simple override to the QWidget.paintEvent required soo the QSS rules have effect over QWidget subclasses.
From: http://doc.qt.io/qt-5/stylesheet-reference.html#qwidget-widget
-
resizeEvent
(self, QResizeEvent)¶
-
set_double_click_handler
(handler)¶ Set the handler used for double click in cells of graph.
Unlike other event handlers, double click is exclusive to a single handler. This follows underlying mxGraph implementation that works in this manner, with the likely intention of enforcing a single side-effect happening when a cell is double clicked.
- Parameters
handler (callable|None) – Handler that receives double clicked cell id as only argument. If None it disconnects double click handler from graph.
-
set_error_bridge
(bridge)¶ Redirects errors on JavaScript code from graph drawing widget to bridge.
- Parameters
bridge (ErrorHandlingBridge) – Handler for errors.
-
set_events_bridge
(bridge)¶ Redirects events fired by graph on JavaScript code to Python/Qt side by using a bridge.
- Parameters
bridge (EventsBridge) – Bridge with event handlers.
Set the handler used for popup menu (i.e. right-click) in cells of graph.
Unlike other event handlers, popup menu is exclusive to a single handler. This follows underlying mxGraph implementation that works in this manner, with the likely intention of enforcing a single side-effect happening when a cell is right-clicked.
- Parameters
handler (callable|None) – Handler that receives, respectively, id of cell that was right-clicked, X coordinate in screen coordinates and Y coordinate in screen coordinates as its three arguments. If None it disconnects handler from graph.
-
show_inspector
()¶ Show web inspector bound to QmxGraph page.
-
toggle_inspector
()¶ Toggle visibility state of web inspector bound to QmxGraph page.
-
property
-
class
qmxgraph.widget.
EventsBridge
¶ A bridge object between Python/Qt and JavaScript that provides a series of signals that are connected to events fired on JavaScript.
- Variables
on_cells_removed (pyqtSignal) –
JavaScript client code emits this signal when cells are removed from graph. Arguments:
cell_ids: QVariantList
on_cells_added (pyqtSignal) –
JavaScript client code emits this signal when cells are added to graph. Arguments:
cell_ids: QVariantList
on_label_changed (pyqtSignal) –
JavaScript client code emits this signal when cell is renamed. Arguments:
cell_id: str
new_label: str
old_label: str
on_selection_changed (pyqtSignal) –
JavaScript client code emits this signal when the current selection change. Arguments:
cell_ids: QVariantList
on_terminal_changed (pyqtSignal) –
JavaScript client code emits this signal when a cell terminal change. Arguments:
cell_id: str
terminal_type: str
new_terminal_id: str
old_terminal_id: str
on_terminal_with_port_changed (pyqtSignal) –
JavaScript client code emits this signal when a cell terminal change with port information. Arguments:
cell_id: str
terminal_type: str
new_terminal_id: str
new_terminal_port_id: str
old_terminal_id: str
old_terminal_port_id: str
on_view_update (pyqtSignal) –
JavaScript client code emits this signal when the view is updated. Arguments:
graph_view: str
scale_and_translation: QVariantList
Using this object connecting to events from JavaScript basically becomes a matter of using Qt signals.
def on_cells_added_handler(cell_ids): print(f'added {cell_ids}') def on_terminal_changed_handler( cell_id, terminal_type, new_terminal_id, old_terminal_id): print( f'{terminal_type} of {cell_id} changed from' f' {old_terminal_id} to {new_terminal_id}' ) def on_cells_removed_handler(cell_ids): print(f'removed {cell_ids}') events_bridge = EventsBridge() widget = ... widget.set_events_bridge(events_bridge) events_bridge.on_cells_added.connect(on_cells_added_handler) events_bridge.on_cells_removed.connect(on_cells_removed_handler) events_bridge.on_terminal_changed.connect(on_terminal_changed_handler)
MIME (for drag & drop into the widget)¶
QmxGraph drag & drop format (MIME type: application/x-qmxgraph-dd)¶
QmxGraph drag & drop is a JSON object. Format spec is found below:
{
version: <int>, # version of format used by data, version value is added
# since cross application D&D is supported and it is
# necessary to know the source version
vertices: # optional, vertices are going to be added to graph
[
{
dx: <int>, # how much it should displaced in X axis from
# where user dropped
dy: <int>, # how much it should displaced in Y axis from
# where user dropped
width: <int>, # width of new vertex
height: <int>, # height of new vertex
label: <str>, # label of new vertex
style: <str>, # optional, style of new vertex
tags: <dict[str, str]>, # optional, tags associated
# with vertex
},
...
]
decorations: # optional, decorations are going to be added to graph
[
{
width: <int>, # width of new decoration
height: <int>, # height of new decoration
label: <str>, # label of new decoration
style: <str>, # optional, style of new decoration
tags: <dict[str, str]>, # optional, tags associated
# with decoration
},
...
]
}
-
qmxgraph.mime.
create_qt_mime_data
(data)¶ Creates a Qt’s MIME data object for data in valid QmxGraph’s drag&drop format.
- Parameters
data (dict) – Contents of MIME data.
- Return type
QMimeData
- Returns
MIME data in QmxGraph format.
General graph options¶
-
class
qmxgraph.configuration.
GraphOptions
(allow_create_target=False, allow_dangling_edges=False, cells_cloneable=True, cells_connectable=True, cells_movable=True, cells_resizable=True, connection_image=None, enable_cloning=True, font_family=None, multigraph=False, port_image=None, show_grid=True, show_highlight=True, show_outline=False, snap_to_grid=True)¶ Object that configures features available in graph drawing widget.
- Variables
allow_create_target (bool) – Defines if clones the source if new connection has no target.
allow_dangling_edges (bool) – Defines if it can create edges when they don’t connect two vertices.
cells_cloneable (bool) – Enables the cells to be cloned pressing ctrl and dragging them.
cells_connectable (bool) – Enables new edges between vertices of graph.
cells_movable (bool) – Specifies if the graph should allow moving of cells.
cells_resizable (bool) – Specifies if vertices in graph can be resized.
connection_image (tuple[str,int,int]|None) – If configured, this image is shown to user when he hovers a vertex. It can be clicked and dragged to create edges. Respectively, formed by image path, its width and height.
enable_cloning (bool) – Enables cloning by control-drag.
font_family (tuple[str]|None) – Defines the default family for all fonts in graph. It configures a priority list, trying always to use the left-most family first.
multigraph (bool) – Allow multiple edges between nodes
port_image (tuple[str,int,int]|None) – Replaces image in connection ports. Respectively, formed by image path, its width and height.
show_grid (bool) – Show a grid in background to aid users.
show_highlight (bool) – Show highlight when it hovers over a cell in graph.
show_outline (bool) – Show outline of graph in a floating window.
snap_to_grid (bool) – Snap to background grid when moving vertices in graph.
Cell graph styles¶
-
class
qmxgraph.configuration.
GraphStyles
(styles=None)¶ Object that configures additional styles available in graph drawing widget.
Each key in styles dict given as input will define the name of style. Below are some reserved names:
‘edge’: Style used by edges in graph;
‘group’: Style used when cells are grouped in graph;
‘table’: Style used by table cells;
Each style key must receive as a value other dict, which will configure the style. All options are optional. The available options for each style are:
‘shape’: Name of shape of cell. Can be any of mxGraph’s default shapes plus the custom ones created by additional stencil files;
‘end_arrow’: End arrow of an edge. Possible values are found in mxGraphs constants with an ARROW-prefix;
‘fill_color’: Color used inside of cell;
‘fill_opacity’: Opacity used inside of cell between 0 and 1;
‘stroke_color’: Color used in border of cell;
‘stroke_opacity’: Opacity used in border of cell between 0 and 1;
‘dashed’: If border of cell should be dashed;
‘vertical_label_position’: vertical label position of vertices. Possible values are ‘bottom’, ‘top’ and ‘middle’;
‘vertical_align’: vertical alignment of label text of vertices. Possible values are ‘bottom’, ‘top’ and ‘middle’
Example of styles:
GraphStyles({ 'group': { 'shape': 'rectangle', 'fill_color': None, 'dashed': True, }, 'foo': { 'shape': 'star', 'fill_color': '#ffffff', }, 'bar': { 'fill_color': '#ff00ff', 'dashed': True, }, })
HTML content helpers¶
Classes to used to represent content in:
-
class
qmxgraph.decoration_contents.
Image
(src, width, height)¶ Represents an image tag that could be embedded into a table contents.
The image’s width and height are required since mxgraph will render the html in a helper container in order to get the cell’s size. To avoid the cell size to be wrongly calculated we got some options like passing the image’s size explicitly (as done here) or force the user to pre load the images so when rendering the html the image is already loaded and the correct size is used.
- Variables
tag (str) –
source (str) – The URL to the image, data URIs can be used.
width (int) – The desired width for the image.
height (int) – The desired height for the image.
-
class
qmxgraph.decoration_contents.
Table
(contents)¶ Represents the contents of a table when inserting or updating a table in the graph.
- Variables
tag (str) –
contents (tuple[TableRow]) – The table rows.
-
class
qmxgraph.decoration_contents.
TableData
(contents, colspan=1, rowspan=1, style=None)¶ Represents the contents of a table’s cell when inserting or updating a table in the graph.
- Variables
tag (str) –
contents (tuple[union[str,Image]]) – The table cell’s contents.
colspan (int) – The number of columns the cell should span into.
rowspan (int) – The number of rows the cell should span into.
style (optional[str]) – A inline style for the element.
-
class
qmxgraph.decoration_contents.
TableRow
(contents)¶ Represents the contents of a table’s row when inserting or updating a table in the graph.
- Variables
tag (str) –
contents (tuple[union[str,TableData]]) – The row’s cells. Normal str elements will be interpreted as TableData elements with all the default values and it’s contents equal to a tuple of one element (the str used).
Test helpers¶
Those are helper tools that could help in applications’ tests.
-
qmxgraph.common_testing.
get_cell_count
(widget, filter_function)¶ - Parameters
widget (qmxgraph.widget.QmxGraph) – The widget used to display the graph.
filter_function (str) – A javascript function used to filter the cells.
- Return type
int
-
qmxgraph.common_testing.
get_cell_ids
(widget, filter_function)¶ - Parameters
widget (qmxgraph.widget.QmxGraph) – The widget used to display the graph.
filter_function (str) – A javascript function used to filter the cells.
- Return type
list[str]