def saveCurrent(self): if self.curEdit: oldpath=os.path.join(self.dir,self.curEdit+".template") try: f=open(oldpath,'w') f.write(self.codeEdit.toPlainText()) f.close() except IOError: utils.errorMessage('Cannot write file: {}'.format(oldpath))
def addClicked(self): if not self.dir: utils.errorMessage('Please set template directory first') else: (label,ok)=QtGui.QInputDialog.getText(self,"New Template","Template Name") if ok: self.templatesList.addItem(label) try: f=open(os.path.join(self.dir,label+".template"),'w') f.write("\n") f.close() except IOError: utils.errorMessage('Could not write template file at: {}'.format(self.dir))
def selChanged(self): self.saveCurrent() sel = self.templatesList.selectedItems() if len(sel) == 1: item = sel[0] label = item.text() path = os.path.join(self.dir, label + ".template") try: f = open(path, 'r') code = f.read() self.codeEdit.setPlainText(code) self.curEdit = label except IOError: utils.errorMessage('Cannot read file: {}'.format(path))
def selChanged(self): self.saveCurrent() sel=self.templatesList.selectedItems() if len(sel)==1: item=sel[0] label=item.text() path=os.path.join(self.dir,label+".template") try: f=open(path,'r') code=f.read() self.codeEdit.setPlainText(code) self.curEdit=label except IOError: utils.errorMessage('Cannot read file: {}'.format(path))
def addClicked(self): if not self.dir: utils.errorMessage('Please set template directory first') else: (label, ok) = QtGui.QInputDialog.getText(self, "New Template", "Template Name") if ok: self.templatesList.addItem(label) try: f = open(os.path.join(self.dir, label + ".template"), 'w') f.write("\n") f.close() except IOError: utils.errorMessage( 'Could not write template file at: {}'.format( self.dir))
def __init__(self, msg, returnCode): # Error message is stored formatted in msg and response code stored in returnCode if isinstance(msg, str): self.msg = errorMessage(msg) else: self.msg = msg self.returnCode = returnCode