editors/FileManagementPanel.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 20:28:54 +0300
changeset 1813 c18adf359d21
parent 1768 691083b5682a
child 1847 6198190bc121
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.
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
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: 951
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: 951
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
diff changeset
     8
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
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: 951
diff changeset
    10
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
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: 951
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: 951
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: 951
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: 951
diff changeset
    15
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
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: 951
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: 951
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: 951
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: 951
diff changeset
    20
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 951
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: 951
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: 951
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    24
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    25
import os
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    26
import shutil
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    27
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    28
import wx
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents: 815
diff changeset
    29
import wx.lib.buttons
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    30
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    31
from EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 801
diff changeset
    32
from util.BitmapLibrary import GetBitmap
951
7f9a9c47a317 Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents: 815
diff changeset
    33
from controls import FolderTree
783
f5cea1a6851e Fixing file explorer for Windows
laurent
parents: 782
diff changeset
    34
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    35
FILTER = _("All files (*.*)|*.*|CSV files (*.csv)|*.csv")
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    36
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    37
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    38
class FileManagementPanel(EditorPanel):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    39
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    40
    def _init_Editor(self, parent):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    41
        self.Editor = wx.Panel(parent)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    42
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    43
        main_sizer = wx.BoxSizer(wx.HORIZONTAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    44
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    45
        left_sizer = wx.BoxSizer(wx.VERTICAL)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    46
        main_sizer.AddSizer(left_sizer, 1, border=5, flag=wx.GROW | wx.ALL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    47
815
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents: 814
diff changeset
    48
        managed_dir_label = wx.StaticText(self.Editor, label=_(self.TagName) + ":")
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    49
        left_sizer.AddWindow(managed_dir_label, border=5, flag=wx.GROW | wx.BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    50
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    51
        self.ManagedDir = FolderTree(self.Editor, self.Folder, FILTER)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    52
        left_sizer.AddWindow(self.ManagedDir, 1, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    53
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    54
        managed_treectrl = self.ManagedDir.GetTreeCtrl()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    55
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, managed_treectrl)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    56
        if self.EnableDragNDrop:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    57
            self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag, managed_treectrl)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    58
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    59
        button_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
    60
        main_sizer.AddSizer(button_sizer, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    61
                            flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    62
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    63
        for idx, (name, bitmap, help) in enumerate([
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    64
                ("DeleteButton", "remove_element", _("Remove file from left folder")),
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    65
                ("LeftCopyButton", "LeftCopy", _("Copy file from right folder to left")),
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 794
diff changeset
    66
                ("RightCopyButton", "RightCopy", _("Copy file from left folder to right")),
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
    67
                ("EditButton", "edit", _("Edit file"))]):
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    68
            button = wx.lib.buttons.GenBitmapButton(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    69
                self.Editor,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    70
                bitmap=GetBitmap(bitmap),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
    71
                size=wx.Size(28, 28), style=wx.NO_BORDER)
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    72
            button.SetToolTipString(help)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    73
            setattr(self, name, button)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    74
            if idx > 0:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    75
                flag = wx.TOP
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    76
            else:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    77
                flag = 0
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    78
            self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    79
            button_sizer.AddWindow(button, border=20, flag=flag)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    80
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    81
        right_sizer = wx.BoxSizer(wx.VERTICAL)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    82
        main_sizer.AddSizer(right_sizer, 1, border=5, flag=wx.GROW | wx.ALL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    83
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    84
        if wx.Platform == '__WXMSW__':
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    85
            system_dir_label = wx.StaticText(self.Editor, label=_("My Computer:"))
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    86
        else:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    87
            system_dir_label = wx.StaticText(self.Editor, label=_("Home Directory:"))
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    88
        right_sizer.AddWindow(system_dir_label, border=5, flag=wx.GROW | wx.BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    89
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    90
        self.SystemDir = FolderTree(self.Editor, self.HomeDirectory, FILTER, False)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    91
        right_sizer.AddWindow(self.SystemDir, 1, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    92
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    93
        system_treectrl = self.SystemDir.GetTreeCtrl()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    94
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, system_treectrl)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    95
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    96
        self.Editor.SetSizer(main_sizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    97
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    98
    def __init__(self, parent, controler, name, folder, enable_dragndrop=False):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
    99
        self.Folder = os.path.realpath(folder)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   100
        self.EnableDragNDrop = enable_dragndrop
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   101
783
f5cea1a6851e Fixing file explorer for Windows
laurent
parents: 782
diff changeset
   102
        if wx.Platform == '__WXMSW__':
f5cea1a6851e Fixing file explorer for Windows
laurent
parents: 782
diff changeset
   103
            self.HomeDirectory = "/"
f5cea1a6851e Fixing file explorer for Windows
laurent
parents: 782
diff changeset
   104
        else:
f5cea1a6851e Fixing file explorer for Windows
laurent
parents: 782
diff changeset
   105
            self.HomeDirectory = os.path.expanduser("~")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   106
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   107
        EditorPanel.__init__(self, parent, name, None, None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   108
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   109
        self.Controler = controler
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   110
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   111
        self.EditableFileExtensions = []
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   112
        self.EditButton.Hide()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   113
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   114
        self.SetIcon(GetBitmap("FOLDER"))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   115
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   116
    def __del__(self):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   117
        self.Controler.OnCloseEditor(self)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   118
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   119
    def GetTitle(self):
815
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents: 814
diff changeset
   120
        return _(self.TagName)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   121
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   122
    def SetEditableFileExtensions(self, extensions):
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   123
        self.EditableFileExtensions = extensions
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   124
        if len(self.EditableFileExtensions) > 0:
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   125
            self.EditButton.Show()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   126
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   127
    def RefreshView(self):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   128
        self.ManagedDir.RefreshTree()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   129
        self.SystemDir.RefreshTree()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   130
        self.RefreshButtonsState()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   131
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   132
    def RefreshButtonsState(self):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   133
        managed_filepath = self.ManagedDir.GetPath()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   134
        system_filepath = self.SystemDir.GetPath()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   135
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   136
        self.DeleteButton.Enable(os.path.isfile(managed_filepath))
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   137
        self.LeftCopyButton.Enable(os.path.isfile(system_filepath))
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   138
        self.RightCopyButton.Enable(os.path.isfile(managed_filepath))
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   139
        if len(self.EditableFileExtensions) > 0:
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   140
            self.EditButton.Enable(
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   141
                os.path.isfile(managed_filepath) and
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   142
                os.path.splitext(managed_filepath)[1] in self.EditableFileExtensions)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   143
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   144
    def OnTreeItemChanged(self, event):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   145
        self.RefreshButtonsState()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   146
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   147
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   148
    def OnDeleteButton(self, event):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   149
        filepath = self.ManagedDir.GetPath()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   150
        if os.path.isfile(filepath):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   151
            folder, filename = os.path.split(filepath)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   152
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   153
            dialog = 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
   154
                                      _("Do you really want to delete the file '%s'?") % filename,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   155
                                      _("Delete File"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   156
                                      wx.YES_NO | wx.ICON_QUESTION)
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   157
            remove = dialog.ShowModal() == wx.ID_YES
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   158
            dialog.Destroy()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   159
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   160
            if remove:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   161
                os.remove(filepath)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   162
                self.ManagedDir.RefreshTree()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   163
        event.Skip()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   164
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   165
    def OnEditButton(self, event):
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   166
        filepath = self.ManagedDir.GetPath()
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   167
        if os.path.isfile(filepath) and \
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   168
           os.path.splitext(filepath)[1] in self.EditableFileExtensions:
789
b1b1a8f85e2f Adding support for saving editor choosen when editing project file for reloading project layout
laurent
parents: 784
diff changeset
   169
            self.Controler._OpenView(filepath + "::")
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 783
diff changeset
   170
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   171
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   172
    def CopyFile(self, src, dst):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   173
        if os.path.isfile(src):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   174
            src_folder, src_filename = os.path.split(src)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   175
            if os.path.isfile(dst):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   176
                dst_folder, dst_filename = os.path.split(dst)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   177
            else:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   178
                dst_folder = dst
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   179
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   180
            dst_filepath = os.path.join(dst_folder, src_filename)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   181
            if os.path.isfile(dst_filepath):
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   182
                dialog = wx.MessageDialog(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   183
                    self,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   184
                    _("The file '%s' already exist.\nDo you want to replace it?") % src_filename,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   185
                    _("Replace File"), wx.YES_NO | wx.ICON_QUESTION)
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   186
                copy = dialog.ShowModal() == wx.ID_YES
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   187
                dialog.Destroy()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   188
            else:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   189
                copy = True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   190
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   191
            if copy:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   192
                shutil.copyfile(src, dst_filepath)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   193
                return dst_filepath
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   194
        return None
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   195
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   196
    def OnLeftCopyButton(self, event):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   197
        filepath = self.CopyFile(self.SystemDir.GetPath(), self.ManagedDir.GetPath())
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   198
        if filepath is not None:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   199
            self.ManagedDir.RefreshTree()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   200
            self.ManagedDir.SetPath(filepath)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   201
        event.Skip()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   202
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   203
    def OnRightCopyButton(self, event):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   204
        filepath = self.CopyFile(self.ManagedDir.GetPath(), self.SystemDir.GetPath())
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   205
        if filepath is not None:
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   206
            self.SystemDir.RefreshTree()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   207
            self.SystemDir.SetPath(filepath)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   208
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   209
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   210
    def OnTreeBeginDrag(self, event):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   211
        filepath = self.ManagedDir.GetPath()
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   212
        if os.path.isfile(filepath):
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   213
            relative_filepath = filepath.replace(os.path.join(self.Folder, ""), "")
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   214
            data = wx.TextDataObject(str(("'%s'" % relative_filepath, "Constant")))
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   215
            dragSource = wx.DropSource(self)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   216
            dragSource.SetData(data)
6f0e10085df9 Adding support for file explorer for project files
laurent
parents:
diff changeset
   217
            dragSource.DoDragDrop()