Beispiel #1
0
    def OnExtraParamButton(self, evt=None):
        confdic = C.readConfig()

        dlg = extrapanel.ExtraDialog(self, self.listRef, confdic, outdir=self.extra_parms.get('outdir'), refwave=str(self.extra_parms.get('refwave')))
        val = dlg.ShowModal()

        self.outdir = self.refwave = self.zacuur = None
        if val == wx.ID_OK:
            if not (dlg.outdir_cb.GetValue()):
                self.extra_parms['outdir'] = dlg.outdir
                C.saveConfig(outdir=dlg.outdir)
            if hasattr(dlg, 'refwave_cb') and not (dlg.refwave_cb.GetValue()):
                refwave = dlg.refwave_choice.GetStringSelection()
                try:
                    refwave = eval(refwave)
                except (TypeError, ValueError):
                    pass
                self.extra_parms['refwave'] = refwave

            if hasattr(dlg, 'tseriesListChoice'):
                self.extra_parms['tseries4wave'] = dlg.tseriesListChoice.GetStringSelection()
                
            self.extra_parms['zacuur'] = eval(dlg.accurListChoice.GetStringSelection())
            C.saveConfig(accur=self.extra_parms['zacuur'])

            self.extra_parms['max_shift'] = eval(dlg.maxshift_text.GetValue())
            C.saveConfig(max_shift=self.extra_parms['max_shift'])

        dlg.Destroy()
Beispiel #2
0
 def OnOutFormatChosen(self, evt=None):
     outext = self.outextch.GetStringSelection()
     if outext == self.outext_choices[-1] and not imgio.bioformatsIO.HAS_JDK:
         listbox.imgio_dialog('Writing the file format (%s) requres Java Development Kit (JDK)' % outext)
         confdic = C.readConfig()
         outext = confdic.get('format', aligner.WRITABLE_FORMATS[0])
         self.outextch.SetStringSelection(outext)
    def OnChooseTargetFiles(self, evt):
        """
        set reference files
        """
        confdic = C.readConfig()
        wildcard = confdic.get('lastwildcard', FILTER)

        ll = self.listTgt

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose %s files' % listtype, defaultDir=self.lastpath, style=wx.FD_MULTIPLE)
            
        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, basestring):
                fns = [fns]

            ll.addFiles(fns)
            
            self.lastpath = os.path.dirname(fns[0])
            C.saveConfig(lastwildcard=wildcard, lastpath=self.lastpath)

            self.checkGo()
    def OnChooseReferenceFile(self, evt):
        """
        set reference files
        """
        confdic = C.readConfig()
        wildcard = confdic.get('lastwildcard', FILTER)

        ll = self.listRef
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, direc=self.lastpath, wildcard=wildcard, multiple=False)
        else:
            dlg = wx.FileDialog(self, 'Choose %sfiles'  % listtype, defaultDir=self.lastpath, wildcard=wildcard)
            
        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()

            if not fn:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat

            ll.clearAll()
            ll.addFiles([fn])
            
            self.lastpath = os.path.dirname(fn)
            C.saveConfig(lastwildcard=wildcard, lastpath=self.lastpath)

            self.checkGo()
Beispiel #5
0
 def OnOutFormatChosen(self, evt=None):
     outext = self.outextch.GetStringSelection()
     if outext == self.outext_choices[-1] and not imgio.bioformatsIO.HAS_JDK:
         listbox.imgio_dialog(
             'Writing the file format (%s) requres Java Development Kit (JDK)'
             % outext)
         confdic = C.readConfig()
         outext = confdic.get('format', aligner.WRITABLE_FORMATS[0])
         self.outextch.SetStringSelection(outext)
