Path: blob/main/tools/neteditTestFunctions/files/quit.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 quit.py14# @author Pablo Alvarez Lopez15# @date 28-05-251617# imports18import time19import pyautogui20import subprocess21from ..constants import DELAY_QUIT_NETEDIT22from ..general.functions import typeTwoKeys, waitQuestion23from ..input.keyboard import keyRelease242526def quit(NeteditProcess, openNetDialog=False, saveNet=False,27openAdditionalDialog=False, saveAdditionalElements=False,28openDemandDialog=False, saveDemandElements=False,29openDataDialog=False, saveDataElements=False,30openMeanDataDialog=False, saveMeanDataElements=False):31"""32@brief quit Netedit33"""34# check if Netedit is already closed35if NeteditProcess.poll() is not None:36# print debug information37print("[log] TestFunctions: Netedit already closed")38else:39# first move cursor out of magenta square40pyautogui.moveTo(150, 200)41# quit using hotkey42typeTwoKeys('ctrl', 'q')43# Check if net must be saved44if openNetDialog:45if saveNet:46waitQuestion('s')47else:48waitQuestion('n')49# Check if additionals must be saved50if openAdditionalDialog:51if saveAdditionalElements:52waitQuestion('s')53else:54waitQuestion('n')55# Check if demand elements must be saved56if openDemandDialog:57if saveDemandElements:58waitQuestion('s')59else:60waitQuestion('n')61# Check if data elements must be saved62if openDataDialog:63if saveDataElements:64waitQuestion('s')65else:66waitQuestion('n')67# Check if meanData elements must be saved68if openMeanDataDialog:69if saveMeanDataElements:70waitQuestion('s')71else:72waitQuestion('n')73# wait some seconds for netedit to quit74if hasattr(subprocess, "TimeoutExpired"):75try:76NeteditProcess.wait(DELAY_QUIT_NETEDIT)77print("TestFunctions: Netedit closed successfully")78# all keys up79keyRelease("shift")80keyRelease("control")81keyRelease("alt")82# exit83return84except subprocess.TimeoutExpired:85pass86else:87time.sleep(DELAY_QUIT_NETEDIT)88if NeteditProcess.poll() is not None:89print("TestFunctions: Netedit closed successfully")90# all keys up91keyRelease("shift")92keyRelease("control")93keyRelease("alt")94# exit95return96# error closing NETEDIT then make a screenshot97errorScreenshot = pyautogui.screenshot()98errorScreenshot.saveExistent("errorScreenshot.png")99# kill netedit100NeteditProcess.kill()101print("TestFunctions: Error closing Netedit")102# all keys up103keyRelease("shift")104keyRelease("control")105keyRelease("alt")106# exit107return108109110