-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_content_widget.py
More file actions
87 lines (68 loc) · 3.37 KB
/
Copy pathnode_content_widget.py
File metadata and controls
87 lines (68 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""A module containing the base class for the Node's content graphical representation. It also contains an example of
an overridden Text Widget, which can pass a notification to it's parent about being modified."""
from collections import OrderedDict
from nodeeditor.node_serializable import Serializable
from qtpy.QtWidgets import QWidget, QLabel, QVBoxLayout, QTextEdit
class QDMNodeContentWidget(QWidget, Serializable):
"""Base class for representation of the Node's graphics content. This class also provides layout
for other widgets inside of a :py:class:`~nodeeditor.node_node.Node`"""
def __init__(self, node:'Node', parent:QWidget=None):
"""
:param node: reference to the :py:class:`~nodeeditor.node_node.Node`
:type node: :py:class:`~nodeeditor.node_node.Node`
:param parent: parent widget
:type parent: QWidget
:Instance Attributes:
- **node** - reference to the :class:`~nodeeditor.node_node.Node`
- **layout** - ``QLayout`` container
"""
self.node = node
super().__init__(parent)
self.initUI()
def initUI(self):
"""Sets up layouts and widgets to be rendered in :py:class:`~nodeeditor.node_graphics_node.QDMGraphicsNode` class.
"""
self.layout = QVBoxLayout()
self.layout.setContentsMargins(0,0,0,0)
self.setLayout(self.layout)
self.wdg_label = QLabel("Some Title")
self.layout.addWidget(self.wdg_label)
self.layout.addWidget(QDMTextEdit("foo"))
def setEditingFlag(self, value:bool):
"""
.. note::
If you are handling keyPress events by default Qt Window's shortcuts and ``QActions``, you will not
need to use this method.
Helper function which sets editingFlag inside :py:class:`~nodeeditor.node_graphics_view.QDMGraphicsView` class.
This is a helper function to handle keys inside nodes with ``QLineEdits`` or ``QTextEdits`` (you can
use overridden :py:class:`QDMTextEdit` class) and with QGraphicsView class method ``keyPressEvent``.
:param value: new value for editing flag
"""
self.node.scene.getView().editingFlag = value
def serialize(self) -> OrderedDict:
return OrderedDict([
])
def deserialize(self, data:dict, hashmap:dict={}, restore_id:bool=True) -> bool:
return True
class QDMTextEdit(QTextEdit):
"""
.. note::
This class is an example of a ``QTextEdit`` modification that handles the `Delete` key event with an overridden
Qt's ``keyPressEvent`` (when not using ``QActions`` in menu or toolbar)
Overridden ``QTextEdit`` which sends a notification about being edited to its parent's container :py:class:`QDMNodeContentWidget`
"""
def focusInEvent(self, event:'QFocusEvent'):
"""Example of an overridden focusInEvent to mark the start of editing
:param event: Qt's focus event
:type event: QFocusEvent
"""
self.parentWidget().setEditingFlag(True)
super().focusInEvent(event)
def focusOutEvent(self, event:'QFocusEvent'):
"""Example of an overridden focusOutEvent to mark the end of editing
:param event: Qt's focus event
:type event: QFocusEvent
"""
self.parentWidget().setEditingFlag(False)
super().focusOutEvent(event)