controls/FolderTree.py
branchpython3
changeset 3759 f713566d5d01
parent 3752 9f6f46dbe3ae
equal deleted inserted replaced
3758:bc71b19b45ff 3759:f713566d5d01
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
       
    26 from functools import cmp_to_key
       
    27 from operator import eq
    26 import os
    28 import os
    27 
    29 
    28 import wx
    30 import wx
    29 
    31 
    30 from util.BitmapLibrary import GetBitmap
    32 from util.BitmapLibrary import GetBitmap
    32 DRIVE, FOLDER, FILE = list(range(3))
    34 DRIVE, FOLDER, FILE = list(range(3))
    33 
    35 
    34 
    36 
    35 def sort_folder(x, y):
    37 def sort_folder(x, y):
    36     if x[1] == y[1]:
    38     if x[1] == y[1]:
    37         return cmp(x[0], y[0])
    39         return eq(x[0], y[0])
    38     elif x[1] != FILE:
    40     elif x[1] != FILE:
    39         return -1
    41         return -1
    40     else:
    42     else:
    41         return 1
    43         return 1
    42 
    44 
   133                         items.append((filename, FOLDER, children))
   135                         items.append((filename, FOLDER, children))
   134                     elif (self.CurrentFilter == "" or
   136                     elif (self.CurrentFilter == "" or
   135                           os.path.splitext(filename)[1] == self.CurrentFilter):
   137                           os.path.splitext(filename)[1] == self.CurrentFilter):
   136                         items.append((filename, FILE, None))
   138                         items.append((filename, FILE, None))
   137         if recursive:
   139         if recursive:
   138             items.sort(sort_folder)
   140             items.sort(key=cmp_to_key(sort_folder))
   139         return items
   141         return items
   140 
   142 
   141     def SetFilter(self, filter):
   143     def SetFilter(self, filter):
   142         self.CurrentFilter = filter
   144         self.CurrentFilter = filter
   143 
   145