Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/neteditTestFunctions/frames/select.py
169678 views
1
# -*- coding: utf-8 -*-
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file select.py
15
# @author Pablo Alvarez Lopez
16
# @date 28-05-25
17
18
# imports
19
import os
20
import pyautogui
21
import time
22
from ..enums.attributesEnum import attrs
23
from ..constants import TEXTTEST_SANDBOX, DELAY_SELECT, DELAY_KEY
24
from ..general.functions import focusOnFrame
25
from ..input.mouse import dragDrop
26
from ..input.keyboard import keyPress, keyRelease, typeKey, typeTwoKeys, updateText
27
28
29
def selection(selectionType):
30
"""
31
@brief do a selection
32
"""
33
# focus current frame
34
focusOnFrame()
35
if (selectionType == "default"):
36
for _ in range(attrs.frames.selection.basic.default):
37
typeKey('tab')
38
# type space to select it
39
typeKey('space')
40
elif (selectionType == "save"):
41
# jump to save
42
for _ in range(attrs.frames.selection.basic.save):
43
typeKey('tab')
44
typeKey('space')
45
# jump to filename TextField
46
typeTwoKeys('alt', 'f')
47
filename = os.path.join(TEXTTEST_SANDBOX, "selection.txt")
48
updateText(filename)
49
# type enter to select it
50
typeKey('enter')
51
elif (selectionType == "load"):
52
# jump to save
53
for _ in range(attrs.frames.selection.basic.load):
54
typeKey('tab')
55
typeKey('space')
56
# jump to filename TextField
57
typeTwoKeys('alt', 'f')
58
filename = os.path.join(TEXTTEST_SANDBOX, "selection.txt")
59
updateText(filename)
60
# type enter to select it
61
typeKey('enter')
62
elif (selectionType == "add"):
63
# jump to mode "add"
64
for _ in range(attrs.frames.selection.basic.add):
65
typeKey('tab')
66
# type space to select it
67
typeKey('space')
68
elif (selectionType == "remove"):
69
# jump to mode "remove"
70
for _ in range(attrs.frames.selection.basic.remove):
71
typeKey('tab')
72
# type space to select it
73
typeKey('space')
74
elif (selectionType == "keep"):
75
# jump to mode "keep"
76
for _ in range(attrs.frames.selection.basic.keep):
77
typeKey('tab')
78
# type space to select it
79
typeKey('space')
80
elif (selectionType == "replace"):
81
# jump to mode "replace"
82
for _ in range(attrs.frames.selection.basic.replace):
83
typeKey('tab')
84
# type space to select it
85
typeKey('space')
86
elif (selectionType == "clear"):
87
for _ in range(attrs.frames.selection.basic.clear):
88
typeKey('tab')
89
# type space to select it
90
typeKey('space')
91
elif (selectionType == "invert"):
92
for _ in range(attrs.frames.selection.basic.invert):
93
typeKey('tab')
94
# type space to select it
95
typeKey('space')
96
elif (selectionType == "invertData"):
97
for _ in range(attrs.frames.selection.basic.invertData):
98
typeKey('tab')
99
# type space to select it
100
typeKey('space')
101
elif (selectionType == "delete"):
102
for _ in range(attrs.frames.selection.basic.delete):
103
typeKey('tab')
104
# type space to select it
105
typeKey('space')
106
# wait for gl debug
107
time.sleep(DELAY_SELECT)
108
109
110
def lockSelection(glType):
111
"""
112
@brief lock selection by glType
113
"""
114
# focus current frame
115
focusOnFrame()
116
# move mouse
117
pyautogui.moveTo(550, 200)
118
# open Lock menu
119
typeTwoKeys('alt', 'o')
120
# go to selected glType
121
for _ in range(glType):
122
typeKey("down")
123
# type enter to save change
124
typeKey('space')
125
126
127
def selectNetworkItems(element, attribute, value):
128
"""
129
@brief select network items
130
"""
131
# focus current frame
132
focusOnFrame()
133
# jump to elementClass
134
for _ in range(attrs.frames.selection.networkItem.type):
135
typeKey('tab')
136
# paste the new elementClass
137
updateText("Network elements")
138
# jump to element
139
for _ in range(attrs.frames.selection.networkItem.subType):
140
typeKey('tab')
141
# paste the new elementType
142
updateText(element)
143
# jump to attribute
144
for _ in range(attrs.frames.selection.networkItem.attribute):
145
typeKey('tab')
146
# paste the new attribute
147
updateText(attribute)
148
# jump to value
149
for _ in range(attrs.frames.selection.networkItem.value):
150
typeKey('tab')
151
# paste the new value
152
updateText(value)
153
# type enter to select it
154
typeKey('enter')
155
# wait for gl debug
156
time.sleep(DELAY_SELECT)
157
158
159
def selectStoppingPlaceItems(elementClass, stoppingPlace, elementType, attribute, value):
160
"""
161
@brief select items
162
"""
163
# focus current frame
164
focusOnFrame()
165
# jump to elementClass
166
for _ in range(8):
167
typeKey('tab')
168
# paste the new elementClass
169
updateText(elementClass)
170
# jump to element
171
for _ in range(2):
172
typeKey('tab')
173
# paste the new elementType
174
updateText(stoppingPlace)
175
# jump to stoppingPlace
176
for _ in range(2):
177
typeKey('tab')
178
# paste the new elementType
179
updateText(elementType)
180
# jump to attribute
181
for _ in range(3):
182
typeKey('tab')
183
# paste the new attribute
184
updateText(attribute)
185
# jump to value
186
for _ in range(2):
187
typeKey('tab')
188
# paste the new value
189
updateText(value)
190
# type enter to select it
191
typeKey('enter')
192
# wait for gl debug
193
time.sleep(DELAY_SELECT)
194
195
196
def selectionRectangle(referencePosition, positionA, positionB):
197
"""
198
@brief select using an rectangle
199
"""
200
# Leave Shift key pressedX
201
keyPress('shift')
202
# move element
203
dragDrop(referencePosition, positionA.x, positionA.y, positionB.x, positionB.y)
204
# wait after key up
205
time.sleep(DELAY_KEY)
206
# Release Shift key
207
keyRelease('shift')
208
# wait for gl debug
209
time.sleep(DELAY_SELECT)
210
211