Browse Source

Define some variables instead of hardcoding numbers

tags/v1.9.9
falkTX FilipeCSnuk 6 years ago
parent
commit
ed61465d5c
1 changed files with 13 additions and 9 deletions
  1. +13
    -9
      source/carla_host.py

+ 13
- 9
source/carla_host.py View File

@@ -97,6 +97,11 @@ class HostWindow(QMainWindow):
SIGTERM = pyqtSignal() SIGTERM = pyqtSignal()
SIGUSR1 = pyqtSignal() SIGUSR1 = pyqtSignal()


# CustomActions
CUSTOM_ACTION_NONE = 0
CUSTOM_ACTION_APP_CLOSE = 1
CUSTOM_ACTION_PROJECT_LOAD = 2

# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------


def __init__(self, host, withCanvas, parent=None): def __init__(self, host, withCanvas, parent=None):
@@ -137,8 +142,7 @@ class HostWindow(QMainWindow):
self.fSampleRate = 0.0 self.fSampleRate = 0.0


# run a custom action after engine is properly closed # run a custom action after engine is properly closed
# 1 for close carla, 2 for load project
self.fCustomStopAction = 0
self.fCustomStopAction = self.CUSTOM_ACTION_NONE


# first attempt of auto-start engine doesn't show an error # first attempt of auto-start engine doesn't show an error
self.fFirstEngineInit = True self.fFirstEngineInit = True
@@ -802,14 +806,14 @@ class HostWindow(QMainWindow):
self.ui.text_logs.appendPlainText("Failed to stop engine, error was:") self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
self.ui.text_logs.appendPlainText(self.host.get_last_error()) self.ui.text_logs.appendPlainText(self.host.get_last_error())


if self.fCustomStopAction == 1:
if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
self.close() self.close()
elif self.fCustomStopAction == 2:
elif self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
self.slot_engineStart() self.slot_engineStart()
self.loadProjectNow() self.loadProjectNow()
self.host.nsm_ready(2) # open self.host.nsm_ready(2) # open


self.fCustomStopAction = 0
self.fCustomStopAction = self.CUSTOM_ACTION_NONE


# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------
# Engine (host callbacks) # Engine (host callbacks)
@@ -2041,7 +2045,7 @@ class HostWindow(QMainWindow):
self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath() self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
self.setProperWindowTitle() self.setProperWindowTitle()


self.fCustomStopAction = 2
self.fCustomStopAction = self.CUSTOM_ACTION_PROJECT_LOAD
self.slot_engineStop(True) self.slot_engineStop(True)
return return


@@ -2094,7 +2098,7 @@ class HostWindow(QMainWindow):
@pyqtSlot() @pyqtSlot()
def slot_handleSIGTERM(self): def slot_handleSIGTERM(self):
print("Got SIGTERM -> Closing now") print("Got SIGTERM -> Closing now")
self.fCustomStopAction = 1
self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
self.slot_engineStop(True) self.slot_engineStop(True)


# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------
@@ -2298,7 +2302,7 @@ class HostWindow(QMainWindow):
# close event # close event


def closeEvent(self, event): def closeEvent(self, event):
if self.fCustomStopAction != 1 and self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
if self.fCustomStopAction != self.CUSTOM_ACTION_APP_CLOSE and self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
ask = QMessageBox.question(self, self.tr("Quit"), ask = QMessageBox.question(self, self.tr("Quit"),
self.tr("Are you sure you want to quit Carla?"), self.tr("Are you sure you want to quit Carla?"),
QMessageBox.Yes|QMessageBox.No) QMessageBox.Yes|QMessageBox.No)
@@ -2312,7 +2316,7 @@ class HostWindow(QMainWindow):


if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin): if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
if not self.slot_engineStop(True): if not self.slot_engineStop(True):
self.fCustomStopAction = 1
self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
event.ignore() event.ignore()
return return




Loading…
Cancel
Save