eric6/MicroPython/MicroPythonFileManagerWidget.py

Mon, 12 Aug 2019 14:53:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Aug 2019 14:53:07 +0200
branch
micropython
changeset 7131
f75e990caf99
parent 7130
6014d37d9683
child 7134
21d23ca51680
permissions
-rw-r--r--

MicroPythonFileManager: finished the file access via a local directory.

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
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
bca506f8c756 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 from __future__ import unicode_literals
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
bca506f8c756 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 import os
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
13 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
14
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
15 from PyQt5.QtCore import pyqtSlot, Qt, QPoint
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
16 from PyQt5.QtWidgets import (
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
17 QWidget, QTreeWidgetItem, QHeaderView, QMenu, QInputDialog, QLineEdit,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
18 QDialog
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
19 )
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
20
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
21 from E5Gui import E5MessageBox, E5PathPickerDialog
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
22 from E5Gui.E5PathPicker import E5PathPickerModes
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
23 from E5Gui.E5FileSaveConfirmDialog import confirmOverwrite
7078
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 from E5Gui.E5Application import e5App
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 from .Ui_MicroPythonFileManagerWidget import 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
27
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
28 from .MicroPythonFileManager import MicroPythonFileManager
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
29 from .MicroPythonFileSystemUtilities import (
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
30 mtime2string, mode2string, decoratedName, listdirStat
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 )
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
33 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
34
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
35 import UI.PixmapCache
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 import Preferences
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
37 import Utilities
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
38 import Globals
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 """
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
45 def __init__(self, commandsInterface, deviceWithLocalAccess, 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
46 """
bca506f8c756 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 Constructor
bca506f8c756 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
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
49 @param commandsInterface reference to the commands interface object
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
50 @type MicroPythonCommandsInterface
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
51 @param deviceWithLocalAccess flag indicating the device supports file
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
52 access via a local 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
53 @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
54 @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
55 @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
56 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 super(MicroPythonFileManagerWidget, self).__init__(parent)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.setupUi(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
59
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
60 self.__repl = parent
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
61 self.__deviceWithLocalAccess = deviceWithLocalAccess
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
62
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
63 self.syncButton.setIcon(UI.PixmapCache.getIcon("2rightarrow"))
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
64 self.putButton.setIcon(UI.PixmapCache.getIcon("1rightarrow"))
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
65 self.putAsButton.setIcon(UI.PixmapCache.getIcon("putAs"))
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
66 self.getButton.setIcon(UI.PixmapCache.getIcon("1leftarrow"))
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
67 self.getAsButton.setIcon(UI.PixmapCache.getIcon("getAs"))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
68 self.localUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
69 self.localReloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
70 self.deviceUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
71 self.deviceReloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
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
72
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
73 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit())
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
74
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
75 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
76 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
77 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
78 self.getAsButton.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
79
bca506f8c756 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.localFileTreeWidget.header().setSortIndicator(
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 0, Qt.AscendingOrder)
bca506f8c756 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.deviceFileTreeWidget.header().setSortIndicator(
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 0, Qt.AscendingOrder)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
85 self.__progressInfoDialog = None
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
86 self.__fileManager = MicroPythonFileManager(commandsInterface, self)
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
87
bca506f8c756 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.__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
89 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
90 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
91 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
92 self.__fileManager.getFileDone.connect(self.__handleGetDone)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
93 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
94 self.__fileManager.rsyncProgressMessage.connect(
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
95 self.__handleRsyncProgressMessage)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
96 self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
97 self.__fileManager.createDirectoryDone.connect(self.__newDeviceList)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
98 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
99 self.__fileManager.fsinfoDone.connect(self.__fsInfoResultReceived)
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
100
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
101 self.__fileManager.error.connect(self.__handleError)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
102
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
103 self.localFileTreeWidget.customContextMenuRequested.connect(
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
104 self.__showLocalContextMenu)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
105 self.deviceFileTreeWidget.customContextMenuRequested.connect(
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
106 self.__showDeviceContextMenu)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
107
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
108 self.__localMenu = QMenu(self)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
109 self.__localMenu.addAction(self.tr("Change Directory"),
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
110 self.__changeLocalDirectory)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
111 self.__localMenu.addAction(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
112 self.tr("Create Directory"), self.__createLocalDirectory)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
113 self.__localDelDirTreeAct = self.__localMenu.addAction(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
114 self.tr("Delete Directory Tree"), self.__deleteLocalDirectoryTree)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
115 self.__localMenu.addSeparator()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
116 self.__localDelFileAct = self.__localMenu.addAction(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
117 self.tr("Delete File"), self.__deleteLocalFile)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
118
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
119 self.__deviceMenu = QMenu(self)
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
120 if not self.__repl.isMicrobit():
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
121 self.__deviceMenu.addAction(
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
122 self.tr("Change Directory"), self.__changeDeviceDirectory)
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
123 self.__deviceMenu.addAction(
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
124 self.tr("Create Directory"), self.__createDeviceDirectory)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
125 if not self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
126 self.__devDelDirAct = self.__deviceMenu.addAction(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
127 self.tr("Delete Directory"), self.__deleteDeviceDirectory)
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
128 self.__devDelDirTreeAct = self.__deviceMenu.addAction(
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
129 self.tr("Delete Directory Tree"),
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
130 self.__deleteDeviceDirectoryTree)
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
131 self.__deviceMenu.addSeparator()
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
132 self.__devDelFileAct = self.__deviceMenu.addAction(
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
133 self.tr("Delete File"), self.__deleteDeviceFile)
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
134 if not parent.isMicrobit():
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
135 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
136 self.__deviceMenu.addAction(
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
137 self.tr("Show Filesystem Info"), self.__showFileSystemInfo)
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
138
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 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
140 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 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
142 """
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
143 dirname = ""
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
144 vm = e5App().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
145 aw = vm.activeWindow()
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if aw:
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 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
148 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
149 dirname = (Preferences.getMultiProject("Workspace") or
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 os.path.expanduser("~"))
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.__listLocalFiles(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
152
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
153 if self.__deviceWithLocalAccess:
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
154 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
155 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
156 self.__listLocalFiles(dirname, 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
157 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
158 self.__fileManager.pwd()
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
159
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 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
161 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 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
163 """
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
164 pass
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
165
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
166 @pyqtSlot(str, str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
167 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
168 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 Private slot to handle errors.
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
171 @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
172 @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
173 @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
174 @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
175 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 E5MessageBox.warning(
bca506f8c756 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 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
178 self.tr("Error handling device"),
bca506f8c756 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 self.tr("<p>There was an error communicating with the connected"
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
180 " device.</p><p>Method: {0}</p><p>Message: {1}</p>")
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
181 .format(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
182
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @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
184 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
185 """
bca506f8c756 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 Private slot to handle a change of the current directory of the device.
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @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
189 @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
190 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.deviceCwd.setText(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
192 self.__fileManager.lls(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
193
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 @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
195 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
196 """
bca506f8c756 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 Private slot to receive a long directory listing.
bca506f8c756 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 @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
200 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
201 @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
202 """
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.deviceFileTreeWidget.clear()
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
204 for name, mode, size, dateTime in filesList:
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 itm = QTreeWidgetItem(self.deviceFileTreeWidget,
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
206 [name, mode, size, dateTime])
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
207 itm.setTextAlignment(1, Qt.AlignHCenter)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 itm.setTextAlignment(2, Qt.AlignRight)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 self.deviceFileTreeWidget.header().resizeSections(
bca506f8c756 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 QHeaderView.ResizeToContents)
bca506f8c756 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
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
212 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
213 """
bca506f8c756 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 Private method to populate the local files list.
bca506f8c756 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
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @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
217 @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
218 @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
219 @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
220 """
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
221 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
222 dirname = os.getcwd()
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
223 if dirname.endswith(os.sep):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
224 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
225 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
226 self.deviceCwd.setText(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
227 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
228 self.localCwd.setText(dirname)
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
229
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
230 filesStatList = listdirStat(dirname)
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
231 filesList = [(
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
232 decoratedName(f, s[0], os.path.isdir(os.path.join(dirname, f))),
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 mode2string(s[0]),
bca506f8c756 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 str(s[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
235 mtime2string(s[8])) for f, s in filesStatList]
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
236 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
237 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
238 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
239 fileTreeWidget = self.localFileTreeWidget
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
240 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
241 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
242 itm = QTreeWidgetItem(fileTreeWidget, 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
243 itm.setTextAlignment(1, Qt.AlignHCenter)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 itm.setTextAlignment(2, Qt.AlignRight)
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
245 fileTreeWidget.header().resizeSections(
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
246 QHeaderView.ResizeToContents)
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 @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
249 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
250 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
251 Private slot to handle the activation of a local 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
252
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
253 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
254 directory.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
255
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
256 @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
257 @type QTreeWidgetItem
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
258 @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
259 @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
260 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
261 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
262 if name.endswith("/"):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
263 # directory names end with a '/'
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
264 self.__listLocalFiles(name[:-1])
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
265 elif Utilities.MimeTypes.isTextFile(name):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
266 e5App().getObject("ViewManager").getEditor(name)
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
267
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 @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
269 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
270 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
271 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
272 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
273 enable = bool(len(self.localFileTreeWidget.selectedItems()))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
274 if enable:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
275 enable &= not (
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
276 self.localFileTreeWidget.selectedItems()[0].text(0)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
277 .endswith("/"))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
278 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
279 self.putAsButton.setEnabled(enable)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
280
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
281 @pyqtSlot()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
282 def on_localUpButton_clicked(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
283 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
284 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
285 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
286 cwd = self.localCwd.text()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
287 dirname = os.path.dirname(cwd)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
288 self.__listLocalFiles(dirname)
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
289
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
290 @pyqtSlot()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
291 def on_localReloadButton_clicked(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
292 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
293 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
294 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
295 dirname = self.localCwd.text()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
296 self.__listLocalFiles(dirname)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
297
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
298 @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
299 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
300 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
301 Private slot to handle the activation of a device 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
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
303 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
304 and the list will be re-populated for this directory.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
305
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
306 @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
307 @type QTreeWidgetItem
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
308 @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
309 @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
310 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
311 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
312 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
313 if name.endswith("/"):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
314 # 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
315 self.__listLocalFiles(name[:-1], True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
316 elif Utilities.MimeTypes.isTextFile(name):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
317 e5App().getObject("ViewManager").getEditor(name)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
318 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
319 if name.endswith("/"):
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
320 # 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
321 self.__fileManager.cd(name[:-1])
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
322
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 @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
324 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
325 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
326 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
327 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
328 enable = bool(len(self.deviceFileTreeWidget.selectedItems()))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
329 if enable:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
330 enable &= not (
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
331 self.deviceFileTreeWidget.selectedItems()[0].text(0)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
332 .endswith("/"))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
333 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
334 self.getAsButton.setEnabled(enable)
7078
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 @pyqtSlot()
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
337 def on_deviceUpButton_clicked(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
338 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
339 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
340 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
341 cwd = self.deviceCwd.text()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
342 dirname = os.path.dirname(cwd)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
343 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
344 self.__listLocalFiles(dirname, True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
345 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
346 self.__fileManager.cd(dirname)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
347
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
348 @pyqtSlot()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
349 def on_deviceReloadButton_clicked(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
350 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
351 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
352 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
353 dirname = self.deviceCwd.text()
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
354 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
355 self.__listLocalFiles(dirname, True)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
356 else:
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
357 if dirname:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
358 self.__fileManager.lls(dirname)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
359 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
360 self.__fileManager.pwd()
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
361
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
362 def __isFileInList(self, filename, treeWidget):
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
363 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
364 Private method to check, if a file name is contained in a tree widget.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
365
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
366 @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
367 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
368 @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
369 @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
370 @rtype bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
371 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
372 itemCount = treeWidget.topLevelItemCount()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
373 if itemCount:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
374 for row in range(itemCount):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
375 if treeWidget.topLevelItem(row).text(0) == filename:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
376 return True
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
377
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
378 return False
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
379
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7078
diff changeset
380 @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
381 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
382 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
383 Private slot to copy the selected file to the connected device.
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
384
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
385 @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
386 @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
387 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
388 selectedItems = self.localFileTreeWidget.selectedItems()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
389 if selectedItems:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
390 filename = selectedItems[0].text(0).strip()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
391 if not filename.endswith("/"):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
392 # 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
393 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
394 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
395 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
396 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
397 self.tr("Enter a new name for the file"),
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
398 QLineEdit.Normal,
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
399 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
400 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
401 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
402 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
403 deviceFilename = 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
404
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
405 if self.__isFileInList(deviceFilename,
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
406 self.deviceFileTreeWidget):
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
407 # ask for overwrite permission
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
408 action, resultFilename = confirmOverwrite(
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
409 deviceFilename, self.tr("Copy File to Device"),
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
410 self.tr("The given file exists already"
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
411 " (Enter file name only)."),
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
412 False, self)
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
413 if action == "cancel":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
414 return
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
415 elif action == "rename":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
416 deviceFilename = os.path.basename(resultFilename)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
417
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
418 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
419 shutil.copy2(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
420 os.path.join(self.localCwd.text(), filename),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
421 os.path.join(self.deviceCwd.text(), deviceFilename)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
422 )
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
423 self.__listLocalFiles(self.deviceCwd.text(),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
424 localDevice=True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
425 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
426 deviceCwd = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
427 if deviceCwd and deviceCwd != "/":
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
428 deviceFilename = deviceCwd + "/" + deviceFilename
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
429 self.__fileManager.put(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
430 os.path.join(self.localCwd.text(), filename),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
431 deviceFilename
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
432 )
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
433
bca506f8c756 MicroPython: started to implement the file manager widget; added the forgotten MicroPythonFileManagerWidget.[py, ui] files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 @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
435 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
436 """
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
437 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
438 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
439 """
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
440 self.on_putButton_clicked(putAs=True)
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
441
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
442 @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
443 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
444 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
445 Private slot to copy the selected file from the connected device.
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
446
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
447 @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
448 @type bool
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
449 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
450 selectedItems = self.deviceFileTreeWidget.selectedItems()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
451 if selectedItems:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
452 filename = selectedItems[0].text(0).strip()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
453 if not filename.endswith("/"):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
454 # 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
455 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
456 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
457 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
458 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
459 self.tr("Enter a new name for the file"),
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7108
diff changeset
460 QLineEdit.Normal,
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
461 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
462 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
463 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
464 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
465 localFilename = 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
466
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
467 if self.__isFileInList(localFilename,
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
468 self.localFileTreeWidget):
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
469 # ask for overwrite permission
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
470 action, resultFilename = confirmOverwrite(
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
471 localFilename, 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
472 self.tr("The given file exists already."),
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
473 True, self)
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
474 if action == "cancel":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
475 return
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
476 elif action == "rename":
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
477 localFilename = resultFilename
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
478
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
479 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
480 shutil.copy2(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
481 os.path.join(self.deviceCwd.text(), filename),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
482 os.path.join(self.localCwd.text(), localFilename)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
483 )
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
484 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
485 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
486 deviceCwd = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
487 if deviceCwd:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
488 filename = deviceCwd + "/" + filename
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
489 self.__fileManager.get(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
490 filename,
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
491 os.path.join(self.localCwd.text(), localFilename)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
492 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
493
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
494 @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
495 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
496 """
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 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
498 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
499 """
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
500 self.on_getButton_clicked(getAs=True)
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
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
502 @pyqtSlot(str, str)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
503 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
504 """
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
505 Private slot handling a successful copy of a file from the device.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
506
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
507 @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
508 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
509 @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
510 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
511 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
512 self.__listLocalFiles(self.localCwd.text())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
513
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
514 @pyqtSlot()
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
515 def on_syncButton_clicked(self):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
516 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
517 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
518 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
519 self.__fileManager.rsync(
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
520 self.localCwd.text(),
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
521 self.deviceCwd.text(),
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
522 mirror=True,
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
523 localDevice=self.__deviceWithLocalAccess,
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
524 )
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
525
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
526 @pyqtSlot(str, str)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
527 def __handleRsyncDone(self, localDir, deviceDir):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
528 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
529 Private method to handle the completion of the rsync operation.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
530
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
531 @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
532 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
533 @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
534 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
535 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
536 self.__listLocalFiles(self.localCwd.text())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
537 self.__fileManager.lls(self.deviceCwd.text())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
538
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
539 @pyqtSlot(str)
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
540 def __handleRsyncProgressMessage(self, message):
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
541 """
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
542 Private slot handling progress messages sent by the file manager.
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
543
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
544 @param message message to be shown
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
545 @type str
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
546 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
547 if self.__progressInfoDialog is None:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
548 from .MicroPythonProgressInfoDialog import (
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
549 MicroPythonProgressInfoDialog
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
550 )
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
551 self.__progressInfoDialog = MicroPythonProgressInfoDialog(self)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
552 self.__progressInfoDialog.finished.connect(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
553 self.__progressInfoDialogFinished)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
554 self.__progressInfoDialog.show()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
555 self.__progressInfoDialog.addMessage(message)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
556
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
557 @pyqtSlot()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
558 def __progressInfoDialogFinished(self):
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
559 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
560 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
561 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
562 self.__progressInfoDialog.deleteLater()
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
563 self.__progressInfoDialog = None
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
564
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
565 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
566 def __newDeviceList(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
567 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
568 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
569 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
570 self.__fileManager.lls(self.deviceCwd.text())
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
571
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
572 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
573 ## 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
574 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
575
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
576 @pyqtSlot(QPoint)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
577 def __showLocalContextMenu(self, pos):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
578 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
579 Private slot to show the REPL context menu.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
580
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
581 @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
582 @type QPoint
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
583 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
584 hasSelection = bool(len(self.localFileTreeWidget.selectedItems()))
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
585 if hasSelection:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
586 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
587 isDir = name.endswith("/")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
588 isFile = not isDir
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
589 else:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
590 isDir = False
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
591 isFile = False
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
592 self.__localDelDirTreeAct.setEnabled(isDir)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
593 self.__localDelFileAct.setEnabled(isFile)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
594
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
595 self.__localMenu.exec_(self.localFileTreeWidget.mapToGlobal(pos))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
596
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
597 @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
598 def __changeLocalDirectory(self, localDevice=False):
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
599 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
600 Private slot to change the local directory.
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
601
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
602 @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
603 @type bool
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
604 """
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
605 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
606 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
607 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
608 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
609
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
610 dirPath, ok = E5PathPickerDialog.getPath(
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
611 self,
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
612 self.tr("Change Directory"),
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
613 self.tr("Select Directory"),
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
614 E5PathPickerModes.DirectoryShowFilesMode,
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
615 path=cwdWidget.text(),
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
616 defaultDirectory=cwdWidget.text(),
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
617 )
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
618 if ok and dirPath:
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
619 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
620 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
621 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
622 self.__listLocalFiles(dirPath, localDevice=localDevice)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
623
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
624 @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
625 def __createLocalDirectory(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
626 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
627 Private slot to create a local directory.
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
628
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
629 @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
630 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
631 """
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
632 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
633 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
634 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
635 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
636
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
637 dirPath, ok = QInputDialog.getText(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
638 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
639 self.tr("Create Directory"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
640 self.tr("Enter directory name:"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
641 QLineEdit.Normal)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
642 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
643 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
644 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
645 os.mkdir(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
646 self.__listLocalFiles(cwdWidget.text(),
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
647 localDevice=localDevice)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
648 except (OSError, IOError) as exc:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
649 E5MessageBox.critical(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
650 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
651 self.tr("Create Directory"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
652 self.tr("""<p>The directory <b>{0}</b> could not be"""
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
653 """ created.</p><p>Reason: {1}</p>""").format(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
654 dirPath, str(exc))
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
655 )
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
656
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
657 @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
658 def __deleteLocalDirectoryTree(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
659 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
660 Private slot to delete a local directory tree.
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
661
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
662 @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
663 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
664 """
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
665 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
666 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
667 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
668 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
669 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
670 fileTreeWidget = self.localFileTreeWidget
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
671
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
672 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
673 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
674 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
675 dlg = DeleteFilesConfirmationDialog(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
676 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
677 self.tr("Delete Directory Tree"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
678 self.tr(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
679 "Do you really want to delete this directory tree?"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
680 [dirname])
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
681 if dlg.exec_() == QDialog.Accepted:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
682 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
683 shutil.rmtree(dirname)
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
684 self.__listLocalFiles(cwdWidget.text(),
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
685 localDevice=localDevice)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
686 except Exception as exc:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
687 E5MessageBox.critical(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
688 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
689 self.tr("Delete Directory Tree"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
690 self.tr("""<p>The directory <b>{0}</b> could not be"""
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
691 """ deleted.</p><p>Reason: {1}</p>""").format(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
692 dirname, str(exc))
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
693 )
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
694
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
695 @pyqtSlot()
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
696 def __deleteLocalFile(self, localDevice=False):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
697 """
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
698 Private slot to delete a local file.
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
699
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
700 @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
701 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
702 """
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
703 if localDevice:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
704 cwdWidget = self.deviceCwd
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
705 fileTreeWidget = self.deviceFileTreeWidget
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
706 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
707 cwdWidget = self.localCwd
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
708 fileTreeWidget = self.localFileTreeWidget
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
709
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
710 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
711 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
712 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
713 dlg = DeleteFilesConfirmationDialog(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
714 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
715 self.tr("Delete File"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
716 self.tr(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
717 "Do you really want to delete this file?"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
718 [filename])
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
719 if dlg.exec_() == QDialog.Accepted:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
720 try:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
721 os.remove(filename)
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
722 self.__listLocalFiles(cwdWidget.text(),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
723 localDevice=localDevice)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
724 except (OSError, IOError) as exc:
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
725 E5MessageBox.critical(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
726 self,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
727 self.tr("Delete File"),
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
728 self.tr("""<p>The file <b>{0}</b> could not be"""
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
729 """ deleted.</p><p>Reason: {1}</p>""").format(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
730 filename, str(exc))
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
731 )
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
732
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
733 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
734 ## 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
735 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
736
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
737 @pyqtSlot(QPoint)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
738 def __showDeviceContextMenu(self, pos):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
739 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
740 Private slot to show the REPL context menu.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
741
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
742 @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
743 @type QPoint
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
744 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
745 hasSelection = bool(len(self.deviceFileTreeWidget.selectedItems()))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
746 if hasSelection:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
747 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
748 isDir = name.endswith("/")
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
749 isFile = not isDir
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
750 else:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
751 isDir = False
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
752 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
753 if not self.__repl.isMicrobit():
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
754 if not self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
755 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
756 self.__devDelDirTreeAct.setEnabled(isDir)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
757 self.__devDelFileAct.setEnabled(isFile)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
758
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
759 self.__deviceMenu.exec_(self.deviceFileTreeWidget.mapToGlobal(pos))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
760
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
761 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
762 def __changeDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
763 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
764 Private slot to change the current directory of the device.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
765
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
766 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
767 current directory.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
768 """
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
769 if self.__deviceWithLocalAccess:
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
770 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
771 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
772 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
773 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
774 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
775 self.tr("Enter the directory path on the device:"),
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
776 QLineEdit.Normal,
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
777 self.deviceCwd.text())
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
778 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
779 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
780 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
781 self.__fileManager.cd(dirPath)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
782
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
783 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
784 def __createDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
785 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
786 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
787 """
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
788 if self.__deviceWithLocalAccess:
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
789 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
790 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
791 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
792 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
793 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
794 self.tr("Enter directory name:"),
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
795 QLineEdit.Normal)
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
796 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
797 self.__fileManager.mkdir(dirPath)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
798
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
799 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
800 def __deleteDeviceDirectory(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
801 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
802 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
803 """
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
804 if self.__deviceWithLocalAccess:
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
805 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
806 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
807 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
808 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
809 cwd = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
810 if cwd and cwd != "/":
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
811 dirname = cwd + "/" + name[:-1]
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
812 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
813 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
814 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
815 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
816 self.tr("Delete 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
817 self.tr(
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
818 "Do you really want to delete this 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
819 [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
820 if dlg.exec_() == QDialog.Accepted:
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
821 self.__fileManager.rmdir(dirname)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
822
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
823 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
824 def __deleteDeviceDirectoryTree(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
825 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
826 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
827 recursively.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
828 """
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
829 if self.__deviceWithLocalAccess:
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
830 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
831 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
832 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
833 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
834 cwd = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
835 if cwd and cwd != "/":
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
836 dirname = cwd + "/" + name[:-1]
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
837 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
838 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
839 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
840 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
841 self.tr("Delete Directory Tree"),
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 self.tr(
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 "Do you really want to delete this directory tree?"),
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
844 [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
845 if dlg.exec_() == QDialog.Accepted:
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
846 self.__fileManager.rmdir(dirname, recursive=True)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
847
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
848 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
849 def __deleteDeviceFile(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
850 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
851 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
852 """
7131
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
853 if self.__deviceWithLocalAccess:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
854 self.__deleteLocalFile(True)
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
855 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
856 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
857 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
858 dirname = self.deviceCwd.text()
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
859 if dirname and dirname != "/":
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
860 filename = dirname + "/" + name
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
861 else:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
862 filename = "/" + name
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
863 dlg = DeleteFilesConfirmationDialog(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
864 self,
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
865 self.tr("Delete File"),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
866 self.tr(
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
867 "Do you really want to delete this file?"),
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
868 [filename])
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
869 if dlg.exec_() == QDialog.Accepted:
f75e990caf99 MicroPythonFileManager: finished the file access via a local directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7130
diff changeset
870 self.__fileManager.delete(filename)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
871
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
872 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
873 def __showFileSystemInfo(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
874 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
875 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
876 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
877 self.__fileManager.fileSystemInfo()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
878
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
879 @pyqtSlot(tuple)
7108
4f6133a01c6a Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7095
diff changeset
880 def __fsInfoResultReceived(self, fsinfo):
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
881 """
7108
4f6133a01c6a Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7095
diff changeset
882 Private slot to show the file system information of the device.
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
883
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
884 @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
885 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
886 @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
887 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
888 msg = self.tr("<h3>Filesystem Information</h3>")
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
889 for name, totalSize, usedSize, freeSize in fsinfo:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
890 msg += self.tr(
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
891 "<h4>{0}</h4"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
892 "<table>"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
893 "<tr><td>Total Size: </td><td align='right'>{1}</td></tr>"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
894 "<tr><td>Used Size: </td><td align='right'>{2}</td></tr>"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
895 "<tr><td>Free Size: </td><td align='right'>{3}</td></tr>"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
896 "</table>"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
897 ).format(name,
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
898 Globals.dataString(totalSize),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
899 Globals.dataString(usedSize),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
900 Globals.dataString(freeSize),
7089
9f9816b19aa4 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7088
diff changeset
901 )
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
902 E5MessageBox.information(
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
903 self,
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
904 self.tr("Filesystem Information"),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
905 msg)

eric ide

mercurial