Sat, 31 Aug 2024 15:49:16 +0200
Fixed a few issues in the MicroPython file manager.
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10428
diff
changeset
|
3 | # Copyright (c) 2019 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a file manager for MicroPython devices. |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
10523 | 10 | import contextlib |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | import os |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
12 | import shutil |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
14 | from PyQt6.QtCore import QPoint, Qt, pyqtSlot |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
15 | from PyQt6.QtWidgets import ( |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
16 | QDialog, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
17 | QHeaderView, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | QInputDialog, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
19 | QLineEdit, |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
20 | QMenu, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
21 | QTreeWidgetItem, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
22 | QWidget, |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
23 | ) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10690
diff
changeset
|
25 | from eric7 import EricUtilities, Preferences |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
26 | from eric7.EricGui import EricPixmapCache |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
27 | from eric7.EricWidgets import EricMessageBox, EricPathPickerDialog |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
28 | from eric7.EricWidgets.EricApplication import ericApp |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
29 | from eric7.EricWidgets.EricFileSaveConfirmDialog import confirmOverwrite |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
30 | from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
10388
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10236
diff
changeset
|
31 | from eric7.SystemUtilities import FileSystemUtilities |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
32 | from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
10518 | 33 | from eric7.Utilities import MimeTypes |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
35 | from .MicroPythonFileSystemUtilities import ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
36 | decoratedName, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | listdirStat, |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
38 | mode2string, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
39 | mtime2string, |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | ) |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
41 | from .Ui_MicroPythonFileManagerWidget import Ui_MicroPythonFileManagerWidget |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | Class implementing a file manager for MicroPython devices. |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | |
9853
080e060a0383
Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9802
diff
changeset
|
49 | def __init__(self, fileManager, parent=None): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
9853
080e060a0383
Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9802
diff
changeset
|
53 | @param fileManager reference to the device file manager interface |
080e060a0383
Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9802
diff
changeset
|
54 | @type MicroPythonFileManager |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | @param parent reference to the parent widget |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | @type QWidget |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
58 | super().__init__(parent) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | self.setupUi(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
61 | self.__repl = parent |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
62 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
63 | self.syncButton.setIcon(EricPixmapCache.getIcon("2rightarrow")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
64 | self.putButton.setIcon(EricPixmapCache.getIcon("1rightarrow")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
65 | self.putAsButton.setIcon(EricPixmapCache.getIcon("putAs")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
66 | self.getButton.setIcon(EricPixmapCache.getIcon("1leftarrow")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
67 | self.getAsButton.setIcon(EricPixmapCache.getIcon("getAs")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
68 | self.localUpButton.setIcon(EricPixmapCache.getIcon("1uparrow")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
69 | self.localHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
70 | self.localReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
71 | self.deviceUpButton.setIcon(EricPixmapCache.getIcon("1uparrow")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
72 | self.deviceHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9238
diff
changeset
|
73 | self.deviceReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
9760 | 74 | self.openButton.setIcon(EricPixmapCache.getIcon("open")) |
75 | self.saveButton.setIcon(EricPixmapCache.getIcon("fileSave")) | |
76 | self.saveAsButton.setIcon(EricPixmapCache.getIcon("fileSaveAs")) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
78 | isMicrobitDeviceWithMPy = self.__repl.isMicrobit() |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
79 | |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
80 | self.deviceUpButton.setEnabled(not isMicrobitDeviceWithMPy) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
81 | self.deviceHomeButton.setEnabled(not isMicrobitDeviceWithMPy) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | self.putButton.setEnabled(False) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
84 | self.putAsButton.setEnabled(False) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | self.getButton.setEnabled(False) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
86 | self.getAsButton.setEnabled(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | |
9760 | 88 | self.openButton.setEnabled(False) |
89 | self.saveButton.setEnabled(False) | |
10523 | 90 | self.saveAsButton.setEnabled(False) |
9760 | 91 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | self.localFileTreeWidget.header().setSortIndicator( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | 0, Qt.SortOrder.AscendingOrder |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | ) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | self.deviceFileTreeWidget.header().setSortIndicator( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | 0, Qt.SortOrder.AscendingOrder |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
97 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
99 | self.__progressInfoDialog = None |
9853
080e060a0383
Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9802
diff
changeset
|
100 | self.__fileManager = fileManager |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | self.__fileManager.longListFiles.connect(self.__handleLongListFiles) |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | self.__fileManager.currentDir.connect(self.__handleCurrentDir) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
104 | self.__fileManager.currentDirChanged.connect(self.__handleCurrentDir) |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
105 | self.__fileManager.putFileDone.connect(self.__newDeviceList) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
106 | self.__fileManager.getFileDone.connect(self.__handleGetDone) |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
107 | self.__fileManager.rsyncDone.connect(self.__handleRsyncDone) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
108 | self.__fileManager.rsyncProgressMessage.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
109 | self.__handleRsyncProgressMessage |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | ) |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
111 | self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
112 | self.__fileManager.createDirectoryDone.connect(self.__newDeviceList) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
113 | self.__fileManager.deleteFileDone.connect(self.__newDeviceList) |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7095
diff
changeset
|
114 | self.__fileManager.fsinfoDone.connect(self.__fsInfoResultReceived) |
9760 | 115 | self.__fileManager.putDataDone.connect(self.__newDeviceList) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
117 | self.__fileManager.error.connect(self.__handleError) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
119 | self.localFileTreeWidget.customContextMenuRequested.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | self.__showLocalContextMenu |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | ) |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
122 | self.deviceFileTreeWidget.customContextMenuRequested.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | self.__showDeviceContextMenu |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
125 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
126 | self.__localMenu = QMenu(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
127 | self.__localMenu.addAction( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
128 | self.tr("Change Directory"), self.__changeLocalDirectory |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
130 | self.__localMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | self.tr("Create Directory"), self.__createLocalDirectory |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
133 | self.__localDelDirTreeAct = self.__localMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
134 | self.tr("Delete Directory Tree"), self.__deleteLocalDirectoryTree |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
136 | self.__localMenu.addSeparator() |
10515 | 137 | self.__localRenameFileAct = self.__localMenu.addAction( |
138 | self.tr("Rename File"), self.__renameLocalFile | |
139 | ) | |
140 | self.__localMenu.addSeparator() | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
141 | self.__localDelFileAct = self.__localMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
142 | self.tr("Delete File"), self.__deleteLocalFile |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | ) |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
144 | self.__localMenu.addSeparator() |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
145 | act = self.__localMenu.addAction(self.tr("Show Hidden Files")) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
146 | act.setCheckable(True) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
147 | act.setChecked(Preferences.getMicroPython("ShowHiddenLocal")) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
148 | act.triggered[bool].connect(self.__localHiddenChanged) |
10523 | 149 | self.__localMenu.addSeparator() |
150 | self.__localClearSelectionAct = self.__localMenu.addAction( | |
151 | self.tr("Clear Selection"), self.__clearLocalSelection | |
152 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
153 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
154 | self.__deviceMenu = QMenu(self) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
155 | if not isMicrobitDeviceWithMPy: |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
156 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
157 | self.tr("Change Directory"), self.__changeDeviceDirectory |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
158 | ) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
159 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | self.tr("Create Directory"), self.__createDeviceDirectory |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | ) |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
162 | self.__devDelDirAct = self.__deviceMenu.addAction( |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
163 | self.tr("Delete Directory"), self.__deleteDeviceDirectory |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
164 | ) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
165 | self.__devDelDirTreeAct = self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | self.tr("Delete Directory Tree"), self.__deleteDeviceDirectoryTree |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | ) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
168 | self.__deviceMenu.addSeparator() |
10515 | 169 | self.__devRenameFileAct = self.__deviceMenu.addAction( |
170 | self.tr("Rename File"), self.__renameDeviceFile | |
171 | ) | |
172 | self.__deviceMenu.addSeparator() | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
173 | self.__devDelFileAct = self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
174 | self.tr("Delete File"), self.__deleteDeviceFile |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
175 | ) |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
176 | self.__deviceMenu.addSeparator() |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
177 | act = self.__deviceMenu.addAction(self.tr("Show Hidden Files")) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
178 | act.setCheckable(True) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
179 | act.setChecked(Preferences.getMicroPython("ShowHiddenDevice")) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
180 | act.triggered[bool].connect(self.__deviceHiddenChanged) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
181 | if not isMicrobitDeviceWithMPy: |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
182 | self.__deviceMenu.addSeparator() |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
183 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
184 | self.tr("Show Filesystem Info"), self.__showFileSystemInfo |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | ) |
10523 | 186 | self.__deviceMenu.addSeparator() |
187 | self.__deviceClearSelectionAct = self.__deviceMenu.addAction( | |
188 | self.tr("Clear Selection"), self.__clearDeviceSelection | |
189 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
190 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | def start(self): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | Public method to start the widget. |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | """ |
10523 | 195 | self.__viewmanager = ericApp().getObject("ViewManager") |
196 | self.__viewmanager.editorCountChanged.connect(self.__updateSaveButtonStates) | |
197 | ||
7095
8e10acb1cd85
Refactored and improved the MicroPython code to be able to show the file manager and the REPL simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7089
diff
changeset
|
198 | dirname = "" |
10523 | 199 | aw = self.__viewmanager.activeWindow() |
10388
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10236
diff
changeset
|
200 | if aw and FileSystemUtilities.isPlainFileName(aw.getFileName()): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | dirname = os.path.dirname(aw.getFileName()) |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | if not dirname: |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
203 | dirname = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
204 | Preferences.getMicroPython("MpyWorkspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
205 | or Preferences.getMultiProject("Workspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
206 | or os.path.expanduser("~") |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
207 | ) |
10523 | 208 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
209 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
210 | if self.__repl.deviceSupportsLocalFileAccess(): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
211 | dirname = self.__repl.getDeviceWorkspace() |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
212 | if dirname: |
10523 | 213 | self.__listLocalFiles(dirname=dirname, localDevice=True) |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
214 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
215 | |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
216 | # list files via device script |
10523 | 217 | self.__expandedDeviceEntries = [] |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
218 | self.__fileManager.pwd() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | def stop(self): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | Public method to stop the widget. |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | """ |
10523 | 224 | self.__viewmanager.editorCountChanged.disconnect(self.__updateSaveButtonStates) |
225 | ||
226 | @pyqtSlot() | |
227 | def __updateSaveButtonStates(self): | |
228 | """ | |
229 | Private slot to update the enabled state of the save buttons. | |
230 | """ | |
231 | enable = bool(len(self.deviceFileTreeWidget.selectedItems())) | |
232 | if enable: | |
233 | enable &= not ( | |
234 | self.deviceFileTreeWidget.selectedItems()[0].text(0).endswith("/") | |
235 | ) | |
236 | editorsCount = self.__viewmanager.getOpenEditorsCount() | |
237 | ||
238 | self.saveButton.setEnabled(enable and bool(editorsCount)) | |
239 | self.saveAsButton.setEnabled(bool(editorsCount)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
241 | @pyqtSlot(str, str) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
242 | def __handleError(self, method, error): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | Private slot to handle errors. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
245 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
246 | @param method name of the method the error occured in |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
247 | @type str |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | @param error error message |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | @type str |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
251 | EricMessageBox.warning( |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | self, |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | self.tr("Error handling device"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
254 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
255 | "<p>There was an error communicating with the connected" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | " device.</p><p>Method: {0}</p><p>Message: {1}</p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
257 | ).format(method, error), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
258 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
259 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | @pyqtSlot(str) |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | def __handleCurrentDir(self, dirname): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | Private slot to handle a change of the current directory of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
264 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | @param dirname name of the current directory |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | @type str |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | self.deviceCwd.setText(dirname) |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
269 | self.__newDeviceList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
270 | |
10523 | 271 | def __findDirectoryItem(self, dirPath, fileTreeWidget): |
272 | """ | |
273 | Private method to find a file tree item for the given path. | |
274 | ||
275 | @param dirPath path to be searched for | |
276 | @type str | |
277 | @param fileTreeWidget reference to the file list to be searched | |
278 | @type QTreeWidget | |
279 | @return reference to the item for the path | |
280 | @rtype QTreeWidgetItem | |
281 | """ | |
282 | itm = fileTreeWidget.topLevelItem(0) | |
283 | while itm is not None: | |
284 | if itm.data(0, Qt.ItemDataRole.UserRole) == dirPath: | |
285 | return itm | |
286 | itm = fileTreeWidget.itemBelow(itm) | |
287 | ||
288 | return None | |
289 | ||
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | @pyqtSlot(tuple) |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | def __handleLongListFiles(self, filesList): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | Private slot to receive a long directory listing. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
294 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | @param filesList tuple containing tuples with name, mode, size and time |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | for each directory entry |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | @type tuple of (str, str, str, str) |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | """ |
10523 | 299 | if filesList: |
300 | dirPath = os.path.dirname(filesList[0][-1]) | |
301 | dirItem = ( | |
302 | self.__findDirectoryItem(dirPath, self.deviceFileTreeWidget) | |
303 | if dirPath != self.deviceCwd.text() | |
304 | else None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
305 | ) |
10523 | 306 | |
307 | if dirItem: | |
308 | dirItem.takeChildren() | |
309 | else: | |
310 | self.deviceFileTreeWidget.clear() | |
311 | ||
312 | for name, mode, size, dateTime, filePath in filesList: | |
313 | itm = QTreeWidgetItem( | |
314 | self.deviceFileTreeWidget if dirItem is None else dirItem, | |
315 | [name, mode, size, dateTime], | |
316 | ) | |
317 | itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter) | |
318 | itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) | |
319 | itm.setData(0, Qt.ItemDataRole.UserRole, filePath) | |
320 | if name.endswith("/"): | |
321 | itm.setChildIndicatorPolicy( | |
322 | QTreeWidgetItem.ChildIndicatorPolicy.ShowIndicator | |
323 | ) | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | self.deviceFileTreeWidget.header().resizeSections( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
325 | QHeaderView.ResizeMode.ResizeToContents |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | |
10523 | 328 | if self.__expandedDeviceEntries: |
329 | dirPath = self.__expandedDeviceEntries.pop(0) | |
330 | dirItem = self.__findDirectoryItem(dirPath, self.deviceFileTreeWidget) | |
331 | if dirItem: | |
332 | dirItem.setExpanded(True) | |
333 | ||
334 | def __listLocalFiles(self, dirname="", localDevice=False, parentItem=None): | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | """ |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | Private method to populate the local files list. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
337 | |
10523 | 338 | @param dirname name of the local directory to be listed (defaults to "") |
339 | @type str (optional) | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
340 | @param localDevice flag indicating device access via local file system |
10523 | 341 | (defaults to False) |
342 | @type bool (optional) | |
343 | @param parentItem reference to the parent item (defaults to None) | |
344 | @type QTreeWidgetItem (optional) | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
345 | """ |
10523 | 346 | if parentItem: |
347 | dirname = parentItem.data(0, Qt.ItemDataRole.UserRole) | |
348 | showHidden = ( | |
349 | Preferences.getMicroPython("ShowHiddenDevice") | |
350 | if localDevice | |
351 | else Preferences.getMicroPython("ShowHiddenLocal") | |
352 | ) | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
353 | else: |
10523 | 354 | if not dirname: |
355 | dirname = os.getcwd() | |
356 | if dirname != os.sep and dirname.endswith(os.sep): | |
357 | dirname = dirname[:-1] | |
358 | if localDevice: | |
359 | self.deviceCwd.setText(dirname) | |
360 | showHidden = Preferences.getMicroPython("ShowHiddenDevice") | |
361 | else: | |
362 | self.localCwd.setText(dirname) | |
363 | showHidden = Preferences.getMicroPython("ShowHiddenLocal") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
365 | filesStatList = listdirStat(dirname, showHidden=showHidden) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
366 | filesList = [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
367 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
368 | decoratedName(f, s[0], os.path.isdir(os.path.join(dirname, f))), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | mode2string(s[0]), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
370 | str(s[6]), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
371 | mtime2string(s[8]), |
10523 | 372 | os.path.join(dirname, f), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
373 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
374 | for f, s in filesStatList |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
375 | ] |
8259
2bbec88047dd
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
376 | fileTreeWidget = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
377 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget |
8259
2bbec88047dd
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
378 | ) |
10523 | 379 | if parentItem: |
380 | parentItem.takeChildren() | |
381 | else: | |
382 | fileTreeWidget.clear() | |
383 | parentItem = fileTreeWidget | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | for item in filesList: |
10523 | 385 | itm = QTreeWidgetItem(parentItem, item[:4]) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
386 | itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter) |
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
387 | itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) |
10523 | 388 | itm.setData(0, Qt.ItemDataRole.UserRole, item[4]) |
389 | if os.path.isdir(item[4]): | |
390 | itm.setChildIndicatorPolicy( | |
391 | QTreeWidgetItem.ChildIndicatorPolicy.ShowIndicator | |
392 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
393 | fileTreeWidget.header().resizeSections(QHeaderView.ResizeMode.ResizeToContents) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
394 | |
10523 | 395 | def __repopulateLocalFilesList(self, dirname="", localDevice=False): |
396 | """ | |
397 | Private method to re-populate the local files tree. | |
398 | ||
399 | @param dirname name of the local directory to be listed (defaults to "") | |
400 | @type str (optional) | |
401 | @param localDevice flag indicating device access via local file system | |
402 | (defaults to False) | |
403 | @type bool (optional) | |
404 | """ | |
405 | fileTreeWidget = ( | |
406 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
407 | ) | |
408 | ||
409 | # Step 1: record all expanded directories | |
410 | expanded = [] | |
411 | itm = fileTreeWidget.topLevelItem(0) | |
412 | while itm: | |
413 | if itm.isExpanded(): | |
414 | expanded.append(itm.data(0, Qt.ItemDataRole.UserRole)) | |
415 | itm = fileTreeWidget.itemBelow(itm) | |
416 | ||
417 | # Step 2: re-populate the top level directory | |
418 | self.__listLocalFiles(dirname=dirname, localDevice=localDevice) | |
419 | ||
420 | # Step 3: re-populate expanded directories | |
421 | itm = fileTreeWidget.topLevelItem(0) | |
422 | while itm: | |
423 | if itm.data(0, Qt.ItemDataRole.UserRole) in expanded: | |
424 | itm.setExpanded(True) | |
425 | itm = fileTreeWidget.itemBelow(itm) | |
426 | ||
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | @pyqtSlot(QTreeWidgetItem, int) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
428 | def on_localFileTreeWidget_itemActivated(self, item, _column): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | """ |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
430 | Private slot to handle the activation of a local item. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
431 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
432 | If the item is a directory, the list will be re-populated for this |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
433 | directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
434 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
435 | @param item reference to the activated item |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | @type QTreeWidgetItem |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
437 | @param _column column of the activation (unused) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | @type int |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | """ |
10523 | 440 | name = item.data(0, Qt.ItemDataRole.UserRole) |
441 | if item.text(0).endswith("/"): | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
442 | # directory names end with a '/' |
10523 | 443 | self.__listLocalFiles(dirname=name) |
10518 | 444 | elif MimeTypes.isTextFile(name): |
10523 | 445 | self.__viewmanager.getEditor(name) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
446 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | @pyqtSlot() |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | def on_localFileTreeWidget_itemSelectionChanged(self): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | """ |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
450 | Private slot handling a change of selection in the local pane. |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | """ |
10523 | 452 | enable = bool(self.localFileTreeWidget.selectedItems()) |
453 | self.__localClearSelectionAct.setEnabled(enable) | |
454 | ||
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
455 | if enable: |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
456 | enable &= not ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
457 | self.localFileTreeWidget.selectedItems()[0].text(0).endswith("/") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
458 | ) |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
459 | self.putButton.setEnabled(enable) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
460 | self.putAsButton.setEnabled(enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
461 | |
10523 | 462 | @pyqtSlot(QTreeWidgetItem) |
463 | def on_localFileTreeWidget_itemExpanded(self, item): | |
464 | """ | |
465 | Private slot handling the expansion of a local directory item. | |
466 | ||
467 | @param item reference to the directory item | |
468 | @type QTreeWidgetItem | |
469 | """ | |
470 | if item.childCount() == 0: | |
471 | # it was not populated yet | |
472 | self.__listLocalFiles(parentItem=item) | |
473 | ||
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
474 | @pyqtSlot(str) |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
475 | def on_localCwd_textChanged(self, cwd): |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
476 | """ |
9786
f94b530722af
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9769
diff
changeset
|
477 | Private slot handling a change of the current local working directory. |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
478 | |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
479 | @param cwd current local working directory |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
480 | @type str |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
481 | """ |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
482 | self.localUpButton.setEnabled(cwd != os.sep) |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
483 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
484 | @pyqtSlot() |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
485 | def on_localUpButton_clicked(self): |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
486 | """ |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
487 | Private slot to go up one directory level. |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
488 | """ |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
489 | cwd = self.localCwd.text() |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
490 | dirname = os.path.dirname(cwd) |
10523 | 491 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
492 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
493 | @pyqtSlot() |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
494 | def on_localHomeButton_clicked(self): |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
495 | """ |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
496 | Private slot to change directory to the configured workspace. |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
497 | """ |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
498 | dirname = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
499 | Preferences.getMicroPython("MpyWorkspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
500 | or Preferences.getMultiProject("Workspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
501 | or os.path.expanduser("~") |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
502 | ) |
10523 | 503 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
504 | |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
505 | @pyqtSlot() |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
506 | def on_localReloadButton_clicked(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
507 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
508 | Private slot to reload the local list. |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
509 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
510 | dirname = self.localCwd.text() |
10523 | 511 | self.__repopulateLocalFilesList(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
512 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | @pyqtSlot(QTreeWidgetItem, int) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
514 | def on_deviceFileTreeWidget_itemActivated(self, item, _column): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
516 | Private slot to handle the activation of a device item. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
517 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
518 | If the item is a directory, the current working directory is changed |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
519 | and the list will be re-populated for this directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
520 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
521 | @param item reference to the activated item |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | @type QTreeWidgetItem |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
523 | @param _column column of the activation (unused) |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | @type int |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | """ |
10523 | 526 | name = item.data(0, Qt.ItemDataRole.UserRole) |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
527 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 528 | if item.text(0).endswith("/"): |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
529 | # directory names end with a '/' |
10523 | 530 | self.__listLocalFiles(dirname=name) |
10143 | 531 | else: |
532 | if not os.path.exists(name): | |
533 | EricMessageBox.warning( | |
534 | self, | |
535 | self.tr("Open Device File"), | |
536 | self.tr( | |
537 | """<p>The file <b>{0}</b> does not exist.</p>""" | |
538 | ).format(name), | |
539 | ) | |
540 | return | |
10518 | 541 | if MimeTypes.isTextFile(name): |
10523 | 542 | self.__viewmanager.getEditor(name) |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
543 | else: |
10523 | 544 | if item.text(0).endswith("/"): |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
545 | # directory names end with a '/' |
10523 | 546 | self.__fileManager.cd(name) |
9760 | 547 | else: |
548 | data = self.__fileManager.getData(name) | |
10236
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
549 | try: |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
550 | text = data.decode(encoding="utf-8") |
10523 | 551 | self.__viewmanager.newEditorWithText( |
10388
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10236
diff
changeset
|
552 | text, fileName=FileSystemUtilities.deviceFileName(name) |
10236
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
553 | ) |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
554 | except UnicodeDecodeError: |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
555 | EricMessageBox.warning( |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
556 | self, |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
557 | self.tr("Open Device File"), |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
558 | self.tr( |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
559 | "<p>The file <b>{0}</b> does not contain Unicode text.</p>" |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
560 | ).format(name), |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
561 | ) |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
562 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
563 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
564 | @pyqtSlot() |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | def on_deviceFileTreeWidget_itemSelectionChanged(self): |
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
567 | Private slot handling a change of selection in the local pane. |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | """ |
10523 | 569 | enable = bool(self.deviceFileTreeWidget.selectedItems()) |
570 | self.__deviceClearSelectionAct.setEnabled(enable) | |
571 | ||
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
572 | if enable: |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
573 | enable &= not ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
574 | self.deviceFileTreeWidget.selectedItems()[0].text(0).endswith("/") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
575 | ) |
10523 | 576 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
577 | self.getButton.setEnabled(enable) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
578 | self.getAsButton.setEnabled(enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
579 | |
9760 | 580 | self.openButton.setEnabled(enable) |
10523 | 581 | |
582 | self.__updateSaveButtonStates() | |
583 | ||
584 | @pyqtSlot(QTreeWidgetItem) | |
585 | def on_deviceFileTreeWidget_itemExpanded(self, item): | |
586 | """ | |
587 | Private slot handling the expansion of a local directory item. | |
588 | ||
589 | @param item reference to the directory item | |
590 | @type QTreeWidgetItem | |
591 | """ | |
592 | if item.childCount() == 0: | |
593 | # it was not populated yet | |
594 | if self.__repl.deviceSupportsLocalFileAccess(): | |
595 | self.__listLocalFiles(localDevice=True, parentItem=item) | |
596 | else: | |
597 | self.__fileManager.lls( | |
598 | item.data(0, Qt.ItemDataRole.UserRole), | |
599 | showHidden=Preferences.getMicroPython("ShowHiddenDevice"), | |
600 | ) | |
9760 | 601 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
602 | @pyqtSlot(str) |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
603 | def on_deviceCwd_textChanged(self, cwd): |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
604 | """ |
9786
f94b530722af
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9769
diff
changeset
|
605 | Private slot handling a change of the current device working directory. |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
606 | |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
607 | @param cwd current device working directory |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
608 | @type str |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
609 | """ |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
610 | self.deviceUpButton.setEnabled(cwd != "/") |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
611 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
612 | @pyqtSlot() |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
613 | def on_deviceUpButton_clicked(self): |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
614 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
615 | Private slot to go up one directory level on the device. |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
616 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
617 | cwd = self.deviceCwd.text() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
618 | dirname = os.path.dirname(cwd) |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
619 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 620 | self.__listLocalFiles(dirname=dirname, localDevice=True) |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
621 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
622 | self.__fileManager.cd(dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
623 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
624 | @pyqtSlot() |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
625 | def on_deviceHomeButton_clicked(self): |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
626 | """ |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
627 | Private slot to move to the device home directory. |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
628 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
629 | if self.__repl.deviceSupportsLocalFileAccess(): |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
630 | dirname = self.__repl.getDeviceWorkspace() |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
631 | if dirname: |
10523 | 632 | self.__listLocalFiles(dirname=dirname, localDevice=True) |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
633 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
634 | |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
635 | # list files via device script |
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
636 | self.__fileManager.cd("/") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
637 | |
8067
a467ab075be0
MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8058
diff
changeset
|
638 | @pyqtSlot() |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
639 | def on_deviceReloadButton_clicked(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
640 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
641 | Private slot to reload the device list. |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
642 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
643 | dirname = self.deviceCwd.text() |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
644 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 645 | self.__repopulateLocalFilesList(dirname=dirname, localDevice=True) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
646 | else: |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
647 | if dirname: |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
648 | self.__newDeviceList() |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
649 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
650 | self.__fileManager.pwd() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
651 | |
10523 | 652 | def __isFileInList(self, filename, parent): |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
653 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
654 | Private method to check, if a file name is contained in a tree widget. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
655 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
656 | @param filename name of the file to check |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
657 | @type str |
10523 | 658 | @param parent reference to the parent to be checked against |
659 | @type QTreeWidget or QTreeWidgetItem | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
660 | @return flag indicating that the file name is present |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
661 | @rtype bool |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
662 | """ |
10523 | 663 | if isinstance(parent, QTreeWidgetItem): |
664 | itemCount = parent.childCount() | |
665 | return itemCount > 0 and any( | |
666 | parent.child(row).text(0) == filename for row in range(itemCount) | |
667 | ) | |
668 | else: | |
669 | itemCount = parent.topLevelItemCount() | |
670 | return itemCount > 0 and any( | |
671 | parent.topLevelItem(row).text(0) == filename for row in range(itemCount) | |
672 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
673 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
674 | @pyqtSlot() |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
675 | def on_putButton_clicked(self, putAs=False): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
676 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
677 | Private slot to copy the selected file to the connected device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
678 | |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
679 | @param putAs flag indicating to give it a new name |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
680 | @type bool |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
681 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
682 | selectedItems = self.localFileTreeWidget.selectedItems() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
683 | if selectedItems: |
10523 | 684 | filepath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
685 | filename = os.path.basename(filepath) | |
686 | if not selectedItems[0].text(0).endswith("/"): | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
687 | # it is really a file |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
688 | if putAs: |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
689 | deviceFilename, ok = QInputDialog.getText( |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
690 | self, |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
691 | self.tr("Put File As"), |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
692 | self.tr("Enter a new name for the file"), |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
693 | QLineEdit.EchoMode.Normal, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
694 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
695 | ) |
10523 | 696 | if not ok or not deviceFilename: |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
697 | return |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
698 | else: |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
699 | deviceFilename = filename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
700 | |
10523 | 701 | selectedDeviceItems = self.deviceFileTreeWidget.selectedItems() |
702 | if selectedDeviceItems: | |
703 | item = selectedDeviceItems[0] | |
704 | if not item.text(0).endswith("/"): | |
705 | # it is no directory, take its parent | |
706 | item = item.parent() | |
707 | devicePath = ( | |
708 | self.deviceCwd.text() | |
709 | if item is None | |
710 | else item.data(0, Qt.ItemDataRole.UserRole) | |
711 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
712 | deviceParent = self.deviceFileTreeWidget if item is None else item |
10523 | 713 | else: |
714 | devicePath = self.deviceCwd.text() | |
715 | deviceParent = self.deviceFileTreeWidget | |
716 | ||
717 | if self.__isFileInList(deviceFilename, deviceParent): | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
718 | # ask for overwrite permission |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
719 | action, resultFilename = confirmOverwrite( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
720 | deviceFilename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
721 | self.tr("Copy File to Device"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
722 | self.tr( |
9576
be9f8e7e42e0
Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
723 | "The given file exists already (Enter file name only)." |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
724 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
725 | False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
726 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
727 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
728 | if action == "cancel": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
729 | return |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
730 | elif action == "rename": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
731 | deviceFilename = os.path.basename(resultFilename) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
732 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
733 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 734 | shutil.copy2(filepath, os.path.join(devicePath, deviceFilename)) |
735 | self.__listLocalFiles(dirname=devicePath, localDevice=True) | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
736 | else: |
10523 | 737 | if devicePath: |
738 | deviceFilename = ( | |
739 | f"{devicePath}/{deviceFilename}" | |
740 | if devicePath != "/" | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
741 | else f"/{deviceFilename}" |
10523 | 742 | ) |
743 | self.__fileManager.put(filepath, deviceFilename) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
744 | |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
745 | @pyqtSlot() |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
746 | def on_putAsButton_clicked(self): |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
747 | """ |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
748 | Private slot to copy the selected file to the connected device |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
749 | with a different name. |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
750 | """ |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
751 | self.on_putButton_clicked(putAs=True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
752 | |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
753 | @pyqtSlot() |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
754 | def on_getButton_clicked(self, getAs=False): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
755 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
756 | Private slot to copy the selected file from the connected device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
757 | |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
758 | @param getAs flag indicating to give it a new name |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
759 | @type bool |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
760 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
761 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
762 | if selectedItems: |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
763 | filename = selectedItems[0].text(0).strip() |
10523 | 764 | deviceFilename = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
765 | if not filename.endswith("/"): |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
766 | # it is really a file |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
767 | if getAs: |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
768 | localFilename, ok = QInputDialog.getText( |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
769 | self, |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
770 | self.tr("Get File As"), |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
771 | self.tr("Enter a new name for the file"), |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
772 | QLineEdit.EchoMode.Normal, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
773 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
774 | ) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
775 | if not ok or not filename: |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
776 | return |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
777 | else: |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
778 | localFilename = filename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
779 | |
10523 | 780 | selectedLocalItems = self.localFileTreeWidget.selectedItems() |
781 | if selectedLocalItems: | |
782 | item = selectedLocalItems[0] | |
783 | if not item.text(0).endswith("/"): | |
784 | # it is no directory, take its parent | |
785 | item = item.parent() | |
786 | localPath = ( | |
787 | self.localCwd.text() | |
788 | if item is None | |
789 | else item.data(0, Qt.ItemDataRole.UserRole) | |
790 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
791 | localParent = self.localFileTreeWidget if item is None else item |
10523 | 792 | else: |
793 | localPath = self.localCwd.text() | |
794 | localParent = self.localFileTreeWidget | |
795 | ||
796 | if self.__isFileInList(localFilename, localParent): | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
797 | # ask for overwrite permission |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
798 | action, resultFilename = confirmOverwrite( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
799 | localFilename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
800 | self.tr("Copy File from Device"), |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
801 | self.tr("The given file exists already."), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
802 | True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
803 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
804 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
805 | if action == "cancel": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
806 | return |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
807 | elif action == "rename": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
808 | localFilename = resultFilename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
809 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
810 | if self.__repl.deviceSupportsLocalFileAccess(): |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
811 | shutil.copy2( |
10523 | 812 | deviceFilename, |
813 | os.path.join(localPath, localFilename), | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
814 | ) |
10523 | 815 | if isinstance(localParent, QTreeWidgetItem): |
816 | self.__listLocalFiles(parentItem=localParent) | |
817 | else: | |
818 | self.__listLocalFiles(dirname=localPath) | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
819 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
820 | self.__fileManager.get( |
10523 | 821 | deviceFilename, os.path.join(localPath, localFilename) |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
822 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
823 | |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
824 | @pyqtSlot() |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
825 | def on_getAsButton_clicked(self): |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
826 | """ |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
827 | Private slot to copy the selected file from the connected device |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
828 | with a different name. |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
829 | """ |
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
830 | self.on_getButton_clicked(getAs=True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
831 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
832 | @pyqtSlot(str, str) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
833 | def __handleGetDone(self, _deviceFile, localFile): |
7078
bca506f8c756
MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
834 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
835 | Private slot handling a successful copy of a file from the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
836 | |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
837 | @param _deviceFile name of the file on the device (unused) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
838 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
839 | @param localFile name of the local file |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
840 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
841 | """ |
10523 | 842 | localPath = os.path.dirname(localFile) |
843 | ||
844 | # find the directory entry associated with the new file | |
845 | localParent = self.__findDirectoryItem(localPath, self.localFileTreeWidget) | |
846 | ||
847 | if localParent: | |
848 | self.__listLocalFiles(parentItem=localParent) | |
849 | else: | |
850 | self.__listLocalFiles(dirname=self.localCwd.text()) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
851 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
852 | @pyqtSlot() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
853 | def on_syncButton_clicked(self): |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
854 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
855 | Private slot to synchronize the local directory to the device. |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
856 | """ |
10523 | 857 | # 1. local directory |
858 | selectedItems = self.localFileTreeWidget.selectedItems() | |
859 | if selectedItems: | |
860 | localName = selectedItems[0].text(0) | |
861 | if localName.endswith("/"): | |
862 | localDirPath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
863 | else: | |
864 | # it is not a directory | |
865 | localDirPath = os.path.dirname( | |
866 | selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
867 | ) | |
868 | else: | |
869 | localName = "" | |
870 | localDirPath = self.localCwd.text() | |
871 | ||
872 | # 2. device directory | |
873 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
874 | if selectedItems: | |
875 | if not selectedItems[0].text(0).endswith("/"): | |
876 | # it is not a directory | |
877 | deviceDirPath = os.path.dirname( | |
878 | selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
879 | ) | |
880 | else: | |
881 | deviceDirPath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
882 | else: | |
883 | if localDirPath == self.localCwd.text(): | |
884 | # syncronize complete local directory | |
885 | deviceDirPath = self.deviceCwd.text() | |
886 | else: | |
887 | deviceCwd = self.deviceCwd.text() | |
888 | deviceDirPath = ( | |
889 | f"{deviceCwd}{localName[:-1]}" | |
890 | if deviceCwd.endswith("/") | |
891 | else f"{deviceCwd}/{localName[:-1]}" | |
892 | ) | |
893 | ||
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
894 | self.__fileManager.rsync( |
10523 | 895 | localDirPath, |
896 | deviceDirPath, | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
897 | mirror=True, |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
898 | localDevice=self.__repl.deviceSupportsLocalFileAccess(), |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
899 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
900 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
901 | @pyqtSlot(str, str) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
902 | def __handleRsyncDone(self, _localDir, _deviceDir): |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
903 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
904 | Private method to handle the completion of the rsync operation. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
905 | |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
906 | @param _localDir name of the local directory (unused) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
907 | @type str |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10523
diff
changeset
|
908 | @param _deviceDir name of the device directory (unused) |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
909 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
910 | """ |
8058
9769eb548f0d
MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
911 | # simulate button presses to reload the two lists |
9769eb548f0d
MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
912 | self.on_localReloadButton_clicked() |
9769eb548f0d
MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
913 | self.on_deviceReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
914 | |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
915 | @pyqtSlot(str) |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
916 | def __handleRsyncProgressMessage(self, message): |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
917 | """ |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
918 | Private slot handling progress messages sent by the file manager. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
919 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
920 | @param message message to be shown |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
921 | @type str |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
922 | """ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
923 | from .MicroPythonProgressInfoDialog import MicroPythonProgressInfoDialog |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
924 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
925 | if self.__progressInfoDialog is None: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
926 | self.__progressInfoDialog = MicroPythonProgressInfoDialog(self) |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
927 | self.__progressInfoDialog.finished.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
928 | self.__progressInfoDialogFinished |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
929 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
930 | self.__progressInfoDialog.show() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
931 | self.__progressInfoDialog.addMessage(message) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
932 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
933 | @pyqtSlot() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
934 | def __progressInfoDialogFinished(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
935 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
936 | Private slot handling the closing of the progress info dialog. |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
937 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
938 | self.__progressInfoDialog.deleteLater() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
939 | self.__progressInfoDialog = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
940 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
941 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
942 | def __newDeviceList(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
943 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
944 | Private slot to initiate a new long list of the device directory. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
945 | """ |
10523 | 946 | self.__expandedDeviceEntries.clear() |
947 | itm = self.deviceFileTreeWidget.topLevelItem(0) | |
948 | while itm: | |
949 | if itm.isExpanded(): | |
950 | self.__expandedDeviceEntries.append( | |
951 | itm.data(0, Qt.ItemDataRole.UserRole) | |
952 | ) | |
953 | itm = self.deviceFileTreeWidget.itemBelow(itm) | |
954 | ||
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
955 | self.__fileManager.lls( |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
956 | self.deviceCwd.text(), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
957 | showHidden=Preferences.getMicroPython("ShowHiddenDevice"), |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
958 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
959 | |
9760 | 960 | @pyqtSlot() |
961 | def on_openButton_clicked(self): | |
962 | """ | |
963 | Private slot to open the selected file in a new editor. | |
964 | """ | |
965 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
966 | if selectedItems: | |
10523 | 967 | name = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
968 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 969 | if not selectedItems[0].text(0).endswith("/") and MimeTypes.isTextFile( |
970 | name | |
971 | ): | |
972 | self.__viewmanager.getEditor(name) | |
9760 | 973 | else: |
10523 | 974 | if not selectedItems[0].text(0).endswith("/"): |
9760 | 975 | data = self.__fileManager.getData(name) |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
976 | text = data.decode(encoding="utf-8") |
10523 | 977 | self.__viewmanager.newEditorWithText( |
10388
a34ce7f42e8b
Made the code dealing with "device:" and "remote:" file names generally available in FileSystemUtilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10236
diff
changeset
|
978 | text, "Python3", FileSystemUtilities.deviceFileName(name) |
9760 | 979 | ) |
980 | ||
981 | @pyqtSlot() | |
982 | def on_saveButton_clicked(self, saveAs=False): | |
983 | """ | |
984 | Private slot to save the text of the current editor to a file on the device. | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
985 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
986 | @param saveAs flag indicating to save the file with a new name |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
987 | @type bool |
9760 | 988 | """ |
10523 | 989 | aw = self.__viewmanager.activeWindow() |
10512 | 990 | if aw: |
991 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
10523 | 992 | |
10512 | 993 | if selectedItems: |
10523 | 994 | filepath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
995 | filename = os.path.basename(filepath) | |
996 | if selectedItems[0].text(0).endswith("/"): | |
10512 | 997 | saveAs = True |
998 | else: | |
9760 | 999 | saveAs = True |
10512 | 1000 | filename = "" |
9760 | 1001 | |
10512 | 1002 | if saveAs: |
1003 | filename, ok = QInputDialog.getText( | |
1004 | self, | |
1005 | self.tr("Save File As"), | |
1006 | self.tr("Enter a new name for the file:"), | |
1007 | QLineEdit.EchoMode.Normal, | |
1008 | filename, | |
1009 | ) | |
1010 | if not ok or not filename: | |
1011 | return | |
9760 | 1012 | |
10512 | 1013 | if not saveAs: |
1014 | # check editor and selected file names for an implicit 'save as' | |
1015 | editorFileName = os.path.basename( | |
1016 | FileSystemUtilities.plainFileName(aw.getFileName()) | |
1017 | ) | |
1018 | if editorFileName != filename: | |
1019 | saveAs = True | |
9764
57496966803c
Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9760
diff
changeset
|
1020 | |
10523 | 1021 | if selectedItems: |
1022 | item = selectedItems[0] | |
1023 | if not item.text(0).endswith("/"): | |
1024 | # it is no directory, take its parent | |
1025 | item = item.parent() | |
1026 | devicePath = ( | |
1027 | self.deviceCwd.text() | |
1028 | if item is None | |
1029 | else item.data(0, Qt.ItemDataRole.UserRole) | |
1030 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1031 | deviceParent = self.deviceFileTreeWidget if item is None else item |
10523 | 1032 | else: |
1033 | devicePath = self.deviceCwd.text() | |
1034 | deviceParent = self.deviceFileTreeWidget | |
1035 | ||
1036 | if saveAs and self.__isFileInList(filename, deviceParent): | |
10512 | 1037 | # ask for overwrite permission |
1038 | action, resultFilename = confirmOverwrite( | |
1039 | filename, | |
1040 | self.tr("Save File As"), | |
1041 | self.tr("The given file exists already (Enter file name only)."), | |
1042 | False, | |
1043 | self, | |
1044 | ) | |
1045 | if action == "cancel": | |
1046 | return | |
1047 | elif action == "rename": | |
1048 | filename = os.path.basename(resultFilename) | |
9760 | 1049 | |
10512 | 1050 | text = aw.text() |
1051 | if self.__repl.deviceSupportsLocalFileAccess(): | |
10523 | 1052 | filename = os.path.join(devicePath, filename) |
10512 | 1053 | os.makedirs(os.path.dirname(filename), exist_ok=True) |
1054 | with open(filename, "w") as f: | |
1055 | f.write(text) | |
1056 | self.__newDeviceList() | |
1057 | aw.setFileName(filename) | |
1058 | else: | |
10523 | 1059 | filename = ( |
1060 | f"{devicePath}/{filename}" | |
1061 | if devicePath != "/" | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1062 | else f"/{filename}" |
10523 | 1063 | ) |
10512 | 1064 | dirname = filename.rsplit("/", 1)[0] |
1065 | self.__fileManager.makedirs(dirname) | |
1066 | self.__fileManager.putData(filename, text.encode("utf-8")) | |
1067 | aw.setFileName(FileSystemUtilities.deviceFileName(filename)) | |
9760 | 1068 | |
10512 | 1069 | aw.setModified(False) |
10523 | 1070 | with contextlib.suppress(AttributeError): |
1071 | aw.resetOnlineChangeTraceInfo() | |
9760 | 1072 | |
1073 | @pyqtSlot() | |
1074 | def on_saveAsButton_clicked(self): | |
1075 | """ | |
1076 | Private slot to save the current editor in a new file on the connected device. | |
1077 | """ | |
1078 | self.on_saveButton_clicked(saveAs=True) | |
1079 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1080 | ################################################################## |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1081 | ## Context menu methods for the local files below |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1082 | ################################################################## |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1083 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1084 | @pyqtSlot(QPoint) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1085 | def __showLocalContextMenu(self, pos): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1086 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1087 | Private slot to show the REPL context menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1088 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1089 | @param pos position to show the menu at |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1090 | @type QPoint |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1091 | """ |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1092 | hasSelection = bool(len(self.localFileTreeWidget.selectedItems())) |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1093 | if hasSelection: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1094 | name = self.localFileTreeWidget.selectedItems()[0].text(0) |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1095 | isDir = name.endswith("/") |
10523 | 1096 | isLink = name.endswith("@") |
1097 | isFile = not (isDir or isLink) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1098 | else: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1099 | isDir = False |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1100 | isFile = False |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1101 | self.__localDelDirTreeAct.setEnabled(isDir) |
10515 | 1102 | self.__localRenameFileAct.setEnabled(isFile) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1103 | self.__localDelFileAct.setEnabled(isFile) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1104 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
1105 | self.__localMenu.exec(self.localFileTreeWidget.mapToGlobal(pos)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1106 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1107 | @pyqtSlot() |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1108 | def __changeLocalDirectory(self, localDevice=False): |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1109 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1110 | Private slot to change the local directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1111 | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1112 | @param localDevice flag indicating device access via local file system |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1113 | @type bool |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1114 | """ |
8234
fcb6b4b96274
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8221
diff
changeset
|
1115 | cwdWidget = self.deviceCwd if localDevice else self.localCwd |
10523 | 1116 | fileTreeWidget = ( |
1117 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1118 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1119 | |
10523 | 1120 | if fileTreeWidget.selectedItems(): |
1121 | defaultPath = fileTreeWidget.selectedItems()[0].data( | |
1122 | 0, Qt.ItemDataRole.UserRole | |
1123 | ) | |
1124 | if not os.path.isdir(defaultPath): | |
1125 | defaultPath = os.path.dirname(defaultPath) | |
1126 | else: | |
1127 | defaultPath = cwdWidget.text() | |
9238
a7cbf3d61498
EricPathPicker, EricPathPickerDialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
1128 | dirPath, ok = EricPathPickerDialog.getStrPath( |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1129 | self, |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1130 | self.tr("Change Directory"), |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1131 | self.tr("Select Directory"), |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
1132 | EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, |
10523 | 1133 | strPath=defaultPath, |
1134 | defaultDirectory=defaultPath, | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1135 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
1136 | if ok and dirPath: |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
1137 | if not os.path.isabs(dirPath): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1138 | dirPath = os.path.join(cwdWidget.text(), dirPath) |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1139 | cwdWidget.setText(dirPath) |
10523 | 1140 | self.__listLocalFiles(dirname=dirPath, localDevice=localDevice) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1141 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1142 | @pyqtSlot() |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1143 | def __createLocalDirectory(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1144 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1145 | Private slot to create a local directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1146 | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1147 | @param localDevice flag indicating device access via local file system |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1148 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1149 | """ |
8234
fcb6b4b96274
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8221
diff
changeset
|
1150 | cwdWidget = self.deviceCwd if localDevice else self.localCwd |
10523 | 1151 | fileTreeWidget = ( |
1152 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1153 | ) | |
1154 | ||
1155 | if fileTreeWidget.selectedItems(): | |
1156 | localItem = fileTreeWidget.selectedItems()[0] | |
1157 | defaultPath = localItem.data(0, Qt.ItemDataRole.UserRole) | |
1158 | if not os.path.isdir(defaultPath): | |
1159 | defaultPath = os.path.dirname(defaultPath) | |
1160 | localItem = localItem.parent() | |
1161 | else: | |
1162 | defaultPath = cwdWidget.text() | |
1163 | localItem = None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1164 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1165 | dirPath, ok = QInputDialog.getText( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1166 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1167 | self.tr("Create Directory"), |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1168 | self.tr("Enter directory name:"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1169 | QLineEdit.EchoMode.Normal, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1170 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1171 | if ok and dirPath: |
10523 | 1172 | dirPath = os.path.join(defaultPath, dirPath) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1173 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1174 | os.mkdir(dirPath) |
10523 | 1175 | if localItem: |
1176 | self.__listLocalFiles(localDevice=localDevice, parentItem=localItem) | |
1177 | else: | |
1178 | self.__listLocalFiles( | |
1179 | dirname=cwdWidget.text(), localDevice=localDevice | |
1180 | ) | |
7836
2f0d208b8137
Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7780
diff
changeset
|
1181 | except OSError as exc: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
1182 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1183 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1184 | self.tr("Create Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1185 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1186 | """<p>The directory <b>{0}</b> could not be""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1187 | """ created.</p><p>Reason: {1}</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1188 | ).format(dirPath, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1189 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1190 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1191 | @pyqtSlot() |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1192 | def __deleteLocalDirectoryTree(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1193 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1194 | Private slot to delete a local directory tree. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1195 | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1196 | @param localDevice flag indicating device access via local file system |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1197 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1198 | """ |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1199 | if localDevice: |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1200 | cwdWidget = self.deviceCwd |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1201 | fileTreeWidget = self.deviceFileTreeWidget |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1202 | else: |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1203 | cwdWidget = self.localCwd |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1204 | fileTreeWidget = self.localFileTreeWidget |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1205 | |
10523 | 1206 | if bool(fileTreeWidget.selectedItems()): |
1207 | localItem = fileTreeWidget.selectedItems()[0] | |
1208 | parentItem = localItem.parent() | |
1209 | dirname = localItem.data(0, Qt.ItemDataRole.UserRole) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1210 | dlg = DeleteFilesConfirmationDialog( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1211 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1212 | self.tr("Delete Directory Tree"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1213 | self.tr("Do you really want to delete this directory tree?"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1214 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1215 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1216 | if dlg.exec() == QDialog.DialogCode.Accepted: |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1217 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1218 | shutil.rmtree(dirname) |
10523 | 1219 | if parentItem: |
1220 | self.__listLocalFiles( | |
1221 | localDevice=localDevice, parentItem=parentItem | |
1222 | ) | |
1223 | else: | |
1224 | self.__listLocalFiles( | |
1225 | dirname=cwdWidget.text(), localDevice=localDevice | |
1226 | ) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1227 | except Exception as exc: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
1228 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1229 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1230 | self.tr("Delete Directory Tree"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1231 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1232 | """<p>The directory <b>{0}</b> could not be""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1233 | """ deleted.</p><p>Reason: {1}</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1234 | ).format(dirname, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1235 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1236 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1237 | @pyqtSlot() |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1238 | def __deleteLocalFile(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1239 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1240 | Private slot to delete a local file. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1241 | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1242 | @param localDevice flag indicating device access via local file system |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1243 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1244 | """ |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1245 | if localDevice: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1246 | cwdWidget = self.deviceCwd |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1247 | fileTreeWidget = self.deviceFileTreeWidget |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1248 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1249 | cwdWidget = self.localCwd |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1250 | fileTreeWidget = self.localFileTreeWidget |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1251 | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1252 | if bool(len(fileTreeWidget.selectedItems())): |
10523 | 1253 | localItem = fileTreeWidget.selectedItems()[0] |
1254 | parentItem = localItem.parent() | |
1255 | filename = localItem.data(0, Qt.ItemDataRole.UserRole) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1256 | dlg = DeleteFilesConfirmationDialog( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1257 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1258 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1259 | self.tr("Do you really want to delete this file?"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1260 | [filename], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1261 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1262 | if dlg.exec() == QDialog.DialogCode.Accepted: |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1263 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1264 | os.remove(filename) |
10523 | 1265 | if parentItem: |
1266 | self.__listLocalFiles( | |
1267 | localDevice=localDevice, parentItem=parentItem | |
1268 | ) | |
1269 | else: | |
1270 | self.__listLocalFiles( | |
1271 | dirname=cwdWidget.text(), localDevice=localDevice | |
1272 | ) | |
7836
2f0d208b8137
Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7780
diff
changeset
|
1273 | except OSError as exc: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8327
diff
changeset
|
1274 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1275 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1276 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1277 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1278 | """<p>The file <b>{0}</b> could not be""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1279 | """ deleted.</p><p>Reason: {1}</p>""" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1280 | ).format(filename, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1281 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1282 | |
10515 | 1283 | @pyqtSlot() |
1284 | def __renameLocalFile(self, localDevice=False): | |
1285 | """ | |
1286 | Private slot to rename a file on the device. | |
1287 | ||
1288 | @param localDevice flag indicating device access via local file system | |
1289 | (defaults to False) | |
1290 | @type bool (optional) | |
1291 | """ | |
10523 | 1292 | fileTreeWidget = ( |
1293 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1294 | ) | |
10515 | 1295 | |
1296 | if bool(len(fileTreeWidget.selectedItems())): | |
10523 | 1297 | localItem = fileTreeWidget.selectedItems()[0] |
1298 | filename = localItem.data(0, Qt.ItemDataRole.UserRole) | |
10515 | 1299 | newname, ok = QInputDialog.getText( |
1300 | self, | |
1301 | self.tr("Rename File"), | |
1302 | self.tr("Enter the new path for the file"), | |
1303 | QLineEdit.EchoMode.Normal, | |
1304 | filename, | |
1305 | ) | |
1306 | if ok and newname: | |
1307 | try: | |
1308 | os.rename(filename, newname) | |
1309 | except OSError as exc: | |
1310 | EricMessageBox.critical( | |
1311 | self, | |
1312 | self.tr("Rename File"), | |
1313 | self.tr( | |
1314 | """<p>The file <b>{0}</b> could not be""" | |
1315 | """ renamed to <b>{1}</b>.</p><p>Reason: {2}</p>""" | |
1316 | ).format(filename, newname, str(exc)), | |
1317 | ) | |
1318 | ||
1319 | # reload the directory listing | |
1320 | if localDevice: | |
1321 | self.on_deviceReloadButton_clicked() | |
1322 | else: | |
1323 | self.on_localReloadButton_clicked() | |
1324 | ||
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1325 | @pyqtSlot(bool) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1326 | def __localHiddenChanged(self, checked): |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1327 | """ |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1328 | Private slot handling a change of the local show hidden menu entry. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1329 | |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1330 | @param checked new check state of the action |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1331 | @type bool |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1332 | """ |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1333 | Preferences.setMicroPython("ShowHiddenLocal", checked) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1334 | self.on_localReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1335 | |
10523 | 1336 | @pyqtSlot() |
1337 | def __clearLocalSelection(self): | |
1338 | """ | |
1339 | Private slot to clear the local selection. | |
1340 | """ | |
1341 | for item in self.localFileTreeWidget.selectedItems()[:]: | |
1342 | item.setSelected(False) | |
1343 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1344 | ################################################################## |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1345 | ## Context menu methods for the device files below |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1346 | ################################################################## |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1347 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1348 | @pyqtSlot(QPoint) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1349 | def __showDeviceContextMenu(self, pos): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1350 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1351 | Private slot to show the REPL context menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1352 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1353 | @param pos position to show the menu at |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1354 | @type QPoint |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1355 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1356 | hasSelection = bool(len(self.deviceFileTreeWidget.selectedItems())) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1357 | if hasSelection: |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1358 | name = self.deviceFileTreeWidget.selectedItems()[0].text(0) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1359 | isDir = name.endswith("/") |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1360 | isFile = not isDir |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1361 | else: |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1362 | isDir = False |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1363 | isFile = False |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
1364 | if not self.__repl.isMicrobit(): |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1365 | self.__devDelDirAct.setEnabled(isDir) |
7126
376deb7fefe7
microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7108
diff
changeset
|
1366 | self.__devDelDirTreeAct.setEnabled(isDir) |
10515 | 1367 | self.__devRenameFileAct.setEnabled(isFile) |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1368 | self.__devDelFileAct.setEnabled(isFile) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1369 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
1370 | self.__deviceMenu.exec(self.deviceFileTreeWidget.mapToGlobal(pos)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1371 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1372 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1373 | def __changeDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1374 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1375 | Private slot to change the current directory of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1376 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1377 | Note: This triggers a re-population of the device list for the new |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1378 | current directory. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1379 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1380 | if self.__repl.deviceSupportsLocalFileAccess(): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1381 | self.__changeLocalDirectory(True) |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1382 | else: |
10523 | 1383 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
1384 | if selectedItems: | |
1385 | item = selectedItems[0] | |
1386 | dirName = ( | |
1387 | item.data(0, Qt.ItemDataRole.UserRole) | |
1388 | if item.text(0).endswith("/") | |
1389 | else os.path.dirname(item.data(0, Qt.ItemDataRole.UserRole)) | |
1390 | ) | |
1391 | else: | |
1392 | dirName = self.deviceCwd.text() | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1393 | dirPath, ok = QInputDialog.getText( |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1394 | self, |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1395 | self.tr("Change Directory"), |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1396 | self.tr("Enter the directory path on the device:"), |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1397 | QLineEdit.EchoMode.Normal, |
10523 | 1398 | dirName, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1399 | ) |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1400 | if ok and dirPath: |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1401 | if not dirPath.startswith("/"): |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1402 | dirPath = self.deviceCwd.text() + "/" + dirPath |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1403 | self.__fileManager.cd(dirPath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1404 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1405 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1406 | def __createDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1407 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1408 | Private slot to create a directory on the device. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1409 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1410 | if self.__repl.deviceSupportsLocalFileAccess(): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1411 | self.__createLocalDirectory(True) |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1412 | else: |
10523 | 1413 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
1414 | if selectedItems: | |
1415 | item = selectedItems[0] | |
1416 | defaultPath = ( | |
1417 | item.data(0, Qt.ItemDataRole.UserRole) | |
1418 | if item.text(0).endswith("/") | |
1419 | else os.path.dirname(item.data(0, Qt.ItemDataRole.UserRole)) | |
1420 | ) | |
1421 | else: | |
1422 | defaultPath = self.deviceCwd.text() | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1423 | dirPath, ok = QInputDialog.getText( |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1424 | self, |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1425 | self.tr("Create Directory"), |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1426 | self.tr("Enter directory name:"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1427 | QLineEdit.EchoMode.Normal, |
10523 | 1428 | defaultPath, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1429 | ) |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1430 | if ok and dirPath: |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1431 | self.__fileManager.mkdir(dirPath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1432 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1433 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1434 | def __deleteDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1435 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1436 | Private slot to delete an empty directory on the device. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1437 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1438 | if self.__repl.deviceSupportsLocalFileAccess(): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1439 | self.__deleteLocalDirectoryTree(True) |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1440 | else: |
10523 | 1441 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1442 | dirname = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1443 | 0, Qt.ItemDataRole.UserRole | |
1444 | ) | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1445 | dlg = DeleteFilesConfirmationDialog( |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1446 | self, |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1447 | self.tr("Delete Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1448 | self.tr("Do you really want to delete this directory?"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1449 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1450 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1451 | if dlg.exec() == QDialog.DialogCode.Accepted: |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1452 | self.__fileManager.rmdir(dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1453 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1454 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1455 | def __deleteDeviceDirectoryTree(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1456 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1457 | Private slot to delete a directory and all its subdirectories |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1458 | recursively. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1459 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1460 | if self.__repl.deviceSupportsLocalFileAccess(): |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1461 | self.__deleteLocalDirectoryTree(True) |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1462 | else: |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1463 | if bool(len(self.deviceFileTreeWidget.selectedItems())): |
10523 | 1464 | dirname = self.deviceFileTreeWidget.selectedItems()[0].data( |
1465 | 0, Qt.ItemDataRole.UserRole | |
1466 | ) | |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1467 | dlg = DeleteFilesConfirmationDialog( |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1468 | self, |
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1469 | self.tr("Delete Directory Tree"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1470 | self.tr("Do you really want to delete this directory tree?"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1471 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1472 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1473 | if dlg.exec() == QDialog.DialogCode.Accepted: |
7130
6014d37d9683
Started to prepare the MicroPython file manager to access the device file system via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
1474 | self.__fileManager.rmdir(dirname, recursive=True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1475 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1476 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1477 | def __deleteDeviceFile(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1478 | """ |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1479 | Private slot to delete a file. |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1480 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1481 | if self.__repl.deviceSupportsLocalFileAccess(): |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1482 | self.__deleteLocalFile(True) |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1483 | else: |
10523 | 1484 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1485 | filename = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1486 | 0, Qt.ItemDataRole.UserRole | |
1487 | ) | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1488 | dlg = DeleteFilesConfirmationDialog( |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1489 | self, |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1490 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1491 | self.tr("Do you really want to delete this file?"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1492 | [filename], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1493 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8067
diff
changeset
|
1494 | if dlg.exec() == QDialog.DialogCode.Accepted: |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1495 | self.__fileManager.delete(filename) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1496 | |
10515 | 1497 | @pyqtSlot() |
1498 | def __renameDeviceFile(self): | |
1499 | """ | |
1500 | Private slot to rename a file on the device. | |
1501 | """ | |
1502 | if self.__repl.deviceSupportsLocalFileAccess(): | |
1503 | self.__renameLocalFile(True) | |
1504 | else: | |
10523 | 1505 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1506 | filename = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1507 | 0, Qt.ItemDataRole.UserRole | |
1508 | ) | |
10515 | 1509 | newname, ok = QInputDialog.getText( |
1510 | self, | |
1511 | self.tr("Rename File"), | |
1512 | self.tr("Enter the new path for the file"), | |
1513 | QLineEdit.EchoMode.Normal, | |
1514 | filename, | |
1515 | ) | |
1516 | if ok and newname: | |
1517 | success = self.__fileManager.rename(filename, newname) | |
1518 | if success: | |
1519 | self.on_deviceReloadButton_clicked() | |
1520 | ||
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1521 | @pyqtSlot(bool) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1522 | def __deviceHiddenChanged(self, checked): |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1523 | """ |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1524 | Private slot handling a change of the device show hidden menu entry. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1525 | |
7137
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1526 | @param checked new check state of the action |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1527 | @type bool |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1528 | """ |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1529 | Preferences.setMicroPython("ShowHiddenDevice", checked) |
4ed2573947ff
MicroPythonFileManagerWidget: added option to show hidden files to the local and device files list context menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
1530 | self.on_deviceReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1531 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1532 | @pyqtSlot() |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1533 | def __showFileSystemInfo(self): |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1534 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1535 | Private slot to show some file system information. |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1536 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1537 | self.__fileManager.fileSystemInfo() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1538 | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1539 | @pyqtSlot(tuple) |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7095
diff
changeset
|
1540 | def __fsInfoResultReceived(self, fsinfo): |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1541 | """ |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7095
diff
changeset
|
1542 | Private slot to show the file system information of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1543 | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1544 | @param fsinfo tuple of tuples containing the file system name, the |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1545 | total size, the used size and the free size |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1546 | @type tuple of tuples of (str, int, int, int) |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1547 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1548 | msg = self.tr("<h3>Filesystem Information</h3>") |
9959 | 1549 | if fsinfo: |
1550 | for name, totalSize, usedSize, freeSize in fsinfo: | |
1551 | msg += self.tr( | |
1552 | "<h4>{0}</h4" | |
1553 | "<table>" | |
1554 | "<tr><td>Total Size: </td><td align='right'>{1}</td></tr>" | |
1555 | "<tr><td>Used Size: </td><td align='right'>{2}</td></tr>" | |
1556 | "<tr><td>Free Size: </td><td align='right'>{3}</td></tr>" | |
1557 | "</table>" | |
1558 | ).format( | |
1559 | name, | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10690
diff
changeset
|
1560 | EricUtilities.dataString(totalSize), |
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10690
diff
changeset
|
1561 | EricUtilities.dataString(usedSize), |
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10690
diff
changeset
|
1562 | EricUtilities.dataString(freeSize), |
9959 | 1563 | ) |
1564 | else: | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1565 | msg += self.tr( |
9959 | 1566 | "<p>No file systems or file system information available.</p>" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1567 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1568 | EricMessageBox.information(self, self.tr("Filesystem Information"), msg) |
10523 | 1569 | |
1570 | @pyqtSlot() | |
1571 | def __clearDeviceSelection(self): | |
1572 | """ | |
1573 | Private slot to clear the local selection. | |
1574 | """ | |
1575 | for item in self.deviceFileTreeWidget.selectedItems()[:]: | |
1576 | item.setSelected(False) |