| | 39 | |
|---|
| | 40 | # A toggleable-image node class. |
|---|
| | 41 | class 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) |
|---|
| 94 | | return |
|---|
| | 116 | # Get rid of the status bar (with the broken buttons). |
|---|
| | 117 | def 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 |
|---|
| 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. |
|---|
| | 138 | def 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) |
|---|
| 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 |
|---|
| 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. |
|---|
| | 153 | def 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 |
|---|
| 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. |
|---|
| | 180 | removeStatusBar() |
|---|
| 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. |
|---|
| | 183 | currentToolNodeButton = createNodeButtons() |
|---|
| | 184 | # Toggle it on by default. |
|---|
| | 185 | currentToolNodeButton.toggle() |
|---|