Beispiel #6
0
    def OnChooseImgFiles(self, evt, listtype='ref'):
        """
        set reference files
        """
        confdic = C.readConfig()
        if listtype == 'ref':
            ll = self.listRef
            wildcard = confdic.get('lastwildcardref', FILTER)
        else:
            ll = self.listTgt
            wildcard = confdic.get('lastwildcardtgt', FILTER)

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self,
                                'Choose %s files' % listtype,
                                defaultDir=self.lastpath,
                                style=wx.FD_MULTIPLE)

        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, six.string_types):  #str):
                fns = [fns]

            ll.addFiles(fns)
            if listtype != 'ref':
                if any([nw > 5 for nw in ll.nws
                        ]) and self.outextch.GetStringSelection() == (
                            os.path.extsep + aligner.WRITABLE_FORMATS[1]):
                    self.outextch.SetStringSelection(
                        os.path.extsep + aligner.WRITABLE_FORMATS[0])
                    G.openMsg(
                        parent=self,
                        msg=
                        'Since number of wavelength in some image file is more than 5,\nthe output file format was changed to tiff',
                        title="Output file format change")

            self.lastpath = os.path.dirname(fns[0])
            if listtype == 'ref':
                C.saveConfig(lastwildcardref=wildcard, lastpath=self.lastpath)
            else:
                C.saveConfig(lastwildcardtgt=wildcard, lastpath=self.lastpath)

            self.checkGo()
Beispiel #7
0
    def onChooseFile(self, evnt):
        """
        get image file
        call self.view()
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.view(fn)

        C.saveConfig(lastpath=os.path.dirname(fn))
Beispiel #8
0
    def onChooseOriginalFile(self, ev):
        """
        get image file
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        wildcard = confdic.get('localfnpat', '*')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath, wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.originalFileTxt.SetValue(fn)

        C.saveConfig(lastpath=os.path.dirname(fn), localfnpat=dlg.fnPat)
Beispiel #9
0
    def onChooseFile(self, evnt):
        """
        get image file
        call self.view()
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.view(fn)

        C.saveConfig(lastpath=os.path.dirname(fn))
Beispiel #10
0
    def onChooseOriginalFile(self, ev):
        """
        get image file
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        wildcard = confdic.get('localfnpat', '*')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath, wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.originalFileTxt.SetValue(fn)

        C.saveConfig(lastpath=os.path.dirname(fn), localfnpat=dlg.fnPat)
Beispiel #11
0
    def OnChooseImgFiles(self, evt, listtype='ref'):
        """
        set reference files
        """
        confdic = C.readConfig()
        if listtype == 'ref':
            ll = self.listRef
            wildcard = confdic.get('lastwildcardref', FILTER)
        else:
            ll = self.listTgt
            wildcard = confdic.get('lastwildcardtgt', FILTER)

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose %s files' % listtype, defaultDir=self.lastpath, style=wx.FD_MULTIPLE)
            
        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, six.string_types):
                fns = [fns]

            ll.addFiles(fns)
            if listtype != 'ref':
                if any([nw > 5 for nw in ll.nws]) and self.outextch.GetStringSelection() == (os.path.extsep + aligner.WRITABLE_FORMATS[1]):
                    self.outextch.SetStringSelection(os.path.extsep + aligner.WRITABLE_FORMATS[0])
                    G.openMsg(parent=self, msg='Since number of wavelength in some image file is more than 5,\nthe output file format was changed to tiff', title="Output file format change")
            
            self.lastpath = os.path.dirname(fns[0])
            if listtype == 'ref':
                C.saveConfig(lastwildcardref=wildcard, lastpath=self.lastpath)
            else:
                C.saveConfig(lastwildcardtgt=wildcard, lastpath=self.lastpath)

            self.checkGo()
