schrodinger.ui.qt.network_views module¶
- schrodinger.ui.qt.network_views.calculateArrow(end_point, arrow_end_point, mag=4, skew=4)¶
Calculate how to draw an arrow at the end_point of a line, this requires the line’s other endpoint so that we know the angle at which the arrow is to be drawn.
- Returns
a QPolygonF containing the arrow
- Parameters
mag (int) – controls the magnitude of the arrow head smaller value smaller smaller head
- class schrodinger.ui.qt.network_views.NetworkNode(model, network)¶
Bases:
PyQt6.QtWidgets.QGraphicsRectItem
This is an abstract class for the Node’s of the graph, you can subclass from this class to render the data “val”, whatever it may be.
- model_scale = 1200¶
- default_size_factor = 50¶
- __init__(model, network)¶
- Parameters
model – the model node corresponding to this view node
network (NetworkViewer) – the graph view to which this node view belongs
- getEdges()¶
Retrieve all the edges connected to this node.
- syncModel()¶
- scalePosToModel(pos)¶
- scalePosFromModel(pos)¶
- contextMenuEvent(e)¶
This is triggered when right clicking on a node
- hoverEnterEvent(self, event: QGraphicsSceneHoverEvent)¶
- hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent)¶
- mousePressEvent(e)¶
Accept mouse events so that selection doesnt get lost (QTBUG-10138)
Without this fix, when context menu is up, mouse events get propagated to the parent and it behaves as if you did not click on a node. This causes th
- mouseMoveEvent(e)¶
Move the item and tell the network to redraw connection lines
- mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent)¶
- mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent)¶
- centerPos()¶
- paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget] = None)¶
- class schrodinger.ui.qt.network_views.TextNetworkNode(model, network, text_attr=None)¶
Bases:
schrodinger.ui.qt.network_views.NetworkNode
Network node that optionally displays the string representation of a node attribute as text.
- text_y_pos = 150¶
- text_size = 100¶
- text_offset = 5¶
- __init__(model, network, text_attr=None)¶
- Parameters
model – the model node corresponding to this view node
network (NetworkViewer) – the graph view to which this node view belongs
text_attr (str or NoneType) – the name of the model node attribute which will be used as the source of the text for this view node (optional)
- syncModel()¶
- class schrodinger.ui.qt.network_views.PosTextNetworkNode(model, network, text_attr=None)¶
Bases:
schrodinger.ui.qt.network_views.TextNetworkNode
- text_size = 50¶
- syncModel()¶
- mouseMoveEvent(e)¶
Move the item and tell the network to redraw connection lines
- class schrodinger.ui.qt.network_views.SmilesNetworkNode(x, y, val, allow_movement, text='')¶
Bases:
schrodinger.ui.qt.network_views.TextNetworkNode
This renders the input variable ‘val’ as a 2D-Structure, assuming it’s a smiles that can be converted to a 2d structure.
- text_y_pos = 10000¶
- text_size = 60¶
- __init__(x, y, val, allow_movement, text='')¶
- Parameters
model – the model node corresponding to this view node
network (NetworkViewer) – the graph view to which this node view belongs
text_attr (str or NoneType) – the name of the model node attribute which will be used as the source of the text for this view node (optional)
- class schrodinger.ui.qt.network_views.NetworkConnectionLabel(*args, **kwargs)¶
Bases:
PyQt6.QtWidgets.QGraphicsTextItem
- __init__(*args, **kwargs)¶
- class schrodinger.ui.qt.network_views.NetworkEdge(node1, node2, network, dotted=False, opacity=1.0, label=None)¶
Bases:
PyQt6.QtWidgets.QGraphicsPathItem
Right now this is just like a regular line, but will allow for extension to avoid connection/node intersections if so desired in the future.
- __init__(node1, node2, network, dotted=False, opacity=1.0, label=None)¶
- getOtherNode(node)¶
- syncModel()¶
- setLabel(text, html=False)¶
Show text along edge :param text: label text :type text: str
- setArrowhead(enable, head_node=None)¶
- showBadEdge(is_bad)¶
Mark this edge as ‘bad’. It will be shown with red color.
- Parameters
is_bad (bool) – True or False to indicate whether this edge is ‘bad’.
- mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent)¶
- hoverEnterEvent(self, event: QGraphicsSceneHoverEvent)¶
- hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent)¶
- contextMenuEvent(e)¶
This is triggered when right clicking on an edge
- boundingRect(self) QRectF ¶
- paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget] = None)¶
- recalculateShape()¶
This function recalculates the shape (line, perhaps with arrow) to draw for the connection between two nodes.
- nodeIntersectionPoint(node)¶
- schrodinger.ui.qt.network_views.intersect_line_and_rect(line, rect)¶
Returns the intersection point of a line and 4 line segments, if it intersects multiple segments, only one intersection will be returned.
- class schrodinger.ui.qt.network_views.NetworkViewer(node_class=<class 'schrodinger.ui.qt.network_views.NetworkNode'>, parent=None, model=None)¶
Bases:
schrodinger.ui.qt.network_visualizer.AbstractNetworkView
,PyQt6.QtWidgets.QWidget
A network diagram representation of the model.
- pickingModeChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- stopPickingConnection¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- __init__(node_class=<class 'schrodinger.ui.qt.network_views.NetworkNode'>, parent=None, model=None)¶
- getSignalsAndSlots(model)¶
Get a list of signal/slot pairs for a model. This list will be used when setting a new model to disconnect the old model signals from their slots and connect the new model’s signals to those slots.
Override this method to modify or extend signals/slots in derived classes.
- Parameters
model (Graph) – the graph model
- setModel(model, fit=True)¶
- Parameters
fit (bool) – whether to fit the zoom to the new model
- makeNodes(nodes)¶
Create new view nodes and return a dictionary mapping supplied model nodes to corresponding view nodes. Do not add new view nodes to the view.
By default this method returns an “identity dictionary” that maps nodes to themselves. Subclasses should override this method to implement their own view nodes.
- addNodes(viewnodes)¶
Takes view nodes and adds them to the view if that makes sense (eg. add graphics items to scene, add rows to table, etc.) It should not add the view node to
self.nodes
; that is handled in_addNodes()
.- Parameters
viewnodes (list(object)) – view nodes to add to the view
- removeNodes(viewnodes)¶
Removes view nodes from the view if that makes sense (eg. remove graphics items from scene, remove table rows, etc.) It should not remove view nodes from
self.nodes
; that is handled in_removeNodes()
.- Parameters
viewnodes (list(object)) – a list of view nodes
- updateNodes(nodes)¶
Performs any operations necessary to update the view to the current model state. Note that this method takes model nodes, not view nodes.
- Parameters
nodes (list(Node)) – model nodes which must have their views updated
- makeEdges(edges)¶
Given a list of model edges, return a dictionary mapping them to corresponding view edges. Does not add view edges to the view.
By default this method returns an identity dictionary, mapping model edges to themselves. Subclasses should override this method if they want to implement their own view edges.
- Parameters
edges – a list model nodes
- Returns
a dictionary mapping model edges to view edges
- Return type
dict(Edge, object)
- addEdges(viewedges)¶
Adds view edges to the view. Does not add view edges to
self.edges
.- Parameters
viewedges (list(object)) – view edges to add to the view
- removeEdges(viewedges)¶
Removes view edges from the view. Does not remove view edges from
self.edges
.- Parameters
viewedges (list(object)) – view edges to remove from the view
- updateEdges(edges)¶
Performs any operations necessary to update the view to the current model state.
- Parameters
edges (list(Edge)) – a list of model edges corresponding to view edges that should be updated
- selectItems(selected_view_objects)¶
Selects view objects in the view. Currently only view nodes will be requested, but may be expanded to allow a combination of nodes and edges to be selected.
- Parameters
selected_view_objects (list(object)) – a list of view objects to be selected
- nodeMenu(e, node)¶
Override this to create a node context menu
- edgeMenu(e, edge)¶
Shows edge context menu. Override this function in derived class.
- edgeHovered(edge)¶
Override this for connection hover behavior
- edgeUnhovered(edge)¶
Override this for connection hover behavior
- exploreEdge(edge)¶
Override this for edge context menu behavior.
- nodeHovered(hovered_node)¶
When a node is hovered, the all nodes with degree of separation greater than 1 are dimmed in order to highlight the immediate neighbors.
- nodeUnhovered(hovered_node)¶
When a node is unhovered, return the dimmed nodes to the normal state.
- setNodesOpacity(nodes, opacity)¶
Change the opacity of a set of nodes and their edges.
- Parameters
nodes (iterable of NetworkNode) – the nodes to change opacity
opacity (float) – opacity value from 0 to 1.
- calcItemZoomFactor(item)¶
Calculates the raw zoom factor necessary for the specified item to fill most of the view
- Parameters
item (QtWidgets.QGraphicsItem) – the item to fit in the view
- calcFitZoomFactor()¶
Calculates a raw zoom factor for the view to fit all the items in the scene
- zoomItem(item)¶
Zoom into a specific item with animation. :param item: item to zoom :type item: QGraphicsItem
- mouseMoveEvent(e)¶
If we’re picking and the mouse is moving then update the path of the arrow which is used for picking.
- createEdge(vnode1, vnode2)¶
MVC “controller” function to add a new edge to the graph between node1 and node2. This can be overridden to implement other edge creation functionality.
- Parameters
vnode1 (NetworkNode) – First node
vnode2 (NetworkNode) – Second node
- selectedNodes()¶
Get a list of currently selected view nodes
- selectedEdges()¶
Get a list of currently selected view edges
- onSelectionChanged()¶
This is used to process UI changes in selection and updating the model from the view selection. This is not for synchronizing the view to the model selection. For that, use self.syncSelection().
- setPickingMode(state)¶
Begins picking nodes to add connections, can be connected to a checkbox. If a python checkbox is connected with “toggled(bool)” to this, the checkbox also needs to have a slot to turn the checkbox off which will be connected to the signal: SIGNAL(“stopPickingConnection()”) This is emitted once a connection has been created and the checkbox should be turned off.
- deleteSelectedItems()¶
Process item deletion request. Deletions are done in the model only; the view is not modified here. Changing the model will automatically result in a corresponding update to the view.
- onKeyPressed(e)¶
- setAllowMovement(val)¶
Allow nodes to be moved with click+drag
- setNodeDeletion(val)¶
Enable deletion of nodes
- setNetworkNodeDefaultClass(cl)¶
Set the default view node class for
- getFitRect(node_set=None)¶
Calculate the rectangle that contains the nodes. If a node_set is specified, only those nodes will be considered. Otherwise, all nodes will be used. This function takes into account the size of the nodes.
- Parameters
node_set (iterable) – a subset of nodes to fit
- expandToNodes()¶
Expand the scene to fit all nodes
- setDefaultScale()¶
This zooms to fits all nodes and sets the default scale
- scaleSmoother(val)¶
Sets the scale between self.start_scale and self.finish_scale, based on ‘val’, which goes from 0->1 as the animation proceeds.
- setRawScale(scale)¶
Sets the scale using the actual multipliers QT does. We use a QTimeLine to do this as an animation. The “finish_scale” is always set here, whether the timeline is already zooming or not, so that it’ll always zoom as far as the users last scroll desired.
- setScale(val)¶
Accepts any scale value in [0, 100]