controls/FolderTree.py
author Edouard Tisserant <edouard@beremiz.fr>
Tue, 23 Jul 2024 15:30:04 +0200
changeset 3998 0145c60b9560
parent 3759 f713566d5d01
permissions -rw-r--r--
MQTT: WIP, PLC starts even if MQTT client can't connect broker, and publish+subscribe again when reconnecting.
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
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    25
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
    26
from functools import cmp_to_key
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
    27
from operator import eq
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    28
import os
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    29
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    30
import wx
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    31
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    32
from util.BitmapLibrary import GetBitmap
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    33
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3636
diff changeset
    34
DRIVE, FOLDER, FILE = list(range(3))
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    35
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    37
def sort_folder(x, y):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    38
    if x[1] == y[1]:
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
    39
        return eq(x[0], y[0])
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    40
    elif x[1] != FILE:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    41
        return -1
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    42
    else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    43
        return 1
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    44
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    46
def splitpath(path):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    47
    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
    48
    if head == "":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    49
        return [tail]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    50
    elif tail == "":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    51
        return splitpath(head)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    52
    return splitpath(head) + [tail]
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    53
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    54
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    55
class FolderTree(wx.Panel):
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
    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
    58
        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
    59
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    60
        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
    61
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    62
        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
    63
                                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
    64
                                       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
    65
                                       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
    66
                                       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
    67
                                       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
    68
                                       wx.TR_EDIT_LABELS))
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    69
        if wx.Platform == '__WXMSW__':
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_ACTIVATED, 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.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
    72
        else:
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_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
    74
        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
    75
        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
    76
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnTreeEndLabelEdit, self.Tree)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2432
diff changeset
    77
        main_sizer.Add(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
    78
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    79
        if filter is not None:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    80
            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
    81
            self.Bind(wx.EVT_COMBOBOX, self.OnFilterChanged, self.Filter)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2432
diff changeset
    82
            main_sizer.Add(self.Filter, flag=wx.GROW)
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    83
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    84
            self.Filter = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    85
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    86
        self.SetSizer(main_sizer)
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.Folder = folder
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    89
        self.Editable = editable
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    90
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    91
        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
    92
        self.TreeImageDict = {}
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    93
        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
    94
                                  (FOLDER, "tree_folder"),
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    95
                                  (FILE, "tree_file")]:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    96
            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
    97
        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
    98
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
    99
        self.Filters = {}
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   100
        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
   101
            filter_parts = filter.split("|")
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3636
diff changeset
   102
            for idx in range(0, len(filter_parts), 2):
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   103
                if filter_parts[idx + 1] == "*.*":
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   104
                    self.Filters[filter_parts[idx]] = ""
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   105
                else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   106
                    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
   107
                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
   108
                if idx == 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   109
                    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
   110
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   111
            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
   112
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   113
            self.CurrentFilter = ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   114
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   115
    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
   116
        items = []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   117
        if wx.Platform == '__WXMSW__' and folderpath == "/":
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3636
diff changeset
   118
            for c in range(ord('a'), ord('z')):
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   119
                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
   120
                if os.path.exists(drive):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   121
                    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
   122
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   123
            try:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   124
                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
   125
            except Exception:
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   126
                return []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   127
            for filename in files:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   128
                if not filename.startswith("."):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   129
                    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
   130
                    if os.path.isdir(filepath):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   131
                        if recursive:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   132
                            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
   133
                        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   134
                            children = 0
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   135
                        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
   136
                    elif (self.CurrentFilter == "" or
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   137
                          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
   138
                        items.append((filename, FILE, None))
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   139
        if recursive:
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   140
            items.sort(key=cmp_to_key(sort_folder))
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   141
        return items
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 SetFilter(self, filter):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   144
        self.CurrentFilter = filter
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 GetTreeCtrl(self):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   147
        return self.Tree
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   148
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   149
    def RefreshTree(self):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   150
        root = self.Tree.GetRootItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   151
        if not root.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   152
            root = self.Tree.AddRoot("")
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   153
        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
   154
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   155
    def GenerateTreeBranch(self, root, folderpath):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   156
        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
   157
        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
   158
            if not item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   159
                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
   160
                if wx.Platform != '__WXMSW__':
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   161
                    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
   162
            elif self.Tree.GetItemText(item) != filename:
3636
99b20dff00d5 IDE: fix exception when removing a file in Project Files manager.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3303
diff changeset
   163
                item = self.Tree.InsertItem(root, idx, filename, self.TreeImageDict[item_type])
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   164
            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
   165
            if item_type != FILE:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   166
                if self.Tree.IsExpanded(item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   167
                    self.GenerateTreeBranch(item, filepath)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   168
                elif children > 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   169
                    self.Tree.SetItemHasChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   170
            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
   171
        to_delete = []
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   172
        while item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   173
            to_delete.append(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   174
            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
   175
        for item in to_delete:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   176
            self.Tree.Delete(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   177
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   178
    def ExpandItem(self, item):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   179
        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
   180
        self.Tree.Expand(item)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   181
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   182
    def OnTreeItemActivated(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   183
        self.ExpandItem(event.GetItem())
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   184
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   185
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   186
    def OnTreeLeftDown(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   187
        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
   188
        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
   189
            self.ExpandItem(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   190
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   191
            event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   192
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   193
    def OnTreeItemExpanded(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   194
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   195
        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
   196
        event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   197
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   198
    def OnTreeItemCollapsed(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   199
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   200
        self.Tree.DeleteChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   201
        self.Tree.SetItemHasChildren(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   202
        event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   203
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   204
    def OnTreeBeginLabelEdit(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   205
        item = event.GetItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   206
        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
   207
            event.Skip()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   208
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   209
            event.Veto()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   210
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   211
    def OnTreeEndLabelEdit(self, event):
1219
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   212
        new_name = event.GetLabel()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   213
        if new_name != "":
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   214
            old_filepath = self.GetPath(event.GetItem())
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   215
            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
   216
            if new_filepath != old_filepath:
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   217
                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
   218
                    os.rename(old_filepath, new_filepath)
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   219
                    event.Skip()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   220
                else:
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   221
                    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
   222
                                               _("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
   223
                                               _("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
   224
                    message.ShowModal()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   225
                    message.Destroy()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   226
                    event.Veto()
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   227
        else:
f5da9702685a Fixed bug when editing file name and close editor without modification
Laurent Bessard
parents: 951
diff changeset
   228
            event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   229
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   230
    def OnFilterChanged(self, event):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   231
        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
   232
        self.RefreshTree()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   233
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   234
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   235
    def _SelectItem(self, root, parts):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   236
        if len(parts) == 0:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   237
            self.Tree.SelectItem(root)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   238
        else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   239
            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
   240
            while item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   241
                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
   242
                    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
   243
                       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
   244
                        self.Tree.Expand(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   245
                        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
   246
                    else:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   247
                        self._SelectItem(item, parts[1:])
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   248
                    return
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   249
                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
   250
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   251
    def SetPath(self, path):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   252
        if path.startswith(self.Folder):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   253
            root = self.Tree.GetRootItem()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   254
            if root.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   255
                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
   256
                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
   257
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   258
    def GetPath(self, item=None):
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   259
        if item is None:
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   260
            item = self.Tree.GetSelection()
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   261
        if item.IsOk():
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   262
            filepath = self.Tree.GetItemText(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   263
            parent = self.Tree.GetItemParent(item)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   264
            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
   265
                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
   266
                parent = self.Tree.GetItemParent(parent)
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
diff changeset
   267
            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
   268
        return self.Folder