def openButtonClicked(self): """Brings up an open dialogue""" # By some unknown reasons the following simple way of getting a file is # not working: # fileName = QFileDialog.getOpenFileName(self, 'Open file', # QDir.currentPath()) # # There is however a workaround. Here it is: dialog = QFileDialog(self) if dialog.exec_() != QDialog.Accepted: return fileNames = dialog.selectedFiles() fileName = str(fileNames[0]) if not os.path.exists(fileName): QMessageBox.critical( self, 'Error', 'The selected file (' + fileName + ') does not exist') return # Check that the file is a python one warning = isPythonFile(fileName) if warning is not None: QMessageBox.critical(self, 'Error', warning) return # set the new file name self.fName = fileName self.updateWindowTitle() # initiate the process self.proceedWithFile()
def __onReloadWithEncoding(self, act): """Triggered when encoding is selected""" # The method is called only for the existing disk files encoding = act.data() if self.__isSameEncodingAsCurrent(encoding): return if self.document().isModified(): res = QMessageBox.warning( self, 'Continue loosing changes', '<p>The buffer has unsaved changes. Are you sure to continue ' 'reloading the content using ' + encoding + ' encoding and ' 'loosing the changes?</p>', QMessageBox.StandardButtons(QMessageBox.Cancel | QMessageBox.Yes), QMessageBox.Cancel) if res == QMessageBox.Cancel: return # Do the reload fileName = self._parent.getFileName() setFileEncoding(fileName, encoding) self.__updateFilePosition() self.readFile(fileName) self.__restoreFilePosition() self.__updateMainWindowStatusBar()
def __onDel(self): """Triggered when a property del is clicked""" selected = list(self.__propsView.selectedItems()) if len(selected) == 0: self.__delButton.setEnabled(False) return name = str(selected[0].text(0)) res = QMessageBox.warning( self, "Deleting Property", "You are about to delete <b>" + name + "</b> SVN property from " + self.__path + ".\nAre you sure?", QMessageBox.StandardButtons(QMessageBox.Cancel | QMessageBox.Yes), QMessageBox.Cancel) if res != QMessageBox.Yes: return try: self.__client.propdel(name, self.__path) self.__populate() self.__plugin.notifyPathChanged(self.__path) self.__propsView.setFocus() except pysvn.ClientError as exc: message = exc.args[0] logging.error(message) except Exception as exc: logging.error(str(exc)) except: logging.error("Unknown property deleting error")
def __svnDelete(self, path): res = QMessageBox.warning( None, "Deleting from SVN", "You are about to delete <b>" + path + "</b> from SVN and from the disk.\nAre you sure?", QMessageBox.StandardButtons(QMessageBox.Cancel | QMessageBox.Yes), QMessageBox.Cancel) if res != QMessageBox.Yes: return client = self.getSVNClient(self.getSettings()) pathList = [] def notifyCallback(event, paths=pathList): if event['path']: path = event['path'] if os.path.isdir(path) and not path.endswith(os.path.sep): path += os.path.sep action = notifyActionToString(event['action']) if action: logging.info(action + " " + path) paths.append(path) return try: client.callback_notify = notifyCallback client.remove(path) if pathList: logging.info("Finished") except Exception as excpt: logging.error(str(excpt)) for revertedPath in pathList: self.notifyPathChanged(revertedPath)
def __selectFile(self, extension): """Picks a file of a certain extension""" dialog = QFileDialog(self, 'Save flowchart as') dialog.setFileMode(QFileDialog.AnyFile) dialog.setLabelText(QFileDialog.Accept, "Save") dialog.setNameFilter(extension.upper() + " files (*." + extension.lower() + ")") urls = [] for dname in QDir.drives(): urls.append(QUrl.fromLocalFile(dname.absoluteFilePath())) urls.append(QUrl.fromLocalFile(QDir.homePath())) project = GlobalData().project if project.isLoaded(): urls.append(QUrl.fromLocalFile(project.getProjectDir())) dialog.setSidebarUrls(urls) suggestedFName = self.__parentWidget.getFileName() if '.' in suggestedFName: dotIndex = suggestedFName.rindex('.') suggestedFName = suggestedFName[:dotIndex] dialog.setDirectory(self.__getDefaultSaveDir()) dialog.selectFile(suggestedFName + "." + extension.lower()) dialog.setOption(QFileDialog.DontConfirmOverwrite, False) dialog.setOption(QFileDialog.DontUseNativeDialog, True) if dialog.exec_() != QDialog.Accepted: return None fileNames = dialog.selectedFiles() fileName = os.path.abspath(str(fileNames[0])) if os.path.isdir(fileName): logging.error("A file must be selected") return None if "." not in fileName: fileName += "." + extension.lower() # Check permissions to write into the file or to a directory if os.path.exists(fileName): # Check write permissions for the file if not os.access(fileName, os.W_OK): logging.error("There is no write permissions for " + fileName) return None else: # Check write permissions to the directory dirName = os.path.dirname(fileName) if not os.access(dirName, os.W_OK): logging.error("There is no write permissions for the " "directory " + dirName) return None if os.path.exists(fileName): res = QMessageBox.warning( self, "Save flowchart as", "<p>The file <b>" + fileName + "</b> already exists.</p>", QMessageBox.StandardButtons(QMessageBox.Abort | QMessageBox.Save), QMessageBox.Abort) if res == QMessageBox.Abort or res == QMessageBox.Cancel: return None # All prerequisites are checked, return a file name return fileName
def exceptionHook(excType, excValue, tracebackObj): """Catches unhandled exceptions""" globalData = GlobalData() # Keyboard interrupt is a special case if issubclass(excType, KeyboardInterrupt): if globalData.application is not None: globalData.application.quit() return error = "%s: %s" % (excType.__name__, excValue) stackTraceString = "".join( traceback.format_exception(excType, excValue, tracebackObj)) # Save the traceback to a file explicitly together with a log window # content. excptFileName = SETTINGS_DIR + "unhandledexceptions.log" try: savedOK = True with open(excptFileName, 'a', encoding=DEFAULT_ENCODING) as diskfile: diskfile.write("------ Unhandled exception report at " + str(datetime.datetime.now()) + "\n") diskfile.write("Traceback:\n") diskfile.write(stackTraceString) diskfile.write("Log window:\n") if globalData.mainWindow is not None: # i.e. the log window is available, save its content too logWindowContent = globalData.mainWindow.getLogViewerContent() logWindowContent = logWindowContent.strip() if logWindowContent: diskfile.write(logWindowContent) diskfile.write('\n') else: diskfile.write('Nothing is there\n') else: diskfile.write('Has not been created yet\n') diskfile.write('------\n\n') except: savedOK = False # This output will be to a console if the application has not started yet # or to a log window otherwise. logging.error('Unhandled exception is caught\n%s', stackTraceString) # Display the message as a QT modal dialog box if the application # has started if globalData.application is not None: message = "<html><body>" if savedOK: message += "Stack trace and log window content saved in " + \ excptFileName + ".<br>" else: message += "Failed to save stack trace and log window " \ "content in " + excptFileName + ".<br>" lines = stackTraceString.split('\n') if len(lines) > 32: message += "First 32 lines of the stack trace " \ "(the rest is truncated):" \ "<pre>" + "\n".join(lines[:32]) + "<pre>" else: message += "Stack trace:" + \ "<pre>" + stackTraceString + "</pre>" message += "</body></html>" QMessageBox.critical(None, "Unhandled exception: " + error, message) globalData.application.exit(1)
def __askForkTo(self): " Asks what to follow, a parent or a child " dlg = QMessageBox(QMessageBox.Question, "Client forking", "Select the fork branch to follow") dlg.addButton(QMessageBox.Ok) dlg.addButton(QMessageBox.Cancel) btn1 = dlg.button(QMessageBox.Ok) btn1.setText("&Child process") btn1.setIcon(getIcon('')) btn2 = dlg.button(QMessageBox.Cancel) btn2.setText("&Parent process") btn2.setIcon(getIcon('')) dlg.setDefaultButton(QMessageBox.Cancel) res = dlg.exec_() if res == QMessageBox.Cancel: self.__sendJSONCommand(METHOD_FORK_TO, {'target': 'parent'}) else: self.__sendJSONCommand(METHOD_FORK_TO, {'target': 'child'})