Example #1
0
    def paint(self, painter, option, widget=None):
        """ Painting is sensitive to mouse/selection issues, but usually with
        :param painter:
        :param option:
        :param widget:
        nodes it is the label of the node that needs complex painting """
        p = QtGui.QPen(self.contextual_color())
        p.setWidth(1)
        if self.drag_data:
            painter.setPen(p)
            #painter.setBrush(self.drag_data.background)
            painter.drawRect(self.inner_rect)
            painter.setBrush(QtCore.Qt.NoBrush)


        elif self.hovering:
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
        elif ctrl.pressed is self or ctrl.is_selected(self):
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
        elif self.has_empty_label() and self.node_alone():
            p.setStyle(QtCore.Qt.DotLine)
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
Example #2
0
 def select(self, adding=False, select_area=False):
     """ Scene has decided that this node has been clicked
     :param adding: bool, we are adding to selection instead of starting a new selection
     :param select_area: bool, we are dragging a selection box, method only informs that this
     node can be included
     :returns: int or str, uid of node if node is selectable
     """
     self.hovering = False
     # if we are selecting an area, select actions are not called here, but once for all
     # objects. In this case return only uid of this object.
     if select_area:
         return self.uid
     #items = [x.uid for x in self.selection]
     #items.append(self.uid)
     if adding:
         if ctrl.is_selected(self):
             print('selected group (adding=True), calling remove_from_selection for it')
             ctrl.ui.get_action('remove_from_selection').run_command([self.uid])
         else:
             print('selected group (adding=True), calling add_to_selection for it')
             ctrl.ui.get_action('add_to_selection').run_command([self.uid])
     else:
         print('selected group, calling select for it')
         ctrl.ui.get_action('select').run_command([self.uid])
     return self.uid
Example #3
0
    def paint(self, painter, option, widget=None):
        """ Painting is sensitive to mouse/selection issues, but usually with
        :param painter:
        :param option:
        :param widget:
        nodes it is the label of the node that needs complex painting """
        if self.drag_data:
            p = QtGui.QPen(self.contextual_color)
            #b = QtGui.QBrush(ctrl.cm.paper())
            #p.setColor(ctrl.cm.hover())
            p.setWidth(1)
            painter.setPen(p)
            #painter.setBrush(self.drag_data.background)
            painter.drawRect(self.inner_rect)
            painter.setBrush(QtCore.Qt.NoBrush)

        elif self._hovering:
            p = QtGui.QPen(self.contextual_color)
            #p.setColor(ctrl.cm.hover())
            p.setWidth(1)
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
        elif ctrl.pressed is self or ctrl.is_selected(self):
            p = QtGui.QPen(self.contextual_color)
            p.setWidth(1)
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
        elif self.has_empty_label() and self.node_alone():
            p = QtGui.QPen(self.contextual_color)
            p.setStyle(QtCore.Qt.DotLine)
            p.setWidth(1)
            painter.setPen(p)
            painter.drawRect(self.inner_rect)
Example #4
0
 def paint(self, painter, option, widget=None):
     """ Painting is sensitive to mouse/selection issues, but usually with
     :param painter:
     :param option:
     :param widget:
     nodes it is the label of the node that needs complex painting """
     if ctrl.pressed == self or self._hovering or ctrl.is_selected(self):
         painter.setPen(ctrl.cm.get('background1'))
         painter.setBrush(self.contextual_background())
         painter.drawRoundedRect(self.inner_rect, 5, 5)
     Node.paint(self, painter, option, widget)
Example #5
0
 def paint(self, painter, option, widget=None):
     """ Painting is sensitive to mouse/selection issues, but usually with
     :param painter:
     :param option:
     :param widget:
     nodes it is the label of the node that needs complex painting """
     if ctrl.pressed == self or self._hovering or ctrl.is_selected(self):
         painter.setPen(ctrl.cm.get('background1'))
         painter.setBrush(self.contextual_background())
         painter.drawRoundedRect(self.inner_rect, 5, 5)
     Node.paint(self, painter, option, widget)
