def SLOT_actionSendToExternalSoftware (self): # Send the scene to another software (mine is called Antidote and # accept only a certain type of encoding). path=AWPreferences['EXTERNAL_SOFT_PATH'] if path=="": QtGui.QMessageBox.information(self, "External Software Sender", "Sorry, there is no path to the external software in the "+\ "configuration file.") return False text=self.textEdit.toXml() i=0 while AWPreferences['TMP_FILE_MARK']+"tmp"+str(i).zfill(3)+'.txt' in \ os.listdir('.'): i+=1 name=AWPreferences['TMP_FILE_MARK']+"tmp"+str(i).zfill(3)+'.txt' FMFileManagement.save(text,name, encoding='utf-8-sig', mode='w') s=subprocess.Popen(path+' '+os.path.abspath(name)) res = QtGui.QMessageBox.question(self, "External Software Sender", "Have you finished to correct the file?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel) if (res == QtGui.QMessageBox.Yes) : text = FMFileManagement.open(name, encoding='utf-8-sig', mode='rb') self.textEdit.setText(text,type='xml')
def SLOT_autosave(self): if self.filepath!=None: direct,file=os.path.split(self.filepath) tmp_filepath = os.path.join(direct, AWPreferences['TMP_FILE_MARK']+file) res = FMFileManagement.save( unicode(self.textEdit.toXml()),tmp_filepath)
def save(filepath,dict_to_save,descriptions=None): """ - dict_to_save: dict that we have to save. - filepath: where to save the file - descriptions: dict that contains the description corresponding keys of dict_to_save """ if descriptions==None: descriptions={} s = CLPreferencesFiles.comment_sign+\ " Preference for the software AthenaWriter." for k,v in dict_to_save.items(): if descriptions.has_key(k): s += CLPreferencesFiles.comment_sign+' '+ descriptions[k]+'\n' if type(v) == list: l = [str(a) for a in v] s += k+' '+CLPreferencesFiles.entry_separator_sign+' ' s+= CLPreferencesFiles.separator_sign.join(l) +'\n' elif type(v) == dict: l = [str(kk)+' '+str(vv) for kk,vv in v.items()] s += k+' '+CLPreferencesFiles.entry_separator_sign+' ' s+= CLPreferencesFiles.separator_sign.join(l) +'\n' else: s += k+' '+CLPreferencesFiles.entry_separator_sign+' ' s += str(v)+'\n' file=FMFileManagement.save(s,filepath=filepath)
def save(words,filepath): words_keys = words.keys() words_keys.sort() words = [(k,words[k]) for k in words_keys] words = [' '.join(w) for w in words] to_save = '\n'.join(words) file=FMFileManagement.save(to_save,filepath=filepath)
def save_file(self,filepath=None,outdir=None): """ - filepath : the complete path where to save the file (with extension) Note: if filepath==None, it will take the self.file name as the path where to save the file. Note : if the DIImport instance was not created with a 'file' argument, this argument is mandatory. - outdir : it will take filemname (if filepath!=None, it will take it own) , and will use the outdir as directory where to save """ assert self.text,"You should run import2xml before" assert filepath!=None or self.file!=None,"Please indiquate the filepath" if self.file!=None and filepath==None: path,ext = os.path.splitext(self.file) filepath = path+'.athw' if outdir!=None: path,fi = os.path.split(self.file) filepath = os.path.join(outdir,fi) FMFileManagement.save(self.text,filepath) return filepath
def CMD_FileSave(self,filepath=None): if filepath==None: if self.filepath==None: raise self.Error('Please specify the filepath') filepath = self.filepath else: self.filepath = filepath res = FMFileManagement.save(unicode(self.textEdit.toXml()),filepath) if res : if not self.metadata.isEmpty(): # we will save the file .athw_meta as well cur = self.textEdit.textCursor() self.metadata.__setitem__('lastpos', int(cur.position()), protected=False) self.metadata['language'] = self.textEdit.language.name to_save = self.metadata.toxml() meta_filepath,tmp = os.path.splitext(self.filepath) meta_filepath += '.athw_meta' res = FMFileManagement.save(to_save,meta_filepath)
def save(words,filepath): words.sort() words = list(set(words)) to_save = '\n'.join(words) file=FMFileManagement.save(to_save,filepath=filepath)