Changeset 2562

Show
Ignore:
Timestamp:
11/06/08 12:52:58 (2 months ago)
Author:
pataphil
Message:

Changed tool buttons in GUESS to change images when in use, so it's obvious what the current tool is.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plugins/visualization/edu.iu.nwb.visualization.guess/ALGORITHM/config.properties

    r2560 r2562  
    11executable=guess 
    2 template=${executable} ${inFile[0]} scripts/guessfixer.py scripts/infoWindowOpener.py scripts/graphModifier.py scripts/zoomUI.py toolsUI.py 
     2template=${executable} ${inFile[0]} scripts/guessfixer.py scripts/infoWindowOpener.py scripts/graphModifier.py scripts/zoomUI.py scripts/toolsUI.py 
  • trunk/plugins/visualization/edu.iu.nwb.visualization.guess/ALGORITHM/default/scripts/toolsUI.py

    r2560 r2562  
    3737               ((testPoint.getX() <= lowerRightBoundingPoint.getX()) and \ 
    3838                (testPoint.getY() <= lowerRightBoundingPoint.getY())) 
     39 
     40# A toggleable-image node class. 
     41class TogglingPImage(PImage): 
     42        baseImageFileName = None 
     43        imageExtension = None 
     44        toggleState = 0 
     45         
     46        def __init__(self, baseImageFileName, imageExtension): 
     47                # Default to off. 
     48                self.baseImageFileName = baseImageFileName 
     49                self.imageExtension = imageExtension 
     50                 
     51                PImage.__init__(self, baseImageFileName + imageExtension) 
     52 
     53        def toggle(self): 
     54                if (self.toggleState): 
     55                        # We're turning off. 
     56                        self.toggleState = 0 
     57                        self.setImage(self.baseImageFileName + self.imageExtension) 
     58                else: 
     59                        # We're turning on. 
     60                        self.toggleState = 1 
     61                        self.setImage(self.baseImageFileName + "On" + self.imageExtension) 
    3962 
    4063# Generic tool button event listener class. 
     
    79102                                        # This line switches the handler for events in the display. 
    80103                                        VisFactory.getFactory().getDisplay().switchHandler(self.toolButtonType - 1) 
    81                                         # Reset the previous tool in use. (TODO: change image, but for now transparency will do.) 
    82                                         currentToolNodeButton.setTransparency(1.0
     104                                        # Reset the previous tool in use. 
     105                                        currentToolNodeButton.toggle(
    83106                                        # Set the current tool in use to this. 
    84107                                        currentToolNodeButton = self.nodeButton 
    85                                         # Set the transparency for the current tool in use to reflect that it's not a valid button. 
    86                                         # (TODO: change image.) 
    87                                         currentToolNodeButton.setTransparency(0.5) 
     108                                        # Toggle the new current tool node button. 
     109                                        currentToolNodeButton.toggle() 
    88110                                 
    89111                                return 
     
    92114                        self.nodeButton.setScale(MOUSE_OVER_SCALE) 
    93115 
    94                 return 
     116# Get rid of the status bar (with the broken buttons). 
     117def removeStatusBar(): 
     118        # First, get the main UI window. 
     119        mainUIWindow = Guess.getMainUIWindow() 
     120        # Get the content pane of the main UI window. 
     121        mainUIWindowContentPane = mainUIWindow.getContentPane() 
     122        # Get the actual components of the content pain. 
     123        mainUIWindowContentPaneComponents = mainUIWindowContentPane.getComponents() 
     124         
     125        # Reflect in the components to find the status bar so we can remove it. 
     126        for component in mainUIWindowContentPaneComponents: 
     127                if (isinstance(component, StatusBar)): 
     128                        # Remove it from the content pane. 
     129                        mainUIWindowContentPane.remove(component) 
     130                        # Repaint the content pane. 
     131                        mainUIWindowContentPane.repaint() 
     132                         
     133                        # Break out of the loop (since there should only be one status bar). 
     134                        break 
    95135 
    96 # Get rid of the status bar (with the broken buttons). 
    97 # First, get the main UI window. 
    98 mainUIWindow = Guess.getMainUIWindow() 
    99 # Get the content pane of the main UI window. 
    100 mainUIWindowContentPane = mainUIWindow.getContentPane() 
    101 # Get the actual components of the content pain. 
    102 mainUIWindowContentPaneComponents = mainUIWindowContentPane.getComponents() 
    103  
    104 # Reflect in the components to find the status bar so we can remove it. 
    105 for i in range(0, mainUIWindowContentPaneComponents.size()): 
    106         # The current component. 
    107         component = mainUIWindowContentPaneComponents[i] 
     136# Create and position a tool node button and its corresponding event listener. 
     137# Return the newly created node button. 
     138def createNodeButton(buttonType, baseImageFileName, fileExtension, xTranslation, yTranslation): 
     139        # Create the node button. 
     140        nodeButton = TogglingPImage(baseImageFileName, fileExtension) 
     141        # Create its event listener. 
     142        nodeButtonEventListener = ToolButtonInputEventListener(nodeButton, buttonType) 
     143        # Add the event listener to the node button. 
     144        nodeButton.addInputEventListener(nodeButtonEventListener) 
     145        # Position the node button. 
     146        nodeButton.translate(xTranslation, yTranslation) 
    108147         
    109         if (component.getClass() == StatusBar): 
    110                 # Remove it from the content pane. 
    111                 mainUIWindowContentPane.remove(component) 
    112                 # Nullify our local array. 
    113                 mainUIWindowContentPaneComponents[i] = None 
    114                 # Repaint the content pane. 
    115                 mainUIWindowContentPane.repaint() 
    116                  
    117                 # Break out of the loop (since there should only be one status bar). 
    118                 break 
    119                          
    120 # Get the camera. 
    121 camera = vf.getDisplay().getCamera() 
     148        # Return the node button. 
     149        return nodeButton 
    122150 
    123151# Create the tool node buttons. 
    124 browseToolNodeButton = PImage("images/browseTool.jpg")  # TODO: Actually default the image to the in-use version. 
    125 manipulateNodesToolNodeButton = PImage("images/manipulateNodesTool.jpg") 
    126 manipulateEdgesToolNodeButton = PImage("images/manipulateEdgesTool.jpg") 
    127 manipulateHullsToolNodeButton = PImage("images/manipulateHullsTool.jpg") 
    128 drawToolNodeButton = PImage("images/drawTool.jpg") 
    129 # This is just a reference to the node button that corresponds to the tool currently in use. 
    130 currentToolNodeButton = browseToolNodeButton 
    131 currentToolNodeButton.setTransparency(0.5) 
     152# Return the default node button. 
     153def createNodeButtons(): 
     154        # Get the camera. 
     155        camera = vf.getDisplay().getCamera() 
     156         
     157        # We need to store the first node so we can use its height for positioning the future node buttons. 
     158        # The first node button will also be the default node button, so it needs to be returned. 
     159        defaultNodeButton = createNodeButton(BUTTON_TYPE_BROWSE, "images/browseTool", ".jpg", \ 
     160                BUTTON_SPACING, TOOL_BUTTON_TOP) 
     161                 
     162        # Add the default node button to the camera, then create and add the rest of them... 
     163        camera.addChild(defaultNodeButton) 
     164         
     165        camera.addChild(createNodeButton(BUTTON_TYPE_MANIPULATE_NODES, "images/manipulateNodesTool", ".jpg", \ 
     166                BUTTON_SPACING, TOOL_BUTTON_TOP + SPACE_IN_BETWEEN_BUTTONS + defaultNodeButton.getHeight())) 
     167         
     168        camera.addChild(createNodeButton(BUTTON_TYPE_MANIPULATE_EDGES, "images/manipulateEdgesTool", ".jpg", \ 
     169                BUTTON_SPACING, TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + defaultNodeButton.getHeight()) * 2)) 
     170         
     171        camera.addChild(createNodeButton(BUTTON_TYPE_MANIPULATE_HULLS, "images/manipulateHullsTool", ".jpg", \ 
     172                BUTTON_SPACING, TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + defaultNodeButton.getHeight()) * 3)) 
     173         
     174        camera.addChild(createNodeButton(BUTTON_TYPE_DRAW, "images/drawTool", ".jpg", BUTTON_SPACING, \ 
     175                TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + defaultNodeButton.getHeight()) * 4)) 
     176         
     177        return defaultNodeButton 
    132178 
    133 # Position the node buttons. 
    134 browseToolNodeButton.translate(BUTTON_SPACING, TOOL_BUTTON_TOP) 
    135 manipulateNodesToolNodeButton.translate(BUTTON_SPACING, TOOL_BUTTON_TOP + SPACE_IN_BETWEEN_BUTTONS + browseToolNodeButton.getHeight()) 
    136 manipulateEdgesToolNodeButton.translate(BUTTON_SPACING, TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + manipulateNodesToolNodeButton.getHeight()) * 2) 
    137 manipulateHullsToolNodeButton.translate(BUTTON_SPACING, TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + manipulateEdgesToolNodeButton.getHeight()) * 3) 
    138 drawToolNodeButton.translate(BUTTON_SPACING, TOOL_BUTTON_TOP + (SPACE_IN_BETWEEN_BUTTONS + manipulateHullsToolNodeButton.getHeight()) * 4) 
     179# Remove the status bar. 
     180removeStatusBar() 
    139181 
    140 # Add the nodes to the camera. 
    141 camera.addChild(browseToolNodeButton) 
    142 camera.addChild(manipulateNodesToolNodeButton) 
    143 camera.addChild(manipulateEdgesToolNodeButton) 
    144 camera.addChild(manipulateHullsToolNodeButton) 
    145 camera.addChild(drawToolNodeButton) 
    146  
    147 # Create the event listeners. 
    148 browseToolNodeButtonEventListener = ToolButtonInputEventListener(browseToolNodeButton, BUTTON_TYPE_BROWSE) 
    149 manipulateNodesToolNodeButtonEventListener = ToolButtonInputEventListener(manipulateNodesToolNodeButton, BUTTON_TYPE_MANIPULATE_NODES) 
    150 manipulateEdgesToolNodeButtonEventListener = ToolButtonInputEventListener(manipulateEdgesToolNodeButton, BUTTON_TYPE_MANIPULATE_EDGES) 
    151 manipulateHullsToolNodeButtonEventListener = ToolButtonInputEventListener(manipulateHullsToolNodeButton, BUTTON_TYPE_MANIPULATE_HULLS) 
    152 drawToolNodeButtonEventListener = ToolButtonInputEventListener(drawToolNodeButton, BUTTON_TYPE_DRAW) 
    153  
    154 # Finally, add the event listeners. 
    155 browseToolNodeButton.addInputEventListener(browseToolNodeButtonEventListener) 
    156 manipulateNodesToolNodeButton.addInputEventListener(manipulateNodesToolNodeButtonEventListener) 
    157 manipulateEdgesToolNodeButton.addInputEventListener(manipulateEdgesToolNodeButtonEventListener) 
    158 manipulateHullsToolNodeButton.addInputEventListener(manipulateHullsToolNodeButtonEventListener) 
    159 drawToolNodeButton.addInputEventListener(drawToolNodeButtonEventListener) 
     182# Create the node buttons and store the reference to the one that corresponds to the default tool. 
     183currentToolNodeButton = createNodeButtons() 
     184# Toggle it on by default. 
     185currentToolNodeButton.toggle()