Example #1
0
    def saveAsFile(self, MainWindow):
        subwindow = self.mdiArea.activeSubWindow()
        try:
            if subwindow == None:
                raise Exception( 'No active Window is selected to save...' )

            filename = QtGui.QFileDialog.getSaveFileName(None,
                'Save a Script/Data File', self.project_path, "Python Files & Parameter Files (*.py *.dat);;")

            if not filename:
                Exception( "Failed to save to a file...")

            subwindow.setFilename(filename)

            if isinstance(subwindow, QMdiParameterBoxSubWindow):
                t = table(filename)
                for row in subwindow.data():
                    t[row[0]] = row[1:]
                t.write()
            elif isinstance(subwindow, QMdiScriptSubWindow):
                with open(filename, 'w') as g:
                    string = subwindow.text()
                    g.write(string)

        except IOError:
            self.statusbar.showMessage( 'Failed to save the file + %s...' % filename)
            return False
        except Exception, e:
            self.statusbar.showMessage( str(e) )
            return False
Example #2
0
    def loadFile(self, MainWindow):

        filename = QtGui.QFileDialog.getOpenFileName(None,
            'Open a Script/Data File', self.project_path, "Python Files & Parameter Files (*.py *.dat);;")

        if filename is None: 
            self.statusbar.showMessage( 'No file has been selected...')
            return False

        try:
            filename = str(filename)

            if filename[-4:] == '.dat':
                subwindow = QMdiParameterBoxSubWindow(self.mdiArea)
                subwindow.setFilename(filename)
                d = table(filename).read()
                for i, (key, values) in enumerate(d.iteritems()):
                    subwindow.setRow(i, key, values)
                
            elif filename[-3:] == '.py':
                with open(filename) as f:
                    subwindow = QMdiScriptSubWindow(self.mdiArea)
                    subwindow.setText(f.read())
                    subwindow.setFilename(filename)


                   
        except IOError:
            self.statusbar.showMessage( 'Failed to load the file. The file cannot be read...')
            return False
        except Exception, e:
            self.statusbar.showMessage( str(e) )
            return False
Example #3
0
    def saveFile(self, MainWindow):
        subwindow = self.mdiArea.activeSubWindow()
        try:
            if subwindow == None:
                raise Exception( 'No active Window is selected to save...' )
            filename = subwindow.filename()

            if isinstance(subwindow, QMdiParameterBoxSubWindow):
                t = table(filename)
                for row in subwindow.data():
                    t[row[0]] = row[1:]
                t.write()
            elif isinstance(subwindow, QMdiScriptSubWindow):
                with open(filename, 'w') as g:
                    string = subwindow.text()
                    g.write(string)

        except IOError:
            self.statusbar.showMessage( 'Failed to save the file + %s...' % filename)
            return False
        except Exception, e:
            self.statusbar.showMessage( str(e) )
            return False