Example #6
0
 def contextual_background(self):
     """ Background color that is sensitive to node's state """
     if ctrl.pressed == self:
         return ctrl.cm.active(ctrl.cm.selection())
     elif self.drag_data:
         return ctrl.cm.hovering(ctrl.cm.selection())
     elif self._hovering:
         return ctrl.cm.hovering(ctrl.cm.selection())
     elif ctrl.is_selected(self):
         return ctrl.cm.selection()
     else:
         return qt_prefs.no_brush
Example #7
0
 def update_text(self, value):
     self.setPlainText(value)
     w = self.document().idealWidth()
     if w > 200:
         self.setTextWidth(200)
     else:
         self.setTextWidth(-1)
     self._size = self.boundingRect().size()
     if value:
         self.placeholder = False
     if self._host:
         self._host.update_selection_status(ctrl.is_selected(self._host))
Example #8
0
 def contextual_background(self):
     """ Background color that is sensitive to node's state """
     if ctrl.pressed == self:
         return ctrl.cm.active(ctrl.cm.selection())
     elif self.drag_data:
         return ctrl.cm.hovering(ctrl.cm.selection())
     elif self._hovering:
         return ctrl.cm.hovering(ctrl.cm.selection())
     elif ctrl.is_selected(self):
         return ctrl.cm.selection()
     else:
         return qt_prefs.no_brush
Example #9
0
 def update_text(self, value):
     self.setPlainText(value)
     w = self.document().idealWidth()
     if w > 200:
         self.setTextWidth(200)
     else:
         self.setTextWidth(-1)
     self._size = self.boundingRect().size()
     if value:
         self.placeholder = False
     if self._host:
         self._host.update_selection_status(ctrl.is_selected(self._host))
Example #10
0
 def update_text(self, value):
     self.setPlainText(value)
     w = self.document().idealWidth()
     if w > 200:
         self.setTextWidth(200)
     else:
         self.setTextWidth(-1)
     self._size = self.boundingRect().size()
     self._w2 = self._size.width() / 2
     self._h2 = self._size.height() / 2
     if self._host:
         self._host.update_selection_status(ctrl.is_selected(self._host))
Example #11
0
 def update_text(self, value):
     self.setPlainText(value)
     w = self.document().idealWidth()
     if w > 200:
         self.setTextWidth(200)
     else:
         self.setTextWidth(-1)
     self._size = self.boundingRect().size()
     self._w2 = self._size.width() / 2
     self._h2 = self._size.height() / 2
     if self._host:
         self._host.update_selection_status(ctrl.is_selected(self._host))
Example #12
0
 def contextual_color(self):
     """ Drawing color that is sensitive to node's state """
     if ctrl.pressed == self:
         return ctrl.cm.get('background1')
     elif self._hovering:
         return ctrl.cm.get('background1')
     elif ctrl.is_selected(self):
         return ctrl.cm.get('background1')
         # return ctrl.cm.selected(ctrl.cm.selection())
     else:
         if getattr(self.syntactic_object, 'unvalued', False):  # fixme: Temporary hack
             return ctrl.cm.get('accent1')
         else:
             return self.color
Example #13
0
 def contextual_color(self):
     """ Drawing color that is sensitive to node's state """
     if ctrl.pressed == self:
         return ctrl.cm.get('background1')
     elif self._hovering:
         return ctrl.cm.get('background1')
     elif ctrl.is_selected(self):
         return ctrl.cm.get('background1')
         # return ctrl.cm.selected(ctrl.cm.selection())
     else:
         if getattr(self.syntactic_object, 'unvalued', False):  # fixme: Temporary hack
             return ctrl.cm.get('accent1')
         else:
             return self.color
Example #14
0
 def edge_visibility_check(self):
     """ Perform check for each edge: hide them if their start/end is
     hidden, show them if necessary.
     """
     if not self._do_edge_visibility_check:
         return
     for edge in set(self.edges.values()) | set(self.arrows.values()):
         changed = edge.update_visibility()
         if changed:
             if edge.is_visible():
                 if ctrl.is_selected(edge):
                     ctrl.ui.add_control_points(edge)
             else:
                 ctrl.ui.remove_ui_for(edge)
     self._do_edge_visibility_check = False