Beispiel #12
0
    def makePanel(self):
        # config
        confdic = C.readConfig()
        self.lastpath = confdic.get('lastpath', '')
        self.extra_parms = {}

        # draw / arrange
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # ---- reference ------
        # \n
        box = G.newSpaceV(sizer)
        self.refAddButton = G.makeButton(self, box, lambda ev:self.OnChooseImgFiles(ev,'ref'), title='Reference files', tip='', enable=True)

        self.refClearButton = G.makeButton(self, box, lambda ev:self.clearSelected(ev, 'ref'), title='Clear selected', tip='', enable=False)

        parmSuffixLabel, self.parm_suffix_txt = G.makeTxtBox(self, box, 'Suffix', defValue=confdic.get('parm_suffix_txt', ''), tip='A suffix for the file extention for the chromagnon file name', sizeX=100)

        extraButton = G.makeButton(self, box, self.OnExtraParamButton, title='Extra parameters')
        
        # ---- target ------

        refsize = self.refAddButton.GetSize()[0] + self.refClearButton.GetSize()[0] + parmSuffixLabel.GetSize()[0] + self.parm_suffix_txt.GetSize()[0] + extraButton.GetSize()[0]
        G.newSpaceH(box, LISTSIZE_X+LISTSPACE-refsize)

        self.tgtAddButton = G.makeButton(self, box, lambda ev:self.OnChooseImgFiles(ev,'target'), title='Target files', tip='', enable=True)
        
        self.tgtClearButton = G.makeButton(self, box, lambda ev:self.clearSelected(ev, 'tareget'), title='Clear selected', tip='', enable=False)

        self.cutoutCb = G.makeCheck(self, box, "crop margins", tip='', defChecked=bool(confdic.get('cutout', True)))

        label, self.img_suffix_txt = G.makeTxtBox(self, box, 'Suffix', defValue=confdic.get('img_suffix_txt', aligner.IMG_SUFFIX), tip='A suffix for the file name', sizeX=100)

        self.outext_choices = [os.path.extsep + form for form in aligner.WRITABLE_FORMATS]
        label, self.outextch = G.makeListChoice(self, box, '', self.outext_choices, defValue=confdic.get('format', aligner.WRITABLE_FORMATS[0]), tip='tif: ImageJ format, dv: DeltaVision format, ome.tif: OME-tif format (slow)', targetFunc=self.OnOutFormatChosen)
        if not self.outextch.GetStringSelection():
            self.outextch.SetSelection(0)
        
        ## --- list ----
        # \n
        box = G.newSpaceV(sizer)
        
        self.listRef = listbox.FileListCtrl(self, wx.NewId(),
                                 style=wx.LC_REPORT
                                 | wx.BORDER_NONE,
                                 #| wx.LC_SORT_ASCENDING,
                                 size=(LISTSIZE_X, LIST_Y)
                                 )
        box.Add(self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, lambda ev:self.OnItemSelected(ev, 'reference'), self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected, self.listRef)
        self.listRef.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
        
        G.newSpaceH(box, LISTSPACE)

        self.listTgt = listbox.FileListCtrl(self, wx.NewId(),
                                 style=wx.LC_REPORT
                                 | wx.BORDER_NONE,
                                # | wx.LC_SORT_ASCENDING,
        size=(LISTSIZE_X, LIST_Y)
                                 )
        box.Add(self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, lambda ev:self.OnItemSelected(ev, 'target'), self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected, self.listTgt)
        self.listTgt.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

        self.listRef.setDefaultFileLoadFunc(self._load_func)
        self.listTgt.setDefaultFileLoadFunc(self._load_func)
        #------- execute ------

        # \n
        box = G.newSpaceV(sizer)
        
        self.goButton = G.makeToggleButton(self, box, self.OnGo, title='Run all', tip='', enable=False)

        if sys.platform.startswith('win'):
            ft = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        elif sys.platform.startswith('linux'):
            ft = wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        else:
            ft = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        self.goButton.SetFont(ft)
        self.listRef.setOnDrop(self.goButton.Enable, 1)
        self.listTgt.setOnDrop(self.goButton.Enable, 1)
        
        self.averageCb = G.makeCheck(self, box, "average references  ", tip='Multiple reference images are maximum intensity projected to make a single high SNR image for shift calculation.', defChecked=bool(confdic.get('average', False)))

        self.localChoice = LOCAL_CHOICE
        label, self.localListChoice = G.makeListChoice(self, box, 'Local align', self.localChoice, defValue=confdic.get('local', 'None'), targetFunc=self.OnLocalListChose)

        self.min_pxls_label, self.min_pxls_choice = G.makeListChoice(self, box, 'min window size', af.MIN_PXLS_YXS, defValue=confdic.get('min_pxls_yx', af.MIN_PXLS_YXS[1]), tip='Minimum number of pixel to divide as elements of local alignment')

        self.OnLocalListChose()

        self.progress = wx.Gauge(self, -1, 100, size=(100,-1))
        box.Add(self.progress)
        
        self.label = G.makeTxt(self, box, ' ')

        _col_sizes=[(key, val) for key, val in listbox.__dict__.items() if key.startswith('SIZE_COL')]
        _col_sizes.sort()

        LISTSIZE_X2 = sum([val for key, val in _col_sizes[:3]])
        LIST_Y2 = 30
        
        #------ flat fielder --------

        self.flatButton = wx.Button(self, -1, 'Open Flat Fielder')
        self.flatButton.SetToolTip(wx.ToolTip('Open a graphical interphase to flat field images'))

        flatsize = self.goButton.GetSize()[0] + self.averageCb.GetSize()[0] + label.GetSize()[0] + self.localListChoice.GetSize()[0] + self.min_pxls_label.GetSize()[0] + self.min_pxls_choice.GetSize()[0] + self.progress.GetSize()[0] + self.flatButton.GetSize()[0] + 5

        G.newSpaceH(box, FRAMESIZE_X-flatsize)

        box.Add(self.flatButton)
        frame = self.GetTopLevelParent()
        frame.Bind(wx.EVT_BUTTON, self.onFlatFielder, self.flatButton)
        
        # ----- finishing -----
        self.Layout()
        self.parent.Layout()

        self.checkGo()
