summaryrefslogtreecommitdiff
path: root/cad/src/dna/commands/MakeCrossovers/ListWidgetItems_GraphicsMode_Mixin.py
blob: 0559e57953a3588fb793e6893b0bc5cc072ab69e (plain)
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
# Copyright 2008-2009 Nanorex, Inc.  See LICENSE file for details.
"""

@author: Ninad
@version: $Id$
@copyright: 2008-2009 Nanorex, Inc.  See LICENSE file for details.

History:

TODO:
See ListWidgetItems_Command_Mixin for details.

@see: MakeCrossovers_GraphicsMode
      ListWidgetItems_Command_Mixin
      ListWidgetItems_PM_Mixin
"""

class ListWidgetItems_GraphicsMode_Mixin:

    def update_cursor_for_no_MB(self):
        """
        Update the cursor for no mouse button pressed
        """
        if self.command:
            if self.command.isAddSegmentsToolActive():
                self.o.setCursor(self.win.addSegmentToResizeSegmentListCursor)
                return
            if self.command.isRemoveSegmentsToolActive():
                self.o.setCursor(self.win.removeSegmentFromResizeSegmentListCursor)
                return

    def chunkLeftUp(self, a_chunk, event):
        """
        Overrides superclass method. If add or remove segments tool is active,
        upon leftUp, when this method gets called, it modifies the list
        of segments by self.command.
        @see: self.update_cursor_for_no_MB()
        @see: self.end_selection_from_GLPane()
        """
        if self.command.isAddSegmentsToolActive() or \
           self.command.isRemoveSegmentsToolActive():
            if a_chunk.isAxisChunk():
                segmentGroup = a_chunk.parent_node_of_class(
                    self.win.assy.DnaSegment)
                if segmentGroup is not None:
                    if self.command.isAddSegmentsToolActive():
                        segmentList = [segmentGroup]
                        self.command.ensureSegmentListItemsWithinLimit(segmentList)
                    if self.command.isRemoveSegmentsToolActive():
                        self.command.removeSegmentFromSegmentList(segmentGroup)

            self.end_selection_from_GLPane()
            return


    def end_selection_from_GLPane(self):
        """
        Overrides superclass method.  In addition to selecting  or deselecting
        the chunk, if  a tool that adds Dna segments to the segment list in
        the property manager is active, this method also adds
        the selected dna segments to that list. Example, if user selects
        'Add Dna segments' tool and does a lasso selection , then this also
        method adds the selected segments to the list. Opposite behavior if
        the 'remove segments from segment list too, is active)
        """
        selectedSegments = self.win.assy.getSelectedDnaSegments()
        if self.command.isAddSegmentsToolActive():
            self.command.ensureSegmentListItemsWithinLimit(selectedSegments)
        if self.command.isRemoveSegmentsToolActive():
            for segment in selectedSegments:
                self.command.removeSegmentFromSegmentList(segment)