From 1f3de4500f2c178ee8527793018a9e0a39342ab1 Mon Sep 17 00:00:00 2001 From: Tom Grundy Date: Tue, 6 Dec 2022 04:59:59 -0800 Subject: [PATCH] WIP #598 - improve options dialog sartopo fields callback logic: disconnect when checkboxes are unchecked, reconnect when checkboxes are rechecked if URL field is not blank; disconnect if URL field is blank --- designer/options.ui | 14 +++++++++---- radiolog.py | 48 ++++++++++++++++++++++++++++++++++----------- ui/options_ui.py | 12 +++++++----- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/designer/options.ui b/designer/options.ui index 20a02a9..37c2d8c 100644 --- a/designer/options.ui +++ b/designer/options.ui @@ -327,19 +327,25 @@ - + - 40 + 20 0 - 16777215 - 30 + 20 + 20 + + background-color:#aaaaaa + + + true + diff --git a/radiolog.py b/radiolog.py index 18ee563..52ccdf6 100644 --- a/radiolog.py +++ b/radiolog.py @@ -838,6 +838,12 @@ def __init__(self,parent): self.incidentStartDate=time.strftime("%a %b %d, %Y") self.isContinuedIncident=False + self.sts=None + self.sartopoURL='' + self.sartopoLink=None + self.radioMarkerDict={} + self.radioMarkerFID=None + self.optionsDialog=optionsDialog(self) self.optionsDialog.accepted.connect(self.optionsAccepted) @@ -1020,12 +1026,6 @@ def __init__(self,parent): self.comPortScanInProgress=False self.comPortTryList=[] - self.sts=None - self.sartopoURL='' - self.sartopoLink=None - self.radioMarkerDict={} - self.radioMarkerFID=None - ## if develMode: ## self.comPortTryList=[serial.Serial("\\\\.\\CNCB0")] # DEVEL self.fsBuffer="" @@ -5025,7 +5025,7 @@ def createSTS(self): rprint('createSTS called:') if self.sts is not None: # close out any previous session print('Closing previous SartopoSession') - self.sts=None + self.closeSTS() # self.ui.linkIndicator.setText("") # self.updateLinkIndicator() # self.link=-1 @@ -5033,7 +5033,7 @@ def createSTS(self): # self.updateFeatureList("Marker") if self.optionsDialog.ui.sartopoMapURLField.text(): u=self.optionsDialog.ui.sartopoMapURLField.text() - if u==self.sartopoURL: # url has not changed; keep the existing link and folder list + if u==self.sartopoURL and self.sts: # url has not changed; keep the existing link and folder list return self.sartopoURL=u if self.sartopoURL.endswith("#"): # pound sign at end of URL causes crash; brute force fix it here @@ -5054,6 +5054,7 @@ def createSTS(self): # self.sts=SartopoSession(domainAndPort=domainAndPort,mapID=mapID,sync=False,syncTimeout=0.001) self.sartopoLink=self.sts.apiVersion print("link status:"+str(self.sartopoLink)) + self.updateSartopoLinkIndicator() # self.updateLinkIndicator() # if self.link>0: # self.ui.linkIndicator.setText(self.sts.mapID) @@ -5068,6 +5069,23 @@ def createSTS(self): id=self.sts.addMarker(val[2],val[3],key,val[1],folderId=self.radioMarkerFID) self.radioMarkerDict[key][0]=id + def closeSTS(self): + rprint('closeSTS called') + if self.sts: + del self.sts + self.sts=None + self.sartopoLink=0 + self.updateSartopoLinkIndicator() + + def updateSartopoLinkIndicator(self): + rprint('updateSartopoLinkIndcator called: sartopoLink='+str(self.sartopoLink)) + if self.sartopoLink==1: + self.optionsDialog.ui.sartopoLinkIndicator.setStyleSheet("background-color:#00ff00") + elif self.sartopoLink==-1: + self.optionsDialog.ui.sartopoLinkIndicator.setStyleSheet("background-color:#ff0000") + else: + self.optionsDialog.ui.sartopoLinkIndicator.setStyleSheet("background-color:#aaaaaa") + class helpWindow(QDialog,Ui_Help): def __init__(self, *args): QDialog.__init__(self) @@ -5103,7 +5121,6 @@ def __init__(self,parent): self.ui.formatField.setEnabled(False) # since convert menu is not working yet, TMG 4-8-15 self.setFixedSize(self.size()) self.secondWorkingDirCB() - self.sartopoEnabledCB() def showEvent(self,event): # clear focus from all fields, otherwise previously edited field gets focus on next show, @@ -5113,6 +5130,7 @@ def showEvent(self,event): self.ui.formatField.clearFocus() self.ui.timeoutField.clearFocus() self.ui.secondWorkingDirCheckBox.clearFocus() + self.sartopoEnabledCB() def displayTimeout(self): self.ui.timeoutLabel.setText("Timeout: "+timeoutDisplayList[self.ui.timeoutField.value()][0]) @@ -5137,20 +5155,28 @@ def toggleShow(self): self.show() self.raise_() - def sartopoEnabledCB(self): + def sartopoEnabledCB(self): # called from stateChanged of group box AND of radio markers checkbox a=self.ui.sartopoGroupBox.isChecked() radios=self.ui.sartopoRadioMarkersCheckBox.isChecked() self.ui.sartopoLocationUpdatesCheckBox.setEnabled(a) self.ui.sartopoRadioMarkersCheckBox.setEnabled(a) enableMapFields=a and radios self.ui.sartopoMapURLField.setEnabled(enableMapFields) - self.ui.sartopoLinkStatusField.setEnabled(enableMapFields) + self.ui.sartopoLinkIndicator.setEnabled(enableMapFields) self.ui.sartopoMapURLLabel.setEnabled(enableMapFields) self.ui.sartopoMapNameLabel.setEnabled(enableMapFields) + if enableMapFields: + self.sartopoURLCB() # try to reconnect if mapURL is not blank + else: + self.parent.closeSTS() def sartopoURLCB(self): + if self.ui.sartopoMapURLField.text()=='': + self.parent.closeSTS() + return self.parent.createSTS() + class printDialog(QDialog,Ui_printDialog): def __init__(self,parent): QDialog.__init__(self) diff --git a/ui/options_ui.py b/ui/options_ui.py index ed7ab10..f39c7ed 100644 --- a/ui/options_ui.py +++ b/ui/options_ui.py @@ -156,11 +156,13 @@ def setupUi(self, optionsDialog): self.sartopoMapURLField = QtWidgets.QLineEdit(self.sartopoGroupBox) self.sartopoMapURLField.setObjectName("sartopoMapURLField") self.horizontalLayout_3.addWidget(self.sartopoMapURLField) - self.sartopoLinkStatusField = QtWidgets.QLineEdit(self.sartopoGroupBox) - self.sartopoLinkStatusField.setMinimumSize(QtCore.QSize(40, 0)) - self.sartopoLinkStatusField.setMaximumSize(QtCore.QSize(16777215, 30)) - self.sartopoLinkStatusField.setObjectName("sartopoLinkStatusField") - self.horizontalLayout_3.addWidget(self.sartopoLinkStatusField) + self.sartopoLinkIndicator = QtWidgets.QLineEdit(self.sartopoGroupBox) + self.sartopoLinkIndicator.setMinimumSize(QtCore.QSize(20, 0)) + self.sartopoLinkIndicator.setMaximumSize(QtCore.QSize(20, 20)) + self.sartopoLinkIndicator.setStyleSheet("background-color:#aaaaaa") + self.sartopoLinkIndicator.setReadOnly(True) + self.sartopoLinkIndicator.setObjectName("sartopoLinkIndicator") + self.horizontalLayout_3.addWidget(self.sartopoLinkIndicator) self.horizontalLayout_3.setStretch(0, 20) self.horizontalLayout_3.setStretch(1, 1) self.gridLayout_2.addLayout(self.horizontalLayout_3, 2, 1, 1, 1)