Beispiel #13
0
    def OnGo(self, ev=None):
        """
        run or cancel the alignment program

        The actual sequence of processes is written in threads.ThreadWithExc.run()
        """
        if self.goButton.GetValue():
            
            if not self.listRef.columnkeys:
                return

            fns = [os.path.join(*self.listRef.getFile(index)[:2]) for index in self.listRef.columnkeys]
            targets = [os.path.join(*self.listTgt.getFile(index)[:2]) for index in self.listTgt.columnkeys]

            # other parameters
            #initguess = ''
            confdic = C.readConfig()

            form = self.outextch.GetStringSelection()
            if not form:
                self.quit('Please select the output file format next to the Suffix text box', title="The format type is missing")
                return

            # check wavelengths
            waves1 = [list(map(int, self.listRef.getFile(index)[2].split(','))) for index in self.listRef.columnkeys]
            waves2 = [list(map(int, self.listTgt.getFile(index)[2].split(','))) for index in self.listTgt.columnkeys]
            nts = all([t == 1 for t in self.listRef.nts])
            ids = af.checkWaves(waves1, waves2)
            if ids is not None and nts:
                for i, listbox in zip(ids, (self.listRef, self.listTgt)):
                    listbox.SetItemTextColour(i, 'purple')
                    #listbox.SetBackGroundColour(i, 'gray')
                msg = 'Less than two Common wavelengths were found at least in %s and %s\n\nThe program will not run.' % (self.listRef.getFile(ids[0])[1], self.listTgt.getFile(ids[1])[1])
                self.quit(msg, title='Error in input files')
                return
            
            # averaging
            if self.averageCb.GetValue() and len(fns) > 1:
                if any([waves1[0] != ws1 for ws1 in waves1[1:]]):
                    self.quit('There are inconsistency in channel composition in the reference files', title="Reference files are not appropriate for averaging")
                    return
                
                try:
                    self.label.SetLabel('averaging...')
                    self.label.SetForegroundColour('red')
                    wx.Yield()
                    ave_fn = af.averageImage(fns, ext=form)
                except Exception as e:
                    self.quit(e.args[0], title="Reference files are not appropriate for averaging")
                    return         
                self.listRef.clearAll()
                self.listRef.addFile(ave_fn)
                fns = [ave_fn]
            elif self.averageCb.GetValue() and len(fns) == 1:
                self.averageCb.SetValue(0)


            accur = self.extra_parms.get('zacuur', confdic.get('accur', aligner.ACCUR_CHOICE[0]))
            if accur in aligner.ACCUR_CHOICE_DIC:
                accur = aligner.ACCUR_CHOICE_DIC[accur]
            
            # parameters
            parms = [self.cutoutCb.GetValue(),
                     self.extra_parms.get('outdir'),#initguess,
                     self.localListChoice.GetStringSelection(),
                     self.extra_parms.get('refwave'), #None, #self.maxShift.GetValue(),
                     int(accur),#self.extra_parms.get('zacuur', confdic.get('accur', aligner.ACCUR_CHOICE[0]))), #self.accurListChoice.GetStringSelection(),
                    self.parm_suffix_txt.GetValue(),
                        self.img_suffix_txt.GetValue(),
                     self.extra_parms.get('tseries4wave', 'time'),#[nt for nt in self.listRef.nts], # copy
                     form,
                     int(self.min_pxls_choice.GetStringSelection()),
                         self.extra_parms.get('max_shift', af.MAX_SHIFT)] 

            #print(parms[4], confdic.get('accur', aligner.ACCUR_CHOICE[0]), type(parms[4]))
            # check the user-inputs
            old="""
            try:
                parms[3] = float(parms[3])
            except ValueError:
                G.openMsg(parent=self, msg='The default value (%.2f um) will be used' % af.MAX_SHIFT, title="The value for max shift allowed is missing")
                parms[3] = af.MAX_SHIFT
                self.maxShift.SetValue(str(parms[3]))"""
                        
            if not parms[6]:
                G.openMsg(parent=self, msg='The default suffix will be used', title="The file suffix is missing")
                parms[6] = aligner.IMG_SUFFIX
                self.img_suffix_txt.SetValue(parms[6])

            # save current settings
            C.saveConfig(cutout=parms[0], local=parms[2], accur=parms[4], parm_suffix_txt=parms[5], img_suffix_txt=parms[6], format=parms[8], min_pxls_yx=parms[9])
            #C.saveConfig(cutout=parms[0], local=parms[2], maxShift=parms[3], accur=parms[4], parm_suffix_txt=parms[5], img_suffix_txt=parms[6], format=parms[8], min_pxls_yx=parms[9])

            # run program
            gui = threads.GUImanager(self, __name__)
            
            self.th = threads.ThreadWithExc(gui, self.localChoice, fns, targets, parms)
            self.th.start()

        else:
            tid = self.th._get_my_tid()
            threads.async_raise(tid, threads.MyError)
