Thu, 05 Sep 2024 16:11:33 +0200
Corrected some code formatting issues.
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 | |
10911 | 126 | ######################################################################## |
127 | ## Context menu for the local directory tree. | |
128 | ######################################################################## | |
129 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
130 | self.__localMenu = QMenu(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | self.__localMenu.addAction( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | 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
|
133 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
134 | self.__localMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | 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
|
136 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
137 | 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
|
138 | 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
|
139 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
140 | self.__localMenu.addSeparator() |
10914
f8506ac41ba7
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10911
diff
changeset
|
141 | self.__localMenu.addAction(self.tr("New File"), self.__newLocalFile) |
10911 | 142 | self.__openLocalFileAct = self.__localMenu.addAction( |
143 | self.tr("Open File"), self.__openLocalFile | |
144 | ) | |
10515 | 145 | self.__localRenameFileAct = self.__localMenu.addAction( |
146 | self.tr("Rename File"), self.__renameLocalFile | |
147 | ) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
148 | 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
|
149 | 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
|
150 | ) |
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
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | act.triggered[bool].connect(self.__localHiddenChanged) |
10523 | 156 | self.__localMenu.addSeparator() |
157 | self.__localClearSelectionAct = self.__localMenu.addAction( | |
158 | self.tr("Clear Selection"), self.__clearLocalSelection | |
159 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | |
10911 | 161 | ######################################################################## |
162 | ## Context menu for the device directory tree. | |
163 | ######################################################################## | |
164 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
165 | 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
|
166 | 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
|
167 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
168 | 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
|
169 | ) |
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
|
170 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
171 | 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
|
172 | ) |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
173 | 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
|
174 | 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
|
175 | ) |
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
|
176 | 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
|
177 | 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
|
178 | ) |
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
|
179 | self.__deviceMenu.addSeparator() |
10914
f8506ac41ba7
Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10911
diff
changeset
|
180 | self.__deviceMenu.addAction(self.tr("New File"), self.__newDeviceFile) |
10911 | 181 | self.__openDeviceFileAct = self.__deviceMenu.addAction( |
182 | self.tr("Open File"), self.__openDeviceFile | |
183 | ) | |
10515 | 184 | self.__devRenameFileAct = self.__deviceMenu.addAction( |
185 | self.tr("Rename File"), self.__renameDeviceFile | |
186 | ) | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
187 | 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
|
188 | 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
|
189 | ) |
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
|
190 | 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
|
191 | 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
|
192 | 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
|
193 | 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
|
194 | 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
|
195 | 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
|
196 | 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
|
197 | self.__deviceMenu.addAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
198 | 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
|
199 | ) |
10523 | 200 | self.__deviceMenu.addSeparator() |
201 | self.__deviceClearSelectionAct = self.__deviceMenu.addAction( | |
202 | self.tr("Clear Selection"), self.__clearDeviceSelection | |
203 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
204 | |
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
|
205 | 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
|
206 | """ |
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
|
207 | 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
|
208 | """ |
10523 | 209 | self.__viewmanager = ericApp().getObject("ViewManager") |
210 | self.__viewmanager.editorCountChanged.connect(self.__updateSaveButtonStates) | |
211 | ||
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
|
212 | dirname = "" |
10523 | 213 | 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
|
214 | 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
|
215 | 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
|
216 | 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
|
217 | dirname = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
218 | Preferences.getMicroPython("MpyWorkspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | or Preferences.getMultiProject("Workspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
220 | 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
|
221 | ) |
10523 | 222 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
223 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
224 | 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
|
225 | 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
|
226 | if dirname: |
10523 | 227 | 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
|
228 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
229 | |
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
|
230 | # list files via device script |
10523 | 231 | 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
|
232 | self.__fileManager.pwd() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
233 | |
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
|
234 | 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
|
235 | """ |
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
|
236 | 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
|
237 | """ |
10523 | 238 | self.__viewmanager.editorCountChanged.disconnect(self.__updateSaveButtonStates) |
239 | ||
240 | @pyqtSlot() | |
241 | def __updateSaveButtonStates(self): | |
242 | """ | |
243 | Private slot to update the enabled state of the save buttons. | |
244 | """ | |
245 | enable = bool(len(self.deviceFileTreeWidget.selectedItems())) | |
246 | if enable: | |
247 | enable &= not ( | |
248 | self.deviceFileTreeWidget.selectedItems()[0].text(0).endswith("/") | |
249 | ) | |
250 | editorsCount = self.__viewmanager.getOpenEditorsCount() | |
251 | ||
252 | self.saveButton.setEnabled(enable and bool(editorsCount)) | |
253 | 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
|
254 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
255 | @pyqtSlot(str, str) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
256 | 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
|
257 | """ |
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
|
258 | 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
|
259 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
260 | @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
|
261 | @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
|
262 | @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
|
263 | @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
|
264 | """ |
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
|
265 | 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
|
266 | 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
|
267 | 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
|
268 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
269 | "<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
|
270 | " 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
|
271 | ).format(method, error), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
272 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
273 | |
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
|
274 | @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
|
275 | 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
|
276 | """ |
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
|
277 | 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
|
278 | |
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
|
279 | @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
|
280 | @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
|
281 | """ |
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
|
282 | 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
|
283 | self.__newDeviceList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
284 | |
10523 | 285 | def __findDirectoryItem(self, dirPath, fileTreeWidget): |
286 | """ | |
287 | Private method to find a file tree item for the given path. | |
288 | ||
289 | @param dirPath path to be searched for | |
290 | @type str | |
291 | @param fileTreeWidget reference to the file list to be searched | |
292 | @type QTreeWidget | |
293 | @return reference to the item for the path | |
294 | @rtype QTreeWidgetItem | |
295 | """ | |
296 | itm = fileTreeWidget.topLevelItem(0) | |
297 | while itm is not None: | |
298 | if itm.data(0, Qt.ItemDataRole.UserRole) == dirPath: | |
299 | return itm | |
300 | itm = fileTreeWidget.itemBelow(itm) | |
301 | ||
302 | return None | |
303 | ||
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
|
304 | @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
|
305 | 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
|
306 | """ |
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
|
307 | 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
|
308 | |
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
|
309 | @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
|
310 | 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
|
311 | @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
|
312 | """ |
10523 | 313 | if filesList: |
314 | dirPath = os.path.dirname(filesList[0][-1]) | |
315 | dirItem = ( | |
316 | self.__findDirectoryItem(dirPath, self.deviceFileTreeWidget) | |
317 | if dirPath != self.deviceCwd.text() | |
318 | else None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
319 | ) |
10523 | 320 | |
321 | if dirItem: | |
322 | dirItem.takeChildren() | |
323 | else: | |
324 | self.deviceFileTreeWidget.clear() | |
325 | ||
326 | for name, mode, size, dateTime, filePath in filesList: | |
327 | itm = QTreeWidgetItem( | |
328 | self.deviceFileTreeWidget if dirItem is None else dirItem, | |
329 | [name, mode, size, dateTime], | |
330 | ) | |
331 | itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter) | |
332 | itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) | |
333 | itm.setData(0, Qt.ItemDataRole.UserRole, filePath) | |
334 | if name.endswith("/"): | |
335 | itm.setChildIndicatorPolicy( | |
336 | QTreeWidgetItem.ChildIndicatorPolicy.ShowIndicator | |
337 | ) | |
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
|
338 | self.deviceFileTreeWidget.header().resizeSections( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
339 | QHeaderView.ResizeMode.ResizeToContents |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
341 | |
10523 | 342 | if self.__expandedDeviceEntries: |
343 | dirPath = self.__expandedDeviceEntries.pop(0) | |
344 | dirItem = self.__findDirectoryItem(dirPath, self.deviceFileTreeWidget) | |
345 | if dirItem: | |
346 | dirItem.setExpanded(True) | |
347 | ||
348 | 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
|
349 | """ |
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
|
350 | 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
|
351 | |
10523 | 352 | @param dirname name of the local directory to be listed (defaults to "") |
353 | @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
|
354 | @param localDevice flag indicating device access via local file system |
10523 | 355 | (defaults to False) |
356 | @type bool (optional) | |
357 | @param parentItem reference to the parent item (defaults to None) | |
358 | @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
|
359 | """ |
10523 | 360 | if parentItem: |
361 | dirname = parentItem.data(0, Qt.ItemDataRole.UserRole) | |
362 | showHidden = ( | |
363 | Preferences.getMicroPython("ShowHiddenDevice") | |
364 | if localDevice | |
365 | else Preferences.getMicroPython("ShowHiddenLocal") | |
366 | ) | |
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
|
367 | else: |
10523 | 368 | if not dirname: |
369 | dirname = os.getcwd() | |
370 | if dirname != os.sep and dirname.endswith(os.sep): | |
371 | dirname = dirname[:-1] | |
372 | if localDevice: | |
373 | self.deviceCwd.setText(dirname) | |
374 | showHidden = Preferences.getMicroPython("ShowHiddenDevice") | |
375 | else: | |
376 | self.localCwd.setText(dirname) | |
377 | showHidden = Preferences.getMicroPython("ShowHiddenLocal") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
378 | |
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
|
379 | 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
|
380 | filesList = [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
381 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
382 | 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
|
383 | mode2string(s[0]), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
384 | str(s[6]), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
385 | mtime2string(s[8]), |
10523 | 386 | 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
|
387 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
388 | for f, s in filesStatList |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
389 | ] |
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
|
390 | fileTreeWidget = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
391 | 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
|
392 | ) |
10523 | 393 | if parentItem: |
394 | parentItem.takeChildren() | |
395 | else: | |
396 | fileTreeWidget.clear() | |
397 | 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
|
398 | for item in filesList: |
10523 | 399 | 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
|
400 | 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
|
401 | itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) |
10523 | 402 | itm.setData(0, Qt.ItemDataRole.UserRole, item[4]) |
403 | if os.path.isdir(item[4]): | |
404 | itm.setChildIndicatorPolicy( | |
405 | QTreeWidgetItem.ChildIndicatorPolicy.ShowIndicator | |
406 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
407 | 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
|
408 | |
10523 | 409 | def __repopulateLocalFilesList(self, dirname="", localDevice=False): |
410 | """ | |
411 | Private method to re-populate the local files tree. | |
412 | ||
413 | @param dirname name of the local directory to be listed (defaults to "") | |
414 | @type str (optional) | |
415 | @param localDevice flag indicating device access via local file system | |
416 | (defaults to False) | |
417 | @type bool (optional) | |
418 | """ | |
419 | fileTreeWidget = ( | |
420 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
421 | ) | |
422 | ||
423 | # Step 1: record all expanded directories | |
424 | expanded = [] | |
425 | itm = fileTreeWidget.topLevelItem(0) | |
426 | while itm: | |
427 | if itm.isExpanded(): | |
428 | expanded.append(itm.data(0, Qt.ItemDataRole.UserRole)) | |
429 | itm = fileTreeWidget.itemBelow(itm) | |
430 | ||
431 | # Step 2: re-populate the top level directory | |
432 | self.__listLocalFiles(dirname=dirname, localDevice=localDevice) | |
433 | ||
434 | # Step 3: re-populate expanded directories | |
435 | itm = fileTreeWidget.topLevelItem(0) | |
436 | while itm: | |
437 | if itm.data(0, Qt.ItemDataRole.UserRole) in expanded: | |
438 | itm.setExpanded(True) | |
439 | itm = fileTreeWidget.itemBelow(itm) | |
440 | ||
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
|
441 | @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
|
442 | 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
|
443 | """ |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
444 | 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
|
445 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
446 | 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
|
447 | directory. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
448 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
449 | @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
|
450 | @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
|
451 | @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
|
452 | @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
|
453 | """ |
10523 | 454 | name = item.data(0, Qt.ItemDataRole.UserRole) |
455 | if item.text(0).endswith("/"): | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
456 | # directory names end with a '/' |
10523 | 457 | self.__listLocalFiles(dirname=name) |
10518 | 458 | elif MimeTypes.isTextFile(name): |
10523 | 459 | self.__viewmanager.getEditor(name) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | |
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
|
461 | @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
|
462 | 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
|
463 | """ |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
464 | 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
|
465 | """ |
10523 | 466 | enable = bool(self.localFileTreeWidget.selectedItems()) |
467 | self.__localClearSelectionAct.setEnabled(enable) | |
468 | ||
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
469 | if enable: |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
470 | enable &= not ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
471 | 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
|
472 | ) |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
473 | 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
|
474 | self.putAsButton.setEnabled(enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
475 | |
10523 | 476 | @pyqtSlot(QTreeWidgetItem) |
477 | def on_localFileTreeWidget_itemExpanded(self, item): | |
478 | """ | |
479 | Private slot handling the expansion of a local directory item. | |
480 | ||
481 | @param item reference to the directory item | |
482 | @type QTreeWidgetItem | |
483 | """ | |
484 | if item.childCount() == 0: | |
485 | # it was not populated yet | |
486 | self.__listLocalFiles(parentItem=item) | |
487 | ||
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
488 | @pyqtSlot(str) |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
489 | 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
|
490 | """ |
9786
f94b530722af
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9769
diff
changeset
|
491 | 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
|
492 | |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
493 | @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
|
494 | @type str |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
495 | """ |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
496 | 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
|
497 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
498 | @pyqtSlot() |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
499 | def on_localUpButton_clicked(self): |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
500 | """ |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
501 | 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
|
502 | """ |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
503 | cwd = self.localCwd.text() |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
504 | dirname = os.path.dirname(cwd) |
10523 | 505 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
506 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
507 | @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
|
508 | 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
|
509 | """ |
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
|
510 | 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
|
511 | """ |
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
|
512 | dirname = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
513 | Preferences.getMicroPython("MpyWorkspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
514 | or Preferences.getMultiProject("Workspace") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
515 | 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
|
516 | ) |
10523 | 517 | self.__listLocalFiles(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
518 | |
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
|
519 | @pyqtSlot() |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
520 | def on_localReloadButton_clicked(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
521 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
522 | 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
|
523 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
524 | dirname = self.localCwd.text() |
10523 | 525 | self.__repopulateLocalFilesList(dirname=dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
526 | |
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
|
527 | @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
|
528 | 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
|
529 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
530 | 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
|
531 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
532 | 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
|
533 | 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
|
534 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
535 | @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
|
536 | @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
|
537 | @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
|
538 | @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
|
539 | """ |
10523 | 540 | 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
|
541 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 542 | 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
|
543 | # directory names end with a '/' |
10523 | 544 | self.__listLocalFiles(dirname=name) |
10143 | 545 | else: |
546 | if not os.path.exists(name): | |
547 | EricMessageBox.warning( | |
548 | self, | |
549 | self.tr("Open Device File"), | |
550 | self.tr( | |
551 | """<p>The file <b>{0}</b> does not exist.</p>""" | |
552 | ).format(name), | |
553 | ) | |
554 | return | |
10518 | 555 | if MimeTypes.isTextFile(name): |
10523 | 556 | 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
|
557 | else: |
10523 | 558 | 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
|
559 | # directory names end with a '/' |
10523 | 560 | self.__fileManager.cd(name) |
9760 | 561 | else: |
562 | data = self.__fileManager.getData(name) | |
10236
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
563 | try: |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
564 | text = data.decode(encoding="utf-8") |
10523 | 565 | 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
|
566 | text, fileName=FileSystemUtilities.deviceFileName(name) |
10236
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
567 | ) |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
568 | except UnicodeDecodeError: |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
569 | EricMessageBox.warning( |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
570 | self, |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
571 | self.tr("Open Device File"), |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
572 | self.tr( |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
573 | "<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
|
574 | ).format(name), |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
575 | ) |
c270c9501f1c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10143
diff
changeset
|
576 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
577 | |
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
|
578 | @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
|
579 | 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
|
580 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
581 | 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
|
582 | """ |
10523 | 583 | enable = bool(self.deviceFileTreeWidget.selectedItems()) |
584 | self.__deviceClearSelectionAct.setEnabled(enable) | |
585 | ||
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
586 | if enable: |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
587 | enable &= not ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
588 | 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
|
589 | ) |
10523 | 590 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
591 | 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
|
592 | self.getAsButton.setEnabled(enable) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
593 | |
9760 | 594 | self.openButton.setEnabled(enable) |
10523 | 595 | |
596 | self.__updateSaveButtonStates() | |
597 | ||
598 | @pyqtSlot(QTreeWidgetItem) | |
599 | def on_deviceFileTreeWidget_itemExpanded(self, item): | |
600 | """ | |
601 | Private slot handling the expansion of a local directory item. | |
602 | ||
603 | @param item reference to the directory item | |
604 | @type QTreeWidgetItem | |
605 | """ | |
606 | if item.childCount() == 0: | |
607 | # it was not populated yet | |
608 | if self.__repl.deviceSupportsLocalFileAccess(): | |
609 | self.__listLocalFiles(localDevice=True, parentItem=item) | |
610 | else: | |
611 | self.__fileManager.lls( | |
612 | item.data(0, Qt.ItemDataRole.UserRole), | |
613 | showHidden=Preferences.getMicroPython("ShowHiddenDevice"), | |
614 | ) | |
9760 | 615 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
616 | @pyqtSlot(str) |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
617 | 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
|
618 | """ |
9786
f94b530722af
Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9769
diff
changeset
|
619 | 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
|
620 | |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
621 | @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
|
622 | @type str |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
623 | """ |
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
624 | 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
|
625 | |
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
|
626 | @pyqtSlot() |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
627 | def on_deviceUpButton_clicked(self): |
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
628 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
629 | 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
|
630 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
631 | cwd = self.deviceCwd.text() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
632 | 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
|
633 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 634 | 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
|
635 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
636 | self.__fileManager.cd(dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
637 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
638 | @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
|
639 | 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
|
640 | """ |
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
|
641 | 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
|
642 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
643 | 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
|
644 | 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
|
645 | if dirname: |
10523 | 646 | 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
|
647 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
648 | |
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
|
649 | # 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
|
650 | self.__fileManager.cd("/") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
651 | |
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
|
652 | @pyqtSlot() |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
653 | def on_deviceReloadButton_clicked(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
654 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
655 | 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
|
656 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
657 | 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
|
658 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 659 | 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
|
660 | else: |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
661 | 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
|
662 | self.__newDeviceList() |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
663 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
664 | self.__fileManager.pwd() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
665 | |
10523 | 666 | def __isFileInList(self, filename, parent): |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
667 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
668 | 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
|
669 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
670 | @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
|
671 | @type str |
10523 | 672 | @param parent reference to the parent to be checked against |
673 | @type QTreeWidget or QTreeWidgetItem | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
674 | @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
|
675 | @rtype bool |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
676 | """ |
10523 | 677 | if isinstance(parent, QTreeWidgetItem): |
678 | itemCount = parent.childCount() | |
679 | return itemCount > 0 and any( | |
680 | parent.child(row).text(0) == filename for row in range(itemCount) | |
681 | ) | |
682 | else: | |
683 | itemCount = parent.topLevelItemCount() | |
684 | return itemCount > 0 and any( | |
685 | parent.topLevelItem(row).text(0) == filename for row in range(itemCount) | |
686 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
687 | |
7080
9a3adf033f90
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7078
diff
changeset
|
688 | @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
|
689 | 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
|
690 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
691 | 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
|
692 | |
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
|
693 | @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
|
694 | @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
|
695 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
696 | selectedItems = self.localFileTreeWidget.selectedItems() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
697 | if selectedItems: |
10523 | 698 | filepath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
699 | filename = os.path.basename(filepath) | |
700 | 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
|
701 | # 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
|
702 | 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
|
703 | 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
|
704 | 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
|
705 | 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
|
706 | 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
|
707 | QLineEdit.EchoMode.Normal, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
708 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
709 | ) |
10523 | 710 | 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
|
711 | 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
|
712 | 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
|
713 | deviceFilename = filename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
714 | |
10523 | 715 | selectedDeviceItems = self.deviceFileTreeWidget.selectedItems() |
716 | if selectedDeviceItems: | |
717 | item = selectedDeviceItems[0] | |
718 | if not item.text(0).endswith("/"): | |
719 | # it is no directory, take its parent | |
720 | item = item.parent() | |
721 | devicePath = ( | |
722 | self.deviceCwd.text() | |
723 | if item is None | |
724 | else item.data(0, Qt.ItemDataRole.UserRole) | |
725 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
726 | deviceParent = self.deviceFileTreeWidget if item is None else item |
10523 | 727 | else: |
728 | devicePath = self.deviceCwd.text() | |
729 | deviceParent = self.deviceFileTreeWidget | |
730 | ||
731 | if self.__isFileInList(deviceFilename, deviceParent): | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
732 | # ask for overwrite permission |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
733 | action, resultFilename = confirmOverwrite( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
734 | deviceFilename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
735 | 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
|
736 | 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
|
737 | "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
|
738 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
739 | False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
740 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
741 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
742 | if action == "cancel": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
743 | return |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
744 | elif action == "rename": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
745 | 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
|
746 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
747 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 748 | shutil.copy2(filepath, os.path.join(devicePath, deviceFilename)) |
749 | 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
|
750 | else: |
10523 | 751 | if devicePath: |
752 | deviceFilename = ( | |
753 | f"{devicePath}/{deviceFilename}" | |
754 | if devicePath != "/" | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
755 | else f"/{deviceFilename}" |
10523 | 756 | ) |
757 | 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
|
758 | |
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
|
759 | @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
|
760 | 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
|
761 | """ |
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
|
762 | 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
|
763 | 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
|
764 | """ |
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
|
765 | 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
|
766 | |
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 | @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
|
768 | 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
|
769 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
770 | 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
|
771 | |
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
|
772 | @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
|
773 | @type bool |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
774 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
775 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
776 | if selectedItems: |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
777 | filename = selectedItems[0].text(0).strip() |
10523 | 778 | 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
|
779 | if not filename.endswith("/"): |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
780 | # 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
|
781 | 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
|
782 | 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
|
783 | 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
|
784 | 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
|
785 | 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
|
786 | QLineEdit.EchoMode.Normal, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
787 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
788 | ) |
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
|
789 | 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
|
790 | 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
|
791 | 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
|
792 | localFilename = filename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
793 | |
10523 | 794 | selectedLocalItems = self.localFileTreeWidget.selectedItems() |
795 | if selectedLocalItems: | |
796 | item = selectedLocalItems[0] | |
797 | if not item.text(0).endswith("/"): | |
798 | # it is no directory, take its parent | |
799 | item = item.parent() | |
800 | localPath = ( | |
801 | self.localCwd.text() | |
802 | if item is None | |
803 | else item.data(0, Qt.ItemDataRole.UserRole) | |
804 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
805 | localParent = self.localFileTreeWidget if item is None else item |
10523 | 806 | else: |
807 | localPath = self.localCwd.text() | |
808 | localParent = self.localFileTreeWidget | |
809 | ||
810 | if self.__isFileInList(localFilename, localParent): | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
811 | # ask for overwrite permission |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
812 | action, resultFilename = confirmOverwrite( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
813 | localFilename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
814 | 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
|
815 | 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
|
816 | True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
817 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
818 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
819 | if action == "cancel": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
820 | return |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
821 | elif action == "rename": |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
822 | localFilename = resultFilename |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
823 | |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
824 | 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
|
825 | shutil.copy2( |
10523 | 826 | deviceFilename, |
827 | 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
|
828 | ) |
10523 | 829 | if isinstance(localParent, QTreeWidgetItem): |
830 | self.__listLocalFiles(parentItem=localParent) | |
831 | else: | |
832 | 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
|
833 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
834 | self.__fileManager.get( |
10523 | 835 | 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
|
836 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
837 | |
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
|
838 | @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
|
839 | 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
|
840 | """ |
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
|
841 | 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
|
842 | 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
|
843 | """ |
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
|
844 | 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
|
845 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
846 | @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
|
847 | 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
|
848 | """ |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
849 | 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
|
850 | |
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
|
851 | @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
|
852 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
853 | @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
|
854 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
855 | """ |
10523 | 856 | localPath = os.path.dirname(localFile) |
857 | ||
858 | # find the directory entry associated with the new file | |
859 | localParent = self.__findDirectoryItem(localPath, self.localFileTreeWidget) | |
860 | ||
861 | if localParent: | |
862 | self.__listLocalFiles(parentItem=localParent) | |
863 | else: | |
864 | 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
|
865 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
866 | @pyqtSlot() |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
867 | def on_syncButton_clicked(self): |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
868 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
869 | 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
|
870 | """ |
10523 | 871 | # 1. local directory |
872 | selectedItems = self.localFileTreeWidget.selectedItems() | |
873 | if selectedItems: | |
874 | localName = selectedItems[0].text(0) | |
875 | if localName.endswith("/"): | |
876 | localDirPath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
877 | else: | |
878 | # it is not a directory | |
879 | localDirPath = os.path.dirname( | |
880 | selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
881 | ) | |
882 | else: | |
883 | localName = "" | |
884 | localDirPath = self.localCwd.text() | |
885 | ||
886 | # 2. device directory | |
887 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
888 | if selectedItems: | |
889 | if not selectedItems[0].text(0).endswith("/"): | |
890 | # it is not a directory | |
891 | deviceDirPath = os.path.dirname( | |
892 | selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
893 | ) | |
894 | else: | |
895 | deviceDirPath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) | |
896 | else: | |
897 | if localDirPath == self.localCwd.text(): | |
898 | # syncronize complete local directory | |
899 | deviceDirPath = self.deviceCwd.text() | |
900 | else: | |
901 | deviceCwd = self.deviceCwd.text() | |
902 | deviceDirPath = ( | |
903 | f"{deviceCwd}{localName[:-1]}" | |
904 | if deviceCwd.endswith("/") | |
905 | else f"{deviceCwd}/{localName[:-1]}" | |
906 | ) | |
907 | ||
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
908 | self.__fileManager.rsync( |
10523 | 909 | localDirPath, |
910 | deviceDirPath, | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
911 | mirror=True, |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
912 | localDevice=self.__repl.deviceSupportsLocalFileAccess(), |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
913 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
914 | |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
915 | @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
|
916 | def __handleRsyncDone(self, _localDir, _deviceDir): |
7081
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
917 | """ |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
918 | 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
|
919 | |
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
|
920 | @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
|
921 | @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
|
922 | @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
|
923 | @type str |
ed510767c096
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7080
diff
changeset
|
924 | """ |
8058
9769eb548f0d
MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
925 | # 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
|
926 | self.on_localReloadButton_clicked() |
9769eb548f0d
MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
927 | self.on_deviceReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
928 | |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
929 | @pyqtSlot(str) |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
930 | def __handleRsyncProgressMessage(self, message): |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
931 | """ |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
932 | 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
|
933 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
934 | @param message message to be shown |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
935 | @type str |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
936 | """ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
937 | 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
|
938 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
939 | if self.__progressInfoDialog is None: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
940 | self.__progressInfoDialog = MicroPythonProgressInfoDialog(self) |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
941 | self.__progressInfoDialog.finished.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
942 | self.__progressInfoDialogFinished |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
943 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
944 | self.__progressInfoDialog.show() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
945 | self.__progressInfoDialog.addMessage(message) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
946 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
947 | @pyqtSlot() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
948 | def __progressInfoDialogFinished(self): |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
949 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
950 | 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
|
951 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
952 | self.__progressInfoDialog.deleteLater() |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
953 | self.__progressInfoDialog = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
954 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
955 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
956 | def __newDeviceList(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
957 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
958 | 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
|
959 | """ |
10523 | 960 | self.__expandedDeviceEntries.clear() |
961 | itm = self.deviceFileTreeWidget.topLevelItem(0) | |
962 | while itm: | |
963 | if itm.isExpanded(): | |
964 | self.__expandedDeviceEntries.append( | |
965 | itm.data(0, Qt.ItemDataRole.UserRole) | |
966 | ) | |
967 | itm = self.deviceFileTreeWidget.itemBelow(itm) | |
968 | ||
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
|
969 | 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
|
970 | self.deviceCwd.text(), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
971 | 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
|
972 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
973 | |
9760 | 974 | @pyqtSlot() |
975 | def on_openButton_clicked(self): | |
976 | """ | |
977 | Private slot to open the selected file in a new editor. | |
978 | """ | |
979 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
980 | if selectedItems: | |
10523 | 981 | 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
|
982 | if self.__repl.deviceSupportsLocalFileAccess(): |
10523 | 983 | if not selectedItems[0].text(0).endswith("/") and MimeTypes.isTextFile( |
984 | name | |
985 | ): | |
986 | self.__viewmanager.getEditor(name) | |
9760 | 987 | else: |
10523 | 988 | if not selectedItems[0].text(0).endswith("/"): |
9760 | 989 | data = self.__fileManager.getData(name) |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
990 | text = data.decode(encoding="utf-8") |
10523 | 991 | 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
|
992 | text, "Python3", FileSystemUtilities.deviceFileName(name) |
9760 | 993 | ) |
994 | ||
995 | @pyqtSlot() | |
996 | def on_saveButton_clicked(self, saveAs=False): | |
997 | """ | |
998 | 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
|
999 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9764
diff
changeset
|
1000 | @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
|
1001 | @type bool |
9760 | 1002 | """ |
10523 | 1003 | aw = self.__viewmanager.activeWindow() |
10512 | 1004 | if aw: |
1005 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
10523 | 1006 | |
10512 | 1007 | if selectedItems: |
10523 | 1008 | filepath = selectedItems[0].data(0, Qt.ItemDataRole.UserRole) |
1009 | filename = os.path.basename(filepath) | |
1010 | if selectedItems[0].text(0).endswith("/"): | |
10512 | 1011 | saveAs = True |
1012 | else: | |
9760 | 1013 | saveAs = True |
10512 | 1014 | filename = "" |
9760 | 1015 | |
10512 | 1016 | if saveAs: |
1017 | filename, ok = QInputDialog.getText( | |
1018 | self, | |
1019 | self.tr("Save File As"), | |
1020 | self.tr("Enter a new name for the file:"), | |
1021 | QLineEdit.EchoMode.Normal, | |
1022 | filename, | |
1023 | ) | |
1024 | if not ok or not filename: | |
1025 | return | |
9760 | 1026 | |
10512 | 1027 | if not saveAs: |
1028 | # check editor and selected file names for an implicit 'save as' | |
1029 | editorFileName = os.path.basename( | |
1030 | FileSystemUtilities.plainFileName(aw.getFileName()) | |
1031 | ) | |
1032 | if editorFileName != filename: | |
1033 | saveAs = True | |
9764
57496966803c
Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9760
diff
changeset
|
1034 | |
10523 | 1035 | if selectedItems: |
1036 | item = selectedItems[0] | |
1037 | if not item.text(0).endswith("/"): | |
1038 | # it is no directory, take its parent | |
1039 | item = item.parent() | |
1040 | devicePath = ( | |
1041 | self.deviceCwd.text() | |
1042 | if item is None | |
1043 | else item.data(0, Qt.ItemDataRole.UserRole) | |
1044 | ) | |
10896
9cbbed624751
Fixed a few issues in the MicroPython file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1045 | deviceParent = self.deviceFileTreeWidget if item is None else item |
10523 | 1046 | else: |
1047 | devicePath = self.deviceCwd.text() | |
1048 | deviceParent = self.deviceFileTreeWidget | |
1049 | ||
1050 | if saveAs and self.__isFileInList(filename, deviceParent): | |
10512 | 1051 | # ask for overwrite permission |
1052 | action, resultFilename = confirmOverwrite( | |
1053 | filename, | |
1054 | self.tr("Save File As"), | |
1055 | self.tr("The given file exists already (Enter file name only)."), | |
1056 | False, | |
1057 | self, | |
1058 | ) | |
1059 | if action == "cancel": | |
1060 | return | |
1061 | elif action == "rename": | |
1062 | filename = os.path.basename(resultFilename) | |
9760 | 1063 | |
10512 | 1064 | text = aw.text() |
1065 | if self.__repl.deviceSupportsLocalFileAccess(): | |
10523 | 1066 | filename = os.path.join(devicePath, filename) |
10512 | 1067 | os.makedirs(os.path.dirname(filename), exist_ok=True) |
1068 | with open(filename, "w") as f: | |
1069 | f.write(text) | |
1070 | self.__newDeviceList() | |
1071 | aw.setFileName(filename) | |
1072 | else: | |
10523 | 1073 | filename = ( |
10898
8349907e1319
Corrected a code formatting issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10896
diff
changeset
|
1074 | f"{devicePath}/{filename}" if devicePath != "/" else f"/{filename}" |
10523 | 1075 | ) |
10512 | 1076 | dirname = filename.rsplit("/", 1)[0] |
1077 | self.__fileManager.makedirs(dirname) | |
1078 | self.__fileManager.putData(filename, text.encode("utf-8")) | |
1079 | aw.setFileName(FileSystemUtilities.deviceFileName(filename)) | |
9760 | 1080 | |
10512 | 1081 | aw.setModified(False) |
10523 | 1082 | with contextlib.suppress(AttributeError): |
1083 | aw.resetOnlineChangeTraceInfo() | |
9760 | 1084 | |
1085 | @pyqtSlot() | |
1086 | def on_saveAsButton_clicked(self): | |
1087 | """ | |
1088 | Private slot to save the current editor in a new file on the connected device. | |
1089 | """ | |
1090 | self.on_saveButton_clicked(saveAs=True) | |
1091 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1092 | ################################################################## |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1093 | ## 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
|
1094 | ################################################################## |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1095 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1096 | @pyqtSlot(QPoint) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1097 | def __showLocalContextMenu(self, pos): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1098 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1099 | 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
|
1100 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1101 | @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
|
1102 | @type QPoint |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1103 | """ |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1104 | hasSelection = bool(len(self.localFileTreeWidget.selectedItems())) |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1105 | if hasSelection: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1106 | 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
|
1107 | isDir = name.endswith("/") |
10523 | 1108 | isLink = name.endswith("@") |
1109 | isFile = not (isDir or isLink) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1110 | else: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1111 | isDir = False |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1112 | isFile = False |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1113 | self.__localDelDirTreeAct.setEnabled(isDir) |
10515 | 1114 | self.__localRenameFileAct.setEnabled(isFile) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1115 | self.__localDelFileAct.setEnabled(isFile) |
10911 | 1116 | self.__openLocalFileAct.setEnabled(isFile) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1117 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
1118 | 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
|
1119 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1120 | @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
|
1121 | def __changeLocalDirectory(self, localDevice=False): |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1122 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1123 | 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
|
1124 | |
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
|
1125 | @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
|
1126 | @type bool |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1127 | """ |
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
|
1128 | cwdWidget = self.deviceCwd if localDevice else self.localCwd |
10523 | 1129 | fileTreeWidget = ( |
1130 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1131 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1132 | |
10523 | 1133 | if fileTreeWidget.selectedItems(): |
1134 | defaultPath = fileTreeWidget.selectedItems()[0].data( | |
1135 | 0, Qt.ItemDataRole.UserRole | |
1136 | ) | |
1137 | if not os.path.isdir(defaultPath): | |
1138 | defaultPath = os.path.dirname(defaultPath) | |
1139 | else: | |
1140 | defaultPath = cwdWidget.text() | |
9238
a7cbf3d61498
EricPathPicker, EricPathPickerDialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
1141 | dirPath, ok = EricPathPickerDialog.getStrPath( |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1142 | self, |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1143 | self.tr("Change Directory"), |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1144 | 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
|
1145 | EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, |
10523 | 1146 | strPath=defaultPath, |
1147 | defaultDirectory=defaultPath, | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1148 | ) |
7083
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
1149 | if ok and dirPath: |
217862c28319
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7082
diff
changeset
|
1150 | 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
|
1151 | 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
|
1152 | cwdWidget.setText(dirPath) |
10523 | 1153 | 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
|
1154 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1155 | @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
|
1156 | def __createLocalDirectory(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1157 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1158 | 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
|
1159 | |
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
|
1160 | @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
|
1161 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1162 | """ |
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
|
1163 | cwdWidget = self.deviceCwd if localDevice else self.localCwd |
10523 | 1164 | fileTreeWidget = ( |
1165 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1166 | ) | |
1167 | ||
1168 | if fileTreeWidget.selectedItems(): | |
1169 | localItem = fileTreeWidget.selectedItems()[0] | |
1170 | defaultPath = localItem.data(0, Qt.ItemDataRole.UserRole) | |
1171 | if not os.path.isdir(defaultPath): | |
1172 | defaultPath = os.path.dirname(defaultPath) | |
1173 | localItem = localItem.parent() | |
1174 | else: | |
1175 | defaultPath = cwdWidget.text() | |
1176 | localItem = None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1177 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1178 | dirPath, ok = QInputDialog.getText( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1179 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1180 | self.tr("Create Directory"), |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1181 | 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
|
1182 | QLineEdit.EchoMode.Normal, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1183 | ) |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1184 | if ok and dirPath: |
10523 | 1185 | 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
|
1186 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1187 | os.mkdir(dirPath) |
10523 | 1188 | if localItem: |
1189 | self.__listLocalFiles(localDevice=localDevice, parentItem=localItem) | |
1190 | else: | |
1191 | self.__listLocalFiles( | |
1192 | dirname=cwdWidget.text(), localDevice=localDevice | |
1193 | ) | |
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
|
1194 | 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
|
1195 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1196 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1197 | self.tr("Create Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1198 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1199 | """<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
|
1200 | """ 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
|
1201 | ).format(dirPath, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1202 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1203 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1204 | @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
|
1205 | def __deleteLocalDirectoryTree(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1206 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1207 | 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
|
1208 | |
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
|
1209 | @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
|
1210 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1211 | """ |
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
|
1212 | 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
|
1213 | 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
|
1214 | 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
|
1215 | 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
|
1216 | 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
|
1217 | fileTreeWidget = self.localFileTreeWidget |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1218 | |
10523 | 1219 | if bool(fileTreeWidget.selectedItems()): |
1220 | localItem = fileTreeWidget.selectedItems()[0] | |
1221 | parentItem = localItem.parent() | |
1222 | 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
|
1223 | dlg = DeleteFilesConfirmationDialog( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1224 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1225 | 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
|
1226 | 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
|
1227 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1228 | ) |
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
|
1229 | 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
|
1230 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1231 | shutil.rmtree(dirname) |
10523 | 1232 | if parentItem: |
1233 | self.__listLocalFiles( | |
1234 | localDevice=localDevice, parentItem=parentItem | |
1235 | ) | |
1236 | else: | |
1237 | self.__listLocalFiles( | |
1238 | dirname=cwdWidget.text(), localDevice=localDevice | |
1239 | ) | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1240 | 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
|
1241 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1242 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1243 | 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
|
1244 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1245 | """<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
|
1246 | """ 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
|
1247 | ).format(dirname, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1248 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1249 | |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1250 | @pyqtSlot() |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1251 | def __deleteLocalFile(self, localDevice=False): |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1252 | """ |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1253 | 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
|
1254 | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1255 | @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
|
1256 | @type bool |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1257 | """ |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1258 | if localDevice: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1259 | cwdWidget = self.deviceCwd |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1260 | fileTreeWidget = self.deviceFileTreeWidget |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1261 | else: |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1262 | cwdWidget = self.localCwd |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1263 | fileTreeWidget = self.localFileTreeWidget |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1264 | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1265 | if bool(len(fileTreeWidget.selectedItems())): |
10523 | 1266 | localItem = fileTreeWidget.selectedItems()[0] |
1267 | parentItem = localItem.parent() | |
1268 | 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
|
1269 | dlg = DeleteFilesConfirmationDialog( |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1270 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1271 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1272 | 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
|
1273 | [filename], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1274 | ) |
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
|
1275 | 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
|
1276 | try: |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1277 | os.remove(filename) |
10523 | 1278 | if parentItem: |
1279 | self.__listLocalFiles( | |
1280 | localDevice=localDevice, parentItem=parentItem | |
1281 | ) | |
1282 | else: | |
1283 | self.__listLocalFiles( | |
1284 | dirname=cwdWidget.text(), localDevice=localDevice | |
1285 | ) | |
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
|
1286 | 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
|
1287 | EricMessageBox.critical( |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1288 | self, |
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1289 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1290 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1291 | """<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
|
1292 | """ 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
|
1293 | ).format(filename, str(exc)), |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1294 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1295 | |
10515 | 1296 | @pyqtSlot() |
1297 | def __renameLocalFile(self, localDevice=False): | |
1298 | """ | |
1299 | Private slot to rename a file on the device. | |
1300 | ||
1301 | @param localDevice flag indicating device access via local file system | |
1302 | (defaults to False) | |
1303 | @type bool (optional) | |
1304 | """ | |
10523 | 1305 | fileTreeWidget = ( |
1306 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1307 | ) | |
10515 | 1308 | |
1309 | if bool(len(fileTreeWidget.selectedItems())): | |
10523 | 1310 | localItem = fileTreeWidget.selectedItems()[0] |
1311 | filename = localItem.data(0, Qt.ItemDataRole.UserRole) | |
10515 | 1312 | newname, ok = QInputDialog.getText( |
1313 | self, | |
1314 | self.tr("Rename File"), | |
1315 | self.tr("Enter the new path for the file"), | |
1316 | QLineEdit.EchoMode.Normal, | |
1317 | filename, | |
1318 | ) | |
1319 | if ok and newname: | |
1320 | try: | |
1321 | os.rename(filename, newname) | |
1322 | except OSError as exc: | |
1323 | EricMessageBox.critical( | |
1324 | self, | |
1325 | self.tr("Rename File"), | |
1326 | self.tr( | |
1327 | """<p>The file <b>{0}</b> could not be""" | |
1328 | """ renamed to <b>{1}</b>.</p><p>Reason: {2}</p>""" | |
1329 | ).format(filename, newname, str(exc)), | |
1330 | ) | |
1331 | ||
1332 | # reload the directory listing | |
1333 | if localDevice: | |
1334 | self.on_deviceReloadButton_clicked() | |
1335 | else: | |
1336 | self.on_localReloadButton_clicked() | |
1337 | ||
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
|
1338 | @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
|
1339 | 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
|
1340 | """ |
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
|
1341 | 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
|
1342 | |
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
|
1343 | @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
|
1344 | @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
|
1345 | """ |
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
|
1346 | 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
|
1347 | self.on_localReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1348 | |
10523 | 1349 | @pyqtSlot() |
1350 | def __clearLocalSelection(self): | |
1351 | """ | |
1352 | Private slot to clear the local selection. | |
1353 | """ | |
1354 | for item in self.localFileTreeWidget.selectedItems()[:]: | |
1355 | item.setSelected(False) | |
1356 | ||
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1357 | ################################################################## |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1358 | ## 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
|
1359 | ################################################################## |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1360 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1361 | @pyqtSlot(QPoint) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1362 | def __showDeviceContextMenu(self, pos): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1363 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1364 | 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
|
1365 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1366 | @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
|
1367 | @type QPoint |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1368 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1369 | hasSelection = bool(len(self.deviceFileTreeWidget.selectedItems())) |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1370 | if hasSelection: |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1371 | 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
|
1372 | isDir = name.endswith("/") |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1373 | isFile = not isDir |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1374 | else: |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1375 | isDir = False |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1376 | 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
|
1377 | 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
|
1378 | 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
|
1379 | self.__devDelDirTreeAct.setEnabled(isDir) |
10515 | 1380 | self.__devRenameFileAct.setEnabled(isFile) |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1381 | self.__devDelFileAct.setEnabled(isFile) |
10911 | 1382 | self.__openDeviceFileAct.setEnabled(isFile) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1383 | |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
1384 | 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
|
1385 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1386 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1387 | def __changeDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1388 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1389 | 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
|
1390 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1391 | 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
|
1392 | current directory. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1393 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1394 | 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
|
1395 | 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
|
1396 | else: |
10523 | 1397 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
1398 | if selectedItems: | |
1399 | item = selectedItems[0] | |
1400 | dirName = ( | |
1401 | item.data(0, Qt.ItemDataRole.UserRole) | |
1402 | if item.text(0).endswith("/") | |
1403 | else os.path.dirname(item.data(0, Qt.ItemDataRole.UserRole)) | |
1404 | ) | |
1405 | else: | |
1406 | 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
|
1407 | 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
|
1408 | 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
|
1409 | 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
|
1410 | 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
|
1411 | QLineEdit.EchoMode.Normal, |
10523 | 1412 | dirName, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1413 | ) |
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
|
1414 | 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
|
1415 | 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
|
1416 | 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
|
1417 | self.__fileManager.cd(dirPath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1418 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1419 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1420 | def __createDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1421 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1422 | 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
|
1423 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1424 | 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
|
1425 | 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
|
1426 | else: |
10523 | 1427 | selectedItems = self.deviceFileTreeWidget.selectedItems() |
1428 | if selectedItems: | |
1429 | item = selectedItems[0] | |
1430 | defaultPath = ( | |
1431 | item.data(0, Qt.ItemDataRole.UserRole) | |
1432 | if item.text(0).endswith("/") | |
1433 | else os.path.dirname(item.data(0, Qt.ItemDataRole.UserRole)) | |
1434 | ) | |
1435 | else: | |
1436 | 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
|
1437 | 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
|
1438 | 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
|
1439 | 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
|
1440 | 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
|
1441 | QLineEdit.EchoMode.Normal, |
10523 | 1442 | defaultPath, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1443 | ) |
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
|
1444 | 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
|
1445 | self.__fileManager.mkdir(dirPath) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1446 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1447 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1448 | def __deleteDeviceDirectory(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1449 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1450 | 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
|
1451 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1452 | 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
|
1453 | 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
|
1454 | else: |
10523 | 1455 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1456 | dirname = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1457 | 0, Qt.ItemDataRole.UserRole | |
1458 | ) | |
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
|
1459 | 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
|
1460 | 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
|
1461 | self.tr("Delete Directory"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1462 | 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
|
1463 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1464 | ) |
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
|
1465 | 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
|
1466 | self.__fileManager.rmdir(dirname) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1467 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1468 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1469 | def __deleteDeviceDirectoryTree(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1470 | """ |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1471 | 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
|
1472 | recursively. |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1473 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1474 | 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
|
1475 | 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
|
1476 | 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
|
1477 | if bool(len(self.deviceFileTreeWidget.selectedItems())): |
10523 | 1478 | dirname = self.deviceFileTreeWidget.selectedItems()[0].data( |
1479 | 0, Qt.ItemDataRole.UserRole | |
1480 | ) | |
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
|
1481 | 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
|
1482 | 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
|
1483 | 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
|
1484 | 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
|
1485 | [dirname], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1486 | ) |
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
|
1487 | 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
|
1488 | 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
|
1489 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1490 | @pyqtSlot() |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1491 | def __deleteDeviceFile(self): |
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1492 | """ |
7084
3eddfc540614
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7083
diff
changeset
|
1493 | 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
|
1494 | """ |
9767
2eed840795c0
Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9766
diff
changeset
|
1495 | 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
|
1496 | self.__deleteLocalFile(True) |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1497 | else: |
10523 | 1498 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1499 | filename = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1500 | 0, Qt.ItemDataRole.UserRole | |
1501 | ) | |
7131
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1502 | dlg = DeleteFilesConfirmationDialog( |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1503 | self, |
f75e990caf99
MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7130
diff
changeset
|
1504 | self.tr("Delete File"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1505 | 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
|
1506 | [filename], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1507 | ) |
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
|
1508 | 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
|
1509 | self.__fileManager.delete(filename) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1510 | |
10515 | 1511 | @pyqtSlot() |
1512 | def __renameDeviceFile(self): | |
1513 | """ | |
1514 | Private slot to rename a file on the device. | |
1515 | """ | |
1516 | if self.__repl.deviceSupportsLocalFileAccess(): | |
1517 | self.__renameLocalFile(True) | |
1518 | else: | |
10523 | 1519 | if bool(self.deviceFileTreeWidget.selectedItems()): |
1520 | filename = self.deviceFileTreeWidget.selectedItems()[0].data( | |
1521 | 0, Qt.ItemDataRole.UserRole | |
1522 | ) | |
10515 | 1523 | newname, ok = QInputDialog.getText( |
1524 | self, | |
1525 | self.tr("Rename File"), | |
1526 | self.tr("Enter the new path for the file"), | |
1527 | QLineEdit.EchoMode.Normal, | |
1528 | filename, | |
1529 | ) | |
1530 | if ok and newname: | |
1531 | success = self.__fileManager.rename(filename, newname) | |
1532 | if success: | |
1533 | self.on_deviceReloadButton_clicked() | |
1534 | ||
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
|
1535 | @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
|
1536 | 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
|
1537 | """ |
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
|
1538 | 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
|
1539 | |
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
|
1540 | @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
|
1541 | @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
|
1542 | """ |
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
|
1543 | 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
|
1544 | self.on_deviceReloadButton_clicked() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1545 | |
7082
ec199ef0cfc6
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7081
diff
changeset
|
1546 | @pyqtSlot() |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1547 | def __showFileSystemInfo(self): |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1548 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1549 | 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
|
1550 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1551 | self.__fileManager.fileSystemInfo() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1552 | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1553 | @pyqtSlot(tuple) |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7095
diff
changeset
|
1554 | def __fsInfoResultReceived(self, fsinfo): |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1555 | """ |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7095
diff
changeset
|
1556 | 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
|
1557 | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1558 | @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
|
1559 | 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
|
1560 | @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
|
1561 | """ |
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1562 | msg = self.tr("<h3>Filesystem Information</h3>") |
9959 | 1563 | if fsinfo: |
1564 | for name, totalSize, usedSize, freeSize in fsinfo: | |
1565 | msg += self.tr( | |
1566 | "<h4>{0}</h4" | |
1567 | "<table>" | |
1568 | "<tr><td>Total Size: </td><td align='right'>{1}</td></tr>" | |
1569 | "<tr><td>Used Size: </td><td align='right'>{2}</td></tr>" | |
1570 | "<tr><td>Free Size: </td><td align='right'>{3}</td></tr>" | |
1571 | "</table>" | |
1572 | ).format( | |
1573 | 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
|
1574 | 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
|
1575 | 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
|
1576 | EricUtilities.dataString(freeSize), |
9959 | 1577 | ) |
1578 | else: | |
7088
e29b0ee86b29
MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7084
diff
changeset
|
1579 | msg += self.tr( |
9959 | 1580 | "<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
|
1581 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
1582 | EricMessageBox.information(self, self.tr("Filesystem Information"), msg) |
10523 | 1583 | |
1584 | @pyqtSlot() | |
1585 | def __clearDeviceSelection(self): | |
1586 | """ | |
1587 | Private slot to clear the local selection. | |
1588 | """ | |
1589 | for item in self.deviceFileTreeWidget.selectedItems()[:]: | |
1590 | item.setSelected(False) | |
10911 | 1591 | |
1592 | ############################################################################ | |
1593 | ## Methods for the MicroPython window variant. | |
1594 | ############################################################################ | |
1595 | ||
1596 | @pyqtSlot() | |
1597 | def __newLocalFile(self, localDevice=False): | |
1598 | """ | |
1599 | Private slot to create a new local file. | |
1600 | ||
1601 | @param localDevice flag indicating device access via local file system | |
1602 | @type bool | |
1603 | """ | |
1604 | cwdWidget = self.deviceCwd if localDevice else self.localCwd | |
1605 | fileTreeWidget = ( | |
1606 | self.deviceFileTreeWidget if localDevice else self.localFileTreeWidget | |
1607 | ) | |
1608 | ||
1609 | if fileTreeWidget.selectedItems(): | |
1610 | localItem = fileTreeWidget.selectedItems()[0] | |
1611 | defaultPath = localItem.data(0, Qt.ItemDataRole.UserRole) | |
1612 | if not os.path.isdir(defaultPath): | |
1613 | defaultPath = os.path.dirname(defaultPath) | |
1614 | localItem = localItem.parent() | |
1615 | else: | |
1616 | defaultPath = cwdWidget.text() | |
1617 | localItem = None | |
1618 | ||
1619 | filePath, ok = QInputDialog.getText( | |
1620 | self, | |
1621 | self.tr("New File"), | |
1622 | self.tr("Enter file name:"), | |
1623 | QLineEdit.EchoMode.Normal, | |
1624 | ) | |
1625 | if ok and filePath: | |
1626 | filePath = os.path.join(defaultPath, filePath) | |
1627 | try: | |
1628 | with open(filePath, "w") as f: | |
1629 | f.close() | |
1630 | if localItem: | |
1631 | self.__listLocalFiles(localDevice=localDevice, parentItem=localItem) | |
1632 | else: | |
1633 | self.__listLocalFiles( | |
1634 | dirname=cwdWidget.text(), localDevice=localDevice | |
1635 | ) | |
1636 | except OSError as exc: | |
1637 | EricMessageBox.critical( | |
1638 | self, | |
1639 | self.tr("New File"), | |
1640 | self.tr( | |
1641 | """<p>The file <b>{0}</b> could not be""" | |
1642 | """ created.</p><p>Reason: {1}</p>""" | |
1643 | ).format(filePath, str(exc)), | |
1644 | ) | |
1645 | ||
1646 | @pyqtSlot() | |
1647 | def __openLocalFile(self): | |
1648 | """ | |
1649 | Private slot to open the selected local file in an editor window. | |
1650 | """ | |
1651 | self.on_localFileTreeWidget_itemActivated( | |
1652 | self.localFileTreeWidget.selectedItems()[0], 0 | |
1653 | ) | |
1654 | ||
1655 | @pyqtSlot() | |
1656 | def __newDeviceFile(self): | |
1657 | """ | |
1658 | Private slot to create a new file on the connected device. | |
1659 | """ | |
1660 | # TODO: not implemented yet | |
1661 | if self.__repl.deviceSupportsLocalFileAccess(): | |
1662 | self.__newLocalFile(True) | |
1663 | else: | |
1664 | selectedItems = self.deviceFileTreeWidget.selectedItems() | |
1665 | if selectedItems: | |
1666 | item = selectedItems[0] | |
1667 | defaultPath = ( | |
1668 | item.data(0, Qt.ItemDataRole.UserRole) | |
1669 | if item.text(0).endswith("/") | |
1670 | else os.path.dirname(item.data(0, Qt.ItemDataRole.UserRole)) | |
1671 | ) | |
1672 | else: | |
1673 | defaultPath = self.deviceCwd.text() | |
1674 | fileName, ok = QInputDialog.getText( | |
1675 | self, | |
1676 | self.tr("New File"), | |
1677 | self.tr("Enter file name:"), | |
1678 | QLineEdit.EchoMode.Normal, | |
1679 | defaultPath, | |
1680 | ) | |
1681 | if ok and fileName: | |
1682 | self.__fileManager.writeFile(fileName, "") | |
1683 | ||
1684 | @pyqtSlot() | |
1685 | def __openDeviceFile(self): | |
1686 | """ | |
1687 | Private slot to open the selected device file in an editor window. | |
1688 | """ | |
1689 | self.on_deviceFileTreeWidget_itemActivated( | |
1690 | self.deviceFileTreeWidget.selectedItems()[0], 0 | |
1691 | ) |