def UnitSettingsChanged(self): if self.baseSizeCb.currentText() == "" or self.unitSizeCb.currentText() == "": return # correct baseSize/unitSize not yet selected, but it will be shortly, just do nothing for now. singleBaseX, singleBaseY = [int(size) for size in self.baseSizeCb.currentText().split(' ')[0].split('x')] unitType = QtGui.qApp.DataManager.UnitTypeByName( self.unitTypeCb.currentText() ) unitSize = None for avS in unitType.availableSizes: if self.unitSizeCb.currentText() == str(avS): unitSize = avS break if unitSize is None: raise ValueError("Invalid unit size selected! '%s'" % self.unitSizeCb.currentText()) formation = unitSize.formation unitWidth = singleBaseX * formation[0] unitDepth = singleBaseY * formation[1] self.previewScene.removeItem(self.unit) del self.unit self.unit = RectBaseUnit(name = self.unitNameLe.text(), labelText = self.unitLabelLe.text(), baseSize = (unitWidth * MM_TO_IN, unitDepth * MM_TO_IN), formation=formation) if unitWidth >= 240 or unitDepth >= 120: self.previewGv.setTransform(QtGui.QTransform().scale(10,10)) else: self.previewGv.setTransform(QtGui.QTransform().scale(20,20)) self.previewScene.addItem(self.unit) self.previewGv.ensureVisible(self.unit)
def UnitSettingsChanged(self): if self.baseSizeCb.currentText() == "" or self.unitSizeCb.currentText( ) == "": return # correct baseSize/unitSize not yet selected, but it will be shortly, just do nothing for now. singleBaseX, singleBaseY = [ int(size) for size in self.baseSizeCb.currentText().split(' ')[0].split('x') ] unitType = QtGui.qApp.DataManager.UnitTypeByName( self.unitTypeCb.currentText()) unitSize = None for avS in unitType.availableSizes: if self.unitSizeCb.currentText() == str(avS): unitSize = avS break if unitSize is None: raise ValueError("Invalid unit size selected! '%s'" % self.unitSizeCb.currentText()) formation = unitSize.formation unitWidth = singleBaseX * formation[0] unitDepth = singleBaseY * formation[1] self.previewScene.removeItem(self.unit) del self.unit self.unit = RectBaseUnit(name=self.unitNameLe.text(), labelText=self.unitLabelLe.text(), baseSize=(unitWidth * MM_TO_IN, unitDepth * MM_TO_IN), formation=formation) if unitWidth >= 240 or unitDepth >= 120: self.previewGv.setTransform(QtGui.QTransform().scale(10, 10)) else: self.previewGv.setTransform(QtGui.QTransform().scale(20, 20)) self.previewScene.addItem(self.unit) self.previewGv.ensureVisible(self.unit)
def __init__(self): super(AddUnitDialog, self).__init__() #========================================================================= # member children #========================================================================= self.unit = RectBaseUnit(baseSize=(100*MM_TO_IN, 40*MM_TO_IN), formation=(5,2)) self.previewGv = QtGui.QGraphicsView() self.previewScene = QtGui.QGraphicsScene() self.unitNameLe = QtGui.QLineEdit("Unnamed unit") self.unitLabelLe = QtGui.QLineEdit("?") self.unitTypeCb = QtGui.QComboBox() self.unitSizeCb = QtGui.QComboBox() self.baseSizeCb = QtGui.QComboBox() self.playerCb = QtGui.QComboBox() for i in range(QtGui.qApp.GameManager.NumPlayers()): self.playerCb.addItem(QtGui.qApp.GameManager.GetPlayer(i).name) #========================================================================= # init self and children #========================================================================= self.setWindowTitle("Add unit...") unitTypes = QtGui.qApp.DataManager.GetUnitTypes() for ut in unitTypes: self.unitTypeCb.addItem(ut.typeName) curUt = unitTypes[0] for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.addItems(["20x20", "25x25", "25x50 (Cav.)", "40x40 (L.Inf.)", "50x50 (L.Cav.)", "50x100 (Chariot)", "75x75 (Monster)", "Custom..."]) self.previewGv.setMinimumSize(200,80) self.previewGv.setEnabled(False) self.previewGv.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewGv.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewScene.addItem(self.unit) self.previewScene.setBackgroundBrush(QtGui.QColor(121,217,82)) self.previewGv.setScene(self.previewScene) self.previewGv.scale(20,20) self.cancelBtn = QtGui.QPushButton("Cancel") self.acceptBtn = QtGui.QPushButton("Add >>") self.acceptBtn.setDefault(True) #========================================================================= # Init layout #========================================================================= lay = QtGui.QVBoxLayout() mainLay = QtGui.QGridLayout() btnLay = QtGui.QHBoxLayout() # general group box genGrpBox = QtGui.QGroupBox("General") genLay = QtGui.QGridLayout() row = 0 # unit name genLay.addWidget(QtGui.QLabel("Unit name:"), row, 0) genLay.addWidget(self.unitNameLe, row, 1) row+=1 # label genLay.addWidget(QtGui.QLabel("Unit label:"), row, 0) genLay.addWidget(self.unitLabelLe, row, 1) row+=1 # unit type genLay.addWidget(QtGui.QLabel("Unit type:"), row, 0) genLay.addWidget(self.unitTypeCb, row, 1) row+=1 # unit size genLay.addWidget(QtGui.QLabel("Size:"), row, 0) genLay.addWidget(self.unitSizeCb, row, 1) row+=1 # base size genLay.addWidget(QtGui.QLabel("Base size [mm]:"), row, 0) genLay.addWidget(self.baseSizeCb, row, 1) row+=1 # control group box conGrpBox = QtGui.QGroupBox("Control") conLay = QtGui.QGridLayout() row = 0 # player conLay.addWidget(QtGui.QLabel("Controlled by:"), row, 0) conLay.addWidget(self.playerCb, row, 1) row += 1 #========================================================================= # ASSEMBLE LAYOUTS #========================================================================= genGrpBox.setLayout(genLay) conGrpBox.setLayout(conLay) mainLay.addWidget(genGrpBox, 0, 0) mainLay.addWidget(conGrpBox, 1, 0) mainLay.addWidget(self.previewGv, 0, 1, 2, 1, stretch=1) btnLay.addWidget(self.cancelBtn) btnLay.addStretch(1) btnLay.addWidget(self.acceptBtn) lay.addLayout(mainLay) lay.addLayout(btnLay) self.setLayout(lay) #========================================================================= # INIT CONNECTIONS #========================================================================= self.unitTypeCb.currentIndexChanged.connect(self.UpdateSizeOptions) self.unitSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.baseSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.playerCb.currentIndexChanged.connect(self.PlayerChanged) self.unitNameLe.textChanged.connect(self.UnitNameChanged) self.unitLabelLe.textChanged.connect(self.UnitLabelChanged) self.cancelBtn.clicked.connect(self.reject) self.acceptBtn.clicked.connect(self.accept) #========================================================================= # FINAL INITIALIZATION #========================================================================= self.unitNameLe.selectAll() self.unitNameLe.setFocus()
class AddUnitDialog(QtGui.QDialog): def __init__(self): super(AddUnitDialog, self).__init__() #========================================================================= # member children #========================================================================= self.unit = RectBaseUnit(baseSize=(100*MM_TO_IN, 40*MM_TO_IN), formation=(5,2)) self.previewGv = QtGui.QGraphicsView() self.previewScene = QtGui.QGraphicsScene() self.unitNameLe = QtGui.QLineEdit("Unnamed unit") self.unitLabelLe = QtGui.QLineEdit("?") self.unitTypeCb = QtGui.QComboBox() self.unitSizeCb = QtGui.QComboBox() self.baseSizeCb = QtGui.QComboBox() self.playerCb = QtGui.QComboBox() for i in range(QtGui.qApp.GameManager.NumPlayers()): self.playerCb.addItem(QtGui.qApp.GameManager.GetPlayer(i).name) #========================================================================= # init self and children #========================================================================= self.setWindowTitle("Add unit...") unitTypes = QtGui.qApp.DataManager.GetUnitTypes() for ut in unitTypes: self.unitTypeCb.addItem(ut.typeName) curUt = unitTypes[0] for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.addItems(["20x20", "25x25", "25x50 (Cav.)", "40x40 (L.Inf.)", "50x50 (L.Cav.)", "50x100 (Chariot)", "75x75 (Monster)", "Custom..."]) self.previewGv.setMinimumSize(200,80) self.previewGv.setEnabled(False) self.previewGv.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewGv.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewScene.addItem(self.unit) self.previewScene.setBackgroundBrush(QtGui.QColor(121,217,82)) self.previewGv.setScene(self.previewScene) self.previewGv.scale(20,20) self.cancelBtn = QtGui.QPushButton("Cancel") self.acceptBtn = QtGui.QPushButton("Add >>") self.acceptBtn.setDefault(True) #========================================================================= # Init layout #========================================================================= lay = QtGui.QVBoxLayout() mainLay = QtGui.QGridLayout() btnLay = QtGui.QHBoxLayout() # general group box genGrpBox = QtGui.QGroupBox("General") genLay = QtGui.QGridLayout() row = 0 # unit name genLay.addWidget(QtGui.QLabel("Unit name:"), row, 0) genLay.addWidget(self.unitNameLe, row, 1) row+=1 # label genLay.addWidget(QtGui.QLabel("Unit label:"), row, 0) genLay.addWidget(self.unitLabelLe, row, 1) row+=1 # unit type genLay.addWidget(QtGui.QLabel("Unit type:"), row, 0) genLay.addWidget(self.unitTypeCb, row, 1) row+=1 # unit size genLay.addWidget(QtGui.QLabel("Size:"), row, 0) genLay.addWidget(self.unitSizeCb, row, 1) row+=1 # base size genLay.addWidget(QtGui.QLabel("Base size [mm]:"), row, 0) genLay.addWidget(self.baseSizeCb, row, 1) row+=1 # control group box conGrpBox = QtGui.QGroupBox("Control") conLay = QtGui.QGridLayout() row = 0 # player conLay.addWidget(QtGui.QLabel("Controlled by:"), row, 0) conLay.addWidget(self.playerCb, row, 1) row += 1 #========================================================================= # ASSEMBLE LAYOUTS #========================================================================= genGrpBox.setLayout(genLay) conGrpBox.setLayout(conLay) mainLay.addWidget(genGrpBox, 0, 0) mainLay.addWidget(conGrpBox, 1, 0) mainLay.addWidget(self.previewGv, 0, 1, 2, 1, stretch=1) btnLay.addWidget(self.cancelBtn) btnLay.addStretch(1) btnLay.addWidget(self.acceptBtn) lay.addLayout(mainLay) lay.addLayout(btnLay) self.setLayout(lay) #========================================================================= # INIT CONNECTIONS #========================================================================= self.unitTypeCb.currentIndexChanged.connect(self.UpdateSizeOptions) self.unitSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.baseSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.playerCb.currentIndexChanged.connect(self.PlayerChanged) self.unitNameLe.textChanged.connect(self.UnitNameChanged) self.unitLabelLe.textChanged.connect(self.UnitLabelChanged) self.cancelBtn.clicked.connect(self.reject) self.acceptBtn.clicked.connect(self.accept) #========================================================================= # FINAL INITIALIZATION #========================================================================= self.unitNameLe.selectAll() self.unitNameLe.setFocus() def PlayerChanged(self): index = self.playerCb.currentIndex() self.unit.SetOwner(QtGui.qApp.GameManager.GetPlayer(index)) def UnitLabelChanged(self): label = self.unitLabelLe.text() if label != self.unit.labelText: # only update unit if the label text actually changes self.unitLabelLe.setText(label) self.unit.labelText = label self.unit.UpdateLabel() self.unit.update() def UnitNameChanged(self): name = self.unitNameLe.text() words = name.split(" ") label = "" for w in words: if len(w)>0 and w[0].isalnum() and len(label)<=4: # max 4 chars label += w[0].upper() if label != self.unit.labelText: # only update unit if the label text actually changes self.unitLabelLe.setText(label) self.unit.labelText = label self.unit.UpdateLabel() self.unit.update() def UnitSettingsChanged(self): if self.baseSizeCb.currentText() == "" or self.unitSizeCb.currentText() == "": return # correct baseSize/unitSize not yet selected, but it will be shortly, just do nothing for now. singleBaseX, singleBaseY = [int(size) for size in self.baseSizeCb.currentText().split(' ')[0].split('x')] unitType = QtGui.qApp.DataManager.UnitTypeByName( self.unitTypeCb.currentText() ) unitSize = None for avS in unitType.availableSizes: if self.unitSizeCb.currentText() == str(avS): unitSize = avS break if unitSize is None: raise ValueError("Invalid unit size selected! '%s'" % self.unitSizeCb.currentText()) formation = unitSize.formation unitWidth = singleBaseX * formation[0] unitDepth = singleBaseY * formation[1] self.previewScene.removeItem(self.unit) del self.unit self.unit = RectBaseUnit(name = self.unitNameLe.text(), labelText = self.unitLabelLe.text(), baseSize = (unitWidth * MM_TO_IN, unitDepth * MM_TO_IN), formation=formation) if unitWidth >= 240 or unitDepth >= 120: self.previewGv.setTransform(QtGui.QTransform().scale(10,10)) else: self.previewGv.setTransform(QtGui.QTransform().scale(20,20)) self.previewScene.addItem(self.unit) self.previewGv.ensureVisible(self.unit) def UpdateSizeOptions(self): curUtName = self.unitTypeCb.currentText() curUt = QtGui.qApp.DataManager.UnitTypeByName(curUtName) self.unitSizeCb.clear() for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.clear() for avBs in curUt.availableBaseSizes: self.baseSizeCb.addItem("%dx%d" % (avBs[0], avBs[1])) self.UnitSettingsChanged()
def __init__(self): super(AddUnitDialog, self).__init__() #========================================================================= # member children #========================================================================= self.unit = RectBaseUnit(baseSize=(100 * MM_TO_IN, 40 * MM_TO_IN), formation=(5, 2)) self.previewGv = QtGui.QGraphicsView() self.previewScene = QtGui.QGraphicsScene() self.unitNameLe = QtGui.QLineEdit("Unnamed unit") self.unitLabelLe = QtGui.QLineEdit("?") self.unitTypeCb = QtGui.QComboBox() self.unitSizeCb = QtGui.QComboBox() self.baseSizeCb = QtGui.QComboBox() self.playerCb = QtGui.QComboBox() for i in range(QtGui.qApp.GameManager.NumPlayers()): self.playerCb.addItem(QtGui.qApp.GameManager.GetPlayer(i).name) #========================================================================= # init self and children #========================================================================= self.setWindowTitle("Add unit...") unitTypes = QtGui.qApp.DataManager.GetUnitTypes() for ut in unitTypes: self.unitTypeCb.addItem(ut.typeName) curUt = unitTypes[0] for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.addItems([ "20x20", "25x25", "25x50 (Cav.)", "40x40 (L.Inf.)", "50x50 (L.Cav.)", "50x100 (Chariot)", "75x75 (Monster)", "Custom..." ]) self.previewGv.setMinimumSize(200, 80) self.previewGv.setEnabled(False) self.previewGv.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewGv.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewScene.addItem(self.unit) self.previewScene.setBackgroundBrush(QtGui.QColor(121, 217, 82)) self.previewGv.setScene(self.previewScene) self.previewGv.scale(20, 20) self.cancelBtn = QtGui.QPushButton("Cancel") self.acceptBtn = QtGui.QPushButton("Add >>") self.acceptBtn.setDefault(True) #========================================================================= # Init layout #========================================================================= lay = QtGui.QVBoxLayout() mainLay = QtGui.QGridLayout() btnLay = QtGui.QHBoxLayout() # general group box genGrpBox = QtGui.QGroupBox("General") genLay = QtGui.QGridLayout() row = 0 # unit name genLay.addWidget(QtGui.QLabel("Unit name:"), row, 0) genLay.addWidget(self.unitNameLe, row, 1) row += 1 # label genLay.addWidget(QtGui.QLabel("Unit label:"), row, 0) genLay.addWidget(self.unitLabelLe, row, 1) row += 1 # unit type genLay.addWidget(QtGui.QLabel("Unit type:"), row, 0) genLay.addWidget(self.unitTypeCb, row, 1) row += 1 # unit size genLay.addWidget(QtGui.QLabel("Size:"), row, 0) genLay.addWidget(self.unitSizeCb, row, 1) row += 1 # base size genLay.addWidget(QtGui.QLabel("Base size [mm]:"), row, 0) genLay.addWidget(self.baseSizeCb, row, 1) row += 1 # control group box conGrpBox = QtGui.QGroupBox("Control") conLay = QtGui.QGridLayout() row = 0 # player conLay.addWidget(QtGui.QLabel("Controlled by:"), row, 0) conLay.addWidget(self.playerCb, row, 1) row += 1 #========================================================================= # ASSEMBLE LAYOUTS #========================================================================= genGrpBox.setLayout(genLay) conGrpBox.setLayout(conLay) mainLay.addWidget(genGrpBox, 0, 0) mainLay.addWidget(conGrpBox, 1, 0) mainLay.addWidget(self.previewGv, 0, 1, 2, 1, stretch=1) btnLay.addWidget(self.cancelBtn) btnLay.addStretch(1) btnLay.addWidget(self.acceptBtn) lay.addLayout(mainLay) lay.addLayout(btnLay) self.setLayout(lay) #========================================================================= # INIT CONNECTIONS #========================================================================= self.unitTypeCb.currentIndexChanged.connect(self.UpdateSizeOptions) self.unitSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.baseSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.playerCb.currentIndexChanged.connect(self.PlayerChanged) self.unitNameLe.textChanged.connect(self.UnitNameChanged) self.unitLabelLe.textChanged.connect(self.UnitLabelChanged) self.cancelBtn.clicked.connect(self.reject) self.acceptBtn.clicked.connect(self.accept) #========================================================================= # FINAL INITIALIZATION #========================================================================= self.unitNameLe.selectAll() self.unitNameLe.setFocus()
class AddUnitDialog(QtGui.QDialog): def __init__(self): super(AddUnitDialog, self).__init__() #========================================================================= # member children #========================================================================= self.unit = RectBaseUnit(baseSize=(100 * MM_TO_IN, 40 * MM_TO_IN), formation=(5, 2)) self.previewGv = QtGui.QGraphicsView() self.previewScene = QtGui.QGraphicsScene() self.unitNameLe = QtGui.QLineEdit("Unnamed unit") self.unitLabelLe = QtGui.QLineEdit("?") self.unitTypeCb = QtGui.QComboBox() self.unitSizeCb = QtGui.QComboBox() self.baseSizeCb = QtGui.QComboBox() self.playerCb = QtGui.QComboBox() for i in range(QtGui.qApp.GameManager.NumPlayers()): self.playerCb.addItem(QtGui.qApp.GameManager.GetPlayer(i).name) #========================================================================= # init self and children #========================================================================= self.setWindowTitle("Add unit...") unitTypes = QtGui.qApp.DataManager.GetUnitTypes() for ut in unitTypes: self.unitTypeCb.addItem(ut.typeName) curUt = unitTypes[0] for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.addItems([ "20x20", "25x25", "25x50 (Cav.)", "40x40 (L.Inf.)", "50x50 (L.Cav.)", "50x100 (Chariot)", "75x75 (Monster)", "Custom..." ]) self.previewGv.setMinimumSize(200, 80) self.previewGv.setEnabled(False) self.previewGv.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewGv.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.previewScene.addItem(self.unit) self.previewScene.setBackgroundBrush(QtGui.QColor(121, 217, 82)) self.previewGv.setScene(self.previewScene) self.previewGv.scale(20, 20) self.cancelBtn = QtGui.QPushButton("Cancel") self.acceptBtn = QtGui.QPushButton("Add >>") self.acceptBtn.setDefault(True) #========================================================================= # Init layout #========================================================================= lay = QtGui.QVBoxLayout() mainLay = QtGui.QGridLayout() btnLay = QtGui.QHBoxLayout() # general group box genGrpBox = QtGui.QGroupBox("General") genLay = QtGui.QGridLayout() row = 0 # unit name genLay.addWidget(QtGui.QLabel("Unit name:"), row, 0) genLay.addWidget(self.unitNameLe, row, 1) row += 1 # label genLay.addWidget(QtGui.QLabel("Unit label:"), row, 0) genLay.addWidget(self.unitLabelLe, row, 1) row += 1 # unit type genLay.addWidget(QtGui.QLabel("Unit type:"), row, 0) genLay.addWidget(self.unitTypeCb, row, 1) row += 1 # unit size genLay.addWidget(QtGui.QLabel("Size:"), row, 0) genLay.addWidget(self.unitSizeCb, row, 1) row += 1 # base size genLay.addWidget(QtGui.QLabel("Base size [mm]:"), row, 0) genLay.addWidget(self.baseSizeCb, row, 1) row += 1 # control group box conGrpBox = QtGui.QGroupBox("Control") conLay = QtGui.QGridLayout() row = 0 # player conLay.addWidget(QtGui.QLabel("Controlled by:"), row, 0) conLay.addWidget(self.playerCb, row, 1) row += 1 #========================================================================= # ASSEMBLE LAYOUTS #========================================================================= genGrpBox.setLayout(genLay) conGrpBox.setLayout(conLay) mainLay.addWidget(genGrpBox, 0, 0) mainLay.addWidget(conGrpBox, 1, 0) mainLay.addWidget(self.previewGv, 0, 1, 2, 1, stretch=1) btnLay.addWidget(self.cancelBtn) btnLay.addStretch(1) btnLay.addWidget(self.acceptBtn) lay.addLayout(mainLay) lay.addLayout(btnLay) self.setLayout(lay) #========================================================================= # INIT CONNECTIONS #========================================================================= self.unitTypeCb.currentIndexChanged.connect(self.UpdateSizeOptions) self.unitSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.baseSizeCb.currentIndexChanged.connect(self.UnitSettingsChanged) self.playerCb.currentIndexChanged.connect(self.PlayerChanged) self.unitNameLe.textChanged.connect(self.UnitNameChanged) self.unitLabelLe.textChanged.connect(self.UnitLabelChanged) self.cancelBtn.clicked.connect(self.reject) self.acceptBtn.clicked.connect(self.accept) #========================================================================= # FINAL INITIALIZATION #========================================================================= self.unitNameLe.selectAll() self.unitNameLe.setFocus() def PlayerChanged(self): index = self.playerCb.currentIndex() self.unit.SetOwner(QtGui.qApp.GameManager.GetPlayer(index)) def UnitLabelChanged(self): label = self.unitLabelLe.text() if label != self.unit.labelText: # only update unit if the label text actually changes self.unitLabelLe.setText(label) self.unit.labelText = label self.unit.UpdateLabel() self.unit.update() def UnitNameChanged(self): name = self.unitNameLe.text() words = name.split(" ") label = "" for w in words: if len(w) > 0 and w[0].isalnum( ) and len(label) <= 4: # max 4 chars label += w[0].upper() if label != self.unit.labelText: # only update unit if the label text actually changes self.unitLabelLe.setText(label) self.unit.labelText = label self.unit.UpdateLabel() self.unit.update() def UnitSettingsChanged(self): if self.baseSizeCb.currentText() == "" or self.unitSizeCb.currentText( ) == "": return # correct baseSize/unitSize not yet selected, but it will be shortly, just do nothing for now. singleBaseX, singleBaseY = [ int(size) for size in self.baseSizeCb.currentText().split(' ')[0].split('x') ] unitType = QtGui.qApp.DataManager.UnitTypeByName( self.unitTypeCb.currentText()) unitSize = None for avS in unitType.availableSizes: if self.unitSizeCb.currentText() == str(avS): unitSize = avS break if unitSize is None: raise ValueError("Invalid unit size selected! '%s'" % self.unitSizeCb.currentText()) formation = unitSize.formation unitWidth = singleBaseX * formation[0] unitDepth = singleBaseY * formation[1] self.previewScene.removeItem(self.unit) del self.unit self.unit = RectBaseUnit(name=self.unitNameLe.text(), labelText=self.unitLabelLe.text(), baseSize=(unitWidth * MM_TO_IN, unitDepth * MM_TO_IN), formation=formation) if unitWidth >= 240 or unitDepth >= 120: self.previewGv.setTransform(QtGui.QTransform().scale(10, 10)) else: self.previewGv.setTransform(QtGui.QTransform().scale(20, 20)) self.previewScene.addItem(self.unit) self.previewGv.ensureVisible(self.unit) def UpdateSizeOptions(self): curUtName = self.unitTypeCb.currentText() curUt = QtGui.qApp.DataManager.UnitTypeByName(curUtName) self.unitSizeCb.clear() for avS in curUt.availableSizes: self.unitSizeCb.addItem(str(avS)) self.baseSizeCb.clear() for avBs in curUt.availableBaseSizes: self.baseSizeCb.addItem("%dx%d" % (avBs[0], avBs[1])) self.UnitSettingsChanged()