class Free: title = 'Free' view = None para = None def run(self, para=None): print 'this is a plugin' def load(self): return True def show(self): if self.view == None: return wx.ID_OK self.dialog = ParaDialog(IPy.get_window(), self.title) self.dialog.init_view(self.view, self.para, False, True) return self.dialog.ShowModal() def start(self, para=None, thd=True): if not self.load(): return if para != None or self.show() == wx.ID_OK: if para == None: para = self.para win = TextLogManager.get('Recorder') if win != None: wx.CallAfter(win.append, '%s>%s' % (self.title, para)) self.run(para) '''
def init_view(self, items, para, hist): self.histcvs = HistCanvas(self) self.histcvs.set_hist(hist) self.add_ctrl('hist', self.histcvs) ParaDialog.init_view(self, items, para, True, False)
class Filter: title = 'Filter' modal = True note = [] 'all, 8_bit, 16_bit, rgb, float, not_channel, not_slice, req_roi, auto_snap, auto_msk, preview, 2int, 2float' para = None view = None #[(float, (0,30), 1, 'sigma', 'sigma', 'pix')] def __init__(self, ips=None): if ips == None: ips = IPy.get_ips() self.dialog = None self.ips = ips def show(self): self.dialog = ParaDialog(WindowsManager.get(), self.title) self.dialog.init_view(self.view, self.para, 'preview' in self.note, modal=self.modal) self.dialog.set_handle(lambda x: self.preview(self.para)) if self.modal: return self.dialog.ShowModal() self.dialog.on_ok = lambda: self.ok(self.ips) self.dialog.on_cancel = lambda: self.cancel(self.ips) self.dialog.Show() def run(self, ips, snap, img, para=None): return 255 - img def check(self, ips): note = self.note if ips == None: IPy.alert('no image opened!') return False elif 'req_roi' in note and ips.roi == None: IPy.alert('no Roi found!') return False elif not 'all' in note: if ips.get_imgtype() == 'rgb' and not 'rgb' in note: IPy.alert('do not surport rgb image') return False elif ips.get_imgtype() == '8-bit' and not '8-bit' in note: IPy.alert('do not surport 8-bit image') return False elif ips.get_imgtype() == '16-bit' and not '16-bit' in note: IPy.alert('do not surport 16-bit image') return False elif ips.get_imgtype() == 'float' and not 'float' in note: IPy.alert('do not surport float image') return False return True def preview(self, para): process_one(self, self.ips, self.ips.snap, self.ips.get_img(), para) self.ips.update = 'pix' def load(self, ips): return True def ok(self, ips, para=None): if para == None: para = self.para if not 'not_slice' in self.note and ips.get_nslices() > 1: if para == None: para = {} if para != None and para.has_key('stack'): del para['stack'] win = TextLogManager.get('Recorder') if ips.get_nslices() == 1 or 'not_slice' in self.note: process_one(self, ips, ips.snap, ips.get_img(), para) if win != None: win.append('%s>%s' % (self.title, para)) elif ips.get_nslices() > 1: has, rst = para.has_key('stack'), None if not has: rst = IPy.yes_no('run every slice in current stacks?') if 'auto_snap' in self.note: ips.swap() if has and para['stack'] or rst == 'yes': para['stack'] = True process_stack(self, ips, ips.snap, ips.imgs, para) if win != None: win.append('%s>%s' % (self.title, para)) elif has and not para['stack'] or rst == 'no': para['stack'] = False process_one(self, ips, ips.snap, ips.get_img(), para) if win != None: win.append('%s>%s' % (self.title, para)) elif rst == 'cancel': pass ips.update = 'pix' def cancel(self, ips): if 'auto_snap' in self.note: ips.swap() ips.update = 'pix' def start(self, para=None): ips = self.ips if not self.check(ips): return if not self.load(ips): return if 'auto_snap' in self.note: ips.snapshot() if para != None or self.view == None: self.ok(ips, para) elif self.modal: if self.show() == wx.ID_OK: self.ok(ips) else: self.cancel(ips) self.dialog.Destroy() else: self.show()
class Simple: title = 'SimpleFilter' note = [] para = None 'all, 8_bit, 16_bit, rgb, float, req_roi, stack, stack2d, stack3d' view = None def __init__(self, ips=None): if ips==None:ips = IPy.get_ips() self.dialog = None self.ips = ips def load(self, ips): return True def show(self): if self.view==None:return wx.ID_OK self.dialog = ParaDialog(IPy.get_window(), self.title) self.dialog.init_view(self.view, self.para, modal=True) return self.dialog.ShowModal() def run(self, ips, imgs, para = None):pass def check(self, ips): note = self.note if ips == None: IPy.alert('no image opened!') return False elif 'req_roi' in note and ips.roi == None: IPy.alert('no Roi found!') return False elif not 'all' in note: if ips.get_imgtype()=='rgb' and not 'rgb' in note: IPy.alert('do not surport rgb image') return False elif ips.get_imgtype()=='8-bit' and not '8-bit' in note: IPy.alert('do not surport 8-bit image') return False elif ips.get_imgtype()=='16-bit' and not '16-bit' in note: IPy.alert('do not surport 16-bit image') return False elif ips.get_imgtype()=='float' and not 'float' in note: IPy.alert('do not surport float image') return False elif sum([i in note for i in ('stack','stack2d','stack3d')])>0: if ips.get_nslices()==1: IPy.alert('stack required!') return False elif 'stack2d' in note and ips.is3d: IPy.alert('stack2d required!') return False elif 'stack3d' in note and not ips.is3d: IPy.alert('stack3d required!') return False return True def start(self, para=None): #print self.title, para if not self.check(self.ips):return if not self.load(self.ips):return if para!=None or self.show() == wx.ID_OK: if para == None:para = self.para win = TextLogManager.get('Recorder') if win!=None: win.append('%s>%s'%(self.title, para)) self.run(self.ips, self.ips.imgs, para) self.ips.update = 'pix' if self.dialog!=None:self.dialog.Destroy()
def get_para(title, view, para): pd = ParaDialog(curapp, title) pd.init_view(view, para) rst = pd.ShowModal() pd.Destroy() return rst