def closeEvent(self, e): """ Protected slot implementing a close event handler. @param e close event (QCloseEvent) """ if self.__hgClient: if self.__hgClient.isExecuting(): self.__hgClient.cancel() if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons( E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False e.accept()
def closeEvent(self, e): """ Protected slot implementing a close event handler. @param e close event (QCloseEvent) """ if self.__hgClient.isExecuting(): self.__hgClient.cancel() if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons( E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False e.accept()
def closeEvent(self, evt): """ Protected method handling the close event. @param evt close event (QCloseEvent) """ if self.__modified: res = E5MessageBox.question( self, self.tr("eric6 Snapshot"), self.tr("""The application contains an unsaved snapshot."""), E5MessageBox.StandardButtons(E5MessageBox.Abort | E5MessageBox.Discard | E5MessageBox.Save)) if res == E5MessageBox.Abort: evt.ignore() return elif res == E5MessageBox.Save: self.on_saveButton_clicked() Preferences.Prefs.settings.setValue("Snapshot/Delay", self.delaySpin.value()) Preferences.Prefs.settings.setValue( "Snapshot/Mode", self.modeCombo.itemData(self.modeCombo.currentIndex())) Preferences.Prefs.settings.setValue("Snapshot/Filename", self.__filename) Preferences.Prefs.settings.sync()
def closeEvent(self, evt): """ Protected method handling the close event. @param evt close event (QCloseEvent) """ if self.__modified: res = E5MessageBox.question( self, self.tr("eric6 Snapshot"), self.tr( """The application contains an unsaved snapshot."""), E5MessageBox.StandardButtons( E5MessageBox.Abort | E5MessageBox.Discard | E5MessageBox.Save)) if res == E5MessageBox.Abort: evt.ignore() return elif res == E5MessageBox.Save: self.on_saveButton_clicked() Preferences.Prefs.settings.setValue( "Snapshot/Delay", self.delaySpin.value()) Preferences.Prefs.settings.setValue( "Snapshot/Mode", self.modeCombo.itemData(self.modeCombo.currentIndex())) Preferences.Prefs.settings.setValue( "Snapshot/Filename", self.__filename) Preferences.Prefs.settings.sync()
def closeEvent(self, e): """ Protected slot implementing a close event handler. @param e close event (QCloseEvent) """ if self.__hgClient: if self.__hgClient.isExecuting(): self.__hgClient.cancel() else: if self.process is not None and \ self.process.state() != QProcess.NotRunning: self.process.terminate() QTimer.singleShot(2000, self.process.kill) self.process.waitForFinished(3000) if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons(E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False e.accept()
def closeEvent(self, e): """ Protected slot implementing a close event handler. @param e close event (QCloseEvent) """ if self.__hgClient: if self.__hgClient.isExecuting(): self.__hgClient.cancel() else: if self.process is not None and \ self.process.state() != QProcess.NotRunning: self.process.terminate() QTimer.singleShot(2000, self.process.kill) self.process.waitForFinished(3000) if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons( E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False e.accept()
def on_patchSelector_activated(self, patch): """ Private slot to get the list of guards defined for the given patch name. @param patch selected patch name (empty for current patch) """ if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons( E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False self.guardsList.clear() self.patchNameLabel.setText("") self.guardCombo.clear() guardsList = self.extension.getGuardsList(self.__repodir) self.guardCombo.addItems(guardsList) self.guardCombo.setEditText("") args = self.vcs.initCommand("qguard") if patch: args.append(patch) output = self.__hgClient.runcommand(args)[0] if output: patchName, guards = output.split(":", 1) self.patchNameLabel.setText(patchName) guardsList = guards.strip().split() for guard in guardsList: if guard.startswith("+"): icon = UI.PixmapCache.getIcon("plus.png") guard = guard[1:] sign = "+" elif guard.startswith("-"): icon = UI.PixmapCache.getIcon("minus.png") guard = guard[1:] sign = "-" else: continue itm = QListWidgetItem(icon, guard, self.guardsList) itm.setData(Qt.UserRole, sign) self.on_guardsList_itemSelectionChanged()
def __receive(self, lang): """ Private method to receive the response from the clients. @param lang language of the incomming connection (str) """ connection = self.connections[lang] while connection.bytesAvailable(): if self.__cancelled: connection.readAll() continue header = connection.read(struct.calcsize(b'!II')) length, datahash = struct.unpack(b'!II', header) packedData = b'' while len(packedData) < length: maxSize = length - len(packedData) if connection.bytesAvailable() < maxSize: connection.waitForReadyRead(50) packedData += connection.read(maxSize) assert adler32(packedData) & 0xffffffff == datahash, \ 'Hashes not equal' packedData = packedData.decode('utf-8') # "check" if is's a tuple of 3 values fx, fn, data = json.loads(packedData) if fx == 'INIT': pass elif fx == 'EXCEPTION': # Remove connection because it'll close anyway self.connections.pop(lang, None) # Call sys.excepthook(type, value, traceback) to emulate the # exception which was caught on the client sys.excepthook(*data) res = E5MessageBox.question( None, self.tr("Restart background client?"), self.tr( "<p>The background client for <b>{0}</b> has stopped" " due to an exception. It's used by various plug-ins" " like the different checkers.</p>" "<p>Select" "<ul>" "<li><b>'Yes'</b> to restart the client, but abort the" " last job</li>" "<li><b>'Retry'</b> to restart the client and the last" " job</li>" "<li><b>'No'</b> to leave the client off.</li>" "</ul></p>" "<p>Note: The client can be restarted by opening and" " accepting the preferences dialog or reloading/" "changing the project.</p>").format(lang), E5MessageBox.Yes | E5MessageBox.No | E5MessageBox.Retry, E5MessageBox.Yes) if res == E5MessageBox.Retry: self.enqueueRequest(*self.runningJob) else: fx, lng, fn, data = self.runningJob try: self.services[(fx, lng)][3]( fx, lng, fn, self. tr('An error in Erics background client stopped the' ' service.')) except (KeyError, TypeError): # ignore silently pass if res != E5MessageBox.No: self.isWorking = None self.restartService(lang, True) return elif data == 'Unknown service.': callback = self.services.get((fx, lang)) if callback: callback[3](fx, lang, fn, data) elif fx.startswith("batch_"): fx = fx.replace("batch_", "") if data != "__DONE__": callback = self.services.get((fx, lang)) if callback: if isinstance(data, (list, tuple)): callback[2](fn, *data) elif isinstance(data, str): callback[3](fx, lang, fn, data) continue else: self.batchJobDone.emit(fx, lang) else: callback = self.services.get((fx, lang)) if callback: callback[2](fn, *data) self.isWorking = None self.__processQueue()
def __receive(self, lang): """ Private method to receive the response from the clients. @param lang language of the incomming connection (str) """ connection = self.connections[lang] header = connection.read(8) length, datahash = struct.unpack(b'!II', header) packedData = b'' while len(packedData) < length: connection.waitForReadyRead(50) packedData += connection.read(length - len(packedData)) assert adler32(packedData) & 0xffffffff == datahash, 'Hashes not equal' if sys.version_info[0] == 3: packedData = packedData.decode('utf-8') # "check" if is's a tuple of 3 values fx, fn, data = json.loads(packedData) if fx == 'INIT': pass elif fx == 'EXCEPTION': # Remove connection because it'll close anyway self.connections.pop(lang, None) # Call sys.excepthook(type, value, traceback) to emulate the # exception which was caught on the client sys.excepthook(*data) res = E5MessageBox.question( None, self.tr("Restart background client?"), self.tr( "<p>The background client for <b>{0}</b> has stopped" " due to an exception. It's used by various plug-ins like" " the different checkers.</p>" "<p>Select" "<ul>" "<li><b>'Yes'</b> to restart the client, but abort the" " last job</li>" "<li><b>'Retry'</b> to restart the client and the last" " job</li>" "<li><b>'No'</b> to leave the client off.</li>" "</ul></p>" "<p>Note: The client can be restarted by opening and" " accepting the preferences dialog or reloading/changing" " the project.</p>").format(lang), E5MessageBox.Yes | E5MessageBox.No | E5MessageBox.Retry, E5MessageBox.Yes) if res == E5MessageBox.Retry: self.enqueueRequest(*self.runningJob) else: fx, lng, fn, data = self.runningJob self.services[(fx, lng)][3](fx, lng, fn, self.tr( 'An error in Erics background client stopped the service.') ) if res != E5MessageBox.No: self.isWorking = None self.restartService(lang, True) return elif data == 'Unknown service.': callback = self.services.get((fx, lang)) if callback: callback[3](fx, lang, fn, data) else: callback = self.services.get((fx, lang)) if callback: callback[2](fn, *data) self.isWorking = None self.__processQueue()
def __receive(self, lang): """ Private method to receive the response from the clients. @param lang language of the incomming connection (str) """ connection = self.connections[lang] header = connection.read(8) length, datahash = struct.unpack(b'!II', header) packedData = b'' while len(packedData) < length: connection.waitForReadyRead(50) packedData += connection.read(length - len(packedData)) assert adler32(packedData) & 0xffffffff == datahash, 'Hashes not equal' if sys.version_info[0] == 3: packedData = packedData.decode('utf-8') # "check" if is's a tuple of 3 values fx, fn, data = json.loads(packedData) if fx == 'INIT': pass elif fx == 'EXCEPTION': # Remove connection because it'll close anyway self.connections.pop(lang, None) # Call sys.excepthook(type, value, traceback) to emulate the # exception which was caught on the client sys.excepthook(*data) res = E5MessageBox.question( None, self.tr("Restart background client?"), self.tr( "<p>The background client for <b>{0}</b> has stopped" " due to an exception. It's used by various plug-ins like" " the different checkers.</p>" "<p>Select" "<ul>" "<li><b>'Yes'</b> to restart the client, but abort the" " last job</li>" "<li><b>'Retry'</b> to restart the client and the last" " job</li>" "<li><b>'No'</b> to leave the client off.</li>" "</ul></p>" "<p>Note: The client can be restarted by opening and" " accepting the preferences dialog or reloading/changing" " the project.</p>").format(lang), E5MessageBox.Yes | E5MessageBox.No | E5MessageBox.Retry, E5MessageBox.Yes) if res == E5MessageBox.Retry: self.enqueueRequest(*self.runningJob) else: fx, lng, fn, data = self.runningJob self.services[(fx, lng)][3]( fx, lng, fn, self. tr('An error in Erics background client stopped the service.' )) if res != E5MessageBox.No: self.isWorking = None self.restartService(lang, True) return elif data == 'Unknown service.': callback = self.services.get((fx, lang)) if callback: callback[3](fx, lang, fn, data) else: callback = self.services.get((fx, lang)) if callback: callback[2](fn, *data) self.isWorking = None self.__processQueue()
def on_patchSelector_activated(self, patch): """ Private slot to get the list of guards defined for the given patch name. @param patch selected patch name (empty for current patch) """ if self.__dirtyList: res = E5MessageBox.question( self, self.tr("Unsaved Changes"), self.tr("""The guards list has been changed.""" """ Shall the changes be applied?"""), E5MessageBox.StandardButtons( E5MessageBox.Apply | E5MessageBox.Discard), E5MessageBox.Apply) if res == E5MessageBox.Apply: self.__applyGuards() else: self.__dirtyList = False self.guardsList.clear() self.patchNameLabel.setText("") self.guardCombo.clear() guardsList = self.extension.getGuardsList(self.__repodir) self.guardCombo.addItems(guardsList) self.guardCombo.setEditText("") args = self.vcs.initCommand("qguard") if patch: args.append(patch) output = "" if self.__hgClient: output = self.__hgClient.runcommand(args)[0] else: process = QProcess() process.setWorkingDirectory(self.__repodir) process.start('hg', args) procStarted = process.waitForStarted(5000) if procStarted: finished = process.waitForFinished(30000) if finished and process.exitCode() == 0: output = str(process.readAllStandardOutput(), self.vcs.getEncoding(), 'replace').strip() if output: patchName, guards = output.split(":", 1) self.patchNameLabel.setText(patchName) guardsList = guards.strip().split() for guard in guardsList: if guard.startswith("+"): icon = UI.PixmapCache.getIcon("plus.png") guard = guard[1:] sign = "+" elif guard.startswith("-"): icon = UI.PixmapCache.getIcon("minus.png") guard = guard[1:] sign = "-" else: continue itm = QListWidgetItem(icon, guard, self.guardsList) itm.setData(Qt.UserRole, sign) self.on_guardsList_itemSelectionChanged()
def on_bTest_clicked(self): """ Private method to test the selected options. """ if self.rAbout.isChecked(): E5MessageBox.about( None, self.eCaption.text(), self.eMessage.toPlainText() ) elif self.rAboutQt.isChecked(): E5MessageBox.aboutQt( None, self.eCaption.text() ) elif self.rInformation.isChecked() or \ self.rQuestion.isChecked() or \ self.rWarning.isChecked() or \ self.rCritical.isChecked(): buttons = E5MessageBox.NoButton if self.abortCheck.isChecked(): buttons |= E5MessageBox.Abort if self.applyCheck.isChecked(): buttons |= E5MessageBox.Apply if self.cancelCheck.isChecked(): buttons |= E5MessageBox.Cancel if self.closeCheck.isChecked(): buttons |= E5MessageBox.Close if self.discardCheck.isChecked(): buttons |= E5MessageBox.Discard if self.helpCheck.isChecked(): buttons |= E5MessageBox.Help if self.ignoreCheck.isChecked(): buttons |= E5MessageBox.Ignore if self.noCheck.isChecked(): buttons |= E5MessageBox.No if self.notoallCheck.isChecked(): buttons |= E5MessageBox.NoToAll if self.okCheck.isChecked(): buttons |= E5MessageBox.Ok if self.openCheck.isChecked(): buttons |= E5MessageBox.Open if self.resetCheck.isChecked(): buttons |= E5MessageBox.Reset if self.restoreCheck.isChecked(): buttons |= E5MessageBox.RestoreDefaults if self.retryCheck.isChecked(): buttons |= E5MessageBox.Retry if self.saveCheck.isChecked(): buttons |= E5MessageBox.Save if self.saveallCheck.isChecked(): buttons |= E5MessageBox.SaveAll if self.yesCheck.isChecked(): buttons |= E5MessageBox.Yes if self.yestoallCheck.isChecked(): buttons |= E5MessageBox.YesToAll if buttons == E5MessageBox.NoButton: buttons = E5MessageBox.Ok defaultButton = self.buttonsCodeListBinary[ self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): E5MessageBox.information( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rQuestion.isChecked(): E5MessageBox.question( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rWarning.isChecked(): E5MessageBox.warning( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rCritical.isChecked(): E5MessageBox.critical( self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton ) elif self.rYesNo.isChecked() or \ self.rRetryAbort.isChecked(): if self.iconInformation.isChecked(): icon = E5MessageBox.Information elif self.iconQuestion.isChecked(): icon = E5MessageBox.Question elif self.iconWarning.isChecked(): icon = E5MessageBox.Warning elif self.iconCritical.isChecked(): icon = E5MessageBox.Critical if self.rYesNo.isChecked(): E5MessageBox.yesNo( self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon, yesDefault=self.yesDefaultCheck.isChecked() ) elif self.rRetryAbort.isChecked(): E5MessageBox.retryAbort( self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon ) elif self.rOkToClearData.isChecked(): E5MessageBox.okToClearData( self, self.eCaption.text(), self.eMessage.toPlainText(), lambda: True )
def on_bTest_clicked(self): """ Private method to test the selected options. """ if self.rAbout.isChecked(): E5MessageBox.about(None, self.eCaption.text(), self.eMessage.toPlainText()) elif self.rAboutQt.isChecked(): E5MessageBox.aboutQt(None, self.eCaption.text()) elif self.rInformation.isChecked() or \ self.rQuestion.isChecked() or \ self.rWarning.isChecked() or \ self.rCritical.isChecked(): buttons = E5MessageBox.NoButton if self.abortCheck.isChecked(): buttons |= E5MessageBox.Abort if self.applyCheck.isChecked(): buttons |= E5MessageBox.Apply if self.cancelCheck.isChecked(): buttons |= E5MessageBox.Cancel if self.closeCheck.isChecked(): buttons |= E5MessageBox.Close if self.discardCheck.isChecked(): buttons |= E5MessageBox.Discard if self.helpCheck.isChecked(): buttons |= E5MessageBox.Help if self.ignoreCheck.isChecked(): buttons |= E5MessageBox.Ignore if self.noCheck.isChecked(): buttons |= E5MessageBox.No if self.notoallCheck.isChecked(): buttons |= E5MessageBox.NoToAll if self.okCheck.isChecked(): buttons |= E5MessageBox.Ok if self.openCheck.isChecked(): buttons |= E5MessageBox.Open if self.resetCheck.isChecked(): buttons |= E5MessageBox.Reset if self.restoreCheck.isChecked(): buttons |= E5MessageBox.RestoreDefaults if self.retryCheck.isChecked(): buttons |= E5MessageBox.Retry if self.saveCheck.isChecked(): buttons |= E5MessageBox.Save if self.saveallCheck.isChecked(): buttons |= E5MessageBox.SaveAll if self.yesCheck.isChecked(): buttons |= E5MessageBox.Yes if self.yestoallCheck.isChecked(): buttons |= E5MessageBox.YesToAll if buttons == E5MessageBox.NoButton: buttons = E5MessageBox.Ok defaultButton = self.buttonsCodeListBinary[ self.defaultCombo.currentIndex()] if self.rInformation.isChecked(): E5MessageBox.information(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rQuestion.isChecked(): E5MessageBox.question(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rWarning.isChecked(): E5MessageBox.warning(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rCritical.isChecked(): E5MessageBox.critical(self, self.eCaption.text(), self.eMessage.toPlainText(), E5MessageBox.StandardButtons(buttons), defaultButton) elif self.rYesNo.isChecked() or \ self.rRetryAbort.isChecked(): if self.iconInformation.isChecked(): icon = E5MessageBox.Information elif self.iconQuestion.isChecked(): icon = E5MessageBox.Question elif self.iconWarning.isChecked(): icon = E5MessageBox.Warning elif self.iconCritical.isChecked(): icon = E5MessageBox.Critical if self.rYesNo.isChecked(): E5MessageBox.yesNo(self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon, yesDefault=self.yesDefaultCheck.isChecked()) elif self.rRetryAbort.isChecked(): E5MessageBox.retryAbort(self, self.eCaption.text(), self.eMessage.toPlainText(), icon=icon) elif self.rOkToClearData.isChecked(): E5MessageBox.okToClearData(self, self.eCaption.text(), self.eMessage.toPlainText(), lambda: True)