Ejemplo n.º 1
0
    def _rename__do(cmd):
        self = project[cmd.ws][cmd.old]
        newname = cmd.new
        name = cmd.old
        
        self._name = newname
        
        project.lock_undo()
        try:
            for cdep in self.deps:
                patt = r'\b%s\.%s\b' % (self.worksheet.name, name)
                repl = '%s.%s' % (self.worksheet.name, newname)
                cdep.calc = re.sub (patt, repl, cdep.calc)
        finally:
            project.unlock_undo()
    
        for graph, dset in project.used_by(self.worksheet, name):
            if dset.colx == name:
                dset.colx = newname
            if dset.coly == name:
                dset.coly = newname
            graph.legend.update()

        if self.worksheet._view is not None:
            self.worksheet._view.set_column_name(self.index(), self.name)
        return cmd
Ejemplo n.º 2
0
 def do_undo(self, com):
     id = len(project.undolist) - project.undolist.index(com) - 1
     self.history.changeItem(QPixmap(project.datadir + "pixmaps/undo.png"), self.history.text(id), id)
     project.lock_undo()
     try:
         com.undo()
     finally:
         project.unlock_undo()
     com.undone = True
Ejemplo n.º 3
0
 def do_undo(self, com):
     id = len(project.undolist) - project.undolist.index(com) - 1
     self.history.changeItem(QPixmap(project.datadir + 'pixmaps/undo.png'), self.history.text(id), id)
     project.lock_undo()
     try:
         com.undo()
     finally:
         project.unlock_undo()
     com.undone = True
Ejemplo n.º 4
0
 def do_redo(self, com):
     id = len(project.undolist) - project.undolist.index(com) - 1
     if hasattr(com, "pixmap") and com.pixmap is not None:
         self.history.changeItem(com.pixmap, self.history.text(id), id)
     else:
         self.history.changeItem(self.history.text(id), id)
     project.lock_undo()
     try:
         com.do()
     finally:
         project.unlock_undo()
     com.undone = False
Ejemplo n.º 5
0
 def do_redo(self, com):
     id = len(project.undolist) - project.undolist.index(com) - 1
     if hasattr(com, 'pixmap') and com.pixmap is not None:
         self.history.changeItem(com.pixmap, self.history.text(id), id)
     else:
         self.history.changeItem(self.history.text(id), id)
     project.lock_undo()
     try:
         com.do()
     finally:
         project.unlock_undo()
     com.undone = False
Ejemplo n.º 6
0
    def __setattr__(self, name, value):
        """Set entire column to a new value"""
        # we keep class attributes and names starting with _ as normal attributes
        if name.startswith('_') or hasattr(self.__class__, name):
            object.__setattr__(self, name, value)
            return

        # cannot change the data in a calculated column
        if name in self.column_names and self[name].calc is not None:
            return

        # otherwise, make a column
        if isinstance(
                value, Column
        ) and value.worksheet is self and value.name not in self.column_names:
            col = value
        else:
            col = Column(value, worksheet=self, name=name)

        # create the column if it does not exist
        if name not in self.column_names:
            Worksheet.add_column___(self.name,
                                    name).do().addto(project.undolist)

        # we can set calc with worksheet.col = 'data1.B + 3'
        if isinstance(value, str):
            self[name].calc = value
        elif len(col) > 0:  # ignore
            # clear column
            project.lock_undo()
            try:
                self[name][0:len(self[name])] = nan
            finally:
                project.unlock_undo()

            # set column
            self[name][:len(col)] = col[:len(col)]

        # update columns that depend on this one
        for c in col.deps:
            c.calculate()

        self.emit(msg='update_data', column=col)