Beispiel #14
0
    def makePanel(self, tif=False):
        # config
        confdic = C.readConfig()
        self.lastpath = confdic.get('lastpath', '')

        # draw / arrange
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # ---- reference ------
        # \n
        box = G.newSpaceV(sizer)
        self.refAddButton = G.makeButton(
            self,
            box,
            lambda ev: self.OnChooseImgFiles(ev, 'ref'),
            title='Reference files',
            tip='',
            enable=True)

        self.refClearButton = G.makeButton(
            self,
            box,
            lambda ev: self.clearSelected(ev, 'ref'),
            title='Clear selected',
            tip='',
            enable=False)

        maxShiftLabel, self.maxShift = G.makeTxtBox(
            self,
            box,
            'max shift allowed (um)',
            defValue=confdic.get('maxShift', af.MAX_SHIFT),
            tip='maximum possible shift of each channel',
            sizeX=50)

        parmSuffixLabel, self.parm_suffix_txt = G.makeTxtBox(
            self,
            box,
            'Suffix',
            defValue=confdic.get('parm_suffix_txt', ''),
            tip='A suffix for the file extention for the chromagnon file name',
            sizeX=100)

        #self.refwave = G.makeButton(self, box, lambda ev:self.clearSelected(ev, 'ref'), title='Ref channel', tip='', enable=True)
        # ---- target ------

        refsize = self.refAddButton.GetSize()[0] + self.refClearButton.GetSize(
        )[0] + parmSuffixLabel.GetSize()[0] + self.parm_suffix_txt.GetSize(
        )[0] + maxShiftLabel.GetSize()[0] + self.maxShift.GetSize()[0]
        G.newSpaceH(box, LISTSIZE_X + LISTSPACE - refsize)

        self.tgtAddButton = G.makeButton(
            self,
            box,
            lambda ev: self.OnChooseImgFiles(ev, 'target'),
            title='Target files',
            tip='',
            enable=True)

        self.tgtClearButton = G.makeButton(
            self,
            box,
            lambda ev: self.clearSelected(ev, 'tareget'),
            title='Clear selected',
            tip='',
            enable=False)

        self.cutoutCb = G.makeCheck(self,
                                    box,
                                    "crop margins",
                                    tip='',
                                    defChecked=bool(confdic.get(
                                        'cutout', True)))

        label, self.img_suffix_txt = G.makeTxtBox(
            self,
            box,
            'Suffix',
            defValue=confdic.get('img_suffix_txt', aligner.IMG_SUFFIX),
            tip='A suffix for the file name',
            sizeX=100)

        self.outext_choices = [
            os.path.extsep + form for form in aligner.WRITABLE_FORMATS
        ]
        label, self.outextch = G.makeListChoice(
            self,
            box,
            '',
            self.outext_choices,
            defValue=confdic.get('format', aligner.WRITABLE_FORMATS[0]),
            tip=
            'tif: ImageJ format, dv: DeltaVision format, ome.tif: OME-tif format (slow)',
            targetFunc=self.OnOutFormatChosen)
        if not self.outextch.GetStringSelection():
            self.outextch.SetSelection(0)

        ## --- list ----
        # \n
        box = G.newSpaceV(sizer)

        self.listRef = listbox.FileListCtrl(
            self,
            wx.NewId(),
            style=wx.LC_REPORT
            | wx.BORDER_NONE,
            #| wx.LC_SORT_ASCENDING,
            size=(LISTSIZE_X, LIST_Y))
        box.Add(self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED,
                  lambda ev: self.OnItemSelected(ev, 'reference'),
                  self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected,
                  self.listRef)
        self.listRef.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

        G.newSpaceH(box, LISTSPACE)

        self.listTgt = listbox.FileListCtrl(
            self,
            wx.NewId(),
            style=wx.LC_REPORT
            | wx.BORDER_NONE,
            # | wx.LC_SORT_ASCENDING,
            size=(LISTSIZE_X, LIST_Y))
        box.Add(self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED,
                  lambda ev: self.OnItemSelected(ev, 'target'), self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected,
                  self.listTgt)
        self.listTgt.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

        self.listRef.setDefaultFileLoadFunc(self._load_func)
        self.listTgt.setDefaultFileLoadFunc(self._load_func)
        #------- execute ------

        # \n
        box = G.newSpaceV(sizer)

        self.goButton = G.makeToggleButton(self,
                                           box,
                                           self.OnGo,
                                           title='Run all',
                                           tip='',
                                           enable=False)

        if sys.platform.startswith('win'):
            ft = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.NORMAL,
                         wx.FONTWEIGHT_BOLD)
        elif sys.platform.startswith('linux'):
            ft = wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.NORMAL,
                         wx.FONTWEIGHT_BOLD)
        else:
            ft = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.NORMAL,
                         wx.FONTWEIGHT_BOLD)
        self.goButton.SetFont(ft)
        self.listRef.setOnDrop(self.goButton.Enable, 1)
        self.listTgt.setOnDrop(self.goButton.Enable, 1)

        self.zmaglabel, self.zmagch = G.makeListChoice(
            self,
            box,
            '  Z mag',
            aligner.ZMAG_CHOICE,
            defValue=confdic.get('Zmag', aligner.ZMAG_CHOICE[0]),
            tip=
            'if "Auto" is chosen, then z mag calculation is done if the z stack contains more than 30 Z sections with a sufficient contrast'
        )

        self.localChoice = LOCAL_CHOICE
        label, self.localListChoice = G.makeListChoice(
            self,
            box,
            'Local align',
            self.localChoice,
            defValue=confdic.get('local', 'None'),
            targetFunc=self.OnLocalListChose)

        self.min_pxls_label, self.min_pxls_choice = G.makeListChoice(
            self,
            box,
            'min window size',
            af.MIN_PXLS_YXS,
            defValue=confdic.get('min_pxls_yx', af.MIN_PXLS_YXS[1]),
            tip=
            'Minimum number of pixel to divide as elements of local alignment')

        self.OnLocalListChose()

        self.progress = wx.Gauge(self, -1, 100, size=(100, -1))
        box.Add(self.progress)

        self.label = G.makeTxt(self, box, ' ')

        _col_sizes = [(key, val) for key, val in listbox.__dict__.items()
                      if key.startswith('SIZE_COL')]
        _col_sizes.sort()

        LISTSIZE_X2 = sum([val for key, val in _col_sizes[:3]])
        LIST_Y2 = 30

        #------ flat fielder --------

        self.flatButton = wx.Button(self, -1, 'Open Flat Fielder')
        self.flatButton.SetToolTip(
            wx.ToolTip('Open a graphical interphase to flat field images'))

        flatsize = self.goButton.GetSize()[0] + self.zmaglabel.GetSize(
        )[0] + self.zmagch.GetSize()[0] + label.GetSize(
        )[0] + self.localListChoice.GetSize()[0] + self.min_pxls_label.GetSize(
        )[0] + self.min_pxls_choice.GetSize()[0] + self.progress.GetSize(
        )[0] + self.flatButton.GetSize()[0] + 5

        G.newSpaceH(box, FRAMESIZE_X - flatsize)

        box.Add(self.flatButton)
        frame = self.GetTopLevelParent()
        frame.Bind(wx.EVT_BUTTON, self.onFlatFielder, self.flatButton)

        # ----- finishing -----
        self.Layout()
        self.parent.Layout()

        self.checkGo()
    def makePanel(self, tif=False):
        # config
        confdic = C.readConfig()
        self.lastpath = confdic.get('lastpath', '')

        # draw / arrange
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # ---- reference ------
        # \n
        box = G.newSpaceV(sizer)
        self.refAddButton = G.makeButton(self, box, self.OnChooseReferenceFile, title='Reference file', tip='', enable=True)

        self.refClearButton = G.makeButton(self, box, lambda ev:self.clearSelected(ev, 'ref'), title='Clear selected', tip='', enable=False)

        flatSuffixLabel, self.flat_suffix_txt = G.makeTxtBox(self, box, 'Suffix', defValue=confdic.get('flat_suffix_txt', ''), tip='A suffix before the file extention for the .flat file name', sizeX=100)
        
        #------- execute ------

        self.goButton = wx.ToggleButton(self, -1, 'Run all')

        if sys.platform.startswith('win'):
            ft = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        elif sys.platform.startswith('linux'):
            ft = wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        else:
            ft = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        self.goButton.SetFont(ft)
        #self.goButton.SetToolTipString('Open a graphical interphase to flat field images')
        gosize = self.refAddButton.GetSize()[0] + self.refClearButton.GetSize()[0] + self.goButton.GetSize()[0] + flatSuffixLabel.GetSize()[0] + self.flat_suffix_txt.GetSize()[0]

        G.newSpaceH(box, LISTSIZE_X-gosize)

        box.Add(self.goButton)
        frame = self.GetTopLevelParent()
        frame.Bind(wx.EVT_TOGGLEBUTTON, self.OnGo, self.goButton)

        
        ## --- list reference ----
        # \n
        box = G.newSpaceV(sizer)

        
        self.listRef = listbox.FileListCtrl(self, wx.NewId(),
                                 style=wx.LC_REPORT
                                 | wx.BORDER_NONE
                                 | wx.LC_SORT_ASCENDING,
                                 size=(LISTSIZE_X, LIST_Y2),
                                 multiple=False)
        box.Add(self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, lambda ev:self.OnItemSelected(ev, 'reference'), self.listRef)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected, self.listRef)
        self.listRef.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

        flatfn = confdic.get('flatfn', '_FLAT')
        if os.path.isfile(flatfn):
            self.listRef.addFile(flatfn)
        
        self.listRef.setDefaultFileLoadFunc(self._load_func)
        # ---- list target ------

        # \n
        box = G.newSpaceV(sizer)

        self.tgtAddButton = G.makeButton(self, box, self.OnChooseTargetFiles, title='Target files', tip='', enable=True)
        
        self.tgtClearButton = G.makeButton(self, box, lambda ev:self.clearSelected(ev, 'tareget'), title='Clear selected', tip='', enable=False)

        label, self.flatimg_suffix_txt = G.makeTxtBox(self, box, 'Suffix', defValue=confdic.get('flatimg_suffix_txt', '_'+flatConv.EXT.upper()), tip='A suffix for the output file name', sizeX=100)

        choices = [os.path.extsep + form for form in aligner.WRITABLE_FORMATS]
        label, self.outextch = G.makeListChoice(self, box, '', choices, defValue=confdic.get('flat_format', aligner.WRITABLE_FORMATS[0]), tip='Choose image file formats; for reading with ImageJ, dv is recommended.')
        
        # \n
        box = G.newSpaceV(sizer)
        
        self.listTgt = listbox.FileListCtrl(self, wx.NewId(),
                                 style=wx.LC_REPORT
                                 | wx.BORDER_NONE
                                 | wx.LC_SORT_ASCENDING,
                                size=(LISTSIZE_X, LIST_Y)
                                 )
        box.Add(self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, lambda ev:self.OnItemSelected(ev, 'target'), self.listTgt)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemSelected, self.listTgt)
        self.listTgt.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

        self.listTgt.setDefaultFileLoadFunc(self._load_func)
        # ---- Drop befavior ----
        self.listRef.setOnDrop(self.checkGo, 1)#goButton.Enable, 1)
        self.listTgt.setOnDrop(self.checkGo, 1)#goButton.Enable, 1)

        
        # ---- Output ------

        # \n
        box = G.newSpaceV(sizer)
        self.label = G.makeTxt(self, box, ' ')


        # ----- finishing -----
        self.Layout()
        #self.parent.Layout()

        self.checkGo()