import  wx.lib.filebrowsebutton as filebrowse
import os.path

class DirBrowseButton2(filebrowse.DirBrowseButton):
    """ Same as DirBrowseButton except after the first time, 
    browsing starts from the last gallery.
    """
    
    __init__ = filebrowse.DirBrowseButton.__init__
    
    
    def OnBrowse(self, ev = None):
        """ super class dialog always starts from self.startDirectory.
        Temporarily reset this variable so the last gallery will be used.
        """
        oldStartDirectory = self.startDirectory
        startFrom = self.GetValue()
        if not(startFrom and os.path.exists(startFrom)):
            startFrom = self.startDirectory
        self.startDirectory = startFrom
        
        filebrowse.DirBrowseButton.OnBrowse(self, ev)
        
        self.startDirectory = oldStartDirectory