Ejemplo n.º 7
0
    def __setattr__(self, name, value):
        """Set entire column to a new value"""
        # we keep class attributes and names starting with _ as normal attributes 
        if name.startswith('_') or hasattr(self.__class__, name):
            object.__setattr__(self, name, value)
            return

        # cannot change the data in a calculated column
        if name in self.column_names and self[name].calc is not None:
            return

        # otherwise, make a column
        if isinstance(value, Column) and value.worksheet is self and value.name not in self.column_names:
            col = value
        else:
            col = Column(value, worksheet=self, name=name)

        # create the column if it does not exist
        if name not in self.column_names:
            Worksheet.add_column___(self.name, name).do().addto(project.undolist)

        # we can set calc with worksheet.col = 'data1.B + 3'
        if isinstance(value, str):
            self[name].calc = value
        elif len(col) > 0: # ignore
            # clear column
            project.lock_undo()
            try:
                self[name][0:len(self[name])] = nan
            finally: project.unlock_undo()

            # set column
            self[name][:len(col)] = col[:len(col)]

        # update columns that depend on this one
        for c in col.deps:
            c.calculate() 

        self.emit (msg='update_data', column=col)
Ejemplo n.º 8
0
    def _rename__do(cmd):
        self = project[cmd.old]
        name = cmd.new
#        if not re.match('^[a-zA-Z]\w*$', name):
#            raise NameError, "Invalid name for worksheet: %s" % name

        use = project.used_by(self)

        oldname = self._name
        self._name = name

        for graph, das in use:
            das.wsname = name
        for graph, das in use:
            graph.legend.update()

        if self._view is not None:
            self._view.setCaption(self.name)
        if self._explorer_item is not None:
            self._explorer_item.setText(0, self.name)
 
        if self in project.worksheets:
            try:
                del project.main_dict[oldname]
            except KeyError:
                pass
            project.main_dict[self.name] = self

        project.lock_undo()
        try:
            for col in self.columns:
                for cdep in col.deps:
                    patt = r'\b%s\.%s\b' % (oldname, col.name)
                    repl = '%s.%s' % (self.name, col.name)
                    cdep.calc = re.sub (patt, repl, cdep.calc)
        finally:
            project.unlock_undo()

        return cmd
Ejemplo n.º 9
0
    def _rename__do(cmd):
        self = project[cmd.old]
        name = cmd.new
        #        if not re.match('^[a-zA-Z]\w*$', name):
        #            raise NameError, "Invalid name for worksheet: %s" % name

        use = project.used_by(self)

        oldname = self._name
        self._name = name

        for graph, das in use:
            das.wsname = name
        for graph, das in use:
            graph.legend.update()

        if self._view is not None:
            self._view.setCaption(self.name)
        if self._explorer_item is not None:
            self._explorer_item.setText(0, self.name)

        if self in project.worksheets:
            try:
                del project.main_dict[oldname]
            except KeyError:
                pass
            project.main_dict[self.name] = self

        project.lock_undo()
        try:
            for col in self.columns:
                for cdep in col.deps:
                    patt = r'\b%s\.%s\b' % (oldname, col.name)
                    repl = '%s.%s' % (self.name, col.name)
                    cdep.calc = re.sub(patt, repl, cdep.calc)
        finally:
            project.unlock_undo()

        return cmd
Ejemplo n.º 10
0
def process_windeta_dir(dir, worksheet_names):
    project.lock_undo()
    files = [dir + '/' + fil for fil in os.listdir(dir) if os.path.splitext(fil)[1] in ('.txt', '.TXT')]
    wsheets = []

    project.mainwin.statusBar().message ("Reading ASCII files")
    project.mainwin.progressbar.show()
    project.main_dict['app'].processEvents()
    project.mainwin.progressbar.setTotalSteps(len(files))

    for prog, f in enumerate(files):
        w = project.new_worksheet()
        w.import_ascii(f)
        name = windeta_wstemp(w, 1)
        if name is None:
            name = windeta_wstemp(w, 2)
            if name is None:
                p = Page(None, ('Could not determine temperature\n for ascii file '+f, ['Temperature']))
                p.run()
                try:
                    name = float(p['Temperature'])
                except ValueError:
                    continue
        name = temp_to_wsname(name)
        while name in [s.name for s in wsheets]:
            name += 'a'
        w.name = name
        wsheets.append(w)
        if prog % 5 == 0:
            project.mainwin.progressbar.setProgress(prog+1)
    e1_f = project.new_worksheet('_e1_f')
    e2_f = project.new_worksheet('_e2_f')
    e1_f.freq = e2_f.freq = None

    new_wsheets = [(windeta_wstemp(w), w) for w in wsheets]
    new_wsheets.sort()
    wsheets = [w[1] for w in new_wsheets]

    project.mainwin.statusBar().message ("Creating e1_f and e2_f")
    project.mainwin.progressbar.setTotalSteps(len(files))

    for prog, w in enumerate(wsheets):
        if len(w[0]) > len(e1_f.freq):
            e1_f.freq = w[0]
            e2_f.freq = w[0]
        e1_f[w.name] = w[1]
        e2_f[w.name] = w[2]
        project.remove(w)
        if prog % 5 == 0:
            project.mainwin.progressbar.setProgress(prog+1)

    if 'e1(T)' in worksheet_names or 'e2(T)' in worksheet_names:
        make_isochronal(e1_f, e2_f)
    	if 'e1(T)' in worksheet_names: project.w._e1_T.name = 'e1_T'
    	else: project.remove(project.w._e1_T)
    	if 'e2(T)' in worksheet_names: project.w._e2_T.name = 'e2_T'
    	else: project.remove(project.w._e2_T)
    if 'e2deriv(f)' in worksheet_names:
        make_e2deriv(e1_f)

    if 'e1(f)' in worksheet_names: project.w._e1_f.name = 'e1_f'
    else: project.remove(project.w._e1_f)
    if 'e2(f)' in worksheet_names: project.w._e2_f.name = 'e2_f'
    else: project.remove(project.w._e2_f)

    project.unlock_undo()
    project.mainwin.progressbar.hide()
