Exemplo n.º 1
0
	def saveBook(self):
		data = self.books[self.nameOfBook]['originalData']
		book = self.books[self.nameOfBook]['book']
		conf = self.books[self.nameOfBook]['config']

		whereDot = self.nameOfBook.rfind('.')

		fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save book file' , expanduser('~')+self.nameOfBook[:whereDot] , 'Python pickle (*.p);;Matlab file (*.mat);;')
		
		if len(fileName[0]) == 0:
			return

		bookFileName = str(fileName[0])
		whereDot = bookFileName.rfind('.')
		bookFileName = bookFileName[:whereDot]
		
		# extension = str(fileName[1])
		# t1 = extension.rfind('(')
		# t2 = extension.rfind(')')
		# extension = extension[t1+2:t2]

		if fileName[1][-3:-1] == '.p':
			with open(bookFileName+'.p' , 'wb') as f:
				pickle.dump({'book':book,'config':conf,'originalData':data} , f)
		elif fileName[1][-5:-1] == '.mat':
			msg = saveBookAsMat(book , data , conf , bookFileName+'.mat')
Exemplo n.º 2
0
    def saveBook(self):
        data = self.books[self.nameOfBook]['originalData']
        book = self.books[self.nameOfBook]['book']
        conf = self.books[self.nameOfBook]['config']

        whereDot = self.nameOfBook.rfind('.')

        fileName = QtGui.QFileDialog.getSaveFileName(
            self, 'Save book file',
            expanduser('~') + self.nameOfBook[:whereDot],
            'Python pickle (*.p);;Matlab file (*.mat);;')

        if len(fileName[0]) == 0:
            return

        bookFileName = str(fileName[0])
        whereDot = bookFileName.rfind('.')
        bookFileName = bookFileName[:whereDot]

        # extension = str(fileName[1])
        # t1 = extension.rfind('(')
        # t2 = extension.rfind(')')
        # extension = extension[t1+2:t2]

        if fileName[1][-3:-1] == '.p':
            with open(bookFileName + '.p', 'wb') as f:
                pickle.dump(
                    {
                        'book': book,
                        'config': conf,
                        'originalData': data
                    }, f)
        elif fileName[1][-5:-1] == '.mat':
            msg = saveBookAsMat(book, data, conf, bookFileName + '.mat')
    def saveBooks(self , flag='saving'):
        '''
        possible flags - saving , passing
        '''

        warningCollector = ''
        if flag == 'passing':
            inputs = {}

        for item in self.ui.lst_books.selectedItems():
            nameOfBook = str(item.text())

            whereFrom  = nameOfBook.rfind('/')
            whereTo    = nameOfBook.rfind('.')
            whereBOOK  = nameOfBook.rfind('_BOOK')
            tmpName = nameOfBook[whereFrom:whereTo]

            nameOfData = nameOfBook[:whereBOOK] + nameOfBook[whereBOOK+5:]
            data = self.dataMatrixes[str(self.ui.lst_data.findItems(nameOfData , QtCore.Qt.MatchExactly)[0].text())][0]
            book = self.books[nameOfBook][0]
            conf = self.books[nameOfBook][1]

            if flag == 'passing':
                inputs[nameOfBook]= {'book':book,'config':conf,'originalData':data}
            else:
                (fileName , extension) = QtGui.QFileDialog.getSaveFileNameAndFilter(self , 'Save book file' , expanduser('~')+tmpName , 'Python pickle (*.p);;Matlab file (*.mat);;')
                fileName = str(fileName)
                extension = str(extension)
                if len(fileName) == 0:
                    self.displayInformation('' , 'new')
                    return

                t1 = extension.rfind('(')
                t2 = extension.rfind(')')
                extension = extension[t1+2:t2]

                self.displayInformation('Saving book...' , flag='new')

                if fileName[-2:] == '.p':
                    with open(fileName , 'wb') as f:
                        dump({'book':book , 'originalData':data,'config':conf} , f)
                        msg = 'ok'
                elif fileName[-4:] == '.mat':
                    msg = saveBookAsMat(book , data , conf , fileName)
                elif extension == '.p':
                    with open(fileName+extension , 'wb') as f:
                        dump({'book':book , 'originalData':data,'config':conf} , f)
                        msg = 'ok'
                elif extension == '.mat':
                    msg = saveBookAsMat(book , data , conf , fileName+extension)
                else:
                    msg = 'Error'

                if msg != 'ok':
                    warningCollector += msg + ' in' + nameOfBook + '\n'

        if flag == 'passing':
            return inputs
        else:
            self.displayInformation('' , 'new')
            if warningCollector != '':
                self.warrning('on' , warningCollector)