Path: blob/main/tools/neteditTestFunctions/frames/select.py
169678 views
# -*- coding: utf-8 -*-1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file select.py14# @author Pablo Alvarez Lopez15# @date 28-05-251617# imports18import os19import pyautogui20import time21from ..enums.attributesEnum import attrs22from ..constants import TEXTTEST_SANDBOX, DELAY_SELECT, DELAY_KEY23from ..general.functions import focusOnFrame24from ..input.mouse import dragDrop25from ..input.keyboard import keyPress, keyRelease, typeKey, typeTwoKeys, updateText262728def selection(selectionType):29"""30@brief do a selection31"""32# focus current frame33focusOnFrame()34if (selectionType == "default"):35for _ in range(attrs.frames.selection.basic.default):36typeKey('tab')37# type space to select it38typeKey('space')39elif (selectionType == "save"):40# jump to save41for _ in range(attrs.frames.selection.basic.save):42typeKey('tab')43typeKey('space')44# jump to filename TextField45typeTwoKeys('alt', 'f')46filename = os.path.join(TEXTTEST_SANDBOX, "selection.txt")47updateText(filename)48# type enter to select it49typeKey('enter')50elif (selectionType == "load"):51# jump to save52for _ in range(attrs.frames.selection.basic.load):53typeKey('tab')54typeKey('space')55# jump to filename TextField56typeTwoKeys('alt', 'f')57filename = os.path.join(TEXTTEST_SANDBOX, "selection.txt")58updateText(filename)59# type enter to select it60typeKey('enter')61elif (selectionType == "add"):62# jump to mode "add"63for _ in range(attrs.frames.selection.basic.add):64typeKey('tab')65# type space to select it66typeKey('space')67elif (selectionType == "remove"):68# jump to mode "remove"69for _ in range(attrs.frames.selection.basic.remove):70typeKey('tab')71# type space to select it72typeKey('space')73elif (selectionType == "keep"):74# jump to mode "keep"75for _ in range(attrs.frames.selection.basic.keep):76typeKey('tab')77# type space to select it78typeKey('space')79elif (selectionType == "replace"):80# jump to mode "replace"81for _ in range(attrs.frames.selection.basic.replace):82typeKey('tab')83# type space to select it84typeKey('space')85elif (selectionType == "clear"):86for _ in range(attrs.frames.selection.basic.clear):87typeKey('tab')88# type space to select it89typeKey('space')90elif (selectionType == "invert"):91for _ in range(attrs.frames.selection.basic.invert):92typeKey('tab')93# type space to select it94typeKey('space')95elif (selectionType == "invertData"):96for _ in range(attrs.frames.selection.basic.invertData):97typeKey('tab')98# type space to select it99typeKey('space')100elif (selectionType == "delete"):101for _ in range(attrs.frames.selection.basic.delete):102typeKey('tab')103# type space to select it104typeKey('space')105# wait for gl debug106time.sleep(DELAY_SELECT)107108109def lockSelection(glType):110"""111@brief lock selection by glType112"""113# focus current frame114focusOnFrame()115# move mouse116pyautogui.moveTo(550, 200)117# open Lock menu118typeTwoKeys('alt', 'o')119# go to selected glType120for _ in range(glType):121typeKey("down")122# type enter to save change123typeKey('space')124125126def selectNetworkItems(element, attribute, value):127"""128@brief select network items129"""130# focus current frame131focusOnFrame()132# jump to elementClass133for _ in range(attrs.frames.selection.networkItem.type):134typeKey('tab')135# paste the new elementClass136updateText("Network elements")137# jump to element138for _ in range(attrs.frames.selection.networkItem.subType):139typeKey('tab')140# paste the new elementType141updateText(element)142# jump to attribute143for _ in range(attrs.frames.selection.networkItem.attribute):144typeKey('tab')145# paste the new attribute146updateText(attribute)147# jump to value148for _ in range(attrs.frames.selection.networkItem.value):149typeKey('tab')150# paste the new value151updateText(value)152# type enter to select it153typeKey('enter')154# wait for gl debug155time.sleep(DELAY_SELECT)156157158def selectStoppingPlaceItems(elementClass, stoppingPlace, elementType, attribute, value):159"""160@brief select items161"""162# focus current frame163focusOnFrame()164# jump to elementClass165for _ in range(8):166typeKey('tab')167# paste the new elementClass168updateText(elementClass)169# jump to element170for _ in range(2):171typeKey('tab')172# paste the new elementType173updateText(stoppingPlace)174# jump to stoppingPlace175for _ in range(2):176typeKey('tab')177# paste the new elementType178updateText(elementType)179# jump to attribute180for _ in range(3):181typeKey('tab')182# paste the new attribute183updateText(attribute)184# jump to value185for _ in range(2):186typeKey('tab')187# paste the new value188updateText(value)189# type enter to select it190typeKey('enter')191# wait for gl debug192time.sleep(DELAY_SELECT)193194195def selectionRectangle(referencePosition, positionA, positionB):196"""197@brief select using an rectangle198"""199# Leave Shift key pressedX200keyPress('shift')201# move element202dragDrop(referencePosition, positionA.x, positionA.y, positionB.x, positionB.y)203# wait after key up204time.sleep(DELAY_KEY)205# Release Shift key206keyRelease('shift')207# wait for gl debug208time.sleep(DELAY_SELECT)209210211