src/eric7/MicroPython/MicroPythonFileManagerWidget.py

Sun, 30 Jul 2023 17:33:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 30 Jul 2023 17:33:54 +0200
branch
eric7
changeset 10143
bf84513859ca
parent 9959
8ca27cc20953
child 10236
c270c9501f1c
permissions
-rw-r--r--

MicroPython
- Fixed an issue caused by a forgotten file existence check.

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
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9576
diff changeset
3 # Copyright (c) 2019 - 2023 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
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
10 import os
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
11 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
12
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
13 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
14 from PyQt6.QtWidgets import (
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
15 QDialog,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
16 QHeaderView,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
17 QInputDialog,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
18 QLineEdit,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19 QMenu,
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
20 QTreeWidgetItem,
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
21 QWidget,
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
22 )
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
23
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
24 from eric7 import Globals, Preferences, Utilities
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
25 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
26 from eric7.EricWidgets import EricMessageBox, EricPathPickerDialog
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
27 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
28 from eric7.EricWidgets.EricFileSaveConfirmDialog import confirmOverwrite
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
29 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
30 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
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
31
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
32 from .MicroPythonFileSystemUtilities import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33 decoratedName,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34 listdirStat,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
35 mode2string,
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
36 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
37 )
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
38 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
39
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
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
41 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
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 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
44 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
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
46 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
47 """
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
48 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
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
50 @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
51 @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
52 @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
53 @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
54 """
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
55 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
56 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57
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
58 self.__repl = parent
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59
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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 self.deviceReloadButton.setIcon(EricPixmapCache.getIcon("reload"))
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
71 self.openButton.setIcon(EricPixmapCache.getIcon("open"))
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
72 self.saveButton.setIcon(EricPixmapCache.getIcon("fileSave"))
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
73 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
74
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
75 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
76
f0e22f3a5878 Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9765
diff changeset
77 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
78 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
79
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
80 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
81 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
82 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
83 self.getAsButton.setEnabled(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
85 self.openButton.setEnabled(False)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
86 self.saveButton.setEnabled(False)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
87
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
88 self.localFileTreeWidget.header().setSortIndicator(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89 0, Qt.SortOrder.AscendingOrder
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90 )
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
91 self.deviceFileTreeWidget.header().setSortIndicator(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92 0, Qt.SortOrder.AscendingOrder
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
93 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
95 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
96 self.__fileManager = fileManager
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
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
98 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
99 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
100 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
101 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
102 self.__fileManager.getFileDone.connect(self.__handleGetDone)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
103 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
104 self.__fileManager.rsyncProgressMessage.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105 self.__handleRsyncProgressMessage
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106 )
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
107 self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
108 self.__fileManager.createDirectoryDone.connect(self.__newDeviceList)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
109 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
110 self.__fileManager.fsinfoDone.connect(self.__fsInfoResultReceived)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
111 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
112
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
113 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
114
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
115 self.localFileTreeWidget.customContextMenuRequested.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116 self.__showLocalContextMenu
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117 )
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
118 self.deviceFileTreeWidget.customContextMenuRequested.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119 self.__showDeviceContextMenu
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120 )
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.__localMenu = QMenu(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123 self.__localMenu.addAction(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
124 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
125 )
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
126 self.__localMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127 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
128 )
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
129 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
130 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
131 )
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
132 self.__localMenu.addSeparator()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
133 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
134 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
135 )
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
136 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
137 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
138 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
139 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
140 act.triggered[bool].connect(self.__localHiddenChanged)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
142 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
143 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
144 self.__deviceMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
145 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
146 )
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
147 self.__deviceMenu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148 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
149 )
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
150 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
151 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
152 )
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
153 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
154 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
155 )
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7108
diff changeset
156 self.__deviceMenu.addSeparator()
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
157 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
158 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
159 )
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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
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("Show Filesystem Info"), self.__showFileSystemInfo
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170
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
171 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
172 """
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
173 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
174 """
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
175 dirname = ""
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
176 vm = ericApp().getObject("ViewManager")
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
177 aw = vm.activeWindow()
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
178 if aw and aw.isLocalFile():
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
179 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
180 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
181 dirname = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
182 Preferences.getMicroPython("MpyWorkspace")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
183 or Preferences.getMultiProject("Workspace")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184 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
185 )
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
186 self.__listLocalFiles(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
187
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
188 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
189 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
190 if dirname:
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
191 self.__listLocalFiles(dirname, 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
192 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193
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
194 # 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
195 self.__fileManager.pwd()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196
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
197 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
198 """
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
199 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
200 """
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
201 pass
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
202
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
203 @pyqtSlot(str, str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
204 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
205 """
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 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
207
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
208 @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
209 @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
210 @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
211 @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
212 """
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
213 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
214 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
215 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
216 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217 "<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
218 " 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
219 ).format(method, error),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221
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
222 @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
223 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
224 """
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
225 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
226
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
227 @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
228 @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
229 """
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
230 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
231 self.__newDeviceList()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
232
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
233 @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
234 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
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 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
237
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
238 @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
239 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
240 @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
241 """
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
242 self.deviceFileTreeWidget.clear()
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
243 for name, mode, size, dateTime in filesList:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
244 itm = QTreeWidgetItem(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
245 self.deviceFileTreeWidget, [name, mode, size, dateTime]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
246 )
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
247 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
248 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
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
249 self.deviceFileTreeWidget.header().resizeSections(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
250 QHeaderView.ResizeMode.ResizeToContents
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252
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
253 def __listLocalFiles(self, dirname="", localDevice=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
254 """
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
255 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
256
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 @param dirname name of the local directory to be listed
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 @type str
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
259 @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
260 @type bool
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
261 """
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 if not 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
263 dirname = os.getcwd()
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
264 if dirname != os.sep and dirname.endswith(os.sep):
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
265 dirname = dirname[:-1]
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
266 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
267 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
268 showHidden = Preferences.getMicroPython("ShowHiddenDevice")
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
269 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
270 self.localCwd.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
271 showHidden = Preferences.getMicroPython("ShowHiddenLocal")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272
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
273 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
274 filesList = [
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
276 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
277 mode2string(s[0]),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278 str(s[6]),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279 mtime2string(s[8]),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
280 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281 for f, s in filesStatList
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282 ]
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
283 fileTreeWidget = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 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
285 )
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
286 fileTreeWidget.clear()
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
287 for item in filesList:
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
288 itm = QTreeWidgetItem(fileTreeWidget, item)
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
289 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
290 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
291 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
292
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
293 @pyqtSlot(QTreeWidgetItem, 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
294 def on_localFileTreeWidget_itemActivated(self, item, column):
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
296 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
297
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
298 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
299 directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
300
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
301 @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
302 @type QTreeWidgetItem
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
303 @param column column of the activation
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 @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
305 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
306 name = os.path.join(self.localCwd.text(), item.text(0))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
307 if name.endswith("/"):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
308 # directory names end with a '/'
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
309 self.__listLocalFiles(name[:-1])
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
310 elif Utilities.MimeTypes.isTextFile(name):
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
311 ericApp().getObject("ViewManager").getEditor(name)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
312
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
313 @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
314 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
315 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
316 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
317 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
318 enable = bool(len(self.localFileTreeWidget.selectedItems()))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
319 if enable:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
320 enable &= not (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
321 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
322 )
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
323 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
324 self.putAsButton.setEnabled(enable)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
326 @pyqtSlot(str)
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
327 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
328 """
9786
f94b530722af Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9769
diff changeset
329 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
330
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
331 @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
332 @type str
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
333 """
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
334 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
335
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
336 @pyqtSlot()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
337 def on_localUpButton_clicked(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
338 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
339 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
340 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
341 cwd = self.localCwd.text()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
342 dirname = os.path.dirname(cwd)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
343 self.__listLocalFiles(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
344
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
345 @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
346 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
347 """
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
348 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
349 """
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
350 dirname = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351 Preferences.getMicroPython("MpyWorkspace")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
352 or Preferences.getMultiProject("Workspace")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
353 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
354 )
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
355 self.__listLocalFiles(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
356
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
357 @pyqtSlot()
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
358 def on_localReloadButton_clicked(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
359 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
360 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
361 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
362 dirname = self.localCwd.text()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
363 self.__listLocalFiles(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
364
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
365 @pyqtSlot(QTreeWidgetItem, 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
366 def on_deviceFileTreeWidget_itemActivated(self, item, column):
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
367 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
368 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
369
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
370 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
371 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
372
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
373 @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
374 @type QTreeWidgetItem
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
375 @param column column of the activation
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
376 @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
377 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
378 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
379 name = os.path.join(self.deviceCwd.text(), item.text(0))
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
380 if name.endswith("/"):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
381 # directory names end with a '/'
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
382 self.__listLocalFiles(name[:-1], True)
10143
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
383 else:
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
384 if not os.path.exists(name):
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
385 EricMessageBox.warning(
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
386 self,
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
387 self.tr("Open Device File"),
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
388 self.tr(
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
389 """<p>The file <b>{0}</b> does not exist.</p>"""
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
390 ).format(name),
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
391 )
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
392 return
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
393 if Utilities.MimeTypes.isTextFile(name):
bf84513859ca MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9959
diff changeset
394 ericApp().getObject("ViewManager").getEditor(name)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
395 else:
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
396 cwd = self.deviceCwd.text()
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
397 if cwd:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
398 name = (
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
399 cwd + item.text(0)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
400 if cwd.endswith("/")
9765
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
401 else "{0}/{1}".format(cwd, item.text(0))
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
402 )
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
403 else:
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
404 name = item.text(0)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
405 if name.endswith("/"):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
406 # directory names end with a '/'
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
407 self.__fileManager.cd(name[:-1])
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
408 else:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
409 data = self.__fileManager.getData(name)
9765
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
410 text = data.decode(encoding="utf-8")
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
411 ericApp().getObject("ViewManager").newEditorWithText(
9905
189b7a23c3c6 Changed some code to let the editor determine the highlighter language for files loaded from a connected µPy device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9853
diff changeset
412 text, fileName="device:{0}".format(name)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
413 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
414
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
415 @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
416 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
417 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
418 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
419 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
420 enable = bool(len(self.deviceFileTreeWidget.selectedItems()))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
421 if enable:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
422 enable &= not (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
423 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
424 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
425 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
426 self.getAsButton.setEnabled(enable)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
427
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
428 self.openButton.setEnabled(enable)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
429 self.saveButton.setEnabled(enable)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
430
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
431 @pyqtSlot(str)
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
432 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
433 """
9786
f94b530722af Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9769
diff changeset
434 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
435
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
436 @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
437 @type str
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
438 """
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
439 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
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()
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
442 def on_deviceUpButton_clicked(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
443 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
444 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
445 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
446 cwd = self.deviceCwd.text()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
447 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
448 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
449 self.__listLocalFiles(dirname, True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
450 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
451 self.__fileManager.cd(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
452
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
453 @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
454 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
455 """
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
456 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
457 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
458 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
459 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
460 if dirname:
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
461 self.__listLocalFiles(dirname, True)
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
462 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
463
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
464 # 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
465 self.__fileManager.cd("/")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
466
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
467 @pyqtSlot()
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
468 def on_deviceReloadButton_clicked(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
469 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
470 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
471 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
472 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
473 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
474 self.__listLocalFiles(dirname, True)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
475 else:
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
476 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
477 self.__newDeviceList()
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
478 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
479 self.__fileManager.pwd()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
481 def __isFileInList(self, filename, treeWidget):
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
482 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
483 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
484
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
485 @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
486 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
487 @param treeWidget reference to the tree widget to be checked against
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
488 @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
489 @rtype bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
490 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
491 itemCount = treeWidget.topLevelItemCount()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
492 return itemCount > 0 and any(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
493 treeWidget.topLevelItem(row).text(0) == filename for row in range(itemCount)
8221
0572a215bd2f Applied some more code simplifications suggested by the new Simplify checker (Y110, Y111: use any() or all()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
494 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
495
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
496 @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
497 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
498 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
499 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
500
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
501 @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
502 @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
503 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
504 selectedItems = self.localFileTreeWidget.selectedItems()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
505 if selectedItems:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
506 filename = selectedItems[0].text(0).strip()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
507 if not filename.endswith("/"):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
508 # 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
509 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
510 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
511 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
512 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
513 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
514 QLineEdit.EchoMode.Normal,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
515 filename,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
516 )
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
517 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
518 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
519 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
520 deviceFilename = filename
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
521
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
522 if self.__isFileInList(deviceFilename, self.deviceFileTreeWidget):
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
523 # ask for overwrite permission
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
524 action, resultFilename = confirmOverwrite(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
525 deviceFilename,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
526 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
527 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
528 "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
529 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
530 False,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
531 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
532 )
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
533 if action == "cancel":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
534 return
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
535 elif action == "rename":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
536 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
537
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
538 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
539 shutil.copy2(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
540 os.path.join(self.localCwd.text(), filename),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
541 os.path.join(self.deviceCwd.text(), deviceFilename),
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
542 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
543 self.__listLocalFiles(self.deviceCwd.text(), localDevice=True)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
544 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
545 deviceCwd = self.deviceCwd.text()
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
546 if deviceCwd:
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
547 if deviceCwd != "/":
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
548 deviceFilename = deviceCwd + "/" + deviceFilename
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
549 else:
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
550 deviceFilename = "/" + deviceFilename
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
551 self.__fileManager.put(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
552 os.path.join(self.localCwd.text(), filename), deviceFilename
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
553 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
554
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
555 @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
556 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
557 """
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
558 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
559 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
560 """
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
561 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
562
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
563 @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
564 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
565 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
566 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
567
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
568 @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
569 @type bool
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
570 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
571 selectedItems = self.deviceFileTreeWidget.selectedItems()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
572 if selectedItems:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
573 filename = selectedItems[0].text(0).strip()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
574 if not filename.endswith("/"):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
575 # 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
576 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
577 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
578 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
579 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
580 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
581 QLineEdit.EchoMode.Normal,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
582 filename,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
583 )
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
584 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
585 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
586 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
587 localFilename = filename
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
588
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
589 if self.__isFileInList(localFilename, self.localFileTreeWidget):
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
590 # ask for overwrite permission
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
591 action, resultFilename = confirmOverwrite(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
592 localFilename,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
593 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
594 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
595 True,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
596 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
597 )
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
598 if action == "cancel":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
599 return
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
600 elif action == "rename":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
601 localFilename = resultFilename
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
602
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
603 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
604 shutil.copy2(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
605 os.path.join(self.deviceCwd.text(), filename),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
606 os.path.join(self.localCwd.text(), localFilename),
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
607 )
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
608 self.__listLocalFiles(self.localCwd.text())
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
609 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
610 deviceCwd = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
611 if deviceCwd:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
612 filename = deviceCwd + "/" + filename
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
613 self.__fileManager.get(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
614 filename, os.path.join(self.localCwd.text(), localFilename)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
615 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
616
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
617 @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
618 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
619 """
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
620 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
621 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
622 """
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
623 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
624
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
625 @pyqtSlot(str, str)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
626 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
627 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
628 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
629
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
630 @param deviceFile name of the file on the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
631 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
632 @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
633 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
634 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
635 self.__listLocalFiles(self.localCwd.text())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
636
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
637 @pyqtSlot()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
638 def on_syncButton_clicked(self):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
639 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
640 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
641 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
642 self.__fileManager.rsync(
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
643 self.localCwd.text(),
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
644 self.deviceCwd.text(),
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
645 mirror=True,
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
646 localDevice=self.__repl.deviceSupportsLocalFileAccess(),
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
647 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
648
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
649 @pyqtSlot(str, str)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
650 def __handleRsyncDone(self, localDir, deviceDir):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
651 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
652 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
653
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
654 @param localDir name of the local directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
655 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
656 @param deviceDir name of the device directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
657 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
658 """
8058
9769eb548f0d MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
659 # 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
660 self.on_localReloadButton_clicked()
9769eb548f0d MicroPython: implemented some fixes for issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
661 self.on_deviceReloadButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
662
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
663 @pyqtSlot(str)
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
664 def __handleRsyncProgressMessage(self, message):
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
665 """
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
666 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
667
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
668 @param message message to be shown
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
669 @type str
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
670 """
9482
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
671 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
672
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
673 if self.__progressInfoDialog is None:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
674 self.__progressInfoDialog = MicroPythonProgressInfoDialog(self)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
675 self.__progressInfoDialog.finished.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
676 self.__progressInfoDialogFinished
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
677 )
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
678 self.__progressInfoDialog.show()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
679 self.__progressInfoDialog.addMessage(message)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
680
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
681 @pyqtSlot()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
682 def __progressInfoDialogFinished(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
683 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
684 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
685 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
686 self.__progressInfoDialog.deleteLater()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
687 self.__progressInfoDialog = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
688
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
689 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
690 def __newDeviceList(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
691 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
692 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
693 """
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
694 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
695 self.deviceCwd.text(),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
696 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
697 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
698
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
699 @pyqtSlot()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
700 def on_openButton_clicked(self):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
701 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
702 Private slot to open the selected file in a new editor.
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
703 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
704 selectedItems = self.deviceFileTreeWidget.selectedItems()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
705 if selectedItems:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
706 filename = selectedItems[0].text(0).strip()
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
707 if self.__repl.deviceSupportsLocalFileAccess():
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
708 name = os.path.join(self.deviceCwd.text(), filename)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
709 if not name.endswith("/") and Utilities.MimeTypes.isTextFile(name):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
710 ericApp().getObject("ViewManager").getEditor(name)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
711 else:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
712 cwd = self.deviceCwd.text()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
713 if cwd:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
714 name = (
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
715 cwd + filename
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
716 if cwd.endswith("/")
9765
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
717 else "{0}/{1}".format(cwd, filename)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
718 )
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
719 else:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
720 name = filename
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
721 if not name.endswith("/"):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
722 data = self.__fileManager.getData(name)
9765
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
723 text = data.decode(encoding="utf-8")
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
724 ericApp().getObject("ViewManager").newEditorWithText(
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
725 text, "Python3", "device:{0}".format(name)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
726 )
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
727
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
728 @pyqtSlot()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
729 def on_saveButton_clicked(self, saveAs=False):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
730 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
731 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
732
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
733 @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
734 @type bool
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
735 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
736 aw = ericApp().getObject("ViewManager").activeWindow()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
737 if not aw:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
738 return
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
739
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
740 selectedItems = self.deviceFileTreeWidget.selectedItems()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
741 if selectedItems:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
742 filename = selectedItems[0].text(0).strip()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
743 if filename.endswith("/"):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
744 saveAs = True
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
745 else:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
746 saveAs = True
9764
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
747 filename = ""
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
748
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
749 if saveAs:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
750 filename, ok = QInputDialog.getText(
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
751 self,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
752 self.tr("Save File As"),
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
753 self.tr("Enter a new name for the file:"),
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
754 QLineEdit.EchoMode.Normal,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
755 filename,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
756 )
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
757 if not ok or not filename:
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
758 return
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
759
9764
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
760 if not saveAs:
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
761 # check editor and selected file names for an implicit 'save as'
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
762 editorFileName = os.path.basename(aw.getFileName().replace("device:", ""))
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
763 if editorFileName != filename:
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
764 saveAs = True
57496966803c Fixed a few issues in the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9760
diff changeset
765
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
766 if saveAs and self.__isFileInList(filename, self.deviceFileTreeWidget):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
767 # ask for overwrite permission
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
768 action, resultFilename = confirmOverwrite(
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
769 filename,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
770 self.tr("Save File As"),
9765
6378da868bb0 Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9764
diff changeset
771 self.tr("The given file exists already (Enter file name only)."),
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
772 False,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
773 self,
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
774 )
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
775 if action == "cancel":
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
776 return
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
777 elif action == "rename":
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
778 filename = os.path.basename(resultFilename)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
779
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
780 text = aw.text()
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
781 if self.__repl.deviceSupportsLocalFileAccess():
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
782 filename = os.path.join(self.deviceCwd.text(), filename)
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
783 os.makedirs(os.path.dirname(filename), exist_ok=True)
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
784 with open(filename, "w") as f:
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
785 f.write(text)
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
786 self.__newDeviceList()
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
787 aw.setFileName(filename)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
788 else:
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
789 if not filename.startswith("/"):
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
790 deviceCwd = self.deviceCwd.text()
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
791 if deviceCwd:
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
792 filename = (
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
793 deviceCwd + "/" + filename
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
794 if deviceCwd != "/"
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
795 else "/" + filename
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
796 )
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
797 dirname = filename.rsplit("/", 1)[0]
080e060a0383 Added the capability to save from an editor to a connected MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9802
diff changeset
798 self.__fileManager.makedirs(dirname)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
799 self.__fileManager.putData(filename, text.encode("utf-8"))
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
800 aw.setFileName("device:" + filename)
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
801
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
802 aw.setModified(False)
9791
fdaa2a9011b3 Added code to the MicroPython file manager to reset the current editor change markers upon save.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
803 aw.resetOnlineChangeTraceInfo()
9760
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
804
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
805 @pyqtSlot()
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
806 def on_saveAsButton_clicked(self):
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
807 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
808 Private slot to save the current editor in a new file on the connected device.
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
809 """
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
810 self.on_saveButton_clicked(saveAs=True)
11245ac9c258 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
811
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
812 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
813 ## 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
814 ##################################################################
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
815
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
816 @pyqtSlot(QPoint)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
817 def __showLocalContextMenu(self, pos):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
818 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
819 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
820
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
821 @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
822 @type QPoint
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
823 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
824 hasSelection = bool(len(self.localFileTreeWidget.selectedItems()))
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
825 if hasSelection:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
826 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
827 isDir = name.endswith("/")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
828 isFile = not isDir
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
829 else:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
830 isDir = False
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
831 isFile = False
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
832 self.__localDelDirTreeAct.setEnabled(isDir)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
833 self.__localDelFileAct.setEnabled(isFile)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
834
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
835 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
836
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
837 @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
838 def __changeLocalDirectory(self, localDevice=False):
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
839 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
840 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
841
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
842 @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
843 @type bool
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
844 """
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
845 cwdWidget = self.deviceCwd if localDevice else self.localCwd
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
846
9238
a7cbf3d61498 EricPathPicker, EricPathPickerDialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
847 dirPath, ok = EricPathPickerDialog.getStrPath(
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
848 self,
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
849 self.tr("Change Directory"),
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
850 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
851 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE,
9238
a7cbf3d61498 EricPathPicker, EricPathPickerDialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
852 strPath=cwdWidget.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
853 defaultDirectory=cwdWidget.text(),
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
854 )
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
855 if ok and dirPath:
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
856 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
857 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
858 cwdWidget.setText(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
859 self.__listLocalFiles(dirPath, localDevice=localDevice)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
860
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
861 @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
862 def __createLocalDirectory(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
863 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
864 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
865
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
866 @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
867 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
868 """
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
869 cwdWidget = self.deviceCwd if localDevice else self.localCwd
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
870
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
871 dirPath, ok = QInputDialog.getText(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
872 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
873 self.tr("Create Directory"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
874 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
875 QLineEdit.EchoMode.Normal,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
876 )
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
877 if ok and 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
878 dirPath = os.path.join(cwdWidget.text(), dirPath)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
879 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
880 os.mkdir(dirPath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
881 self.__listLocalFiles(cwdWidget.text(), localDevice=localDevice)
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
882 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
883 EricMessageBox.critical(
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
884 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
885 self.tr("Create Directory"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
886 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
887 """<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
888 """ 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
889 ).format(dirPath, str(exc)),
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
890 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
891
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
892 @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
893 def __deleteLocalDirectoryTree(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
894 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
895 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
896
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
897 @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
898 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
899 """
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
900 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
901 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
902 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
903 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
904 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
905 fileTreeWidget = self.localFileTreeWidget
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
906
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
907 if bool(len(fileTreeWidget.selectedItems())):
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
908 name = fileTreeWidget.selectedItems()[0].text(0)
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
909 dirname = os.path.join(cwdWidget.text(), name[:-1])
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
910 dlg = DeleteFilesConfirmationDialog(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
911 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
912 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
913 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
914 [dirname],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
915 )
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
916 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
917 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
918 shutil.rmtree(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
919 self.__listLocalFiles(cwdWidget.text(), localDevice=localDevice)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
920 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
921 EricMessageBox.critical(
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
922 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
923 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
924 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
925 """<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
926 """ 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
927 ).format(dirname, str(exc)),
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
928 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
929
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
930 @pyqtSlot()
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
931 def __deleteLocalFile(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
932 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
933 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
934
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
935 @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
936 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
937 """
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
938 if localDevice:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
939 cwdWidget = self.deviceCwd
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
940 fileTreeWidget = self.deviceFileTreeWidget
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
941 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
942 cwdWidget = self.localCwd
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
943 fileTreeWidget = self.localFileTreeWidget
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
944
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
945 if bool(len(fileTreeWidget.selectedItems())):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
946 name = fileTreeWidget.selectedItems()[0].text(0)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
947 filename = os.path.join(cwdWidget.text(), name)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
948 dlg = DeleteFilesConfirmationDialog(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
949 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
950 self.tr("Delete File"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
951 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
952 [filename],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
953 )
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
954 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
955 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
956 os.remove(filename)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
957 self.__listLocalFiles(cwdWidget.text(), localDevice=localDevice)
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
958 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
959 EricMessageBox.critical(
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
960 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
961 self.tr("Delete File"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
962 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
963 """<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
964 """ 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
965 ).format(filename, str(exc)),
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
966 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
967
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
968 @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
969 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
970 """
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
971 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
972
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
973 @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
974 @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
975 """
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
976 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
977 self.on_localReloadButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
978
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
979 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
980 ## 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
981 ##################################################################
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
982
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
983 @pyqtSlot(QPoint)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
984 def __showDeviceContextMenu(self, pos):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
985 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
986 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
987
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
988 @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
989 @type QPoint
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
990 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
991 hasSelection = bool(len(self.deviceFileTreeWidget.selectedItems()))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
992 if hasSelection:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
993 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
994 isDir = name.endswith("/")
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
995 isFile = not isDir
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
996 else:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
997 isDir = False
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
998 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
999 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
1000 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
1001 self.__devDelDirTreeAct.setEnabled(isDir)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1002 self.__devDelFileAct.setEnabled(isFile)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1003
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1004 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
1005
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1006 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1007 def __changeDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1008 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1009 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
1010
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1011 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
1012 current directory.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1013 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
1014 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 QLineEdit.EchoMode.Normal,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1022 self.deviceCwd.text(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1023 )
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
1024 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
1025 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
1026 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
1027 self.__fileManager.cd(dirPath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1028
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1029 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1030 def __createDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1031 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1032 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
1033 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 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
1041 QLineEdit.EchoMode.Normal,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1042 )
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
1043 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
1044 self.__fileManager.mkdir(dirPath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1045
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1046 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1047 def __deleteDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1048 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1049 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
1050 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
1051 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
1052 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
1053 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
1054 if bool(len(self.deviceFileTreeWidget.selectedItems())):
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
1055 name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1056 cwd = self.deviceCwd.text()
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
1057 if cwd:
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
1058 if cwd != "/":
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
1059 dirname = cwd + "/" + name[:-1]
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
1060 else:
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
1061 dirname = "/" + name[:-1]
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1062 else:
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
1063 dirname = name[:-1]
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
1064 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
1065 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
1066 self.tr("Delete Directory"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1067 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
1068 [dirname],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1069 )
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
1070 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
1071 self.__fileManager.rmdir(dirname)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1072
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1073 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1074 def __deleteDeviceDirectoryTree(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1075 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1076 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
1077 recursively.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1078 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
1079 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
1080 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
1081 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
1082 if bool(len(self.deviceFileTreeWidget.selectedItems())):
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
1083 name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1084 cwd = self.deviceCwd.text()
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
1085 if cwd:
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
1086 if cwd != "/":
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
1087 dirname = cwd + "/" + name[:-1]
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
1088 else:
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
1089 dirname = "/" + name[:-1]
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1090 else:
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
1091 dirname = name[:-1]
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
1092 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
1093 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
1094 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
1095 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
1096 [dirname],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1097 )
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
1098 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
1099 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
1100
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1101 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1102 def __deleteDeviceFile(self):
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 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
1105 """
9767
2eed840795c0 Fixed a few issues in the MicroPython file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9766
diff changeset
1106 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
1107 self.__deleteLocalFile(True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1108 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1109 if bool(len(self.deviceFileTreeWidget.selectedItems())):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1110 name = self.deviceFileTreeWidget.selectedItems()[0].text(0)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1111 dirname = self.deviceCwd.text()
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
1112 if dirname:
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
1113 if dirname != "/":
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
1114 filename = dirname + "/" + name
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
1115 else:
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
1116 filename = "/" + name
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1117 else:
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
1118 filename = name
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1119 dlg = DeleteFilesConfirmationDialog(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1120 self,
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
1121 self.tr("Delete File"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1122 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
1123 [filename],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1124 )
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
1125 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
1126 self.__fileManager.delete(filename)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1127
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
1128 @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
1129 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
1130 """
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
1131 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
1132
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
1133 @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
1134 @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
1135 """
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
1136 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
1137 self.on_deviceReloadButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1138
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1139 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1140 def __showFileSystemInfo(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1141 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1142 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
1143 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1144 self.__fileManager.fileSystemInfo()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1145
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1146 @pyqtSlot(tuple)
7108
4f6133a01c6a Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7095
diff changeset
1147 def __fsInfoResultReceived(self, fsinfo):
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1148 """
7108
4f6133a01c6a Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7095
diff changeset
1149 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
1150
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1151 @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
1152 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
1153 @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
1154 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1155 msg = self.tr("<h3>Filesystem Information</h3>")
9959
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1156 if fsinfo:
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1157 for name, totalSize, usedSize, freeSize in fsinfo:
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1158 msg += self.tr(
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1159 "<h4>{0}</h4"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1160 "<table>"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1161 "<tr><td>Total Size: </td><td align='right'>{1}</td></tr>"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1162 "<tr><td>Used Size: </td><td align='right'>{2}</td></tr>"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1163 "<tr><td>Free Size: </td><td align='right'>{3}</td></tr>"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1164 "</table>"
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1165 ).format(
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1166 name,
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1167 Globals.dataString(totalSize),
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1168 Globals.dataString(usedSize),
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1169 Globals.dataString(freeSize),
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1170 )
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1171 else:
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1172 msg += self.tr(
9959
8ca27cc20953 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9905
diff changeset
1173 "<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
1174 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1175 EricMessageBox.information(self, self.tr("Filesystem Information"), msg)

eric ide

mercurial