author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 16 Oct 2024 12:18:14 +0200 | |
changeset 4030 | 45532de22b75 |
parent 3765 | 88fe6fc9fd38 |
permissions | -rw-r--r-- |
782 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
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 | 24 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
25 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
26 |
|
782 | 27 |
import os |
28 |
import shutil |
|
29 |
||
30 |
import wx |
|
951
7f9a9c47a317
Extracted FolderTree control from FileManagementPanel to be able to use it anywhere else
Laurent Bessard
parents:
815
diff
changeset
|
31 |
import wx.lib.buttons |
782 | 32 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
33 |
from editors.EditorPanel import EditorPanel |
814 | 34 |
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
|
35 |
from controls import FolderTree |
783 | 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 | 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 | 40 |
def _init_Editor(self, parent): |
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 | 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 | 45 |
left_sizer = wx.BoxSizer(wx.VERTICAL) |
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:
2301
diff
changeset
|
46 |
main_sizer.Add(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) + ":") |
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:
2301
diff
changeset
|
49 |
left_sizer.Add(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 |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
51 |
FILTER = _("All files (*.*)|*.*|CSV files (*.csv)|*.csv") |
782 | 52 |
self.ManagedDir = FolderTree(self.Editor, self.Folder, 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:
2301
diff
changeset
|
53 |
left_sizer.Add(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
|
54 |
|
782 | 55 |
managed_treectrl = self.ManagedDir.GetTreeCtrl() |
56 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, managed_treectrl) |
|
57 |
if self.EnableDragNDrop: |
|
58 |
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
|
59 |
|
782 | 60 |
button_sizer = wx.BoxSizer(wx.VERTICAL) |
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:
2301
diff
changeset
|
61 |
main_sizer.Add(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
|
62 |
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
|
63 |
|
782 | 64 |
for idx, (name, bitmap, help) in enumerate([ |
65 |
("DeleteButton", "remove_element", _("Remove file from left folder")), |
|
66 |
("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
|
67 |
("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
|
68 |
("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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
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:
2301
diff
changeset
|
73 |
button.SetToolTip(help) |
782 | 74 |
setattr(self, name, button) |
75 |
if idx > 0: |
|
76 |
flag = wx.TOP |
|
77 |
else: |
|
78 |
flag = 0 |
|
79 |
self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button) |
|
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:
2301
diff
changeset
|
80 |
button_sizer.Add(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
|
81 |
|
782 | 82 |
right_sizer = wx.BoxSizer(wx.VERTICAL) |
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:
2301
diff
changeset
|
83 |
main_sizer.Add(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
|
84 |
|
782 | 85 |
if wx.Platform == '__WXMSW__': |
86 |
system_dir_label = wx.StaticText(self.Editor, label=_("My Computer:")) |
|
87 |
else: |
|
88 |
system_dir_label = wx.StaticText(self.Editor, label=_("Home Directory:")) |
|
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:
2301
diff
changeset
|
89 |
right_sizer.Add(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
|
90 |
|
782 | 91 |
self.SystemDir = FolderTree(self.Editor, self.HomeDirectory, FILTER, False) |
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:
2301
diff
changeset
|
92 |
right_sizer.Add(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
|
93 |
|
782 | 94 |
system_treectrl = self.SystemDir.GetTreeCtrl() |
95 |
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
|
96 |
|
782 | 97 |
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
|
98 |
|
782 | 99 |
def __init__(self, parent, controler, name, folder, enable_dragndrop=False): |
100 |
self.Folder = os.path.realpath(folder) |
|
101 |
self.EnableDragNDrop = enable_dragndrop |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
102 |
|
783 | 103 |
if wx.Platform == '__WXMSW__': |
104 |
self.HomeDirectory = "/" |
|
105 |
else: |
|
106 |
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
|
107 |
|
782 | 108 |
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
|
109 |
|
782 | 110 |
self.Controler = controler |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
111 |
|
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
112 |
self.EditableFileExtensions = [] |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
113 |
self.EditButton.Hide() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
114 |
|
782 | 115 |
self.SetIcon(GetBitmap("FOLDER")) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
116 |
|
782 | 117 |
def GetTitle(self): |
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
814
diff
changeset
|
118 |
return _(self.TagName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
119 |
|
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
120 |
def SetEditableFileExtensions(self, extensions): |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
121 |
self.EditableFileExtensions = extensions |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
122 |
if len(self.EditableFileExtensions) > 0: |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
123 |
self.EditButton.Show() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
124 |
|
782 | 125 |
def RefreshView(self): |
126 |
self.ManagedDir.RefreshTree() |
|
127 |
self.SystemDir.RefreshTree() |
|
128 |
self.RefreshButtonsState() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
129 |
|
782 | 130 |
def RefreshButtonsState(self): |
131 |
managed_filepath = self.ManagedDir.GetPath() |
|
132 |
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
|
133 |
|
782 | 134 |
self.DeleteButton.Enable(os.path.isfile(managed_filepath)) |
135 |
self.LeftCopyButton.Enable(os.path.isfile(system_filepath)) |
|
136 |
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
|
137 |
if len(self.EditableFileExtensions) > 0: |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
138 |
self.EditButton.Enable( |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
|
782 | 142 |
def OnTreeItemChanged(self, event): |
143 |
self.RefreshButtonsState() |
|
144 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
145 |
|
782 | 146 |
def OnDeleteButton(self, event): |
147 |
filepath = self.ManagedDir.GetPath() |
|
148 |
if os.path.isfile(filepath): |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
149 |
_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
|
150 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
151 |
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
|
152 |
_("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
|
153 |
_("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
|
154 |
wx.YES_NO | wx.ICON_QUESTION) |
782 | 155 |
remove = dialog.ShowModal() == wx.ID_YES |
156 |
dialog.Destroy() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
157 |
|
782 | 158 |
if remove: |
159 |
os.remove(filepath) |
|
160 |
self.ManagedDir.RefreshTree() |
|
161 |
event.Skip() |
|
162 |
||
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
163 |
def OnEditButton(self, event): |
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
self.Controler._OpenView(filepath + "::") |
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
783
diff
changeset
|
168 |
event.Skip() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
169 |
|
782 | 170 |
def CopyFile(self, src, dst): |
171 |
if os.path.isfile(src): |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
172 |
_src_folder, src_filename = os.path.split(src) |
782 | 173 |
if os.path.isfile(dst): |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
174 |
dst_folder, _dst_filename = os.path.split(dst) |
782 | 175 |
else: |
176 |
dst_folder = dst |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
177 |
|
782 | 178 |
dst_filepath = os.path.join(dst_folder, src_filename) |
179 |
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
|
180 |
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
|
181 |
self, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
182 |
_("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
|
183 |
_("Replace File"), wx.YES_NO | wx.ICON_QUESTION) |
782 | 184 |
copy = dialog.ShowModal() == wx.ID_YES |
185 |
dialog.Destroy() |
|
186 |
else: |
|
187 |
copy = True |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
188 |
|
782 | 189 |
if copy: |
190 |
shutil.copyfile(src, dst_filepath) |
|
191 |
return dst_filepath |
|
192 |
return None |
|
193 |
||
194 |
def OnLeftCopyButton(self, event): |
|
195 |
filepath = self.CopyFile(self.SystemDir.GetPath(), self.ManagedDir.GetPath()) |
|
196 |
if filepath is not None: |
|
197 |
self.ManagedDir.RefreshTree() |
|
198 |
self.ManagedDir.SetPath(filepath) |
|
199 |
event.Skip() |
|
200 |
||
201 |
def OnRightCopyButton(self, event): |
|
202 |
filepath = self.CopyFile(self.ManagedDir.GetPath(), self.SystemDir.GetPath()) |
|
203 |
if filepath is not None: |
|
204 |
self.SystemDir.RefreshTree() |
|
205 |
self.SystemDir.SetPath(filepath) |
|
206 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
207 |
|
782 | 208 |
def OnTreeBeginDrag(self, event): |
209 |
filepath = self.ManagedDir.GetPath() |
|
210 |
if os.path.isfile(filepath): |
|
211 |
relative_filepath = filepath.replace(os.path.join(self.Folder, ""), "") |
|
212 |
data = wx.TextDataObject(str(("'%s'" % relative_filepath, "Constant"))) |
|
213 |
dragSource = wx.DropSource(self) |
|
214 |
dragSource.SetData(data) |
|
215 |
dragSource.DoDragDrop() |