How to use attendere method in SeleniumBase

Best Python code snippet using SeleniumBase

qad_scale_cmd.py

Source:qad_scale_cmd.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3/***************************************************************************4 QAD Quantum Aided Design plugin5 comando SCALE per scalare oggetti6 7 -------------------8 begin : 2013-10-019 copyright : iiiii10 email : hhhhh11 developers : bbbbb aaaaa ggggg12 ***************************************************************************/13/***************************************************************************14 * *15 * This program is free software; you can redistribute it and/or modify *16 * it under the terms of the GNU General Public License as published by *17 * the Free Software Foundation; either version 2 of the License, or *18 * (at your option) any later version. *19 * *20 ***************************************************************************/21"""22# Import the PyQt and QGIS libraries23from PyQt4.QtCore import *24from PyQt4.QtGui import *25from qgis.core import *26from qad_scale_maptool import *27from qad_generic_cmd import QadCommandClass28from qad_msg import QadMsg29from qad_getpoint import *30from qad_textwindow import *31from qad_ssget_cmd import QadSSGetClass32from qad_entity import *33import qad_utils34import qad_layer35import qad_label36from qad_dim import *37# Classe che gestisce il comando SCALA38class QadSCALECommandClass(QadCommandClass):39 def instantiateNewCmd(self):40 """ istanzia un nuovo comando dello stesso tipo """41 return QadSCALECommandClass(self.plugIn)42 def getName(self):43 return QadMsg.translate("Command_list", "SCALE")44 def getEnglishName(self):45 return "SCALE"46 def connectQAction(self, action):47 QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runSCALECommand)48 def getIcon(self):49 return QIcon(":/plugins/qad/icons/scale.png")50 def getNote(self):51 # impostare le note esplicative del comando 52 return QadMsg.translate("Command_SCALE", "Enlarges or reduces selected objects.")53 54 def __init__(self, plugIn):55 QadCommandClass.__init__(self, plugIn)56 self.SSGetClass = QadSSGetClass(plugIn)57 self.SSGetClass.onlyEditableLayers = True58 self.entitySet = QadEntitySet()59 self.basePt = None60 self.copyFeatures = False61 self.Pt1ReferenceLen = None62 self.ReferenceLen = 163 self.Pt1NewLen = None64 def __del__(self):65 QadCommandClass.__del__(self)66 del self.SSGetClass67 68 def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):69 if self.step == 0: # quando si é in fase di selezione entità70 return self.SSGetClass.getPointMapTool()71 else:72 if (self.plugIn is not None):73 if self.PointMapTool is None:74 self.PointMapTool = Qad_scale_maptool(self.plugIn)75 return self.PointMapTool76 else:77 return None78 def getCurrentContextualMenu(self):79 if self.step == 0: # quando si é in fase di selezione entità80 return self.SSGetClass.getCurrentContextualMenu()81 else:82 return self.contextualMenu83 #============================================================================84 # scale85 #============================================================================86 def scale(self, f, basePt, scale, sizeFldName, layerEntitySet, entitySet):87 # verifico se l'entità appartiene ad uno stile di quotatura88 dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())89 90 if dimEntity is None:91 # scalo la feature e la rimuovo da entitySet (é la prima)92 f.setGeometry(qad_utils.scaleQgsGeometry(f.geometry(), basePt, scale))93 if sizeFldName is not None:94 sizeValue = f.attribute(sizeFldName)95 # a volte vale None e a volte null (vai a capire...)96 if sizeValue is None or isinstance(sizeValue, QPyNullVariant):97 sizeValue = 198 sizeValue = sizeValue * scale99 f.setAttribute(sizeFldName, sizeValue) 100 101 if self.copyFeatures == False:102 # plugIn, layer, feature, refresh, check_validity103 if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:104 self.plugIn.destroyEditCommand()105 return False106 else: 107 # plugIn, layer, features, coordTransform, refresh, check_validity108 if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:109 self.plugIn.destroyEditCommand()110 return False111 del layerEntitySet.featureIds[0]112 else:113 # scalo la quota e la rimuovo da entitySet114 dimEntitySet = dimEntity.getEntitySet()115 if self.copyFeatures == False:116 if dimEntity.deleteToLayers(self.plugIn) == False:117 return False 118 newDimEntity = QadDimEntity(dimEntity) # la copio119 newDimEntity.scale(basePt, scale)120 if newDimEntity.addToLayers(self.plugIn) == False:121 return False 122 entitySet.subtract(dimEntitySet)123 def scaleGeoms(self, scale): 124 # copio entitySet125 entitySet = QadEntitySet(self.entitySet)126 127 self.plugIn.beginEditCommand("Feature scaled", self.entitySet.getLayerList())128 129 for layerEntitySet in entitySet.layerEntitySetList:130 layer = layerEntitySet.layer131 132 transformedBasePt = self.mapToLayerCoordinates(layer, self.basePt)133 134 sizeFldName = None135 if qad_layer.isTextLayer(layer):136 # se l'altezza testo dipende da un solo campo 137 sizeFldNames = qad_label.get_labelSizeFieldNames(layer)138 if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0:139 sizeFldName = sizeFldNames[0]140 elif qad_layer.isSymbolLayer(layer):141 # se la scala dipende da un campo 142 sizeFldName = qad_layer.get_symbolScaleFieldName(layer)143 if len(sizeFldName) == 0:144 sizeFldName = None145 while len(layerEntitySet.featureIds) > 0:146 featureId = layerEntitySet.featureIds[0]147 f = layerEntitySet.getFeature(featureId)148 if self.scale(f, transformedBasePt, scale, sizeFldName, layerEntitySet, entitySet) == False: 149 self.plugIn.destroyEditCommand()150 return151 self.plugIn.endEditCommand()152 def waitForScale(self):153 # imposto il map tool154 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT)155 keyWords = QadMsg.translate("Command_SCALE", "Copy") + "/" + \156 QadMsg.translate("Command_SCALE", "Reference")157 default = self.plugIn.lastScale158 prompt = QadMsg.translate("Command_SCALE", "Specify scale factor or [{0}] <{1}>: ").format(keyWords, str(default)) 159 160 englishKeyWords = "Copy" + "/" + "Reference"161 keyWords += "_" + englishKeyWords162 # si appresta ad attendere un punto o enter o una parola chiave 163 # msg, inputType, default, keyWords, valori positivi164 self.waitFor(prompt, \165 QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \166 default, \167 keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) 168 self.step = 3 169 def waitForReferenceLen(self):170 # imposto il map tool171 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_LEN)172 173 msg = QadMsg.translate("Command_SCALE", "Specify reference length <{0}>: ")174 # si appresta ad attendere un punto o enter 175 # msg, inputType, default, keyWords, valori positivi176 self.waitFor(msg.format(str(self.plugIn.lastReferenceLen)), \177 QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \178 self.plugIn.lastReferenceLen, \179 "", QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) 180 self.step = 4181 def waitForNewReferenceLen(self):182 # imposto il map tool183 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT)184 185 keyWords = QadMsg.translate("Command_SCALE", "Points")186 if self.plugIn.lastNewReferenceLen == 0:187 default = self.plugIn.lastScale188 else:189 default = self.plugIn.lastNewReferenceLen190 prompt = QadMsg.translate("Command_SCALE", "Specify new length or [{0}] <{1}>: ").format(keyWords, str(default)) 191 192 englishKeyWords = "Points"193 keyWords += "_" + englishKeyWords194 # si appresta ad attendere un punto o enter o una parola chiave 195 # msg, inputType, default, keyWords, valori positivi196 self.waitFor(prompt, \197 QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \198 default, \199 keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE)200 self.step = 6201 202 def run(self, msgMapTool = False, msg = None):203 if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag():204 self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n"))205 return True # fine comando206 207 #=========================================================================208 # RICHIESTA SELEZIONE OGGETTI209 if self.step == 0: # inizio del comando210 if self.SSGetClass.run(msgMapTool, msg) == True:211 # selezione terminata212 self.step = 1213 self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di selezione entità 214 return self.run(msgMapTool, msg)215 216 #=========================================================================217 # RUOTA OGGETTI218 elif self.step == 1:219 self.entitySet.set(self.SSGetClass.entitySet)220 221 if self.entitySet.count() == 0:222 return True # fine comando223 # imposto il map tool224 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT) 225 # si appresta ad attendere un punto226 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify base point: "))227 228 self.step = 2 229 return False230 231 #=========================================================================232 # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1)233 elif self.step == 2: # dopo aver atteso un punto o un numero reale si riavvia il comando234 if msgMapTool == True: # il punto arriva da una selezione grafica235 # la condizione seguente si verifica se durante la selezione di un punto236 # é stato attivato un altro plugin che ha disattivato Qad237 # quindi stato riattivato il comando che torna qui senza che il maptool238 # abbia selezionato un punto 239 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto240 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse241 return True # fine comando242 else:243 self.setMapTool(self.getPointMapTool()) # riattivo il maptool244 return False245 value = self.getPointMapTool().point246 else: # il punto arriva come parametro della funzione247 value = msg248 self.basePt = QgsPoint(value)249 self.getPointMapTool().basePt = self.basePt250 self.getPointMapTool().entitySet.set(self.entitySet)251 # si appresta ad attendere la scala 252 self.waitForScale()253 254 return False 255 256 #=========================================================================257 # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER SCALA (da step = 2)258 elif self.step == 3: # dopo aver atteso un punto o un numero reale si riavvia il comando259 if msgMapTool == True: # il punto arriva da una selezione grafica260 # la condizione seguente si verifica se durante la selezione di un punto261 # é stato attivato un altro plugin che ha disattivato Qad262 # quindi stato riattivato il comando che torna qui senza che il maptool263 # abbia selezionato un punto 264 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto265 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse266 return True # fine comando267 else:268 self.setMapTool(self.getPointMapTool()) # riattivo il maptool269 return False270 value = self.getPointMapTool().point271 else: # il punto arriva come parametro della funzione272 value = msg273 if type(value) == unicode:274 if value == QadMsg.translate("Command_SCALE", "Copy") or value == "Copy":275 self.copyFeatures = True276 self.showMsg(QadMsg.translate("Command_SCALE", "\nScale of a copy of the selected objects."))277 # si appresta ad attendere la scala 278 self.waitForScale() 279 elif value == QadMsg.translate("Command_SCALE", "Reference") or value == "Reference":280 # si appresta ad attendere la lunghezza di riferimento 281 self.waitForReferenceLen()282 elif type(value) == QgsPoint or type(value) == float: # se é stato inserita la scala283 if type(value) == QgsPoint: # se é stato inserita la scala con un punto284 if value == self.basePt:285 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))286 # si appresta ad attendere un punto287 self.waitForScale()288 return False289 290 scale = qad_utils.getDistance(self.basePt, value)291 else:292 scale = value293 self.plugIn.setLastScale(scale)294 self.scaleGeoms(scale)295 return True # fine comando296 297 return False298 299 #=========================================================================300 # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 3)301 elif self.step == 4: # dopo aver atteso un punto o un numero reale si riavvia il comando302 if msgMapTool == True: # il punto arriva da una selezione grafica303 # la condizione seguente si verifica se durante la selezione di un punto304 # é stato attivato un altro plugin che ha disattivato Qad305 # quindi stato riattivato il comando che torna qui senza che il maptool306 # abbia selezionato un punto 307 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto308 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse309 return True # fine comando310 else:311 self.setMapTool(self.getPointMapTool()) # riattivo il maptool312 return False313 value = self.getPointMapTool().point314 else: # il punto arriva come parametro della funzione315 value = msg316 if type(value) == float: # se é stato inserita la lunghezza317 self.ReferenceLen = value318 self.getPointMapTool().ReferenceLen = self.ReferenceLen 319 # si appresta ad attendere la nuova lunghezza 320 self.waitForNewReferenceLen()321 elif type(value) == QgsPoint: # se é stato inserito la scala con un punto 322 self.Pt1ReferenceLen = QgsPoint(value)323 self.getPointMapTool().Pt1ReferenceLen = self.Pt1ReferenceLen 324 # imposto il map tool325 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN)326 # si appresta ad attendere un punto327 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: "))328 self.step = 5 329 330 return False331 #=========================================================================332 # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 4)333 elif self.step == 5: # dopo aver atteso un punto o un numero reale si riavvia il comando334 if msgMapTool == True: # il punto arriva da una selezione grafica335 # la condizione seguente si verifica se durante la selezione di un punto336 # é stato attivato un altro plugin che ha disattivato Qad337 # quindi stato riattivato il comando che torna qui senza che il maptool338 # abbia selezionato un punto 339 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto340 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse341 return True # fine comando342 else:343 self.setMapTool(self.getPointMapTool()) # riattivo il maptool344 return False345 value = self.getPointMapTool().point346 else: # il punto arriva come parametro della funzione347 value = msg348 if self.Pt1ReferenceLen == value:349 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))350 # si appresta ad attendere un punto351 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: "))352 return False353 354 length = qad_utils.getDistance(self.Pt1ReferenceLen, value)355 self.ReferenceLen = length356 self.getPointMapTool().ReferenceLen = self.ReferenceLen357 # si appresta ad attendere la nuova lunghezza 358 self.waitForNewReferenceLen()359 360 return False361 #=========================================================================362 # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 4 e 5)363 elif self.step == 6: # dopo aver atteso un punto o un numero reale si riavvia il comando364 if msgMapTool == True: # il punto arriva da una selezione grafica365 # la condizione seguente si verifica se durante la selezione di un punto366 # é stato attivato un altro plugin che ha disattivato Qad367 # quindi stato riattivato il comando che torna qui senza che il maptool368 # abbia selezionato un punto 369 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto370 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse371 return True # fine comando372 else:373 self.setMapTool(self.getPointMapTool()) # riattivo il maptool374 return False375 value = self.getPointMapTool().point376 else: # il punto arriva come parametro della funzione377 value = msg378 if type(value) == unicode:379 if value == QadMsg.translate("Command_SCALE", "Points") or value == "Points":380 # imposto il map tool381 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_NEW_LEN_PT)382 # si appresta ad attendere un punto383 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify first point: "))384 self.step = 7385 elif type(value) == QgsPoint or type(value) == float: # se é stato inserita la lunghezza386 if type(value) == QgsPoint: # se é stato inserito la lunghezza con un punto387 if value == self.basePt:388 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))389 # si appresta ad attendere un punto390 self.waitForNewReferenceLen()391 return False392 393 length = qad_utils.getDistance(self.basePt, value)394 else:395 length = value396 397 scale = length / self.ReferenceLen398 self.plugIn.setLastScale(scale)399 self.scaleGeoms(scale)400 return True # fine comando401 return False402 403 #=========================================================================404 # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER NUOVA LUNGHEZZA (da step = 6)405 elif self.step == 7: # dopo aver atteso un punto o un numero reale si riavvia il comando406 if msgMapTool == True: # il punto arriva da una selezione grafica407 # la condizione seguente si verifica se durante la selezione di un punto408 # é stato attivato un altro plugin che ha disattivato Qad409 # quindi stato riattivato il comando che torna qui senza che il maptool410 # abbia selezionato un punto 411 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto412 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse413 return True # fine comando414 else:415 self.setMapTool(self.getPointMapTool()) # riattivo il maptool416 return False417 value = self.getPointMapTool().point418 else: # il punto arriva come parametro della funzione419 value = msg420 421 self.Pt1NewLen = value422 # imposto il map tool423 self.getPointMapTool().Pt1NewLen = self.Pt1NewLen424 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT)425 # si appresta ad attendere un punto426 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: "))427 self.step = 8428 429 return False430 #=========================================================================431 # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 7)432 elif self.step == 8: # dopo aver atteso un punto o un numero reale si riavvia il comando433 if msgMapTool == True: # il punto arriva da una selezione grafica434 # la condizione seguente si verifica se durante la selezione di un punto435 # é stato attivato un altro plugin che ha disattivato Qad436 # quindi stato riattivato il comando che torna qui senza che il maptool437 # abbia selezionato un punto 438 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto439 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse440 return True # fine comando441 else:442 self.setMapTool(self.getPointMapTool()) # riattivo il maptool443 return False444 value = self.getPointMapTool().point445 else: # il punto arriva come parametro della funzione446 value = msg447 if value == self.Pt1NewLen:448 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))449 # si appresta ad attendere un punto450 self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: "))451 return False452 453 length = qad_utils.getDistance(self.Pt1NewLen, value)454 455 scale = length / self.ReferenceLen456 self.plugIn.setLastScale(scale)457 self.scaleGeoms(scale)458 return True # fine comando459# Classe che gestisce il comando SCALA per i grip460class QadGRIPSCALECommandClass(QadCommandClass):461 def instantiateNewCmd(self):462 """ istanzia un nuovo comando dello stesso tipo """463 return QadGRIPSCALECommandClass(self.plugIn)464 def __init__(self, plugIn):465 QadCommandClass.__init__(self, plugIn)466 self.entitySet = QadEntitySet()467 self.basePt = QgsPoint()468 self.skipToNextGripCommand = False469 self.copyEntities = False470 self.nOperationsToUndo = 0471 self.Pt1ReferenceLen = None472 self.ReferenceLen = 1473 self.Pt1NewLen = None474 self.__referenceLenMode = False475 def __del__(self):476 QadCommandClass.__del__(self)477 478 def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE):479 if (self.plugIn is not None):480 if self.PointMapTool is None:481 self.PointMapTool = Qad_scale_maptool(self.plugIn)482 return self.PointMapTool483 else:484 return None485 #============================================================================486 # setSelectedEntityGripPoints487 #============================================================================488 def setSelectedEntityGripPoints(self, entitySetGripPoints):489 # lista delle entityGripPoint con dei grip point selezionati490 self.entitySet.clear()491 for entityGripPoints in entitySetGripPoints.entityGripPoints:492 self.entitySet.addEntity(entityGripPoints.entity)493 self.getPointMapTool().entitySet.set(self.entitySet)494 #============================================================================495 # scale496 #============================================================================497 def scale(self, entity, basePt, scale, sizeFldName):498 # entity = entità da scalare499 # basePt = punto base500 # scale = fattore di scala501 # sizeFldName = campo della tabella che memorizza la scala502 # verifico se l'entità appartiene ad uno stile di quotatura503 if entity.whatIs() == "ENTITY":504 f = entity.getFeature()505 # ruoto l'entità506 f.setGeometry(qad_utils.scaleQgsGeometry(entity.getGeometry(), basePt, scale))507 if len(sizeFldName) > 0:508 sizeValue = f.attribute(sizeFldName)509 # a volte vale None e a volte null (vai a capire...)510 if sizeValue is None or isinstance(sizeValue, QPyNullVariant):511 sizeValue = 1512 sizeValue = sizeValue * scale513 f.setAttribute(sizeFldName, sizeValue) 514 515 if self.copyEntities == False:516 # plugIn, layer, feature, refresh, check_validity517 if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:518 return False519 else:520 # plugIn, layer, features, coordTransform, refresh, check_validity521 if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:522 return False523 524 elif entity.whatIs() == "DIMENTITY":525 # stiro la quota526 if self.copyEntities == False:527 if entity.deleteToLayers(self.plugIn) == False:528 return False 529 newDimEntity = QadDimEntity(entity) # la copio530 newDimEntity.scale(basePt, scale)531 if newDimEntity.addToLayers(self.plugIn) == False:532 return False533 def scaleFeatures(self, scale):534 entity = QadEntity()535 self.plugIn.beginEditCommand("Feature scaled", self.entitySet.getLayerList())536 537 dimElaboratedList = [] # lista delle quotature già elaborate538 for layerEntitySet in self.entitySet.layerEntitySetList: 539 layer = layerEntitySet.layer 540 541 transformedBasePt = self.mapToLayerCoordinates(layer, self.basePt)542 543 sizeFldName = ""544 if qad_layer.isTextLayer(layer):545 # se l'altezza testo dipende da un solo campo 546 sizeFldNames = qad_label.get_labelSizeFieldNames(layer)547 if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0:548 sizeFldName = sizeFldNames[0]549 elif qad_layer.isSymbolLayer(layer):550 # se la scala dipende da un campo 551 sizeFldName = qad_layer.get_symbolScaleFieldName(layer)552 for featureId in layerEntitySet.featureIds:553 entity.set(layer, featureId)554 # verifico se l'entità appartiene ad uno stile di quotatura555 dimEntity = QadDimStyles.getDimEntity(entity) 556 if dimEntity is None:557 if self.scale(entity, transformedBasePt, scale, sizeFldName) == False:558 self.plugIn.destroyEditCommand()559 return560 else:561 found = False562 for dimElaborated in dimElaboratedList:563 if dimElaborated == dimEntity:564 found = True565 566 if found == False: # quota non ancora elaborata567 dimElaboratedList.append(dimEntity)568 if self.scale(dimEntity, transformedBasePt, scale, sizeFldName) == False:569 self.plugIn.destroyEditCommand()570 return571 self.plugIn.endEditCommand()572 self.nOperationsToUndo = self.nOperationsToUndo + 1573 def waitForScale(self):574 self.getPointMapTool().basePt = self.basePt575 keyWords = QadMsg.translate("Command_GRIPSCALE", "Base point") + "/" + \576 QadMsg.translate("Command_GRIPSCALE", "Copy") + "/" + \577 QadMsg.translate("Command_GRIPSCALE", "Undo") + "/" + \578 QadMsg.translate("Command_GRIPSCALE", "Reference") + "/" + \579 QadMsg.translate("Command_GRIPSCALE", "eXit")580 581 default = self.plugIn.lastScale582 if self.__referenceLenMode:583 # imposto il map tool584 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT)585 if self.plugIn.lastNewReferenceLen > 0:586 default = self.plugIn.lastNewReferenceLen587 prompt = QadMsg.translate("Command_GRIPSCALE", "Specify new length or [{0}]: ").format(keyWords)588 else:589 # imposto il map tool590 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT)591 prompt = QadMsg.translate("Command_GRIPSCALE", "Specify scale factor or [{0}]: ").format(keyWords) 592 englishKeyWords = "Base point" + "/" + "Copy" + "/" + "Undo" + "/" + "Reference" + "/" + "eXit"593 keyWords += "_" + englishKeyWords594 # si appresta ad attendere un punto o enter o una parola chiave 595 # msg, inputType, default, keyWords, valori positivi596 self.waitFor(prompt, \597 QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \598 None, \599 keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) 600 self.step = 1601 #============================================================================602 # waitForBasePt603 #============================================================================604 def waitForBasePt(self):605 self.step = 2 606 # imposto il map tool607 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT)608 # si appresta ad attendere un punto609 self.waitForPoint(QadMsg.translate("Command_GRIPSCALE", "Specify base point: "))610 def waitForReferenceLen(self):611 self.__referenceLenMode = True612 # imposto il map tool613 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_LEN)614 615 msg = QadMsg.translate("Command_GRIPSCALE", "Specify reference length <{0}>: ")616 # si appresta ad attendere un punto o enter 617 # msg, inputType, default, keyWords, valori positivi618 self.waitFor(msg.format(str(self.plugIn.lastReferenceLen)), \619 QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \620 self.plugIn.lastReferenceLen, \621 "", QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) 622 self.step = 3623 624 def run(self, msgMapTool = False, msg = None):625 if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag():626 self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n"))627 return True # fine comando628 629 #=========================================================================630 # RICHIESTA SELEZIONE OGGETTI631 if self.step == 0: # inizio del comando632 if self.entitySet.isEmpty(): # non ci sono oggetti da ruotare633 return True634 self.showMsg(QadMsg.translate("Command_GRIPSCALE", "\n** SCALE **\n"))635 # si appresta ad attendere la scala636 self.waitForScale()637 return False638 639 #=========================================================================640 # RISPOSTA ALLA RICHIESTA DEL FATTORE DI SCALA641 elif self.step == 1:642 ctrlKey = False 643 if msgMapTool == True: # il punto arriva da una selezione grafica644 # la condizione seguente si verifica se durante la selezione di un punto645 # é stato attivato un altro plugin che ha disattivato Qad646 # quindi stato riattivato il comando che torna qui senza che il maptool647 # abbia selezionato un punto 648 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto649 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse650 value = None651 else:652 self.setMapTool(self.getPointMapTool()) # riattivo il maptool653 return False654 else:655 value = self.getPointMapTool().point656 ctrlKey = self.getPointMapTool().ctrlKey657 else: # il punto arriva come parametro della funzione658 value = msg659 if type(value) == unicode:660 if value == QadMsg.translate("Command_GRIPSCALE", "Base point") or value == "Base point":661 # si appresta ad attendere il punto base662 self.waitForBasePt()663 elif value == QadMsg.translate("Command_GRIPSCALE", "Copy") or value == "Copy":664 # Copia entità lasciando inalterate le originali665 self.copyEntities = True 666 # si appresta ad attendere la scala667 self.waitForScale()668 elif value == QadMsg.translate("Command_GRIPSCALE", "Undo") or value == "Undo":669 if self.nOperationsToUndo > 0: 670 self.nOperationsToUndo = self.nOperationsToUndo - 1671 self.plugIn.undoEditCommand()672 else:673 self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled.")) 674 # si appresta ad attendere la scala675 self.waitForScale()676 elif value == QadMsg.translate("Command_GRIPSCALE", "Reference") or value == "Reference":677 # si appresta ad attendere la lunghezza di riferimento 678 self.waitForReferenceLen()679 elif value == QadMsg.translate("Command_GRIPSCALE", "eXit") or value == "eXit":680 return True # fine comando681 elif type(value) == QgsPoint or type(value) == float: # se é stato inserita la scala682 if type(value) == QgsPoint: # se é stato inserita la scala con un punto683 if value == self.basePt:684 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))685 # si appresta ad attendere un punto686 self.waitForScale()687 return False688 689 scale = qad_utils.getDistance(self.basePt, value)690 else:691 scale = value692 693 if self.__referenceLenMode == True: # scale rappresenta la nuova distanza di riferimento 694 scale = scale / self.ReferenceLen695 696 self.plugIn.setLastScale(scale)697 698 if ctrlKey:699 self.copyEntities = True700 701 self.scaleFeatures(scale)702 if self.copyEntities == False:703 return True704 # si appresta ad attendere la scala705 self.waitForScale()706 707 else:708 if self.copyEntities == False:709 self.skipToNextGripCommand = True710 return True # fine comando711 712 return False 713 #=========================================================================714 # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1)715 elif self.step == 2: # dopo aver atteso un punto o un numero reale si riavvia il comando716 if msgMapTool == True: # il punto arriva da una selezione grafica717 # la condizione seguente si verifica se durante la selezione di un punto718 # é stato attivato un altro plugin che ha disattivato Qad719 # quindi stato riattivato il comando che torna qui senza che il maptool720 # abbia selezionato un punto 721 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto722 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse723 return True # fine comando724 else:725 self.setMapTool(self.getPointMapTool()) # riattivo il maptool726 return False727 value = self.getPointMapTool().point728 else: # il punto arriva come parametro della funzione729 value = msg730 self.basePt = QgsPoint(value)731 self.getPointMapTool().basePt = self.basePt732 # si appresta ad attendere la scala 733 self.waitForScale()734 735 return False 736 737 738 #=========================================================================739 # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 1)740 elif self.step == 3: # dopo aver atteso un punto o un numero reale si riavvia il comando741 if msgMapTool == True: # il punto arriva da una selezione grafica742 # la condizione seguente si verifica se durante la selezione di un punto743 # é stato attivato un altro plugin che ha disattivato Qad744 # quindi stato riattivato il comando che torna qui senza che il maptool745 # abbia selezionato un punto 746 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto747 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse748 return True # fine comando749 else:750 self.setMapTool(self.getPointMapTool()) # riattivo il maptool751 return False752 value = self.getPointMapTool().point753 else: # il punto arriva come parametro della funzione754 value = msg755 if type(value) == float: # se é stato inserita la lunghezza756 self.ReferenceLen = value757 self.getPointMapTool().ReferenceLen = self.ReferenceLen 758 # si appresta ad attendere la nuova lunghezza 759 self.waitForScale()760 elif type(value) == QgsPoint: # se é stato inserito la scala con un punto 761 self.Pt1ReferenceLen = QgsPoint(value)762 self.getPointMapTool().Pt1ReferenceLen = self.Pt1ReferenceLen 763 # imposto il map tool764 self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN)765 # si appresta ad attendere un punto766 self.waitForPoint(QadMsg.translate("Command_GRIPSCALE", "Specify second point: "))767 self.step = 4768 769 return False770 #=========================================================================771 # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 4)772 elif self.step == 4: # dopo aver atteso un punto o un numero reale si riavvia il comando773 if msgMapTool == True: # il punto arriva da una selezione grafica774 # la condizione seguente si verifica se durante la selezione di un punto775 # é stato attivato un altro plugin che ha disattivato Qad776 # quindi stato riattivato il comando che torna qui senza che il maptool777 # abbia selezionato un punto 778 if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto779 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse780 return True # fine comando781 else:782 self.setMapTool(self.getPointMapTool()) # riattivo il maptool783 return False784 value = self.getPointMapTool().point785 else: # il punto arriva come parametro della funzione786 value = msg787 if self.Pt1ReferenceLen == value:788 self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))789 # si appresta ad attendere un punto790 self.waitForPoint(QadMsg.translate("Command_GRIPSCALE", "Specify second point: "))791 return False792 793 length = qad_utils.getDistance(self.Pt1ReferenceLen, value)794 self.ReferenceLen = length795 self.getPointMapTool().ReferenceLen = self.ReferenceLen796 # si appresta ad attendere la nuova lunghezza797 self.waitForScale()798 ...

Full Screen

Full Screen

qad_setvar_cmd.py

Source:qad_setvar_cmd.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3/***************************************************************************4 QAD Quantum Aided Design plugin5 comando SETVAR per settare le variabili di ambiente di QAD6 7 -------------------8 begin : 2013-05-229 copyright : iiiii10 email : hhhhh11 developers : bbbbb aaaaa ggggg12 ***************************************************************************/13/***************************************************************************14 * *15 * This program is free software; you can redistribute it and/or modify *16 * it under the terms of the GNU General Public License as published by *17 * the Free Software Foundation; either version 2 of the License, or *18 * (at your option) any later version. *19 * *20 ***************************************************************************/21"""22# Import the PyQt and QGIS libraries23from PyQt4.QtCore import *24from PyQt4.QtGui import *25from qgis.core import *26from qad_generic_cmd import QadCommandClass27from qad_msg import QadMsg28from qad_variables import *29# Classe che gestisce il comando SETVAR30class QadSETVARCommandClass(QadCommandClass):31 def instantiateNewCmd(self):32 """ istanzia un nuovo comando dello stesso tipo """33 return QadSETVARCommandClass(self.plugIn)34 35 def getName(self):36 return QadMsg.translate("Command_list", "SETVAR")37 def getEnglishName(self):38 return "SETVAR"39 def connectQAction(self, action):40 QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runSETVARCommand)41 def getIcon(self):42 return QIcon(":/plugins/qad/icons/variable.png")43 def getNote(self):44 # impostare le note esplicative del comando 45 return QadMsg.translate("Command_SETVAR", "Sets the QAD environment variables.")46 47 def __init__(self, plugIn):48 QadCommandClass.__init__(self, plugIn)49 self.varName = ""50 51 def run(self, msgMapTool = False, msg = None):52 if self.step == 0: # inizio del comando53 # si appresta ad attendere una stringa54 self.waitForString(QadMsg.translate("Command_SETVAR", "Enter the variable name or [?]: "), \55 QadMsg.translate("Command_SETVAR", "?"))56 self.step = 157 return False58 elif self.step == 1: # dopo aver atteso il nome della variabile si riavvia il comando59 if msgMapTool == True: # niente può arrivare da grafica60 return False61 # il nome della variabile arriva come parametro della funzione62 self.varName = msg63 if self.varName == QadMsg.translate("Command_SETVAR", "?"): # lista delle variabili 64 # si appresta ad attendere una stringa 65 self.waitForString(QadMsg.translate("Command_SETVAR", "Enter variable(s) to list <*>: "), \66 QadMsg.translate("Command_SETVAR", "*"))67 self.step = 368 return False69 else:70 variable = QadVariables.getVariable(self.varName)71 if variable is None: 72 msg = QadMsg.translate("Command_SETVAR", "\nUnknown variable. Enter {0} ? to list variable names.")73 self.showErr(msg.format(QadMsg.translate("Command_list", "SETVAR")))74 return False75 else:76 varValue = variable.value77 varDescr = variable.descr78 varType = str(type(varValue))79 if len(varDescr) > 0:80 self.showMsg("\n" + varDescr)81 82 msg = QadMsg.translate("Command_SETVAR", "Enter new value for variable {0} <{1}>: ")83 if varType == "<type 'str'>":84 # si appresta ad attendere una stringa85 self.waitForString(msg.format(self.varName, varValue), varValue)86 elif varType == "<type 'int'>":87 # si appresta ad attendere un numero intero88 self.waitForInt(msg.format(self.varName, varValue), varValue)89 elif varType == "<type 'float'>":90 # si appresta ad attendere un numero reale91 self.waitForFloat(msg.format(self.varName, varValue), varValue)92 elif varType == "<type 'bool'>":93 # si appresta ad attendere un numero reale94 self.waitForBool(msg.format(self.varName, varValue), varValue)95 self.step = 296 return False97 elif self.step == 2: # dopo aver atteso il valore della variabile si riavvia il comando98 if msgMapTool == True: # niente può arrivare da grafica99 return False100 # il valore della variabile arriva come parametro della funzione101 QadVariables.set(self.varName, msg)102 QadVariables.save()103 self.plugIn.UpdatedVariablesEvent()104 105 return True106 elif self.step == 3: # dopo aver atteso il nome della variabile si riavvia il comando107 if msgMapTool == True: # niente può arrivare da grafica108 return False109 if msg == "*":110 varNames = QadVariables.getVarNames()111 else:112 # il nome della variabile arriva come parametro della funzione113 varNames = msg.strip().split(",")114 115 varNames.sort()116 for self.varName in varNames:117 self.varName = self.varName.strip()118 varValue = QadVariables.get(self.varName)119 if varValue is not None:120 msg = "\n" + self.varName + "=" + str(varValue)121 self.showMsg(msg)122 123 self.plugIn.UpdatedVariablesEvent()124 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful