Example #1
0
    def move_selection(self, direction, add_to_selection=False):
        """ Move selection to best candidate
        :param direction:
        """
        def edge_of_set(my_selectables):
            if direction == 'left':
                sortable = [(po[0], po[1], it) for it, po in my_selectables]
                x, y, item = min(sortable)
            elif direction == 'right':
                sortable = [(po[0], po[1], it) for it, po in my_selectables]
                x, y, item = max(sortable)
            elif direction == 'up':
                sortable = [(po[1], po[0], it) for it, po in my_selectables]
                y, x, item = min(sortable)
            elif direction == 'down':
                sortable = [(po[1], po[0], it) for it, po in my_selectables]
                y, x, item = max(sortable)
            else:
                raise KeyError
            return item

        # debugging plotter
        # for item, pos in selectables:
        # x,y = pos
        # el = QtGui.QGraphicsEllipseItem(x-2, y-2, 4, 4)
        # el.setBrush(colors.drawing)
        # self.addItem(el)
        #

        # ############### Absolute left/right/up/down ###############################
        # if nothing is selected, select the edgemost item from given direction
        if not ctrl.selected:
            selectables = [(item, to_tuple(item.sceneBoundingRect().center())) for item in
                           self.items() if hasattr(item, 'select') and item.is_visible()]
            best = edge_of_set(selectables)
            ctrl.select(best)
            return best
        # ################ Relative left/right/up/down #############################
        else:
            if len(ctrl.selected) == 1:
                current = ctrl.get_single_selected()
            else:
                # when there are many selected items, extend it to given direction, from the
                # edgemost item in that direction.
                # this behavior may give odd results, but there may be no intuitive ways how such
                #  a blob of selections should behave.
                selectables = [(item, to_tuple(item.sceneBoundingRect().center())) for item in
                               ctrl.selected if item.is_visible()]
                current = edge_of_set(selectables)
            best = None
            if isinstance(current, Node):
                best = self.next_selectable_from_node(current, direction)
            elif isinstance(current, Edge):
                best = self.next_selectable_from_edge(current, direction)
            if best:
                if add_to_selection:
                    ctrl.add_to_selection(best)
                else:
                    ctrl.select(best)
            return best
Example #2
0
 def method(self, object_uid):
     """ Add node, edge or other selectable object to selection
     :param object_uid: int or str uid of item to select, or list of uids for adding
      multiple objects. None or empty list does nothingh.
     :return: None
     """
     if not object_uid:
         return
     elif isinstance(object_uid, (list, tuple)):
         objs = []
         for uid in object_uid:
             obj = ctrl.forest.get_object_by_uid(uid)
             if obj:
                 objs.append(obj)
         ctrl.add_to_selection(objs)
     else:
         obj = ctrl.forest.get_object_by_uid(object_uid)
         ctrl.add_to_selection(obj)
Example #3
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 #4
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 #5
0
    def move_selection(self, direction, add_to_selection=False):
        """ Move selection to best candidate
        :param direction:
        """
        def edge_of_set(my_selectables):
            if direction == 'left':
                sortable = [(po[0], po[1], it) for it, po in my_selectables]
                x, y, item = min(sortable)
            elif direction == 'right':
                sortable = [(po[0], po[1], it) for it, po in my_selectables]
                x, y, item = max(sortable)
            elif direction == 'up':
                sortable = [(po[1], po[0], it) for it, po in my_selectables]
                y, x, item = min(sortable)
            elif direction == 'down':
                sortable = [(po[1], po[0], it) for it, po in my_selectables]
                y, x, item = max(sortable)
            else:
                raise KeyError
            return item

        # debugging plotter
        # for item, pos in selectables:
        # x,y = pos
        # el = QtGui.QGraphicsEllipseItem(x-2, y-2, 4, 4)
        # el.setBrush(colors.drawing)
        # self.addItem(el)
        #

        # ############### Absolute left/right/up/down ###############################
        # if nothing is selected, select the edgemost item from given direction
        if not ctrl.selected:
            selectables = [(item, to_tuple(item.sceneBoundingRect().center()))
                           for item in self.items()
                           if hasattr(item, 'select') and item.is_visible()]
            best = edge_of_set(selectables)
            ctrl.select(best)
            return best
        # ################ Relative left/right/up/down #############################
        else:
            if len(ctrl.selected) == 1:
                current = ctrl.get_single_selected()
            else:
                # when there are many selected items, extend it to given direction, from the
                # edgemost item in that direction.
                # this behavior may give odd results, but there may be no intuitive ways how such
                #  a blob of selections should behave.
                selectables = [(item,
                                to_tuple(item.sceneBoundingRect().center()))
                               for item in ctrl.selected if item.is_visible()]
                current = edge_of_set(selectables)
            best = None
            if isinstance(current, Node):
                best = self.next_selectable_from_node(current, direction)
            elif isinstance(current, Edge):
                best = self.next_selectable_from_edge(current, direction)
            if best:
                if add_to_selection:
                    ctrl.add_to_selection(best)
                else:
                    ctrl.select(best)
            return best