Example #15
0
 def edge_visibility_check(self):
     """ Perform check for each edge: hide them if their start/end is
     hidden, show them if necessary.
     """
     if not self._do_edge_visibility_check:
         return
     for edge in set(self.edges.values()):
         changed = edge.update_visibility()
         if changed:
             if edge.is_visible():
                 if ctrl.is_selected(edge):
                     ctrl.ui.add_control_points(edge)
             else:
                 ctrl.ui.remove_ui_for(edge)
     self._do_edge_visibility_check = False
Example #16
0
 def select(self, event=None, multi=False):
     """ Scene has decided that this node has been clicked
     :param event:
     :param multi: assume multiple selection (append, don't replace)
     """
     if not self.persistent:
         return
     ctrl.multiselection_start()
     if (event and event.modifiers() == QtCore.Qt.ShiftModifier) or multi:
         # multiple selection
         if ctrl.is_selected(self):
             ctrl.remove_from_selection(self)
         else:
             ctrl.add_to_selection(self)
             for item in self.selection:
                 ctrl.add_to_selection(item)
     elif ctrl.is_selected(self):
         ctrl.deselect_objects()
     else:
         ctrl.deselect_objects()
         ctrl.add_to_selection(self)
         for item in self.selection:
             ctrl.add_to_selection(item)
     ctrl.multiselection_end()
Example #17
0
 def select(self, event=None, multi=False):
     """ Scene has decided that this node has been clicked
     :param event:
     :param multi: assume multiple selection (append, don't replace)
     """
     if not self.persistent:
         return
     ctrl.multiselection_start()
     if (event and event.modifiers() == QtCore.Qt.ShiftModifier) or multi:
         # multiple selection
         if ctrl.is_selected(self):
             ctrl.remove_from_selection(self)
         else:
             ctrl.add_to_selection(self)
             for item in self.selection:
                 ctrl.add_to_selection(item)
     elif ctrl.is_selected(self):
         ctrl.deselect_objects()
     else:
         ctrl.deselect_objects()
         ctrl.add_to_selection(self)
         for item in self.selection:
             ctrl.add_to_selection(item)
     ctrl.multiselection_end()
Example #18
0
    def contextual_color(self):
        """ Drawing color that is sensitive to node's state
        :return: QColor
        """

        if ctrl.is_selected(self):
            base = ctrl.cm.selection()
        elif self.in_projections:
            base = ctrl.cm.get(self.in_projections[0].color_id)
        else:
            base = self.color
        if self.drag_data:
            return ctrl.cm.lighter(base)
        elif ctrl.pressed is self:
            return ctrl.cm.active(base)
        elif self._hovering:
            return ctrl.cm.hovering(base)
        else:
            return base
Example #19
0
    def contextual_color(self):
        """ Drawing color that is sensitive to node's state
        :return: QColor
        """

        if ctrl.is_selected(self):
            base = ctrl.cm.selection()
        elif self.in_projections:
            base = ctrl.cm.get(self.in_projections[0].color_id)
        else:
            base = self.color
        if self.drag_data:
            return ctrl.cm.lighter(base)
        elif ctrl.pressed is self:
            return ctrl.cm.active(base)
        elif self._hovering:
            return ctrl.cm.hovering(base)
        else:
            return base
Example #20
0
 def click(self, event):
     if self._host and ctrl.is_selected(self._host):
         ctrl.ui.start_edge_label_editing(self._host)
     else:
         self._host.select(event)
Example #21
0
 def is_selected(self):
     """Return the selection status of this object.
     :return: boolean
     """
     return ctrl.is_selected(self)
Example #22
0
 def select(self, adding=False, select_area=False):
     if self._host and ctrl.is_selected(self._host):
         ctrl.ui.start_group_label_editing(self._host)
     else:
         return self._host.select(adding=adding, select_area=select_area)
Example #23
0
 def click(self, event):
     if self._host and ctrl.is_selected(self._host):
         ctrl.ui.start_group_label_editing(self._host)
     else:
         adding = event.modifiers() == Qt.ShiftModifier
         self._host.select(adding=adding, select_area=False)
Example #24
0
 def is_selected(self):
     """Return the selection status of this object.
     :return: boolean
     """
     return ctrl.is_selected(self)
Example #25
0
 def click(self, event):
     if self._host and ctrl.is_selected(self._host):
         ctrl.ui.start_edge_label_editing(self._host)
     else:
         self._host.select(event)