Ejemplo n.º 11
0
def process_windeta_dir(dir, worksheet_names):
    project.lock_undo()
    files = [
        dir + '/' + fil for fil in os.listdir(dir)
        if os.path.splitext(fil)[1] in ('.txt', '.TXT')
    ]
    wsheets = []

    project.mainwin.statusBar().message("Reading ASCII files")
    project.mainwin.progressbar.show()
    project.main_dict['app'].processEvents()
    project.mainwin.progressbar.setTotalSteps(len(files))

    for prog, f in enumerate(files):
        w = project.new_worksheet()
        w.import_ascii(f)
        name = windeta_wstemp(w, 1)
        if name is None:
            name = windeta_wstemp(w, 2)
            if name is None:
                p = Page(None,
                         ('Could not determine temperature\n for ascii file ' +
                          f, ['Temperature']))
                p.run()
                try:
                    name = float(p['Temperature'])
                except ValueError:
                    continue
        name = temp_to_wsname(name)
        while name in [s.name for s in wsheets]:
            name += 'a'
        w.name = name
        wsheets.append(w)
        if prog % 5 == 0:
            project.mainwin.progressbar.setProgress(prog + 1)
    e1_f = project.new_worksheet('_e1_f')
    e2_f = project.new_worksheet('_e2_f')
    e1_f.freq = e2_f.freq = None

    new_wsheets = [(windeta_wstemp(w), w) for w in wsheets]
    new_wsheets.sort()
    wsheets = [w[1] for w in new_wsheets]

    project.mainwin.statusBar().message("Creating e1_f and e2_f")
    project.mainwin.progressbar.setTotalSteps(len(files))

    for prog, w in enumerate(wsheets):
        if len(w[0]) > len(e1_f.freq):
            e1_f.freq = w[0]
            e2_f.freq = w[0]
        e1_f[w.name] = w[1]
        e2_f[w.name] = w[2]
        project.remove(w)
        if prog % 5 == 0:
            project.mainwin.progressbar.setProgress(prog + 1)

    if 'e1(T)' in worksheet_names or 'e2(T)' in worksheet_names:
        make_isochronal(e1_f, e2_f)
        if 'e1(T)' in worksheet_names: project.w._e1_T.name = 'e1_T'
        else: project.remove(project.w._e1_T)
        if 'e2(T)' in worksheet_names: project.w._e2_T.name = 'e2_T'
        else: project.remove(project.w._e2_T)
    if 'e2deriv(f)' in worksheet_names:
        make_e2deriv(e1_f)

    if 'e1(f)' in worksheet_names: project.w._e1_f.name = 'e1_f'
    else: project.remove(project.w._e1_f)
    if 'e2(f)' in worksheet_names: project.w._e2_f.name = 'e2_f'
    else: project.remove(project.w._e2_f)

    project.unlock_undo()
    project.mainwin.progressbar.hide()