Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/neteditTestFunctions/files/quit.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 quit.py
15
# @author Pablo Alvarez Lopez
16
# @date 28-05-25
17
18
# imports
19
import time
20
import pyautogui
21
import subprocess
22
from ..constants import DELAY_QUIT_NETEDIT
23
from ..general.functions import typeTwoKeys, waitQuestion
24
from ..input.keyboard import keyRelease
25
26
27
def quit(NeteditProcess, openNetDialog=False, saveNet=False,
28
openAdditionalDialog=False, saveAdditionalElements=False,
29
openDemandDialog=False, saveDemandElements=False,
30
openDataDialog=False, saveDataElements=False,
31
openMeanDataDialog=False, saveMeanDataElements=False):
32
"""
33
@brief quit Netedit
34
"""
35
# check if Netedit is already closed
36
if NeteditProcess.poll() is not None:
37
# print debug information
38
print("[log] TestFunctions: Netedit already closed")
39
else:
40
# first move cursor out of magenta square
41
pyautogui.moveTo(150, 200)
42
# quit using hotkey
43
typeTwoKeys('ctrl', 'q')
44
# Check if net must be saved
45
if openNetDialog:
46
if saveNet:
47
waitQuestion('s')
48
else:
49
waitQuestion('n')
50
# Check if additionals must be saved
51
if openAdditionalDialog:
52
if saveAdditionalElements:
53
waitQuestion('s')
54
else:
55
waitQuestion('n')
56
# Check if demand elements must be saved
57
if openDemandDialog:
58
if saveDemandElements:
59
waitQuestion('s')
60
else:
61
waitQuestion('n')
62
# Check if data elements must be saved
63
if openDataDialog:
64
if saveDataElements:
65
waitQuestion('s')
66
else:
67
waitQuestion('n')
68
# Check if meanData elements must be saved
69
if openMeanDataDialog:
70
if saveMeanDataElements:
71
waitQuestion('s')
72
else:
73
waitQuestion('n')
74
# wait some seconds for netedit to quit
75
if hasattr(subprocess, "TimeoutExpired"):
76
try:
77
NeteditProcess.wait(DELAY_QUIT_NETEDIT)
78
print("TestFunctions: Netedit closed successfully")
79
# all keys up
80
keyRelease("shift")
81
keyRelease("control")
82
keyRelease("alt")
83
# exit
84
return
85
except subprocess.TimeoutExpired:
86
pass
87
else:
88
time.sleep(DELAY_QUIT_NETEDIT)
89
if NeteditProcess.poll() is not None:
90
print("TestFunctions: Netedit closed successfully")
91
# all keys up
92
keyRelease("shift")
93
keyRelease("control")
94
keyRelease("alt")
95
# exit
96
return
97
# error closing NETEDIT then make a screenshot
98
errorScreenshot = pyautogui.screenshot()
99
errorScreenshot.saveExistent("errorScreenshot.png")
100
# kill netedit
101
NeteditProcess.kill()
102
print("TestFunctions: Error closing Netedit")
103
# all keys up
104
keyRelease("shift")
105
keyRelease("control")
106
keyRelease("alt")
107
# exit
108
return
109
110