# Copyright 2005-2007 Nanorex, Inc. See LICENSE file for details. """ CookieCtrlPanel.py Class used for the GUI controls for the cookie command. $Id$ Note: Till Alpha8, this command was called Cookie Cutter mode. In Alpha9 it has been renamed to 'Build Crystal' mode. -- ninad 20070511 """ from PyQt4 import QtGui from PyQt4.Qt import Qt from PyQt4.Qt import QActionGroup from PyQt4.Qt import QToolButton from PyQt4.Qt import QWidgetAction from PyQt4.Qt import SIGNAL from PyQt4.Qt import QString from PyQt4.Qt import QColor from PyQt4.Qt import QColorDialog from commands.BuildCrystal.CookiePropertyManager import CookiePropertyManager from utilities.icon_utilities import geticon from utilities.constants import dispLabel from ne1_ui.NE1_QWidgetAction import NE1_QWidgetAction class CookieCtrlPanel(CookiePropertyManager): """ This class provides GUI controls to the cookie-cutter command. """ def __init__(self, parentMode): """ """ self.w = parentMode.w self.cookieCommand = parentMode #bruce 071008, probably redundant with some other attribute self.pw = None # pw is active part window self._init_flyoutActions() CookiePropertyManager.__init__(self, parentMode) self._makeConnections() def _init_flyoutActions(self): """ Define flyout toolbar actions for this command """ #Create an action group and add all the cookie selection shape buttons to it self.cookieSelectionGroup = QActionGroup(self.w) #Action List for subcontrol Area buttons. #In cookie cutter, there is really no subcontrol area. #We will treat subcontrol area same as 'command area' #(subcontrol area buttons will have an empty list as their command area #list). We will set the Comamnd Area palette background color to the #subcontrol area. This list will be used in getFlyoutActionList self.subControlAreaActionList =[] self.exitCrystalAction = NE1_QWidgetAction(self.w, win = self.w) self.exitCrystalAction.setText("Exit Crystal") self.exitCrystalAction.setCheckable(True) self.exitCrystalAction.setChecked(True) self.exitCrystalAction.setIcon( geticon('ui/actions/Toolbars/Smart/Exit.png')) self.subControlAreaActionList.append(self.exitCrystalAction) separator = QtGui.QAction(self.w) separator.setSeparator(True) self.subControlAreaActionList.append(separator) self.DefaultSelAction = NE1_QWidgetAction(self.w, win = self.w) self.DefaultSelAction.setObjectName("DEFAULT") self.DefaultSelAction.setText("Default") self.subControlAreaActionList.append(self.DefaultSelAction) self.DefaultSelAction.setToolTip( "Default Selection (D)") self.DefaultSelAction.setWhatsThis( """Default
Defines the crystal shape as a polygon with the user specifying the sides
""") self.CircleSelAction = NE1_QWidgetAction(self.w, win = self.w) self.CircleSelAction.setObjectName("CIRCLE") self.CircleSelAction.setText("Circle") self.subControlAreaActionList.append(self.CircleSelAction) self.CircleSelAction.setToolTip( "Circle (C)") self.CircleSelAction.setWhatsThis( """CircleDraws the crystal geometry as a circle
""") self.RectCtrSelAction = NE1_QWidgetAction(self.w, win = self.w) self.RectCtrSelAction.setObjectName("RECTANGLE") self.RectCtrSelAction.setText("RectCenter") self.subControlAreaActionList.append(self.RectCtrSelAction) self.RectCtrSelAction.setToolTip( "Rectangular Center (R)") self.RectCtrSelAction.setWhatsThis( """Rectangle - Center SelectDraws the crystal geometry as a rectangle with the cursor defining the center of the rectangle
""") self.HexagonSelAction = NE1_QWidgetAction(self.w, win = self.w) self.HexagonSelAction.setObjectName("HEXAGON") self.HexagonSelAction.setText("Hexagon") self.subControlAreaActionList.append(self.HexagonSelAction) self.HexagonSelAction.setToolTip( "Hexagon (H)") self.HexagonSelAction.setWhatsThis( """HexagonDraws the crystal geometry as a hexagon
""") self.TriangleSelAction = NE1_QWidgetAction(self.w, win = self.w) self.TriangleSelAction.setObjectName("TRIANGLE") self.TriangleSelAction.setText("Triangle") self.subControlAreaActionList.append(self.TriangleSelAction) self.TriangleSelAction.setToolTip( "Triangle (T)") self.TriangleSelAction.setWhatsThis( """TriangleDraws the crystal geometry as a triangle
""") self.RectCornerSelAction = NE1_QWidgetAction(self.w, win = self.w) self.RectCornerSelAction.setObjectName("RECT_CORNER") self.RectCornerSelAction.setText("RectCorners") self.subControlAreaActionList.append(self.RectCornerSelAction) self.RectCornerSelAction.setToolTip( "Rectangular Corner (Shift+R)") self.RectCornerSelAction.setWhatsThis( """Rectangle - Corner SelectDraws the crystal geometry as a rectangle with the cursor defining the initial corner
""") self.LassoSelAction = NE1_QWidgetAction(self.w, win = self.w) self.LassoSelAction.setObjectName("LASSO") self.LassoSelAction.setText("Lasso") self.subControlAreaActionList.append(self.LassoSelAction) self.LassoSelAction.setToolTip( "Lasso (L)") self.LassoSelAction.setWhatsThis( """LassoCan be used to draw irregular crystal geometries
""") self.DiamondSelAction = NE1_QWidgetAction(self.w, win = self.w) self.DiamondSelAction.setObjectName("DIAMOND") self.DiamondSelAction.setText("Diamond") self.subControlAreaActionList.append(self.DiamondSelAction) self.DiamondSelAction.setToolTip( "Diamond (D)") self.DiamondSelAction.setWhatsThis( """DiamondDraws the crystal geometry as a diamond
""") self.SquareSelAction = NE1_QWidgetAction(self.w, win = self.w) self.SquareSelAction.setObjectName("SQUARE") self.SquareSelAction.setText("Square") self.subControlAreaActionList.append(self.SquareSelAction) self.SquareSelAction.setToolTip( "Square(S)") self.SquareSelAction.setWhatsThis( """SquareDraws the crystal geometry as a square
""") for action in self.subControlAreaActionList[1:]: if isinstance(action, QtGui.QWidgetAction): action.setCheckable(True) self.cookieSelectionGroup.addAction(action) iconpath = "ui/actions/Toolbars/Smart/" + str(action.text()) + ".png" action.setIcon(geticon(iconpath)) if not self.cookieSelectionGroup.checkedAction(): self.DefaultSelAction.setChecked(True) def getFlyoutActionList(self): """ Returns a tuple that contains mode-specific actionlists in the added in the flyout toolbar of the mode. CommandToolbar._createFlyoutToolBar method calls this @return: params: A tuple that contains 3 lists: (subControlAreaActionList, commandActionLists, allActionsList). """ #'allActionsList' returns all actions in the flyout toolbar #including the subcontrolArea actions allActionsList = [] #Action List for subcontrol Area buttons. #In cookie cutter, there is really no subcontrol area. #We will treat subcontrol area same as 'command area' #(subcontrol area buttons will have an empty list as their command area #list). We will set the Comamnd Area palette background color to the #subcontrol area. subControlAreaActionList = self.subControlAreaActionList allActionsList.extend(subControlAreaActionList) #Empty actionlist for the 'Command Area' commandActionLists = [] #Append empty 'lists' in 'commandActionLists equal to the #number of actions in subControlArea for i in range(len(subControlAreaActionList)): lst = [] commandActionLists.append(lst) #The subcontrol area buuton and its command list form a 'key:value pair #in a python dictionary object flyoutDictionary = {} counter = 0 for k in subControlAreaActionList: # counter is used to sort the keys in the order in which they #were added key = (counter, k) flyoutDictionary[key] = commandActionLists[counter] #Also add command actions to the 'allActionsList' allActionsList.extend(commandActionLists[counter]) counter +=1 params = (subControlAreaActionList, commandActionLists, allActionsList) return params def updateCommandToolbar(self, bool_entering = True): """ Update the Command Toolbar. """ if bool_entering: action = self.w.toolsCookieCutAction else: action = None # object that needs its own flyout toolbar. In this case it is just # the mode itself. # [later, bruce 071009: self is now a PM -- is that what this should # now say, instead of 'mode'?] obj = self self.w.commandToolbar.updateCommandToolbar(action, obj, entering = bool_entering) def _makeConnections(self): """Connect signal to slots """ self.connect(self.latticeCBox, SIGNAL("activated ( int )"), self.changeLatticeType) self.connect(self.orientButtonGroup, SIGNAL("buttonClicked(int)"), self.changeGridOrientation) self.connect(self.rotGridAntiClockwiseButton, SIGNAL("clicked()"), self.antiRotateView) self.connect(self.rotGridClockwiseButton, SIGNAL("clicked()"), self.rotateView) self.connect(self.addLayerButton,SIGNAL("clicked()"), self.addLayer) self.connect(self.currentLayerComboBox,SIGNAL("activated(int)"), self.changeLayer) self.connect(self.layerCellsSpinBox,SIGNAL("valueChanged(int)"), self.setThickness) #self.connect(self.gridColorButton,SIGNAL("clicked()"),self.changeGridColor) self.connect(self.gridLineCheckBox,SIGNAL("toggled(bool)"),self.showGridLine) self.connect(self.freeViewCheckBox,SIGNAL("toggled(bool)"),self.setFreeView) self.connect(self.fullModelCheckBox, SIGNAL("toggled(bool)"),self.toggleFullModel) self.connect(self.snapGridCheckBox, SIGNAL("toggled(bool)"), self.setGridSnap) self.connect(self.dispModeComboBox, SIGNAL("activated(const QString &)"), self.changeDispMode) self.connect(self.cookieSelectionGroup, SIGNAL("triggered(QAction *)"), self.changeSelectionShape) self.connect(self.exitCrystalAction, SIGNAL("triggered()"), self.w.toolsDone) def _setAutoShapeAcclKeys(self, on): """ If