def get_intensity(self):
        """
        Get the intensity of value if valid.

        If not warn and return None
        """
        
        val = str2posnum_or_err(self.entryIntensity.get_text(),
                                self.labelIntensity, parent=self)
        return val
    def get_intensity(self):
        """
        Get the intensity of value if valid.

        If not warn and return None
        """

        val = str2posnum_or_err(self.entryIntensity.get_text(),
                                self.labelIntensity,
                                parent=self)
        return val
Beispiel #3
0
    def validate(self, o):
        dlg = self['dlgReader']

        if o.readerClass!='vtkNiftiImageReader':
            if len(o.pattern)==0:
                msg = 'You must supply a number pattern for entry %s.\n' % \
                      self['labelPattern'].get_label() + 'Consider "%d"'
                return error_msg(msg, dlg)

            if o.pattern[0]!='%':
                msg = '%s format string must begin with a %%.\n' % \
                      self['labelPattern'].get_label() + 'Consider "%d"'
                return error_msg(msg, dlg)

        if widgets['radiobuttonDimOther'].get_active():
            dim1, dim2 = o.dimensions
            val = dim1 = str2posint_or_err(dim1, 'Other: dimension 1', dlg)
            if val is None: return None
            val = dim2 = str2posint_or_err(dim2, 'Other: dimension 2', dlg)
            if val is None: return None
            o.dimensions = dim1, dim2
            
        val = o.first = str2int_or_err(o.first, widgets['labelFirst'], dlg)
        if val is None:
            return None

        val = o.last = str2posint_or_err(o.last, widgets['labelLast'], dlg)
        if val is None: return None

        if o.readerClass!='vtkNiftiImageReader':
            fnames = self.get_file_names(o)
            for fname in fnames:
                print "validate(): doing fname ", fname
                if not os.path.exists(fname):
                    return error_msg('Could not find file %s' % fname, dlg)
                if o.readerClass=='vtkBMPReader':
                    reader = vtk.vtkBMPReader()
                    b = reader.CanReadFile(fname)
                    if not b:
                        return error_msg('Could not read file %s with reader %s'
                                         % (fname, o.readerClass), dlg)
        else:
            if len(o.extension) > 0:
                fname=os.path.join(o.dir,o.pattern+"."+o.extension)
                if not os.path.exists(fname):
                    return error_msg('Could not find file %s' % fname, dlg)
            else:
                fname=o.pattern
                files=os.listdir(o.dir)
                match=False
                for file in files:
                    file=file.split(".")
                    if len(file)>1:
                        if file[0]==fname:
                            if file[1] in ["nii","img","hdr"]:
                                match=True
                                break
                if not match:
                    return error_msg('Could not find file %s with extension nii, img, hdr [.gz]' % fname, dlg)

        # Depth Field Of View
        val = o.dfov = str2posnum_or_err(o.dfov, widgets['labelDFOV'], dlg)
        print "dfov=", val
        if val is None: return None

        # Spacing between slices
        val = o.spacing = str2posnum_or_err(
            o.spacing, widgets['labelSpacing'], dlg)
        print "spacing=", val
        if val is None: return None

        # Size of header
        if o.header=='': o.header = 0
        else:
           val = o.header = str2int_or_err(
              o.header, widgets['labelHeader'], dlg)
           if val is None: return None
        print "header=", val

        # Data mask
        if o.mask is not None:
           if o.mask=='': o.mask = None

           else:
               val = o.mask = str2int_or_err(
                   o.mask, widgets['labelMask'], dlg)
               if val is None: return None
        print "mask=", val

        return o
Beispiel #4
0
    def make_butter_dialog(self):
        dlg = gtk.Dialog('Butterworth Filter')
        
        dlg.set_transient_for(self.parent)

        vbox = dlg.vbox

        lrp = gtk.Label('Ripple pass'); lrp.show()
        lrs = gtk.Label('Ripple stop'); lrs.show()

        lcf = gtk.Label('Low corner freq'); lcf.show()
        lsf = gtk.Label('Low stop freq');   lsf.show()        

        erp = gtk.Entry(); erp.show(); erp.set_width_chars(10)
        ers = gtk.Entry(); ers.show(); ers.set_width_chars(10)
        ecf = gtk.Entry(); ecf.show(); ecf.set_width_chars(10)
        esf = gtk.Entry(); esf.show(); esf.set_width_chars(10)        

        erp.set_text('%d'%self.rp)
        ers.set_text('%d'%self.rs)
        ecf.set_text('%1.1f'%self.cf)
        esf.set_text('%1.1f'%self.sf)        
        
        table = gtk.Table(2,4)
        table.show()
        table.set_row_spacings(4)
        table.set_col_spacings(4)

        table.attach(lrp, 0, 1, 0, 1)
        table.attach(lrs, 0, 1, 1, 2)
        table.attach(lcf, 0, 1, 2, 3)
        table.attach(lsf, 0, 1, 3, 4)                        

        table.attach(erp, 1, 2, 0, 1)
        table.attach(ers, 1, 2, 1, 2)
        table.attach(ecf, 1, 2, 2, 3)
        table.attach(esf, 1, 2, 3, 4)                        

        dlg.vbox.pack_start(table, True, True)

        dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        dlg.set_default_response(gtk.RESPONSE_OK)
        dlg.show()


        while 1:
            response = dlg.run()
            if response == gtk.RESPONSE_OK:
                val = str2posint_or_err(erp.get_text(), lrp, dlg)
                if val is None: continue
                else: self.rp = val
                
                val = str2posint_or_err(ers.get_text(), lrs, dlg)
                if val is None: continue
                else: self.rs = val

                cf = str2posnum_or_err(ecf.get_text(), lcf, dlg)
                if cf is None: continue


                sf = str2posnum_or_err(esf.get_text(), lsf, dlg)
                if sf is None: continue

                if sf<=cf:
                    error_msg('Stop frequency must be greater than corner frequency', dlg)
                    continue
                
                
                self.cf = cf
                self.sf = sf
                break
            else: break
                
        dlg.destroy()