controls/FolderTree.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 20:28:54 +0300
changeset 1813 c18adf359d21
parent 1780 c52d1460cea8
child 1881 091005ec69c4
permissions -rw-r--r--
lazy locale initialization

wx.Locale() can't be called without wx.App. So don't call it at
import. It makes PLCOpenEditor simpler.
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     7
# Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     8
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
     9
# See COPYING file for copyrights details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    10
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    14
# of the License, or (at your option) any later version.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    15
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    16
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    19
# GNU General Public License for more details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    20
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1219
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    24
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    25
import os
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    26
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    27
import wx
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    28
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    29
from util.BitmapLibrary import GetBitmap
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    30
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    31
DRIVE, FOLDER, FILE = range(3)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    32
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    33
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    34
def sort_folder(x, y):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    35
    if x[1] == y[1]:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    36
        return cmp(x[0], y[0])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    37
    elif x[1] != FILE:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    38
        return -1
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    39
    else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    40
        return 1
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    41
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    42
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    43
def splitpath(path):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    44
    head, tail = os.path.split(path)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    45
    if head == "":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    46
        return [tail]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    47
    elif tail == "":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    48
        return splitpath(head)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    49
    return splitpath(head) + [tail]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    50
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    51
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    52
class FolderTree(wx.Panel):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    53
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    54
    def __init__(self, parent, folder, filter=None, editable=True):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    55
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    56
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    57
        main_sizer = wx.BoxSizer(wx.VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    58
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    59
        self.Tree = wx.TreeCtrl(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    60
                                style=(wx.TR_HAS_BUTTONS |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    61
                                       wx.TR_SINGLE |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    62
                                       wx.SUNKEN_BORDER |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    63
                                       wx.TR_HIDE_ROOT |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    64
                                       wx.TR_LINES_AT_ROOT |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    65
                                       wx.TR_EDIT_LABELS))
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    66
        if wx.Platform == '__WXMSW__':
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    67
            self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnTreeItemExpanded, self.Tree)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    68
            self.Tree.Bind(wx.EVT_LEFT_DOWN, self.OnTreeLeftDown)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    69
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    70
            self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnTreeItemExpanded, self.Tree)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    71
        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed, self.Tree)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    72
        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnTreeBeginLabelEdit, self.Tree)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    73
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnTreeEndLabelEdit, self.Tree)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    74
        main_sizer.AddWindow(self.Tree, 1, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    75
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    76
        if filter is not None:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    77
            self.Filter = wx.ComboBox(self, style=wx.CB_READONLY)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    78
            self.Bind(wx.EVT_COMBOBOX, self.OnFilterChanged, self.Filter)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    79
            main_sizer.AddWindow(self.Filter, flag=wx.GROW)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    80
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    81
            self.Filter = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    82
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    83
        self.SetSizer(main_sizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    84
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    85
        self.Folder = folder
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    86
        self.Editable = editable
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    87
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    88
        self.TreeImageList = wx.ImageList(16, 16)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    89
        self.TreeImageDict = {}
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    90
        for item_type, bitmap in [(DRIVE, "tree_drive"),
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    91
                                  (FOLDER, "tree_folder"),
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    92
                                  (FILE, "tree_file")]:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    93
            self.TreeImageDict[item_type] = self.TreeImageList.Add(GetBitmap(bitmap))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    94
        self.Tree.SetImageList(self.TreeImageList)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    95
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    96
        self.Filters = {}
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    97
        if self.Filter is not None:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    98
            filter_parts = filter.split("|")
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    99
            for idx in xrange(0, len(filter_parts), 2):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   100
                if filter_parts[idx + 1] == "*.*":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   101
                    self.Filters[filter_parts[idx]] = ""
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   102
                else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   103
                    self.Filters[filter_parts[idx]] = filter_parts[idx + 1].replace("*", "")
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   104
                self.Filter.Append(filter_parts[idx])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   105
                if idx == 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   106
                    self.Filter.SetStringSelection(filter_parts[idx])
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   107
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   108
            self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   109
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   110
            self.CurrentFilter = ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   111
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   112
    def _GetFolderChildren(self, folderpath, recursive=True):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   113
        items = []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   114
        if wx.Platform == '__WXMSW__' and folderpath == "/":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   115
            for c in xrange(ord('a'), ord('z')):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   116
                drive = os.path.join("%s:\\" % chr(c))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   117
                if os.path.exists(drive):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   118
                    items.append((drive, DRIVE, self._GetFolderChildren(drive, False)))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   119
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   120
            try:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   121
                files = os.listdir(folderpath)
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   122
            except Exception:
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   123
                return []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   124
            for filename in files:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   125
                if not filename.startswith("."):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   126
                    filepath = os.path.join(folderpath, filename)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   127
                    if os.path.isdir(filepath):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   128
                        if recursive:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   129
                            children = len(self._GetFolderChildren(filepath, False))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   130
                        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   131
                            children = 0
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   132
                        items.append((filename, FOLDER, children))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   133
                    elif (self.CurrentFilter == "" or
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   134
                          os.path.splitext(filename)[1] == self.CurrentFilter):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   135
                        items.append((filename, FILE, None))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   136
        if recursive:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   137
            items.sort(sort_folder)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   138
        return items
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   139
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   140
    def SetFilter(self, filter):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   141
        self.CurrentFilter = filter
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   142
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   143
    def GetTreeCtrl(self):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   144
        return self.Tree
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   145
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   146
    def RefreshTree(self):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   147
        root = self.Tree.GetRootItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   148
        if not root.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   149
            root = self.Tree.AddRoot("")
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   150
        self.GenerateTreeBranch(root, self.Folder)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   151
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   152
    def GenerateTreeBranch(self, root, folderpath):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   153
        item, item_cookie = self.Tree.GetFirstChild(root)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   154
        for idx, (filename, item_type, children) in enumerate(self._GetFolderChildren(folderpath)):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   155
            if not item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   156
                item = self.Tree.AppendItem(root, filename, self.TreeImageDict[item_type])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   157
                if wx.Platform != '__WXMSW__':
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   158
                    item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   159
            elif self.Tree.GetItemText(item) != filename:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   160
                item = self.Tree.InsertItemBefore(root, idx, filename, self.TreeImageDict[item_type])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   161
            filepath = os.path.join(folderpath, filename)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   162
            if item_type != FILE:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   163
                if self.Tree.IsExpanded(item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   164
                    self.GenerateTreeBranch(item, filepath)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   165
                elif children > 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   166
                    self.Tree.SetItemHasChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   167
            item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   168
        to_delete = []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   169
        while item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   170
            to_delete.append(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   171
            item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   172
        for item in to_delete:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   173
            self.Tree.Delete(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   174
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   175
    def ExpandItem(self, item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   176
        self.GenerateTreeBranch(item, self.GetPath(item))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   177
        self.Tree.Expand(item)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   178
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   179
    def OnTreeItemActivated(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   180
        self.ExpandItem(event.GetItem())
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   181
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   182
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   183
    def OnTreeLeftDown(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   184
        item, flags = self.Tree.HitTest(event.GetPosition())
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   185
        if flags & wx.TREE_HITTEST_ONITEMBUTTON and not self.Tree.IsExpanded(item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   186
            self.ExpandItem(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   187
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   188
            event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   189
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   190
    def OnTreeItemExpanded(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   191
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   192
        self.GenerateTreeBranch(item, self.GetPath(item))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   193
        event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   194
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   195
    def OnTreeItemCollapsed(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   196
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   197
        self.Tree.DeleteChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   198
        self.Tree.SetItemHasChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   199
        event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   200
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   201
    def OnTreeBeginLabelEdit(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   202
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   203
        if self.Editable and not self.Tree.ItemHasChildren(item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   204
            event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   205
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   206
            event.Veto()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   207
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   208
    def OnTreeEndLabelEdit(self, event):
1219
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   209
        new_name = event.GetLabel()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   210
        if new_name != "":
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   211
            old_filepath = self.GetPath(event.GetItem())
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   212
            new_filepath = os.path.join(os.path.split(old_filepath)[0], new_name)
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   213
            if new_filepath != old_filepath:
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   214
                if not os.path.exists(new_filepath):
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   215
                    os.rename(old_filepath, new_filepath)
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   216
                    event.Skip()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   217
                else:
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   218
                    message = wx.MessageDialog(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   219
                                               _("File '%s' already exists!") % new_name,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   220
                                               _("Error"), wx.OK | wx.ICON_ERROR)
1219
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   221
                    message.ShowModal()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   222
                    message.Destroy()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   223
                    event.Veto()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   224
        else:
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   225
            event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   226
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   227
    def OnFilterChanged(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   228
        self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   229
        self.RefreshTree()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   230
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   231
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   232
    def _SelectItem(self, root, parts):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   233
        if len(parts) == 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   234
            self.Tree.SelectItem(root)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   235
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   236
            item, item_cookie = self.Tree.GetFirstChild(root)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   237
            while item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   238
                if self.Tree.GetItemText(item) == parts[0]:
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   239
                    if self.Tree.ItemHasChildren(item) and \
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   240
                       not self.Tree.IsExpanded(item):
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   241
                        self.Tree.Expand(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   242
                        wx.CallAfter(self._SelectItem, item, parts[1:])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   243
                    else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   244
                        self._SelectItem(item, parts[1:])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   245
                    return
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   246
                item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   247
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   248
    def SetPath(self, path):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   249
        if path.startswith(self.Folder):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   250
            root = self.Tree.GetRootItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   251
            if root.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   252
                relative_path = path.replace(os.path.join(self.Folder, ""), "")
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   253
                self._SelectItem(root, splitpath(relative_path))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   254
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   255
    def GetPath(self, item=None):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   256
        if item is None:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   257
            item = self.Tree.GetSelection()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   258
        if item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   259
            filepath = self.Tree.GetItemText(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   260
            parent = self.Tree.GetItemParent(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   261
            while parent.IsOk() and parent != self.Tree.GetRootItem():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   262
                filepath = os.path.join(self.Tree.GetItemText(parent), filepath)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   263
                parent = self.Tree.GetItemParent(parent)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   264
            return os.path.join(self.Folder, filepath)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   265
        return self.Folder