eric6/MicroPython/MicroPythonFileManagerWidget.py

changeset 8143
2c730d5fd177
parent 8067
a467ab075be0
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
77 self.putAsButton.setEnabled(False) 77 self.putAsButton.setEnabled(False)
78 self.getButton.setEnabled(False) 78 self.getButton.setEnabled(False)
79 self.getAsButton.setEnabled(False) 79 self.getAsButton.setEnabled(False)
80 80
81 self.localFileTreeWidget.header().setSortIndicator( 81 self.localFileTreeWidget.header().setSortIndicator(
82 0, Qt.AscendingOrder) 82 0, Qt.SortOrder.AscendingOrder)
83 self.deviceFileTreeWidget.header().setSortIndicator( 83 self.deviceFileTreeWidget.header().setSortIndicator(
84 0, Qt.AscendingOrder) 84 0, Qt.SortOrder.AscendingOrder)
85 85
86 self.__progressInfoDialog = None 86 self.__progressInfoDialog = None
87 self.__fileManager = MicroPythonFileManager(commandsInterface, self) 87 self.__fileManager = MicroPythonFileManager(commandsInterface, self)
88 88
89 self.__fileManager.longListFiles.connect(self.__handleLongListFiles) 89 self.__fileManager.longListFiles.connect(self.__handleLongListFiles)
218 """ 218 """
219 self.deviceFileTreeWidget.clear() 219 self.deviceFileTreeWidget.clear()
220 for name, mode, size, dateTime in filesList: 220 for name, mode, size, dateTime in filesList:
221 itm = QTreeWidgetItem(self.deviceFileTreeWidget, 221 itm = QTreeWidgetItem(self.deviceFileTreeWidget,
222 [name, mode, size, dateTime]) 222 [name, mode, size, dateTime])
223 itm.setTextAlignment(1, Qt.AlignHCenter) 223 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter)
224 itm.setTextAlignment(2, Qt.AlignRight) 224 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
225 self.deviceFileTreeWidget.header().resizeSections( 225 self.deviceFileTreeWidget.header().resizeSections(
226 QHeaderView.ResizeToContents) 226 QHeaderView.ResizeMode.ResizeToContents)
227 227
228 def __listLocalFiles(self, dirname="", localDevice=False): 228 def __listLocalFiles(self, dirname="", localDevice=False):
229 """ 229 """
230 Private method to populate the local files list. 230 Private method to populate the local files list.
231 231
256 else: 256 else:
257 fileTreeWidget = self.localFileTreeWidget 257 fileTreeWidget = self.localFileTreeWidget
258 fileTreeWidget.clear() 258 fileTreeWidget.clear()
259 for item in filesList: 259 for item in filesList:
260 itm = QTreeWidgetItem(fileTreeWidget, item) 260 itm = QTreeWidgetItem(fileTreeWidget, item)
261 itm.setTextAlignment(1, Qt.AlignHCenter) 261 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter)
262 itm.setTextAlignment(2, Qt.AlignRight) 262 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
263 fileTreeWidget.header().resizeSections( 263 fileTreeWidget.header().resizeSections(
264 QHeaderView.ResizeToContents) 264 QHeaderView.ResizeMode.ResizeToContents)
265 265
266 @pyqtSlot(QTreeWidgetItem, int) 266 @pyqtSlot(QTreeWidgetItem, int)
267 def on_localFileTreeWidget_itemActivated(self, item, column): 267 def on_localFileTreeWidget_itemActivated(self, item, column):
268 """ 268 """
269 Private slot to handle the activation of a local item. 269 Private slot to handle the activation of a local item.
442 if putAs: 442 if putAs:
443 deviceFilename, ok = QInputDialog.getText( 443 deviceFilename, ok = QInputDialog.getText(
444 self, 444 self,
445 self.tr("Put File As"), 445 self.tr("Put File As"),
446 self.tr("Enter a new name for the file"), 446 self.tr("Enter a new name for the file"),
447 QLineEdit.Normal, 447 QLineEdit.EchoMode.Normal,
448 filename) 448 filename)
449 if not ok or not filename: 449 if not ok or not filename:
450 return 450 return
451 else: 451 else:
452 deviceFilename = filename 452 deviceFilename = filename
507 if getAs: 507 if getAs:
508 localFilename, ok = QInputDialog.getText( 508 localFilename, ok = QInputDialog.getText(
509 self, 509 self,
510 self.tr("Get File As"), 510 self.tr("Get File As"),
511 self.tr("Enter a new name for the file"), 511 self.tr("Enter a new name for the file"),
512 QLineEdit.Normal, 512 QLineEdit.EchoMode.Normal,
513 filename) 513 filename)
514 if not ok or not filename: 514 if not ok or not filename:
515 return 515 return
516 else: 516 else:
517 localFilename = filename 517 localFilename = filename
692 692
693 dirPath, ok = QInputDialog.getText( 693 dirPath, ok = QInputDialog.getText(
694 self, 694 self,
695 self.tr("Create Directory"), 695 self.tr("Create Directory"),
696 self.tr("Enter directory name:"), 696 self.tr("Enter directory name:"),
697 QLineEdit.Normal) 697 QLineEdit.EchoMode.Normal)
698 if ok and dirPath: 698 if ok and dirPath:
699 dirPath = os.path.join(cwdWidget.text(), dirPath) 699 dirPath = os.path.join(cwdWidget.text(), dirPath)
700 try: 700 try:
701 os.mkdir(dirPath) 701 os.mkdir(dirPath)
702 self.__listLocalFiles(cwdWidget.text(), 702 self.__listLocalFiles(cwdWidget.text(),
732 self, 732 self,
733 self.tr("Delete Directory Tree"), 733 self.tr("Delete Directory Tree"),
734 self.tr( 734 self.tr(
735 "Do you really want to delete this directory tree?"), 735 "Do you really want to delete this directory tree?"),
736 [dirname]) 736 [dirname])
737 if dlg.exec() == QDialog.Accepted: 737 if dlg.exec() == QDialog.DialogCode.Accepted:
738 try: 738 try:
739 shutil.rmtree(dirname) 739 shutil.rmtree(dirname)
740 self.__listLocalFiles(cwdWidget.text(), 740 self.__listLocalFiles(cwdWidget.text(),
741 localDevice=localDevice) 741 localDevice=localDevice)
742 except Exception as exc: 742 except Exception as exc:
770 self, 770 self,
771 self.tr("Delete File"), 771 self.tr("Delete File"),
772 self.tr( 772 self.tr(
773 "Do you really want to delete this file?"), 773 "Do you really want to delete this file?"),
774 [filename]) 774 [filename])
775 if dlg.exec() == QDialog.Accepted: 775 if dlg.exec() == QDialog.DialogCode.Accepted:
776 try: 776 try:
777 os.remove(filename) 777 os.remove(filename)
778 self.__listLocalFiles(cwdWidget.text(), 778 self.__listLocalFiles(cwdWidget.text(),
779 localDevice=localDevice) 779 localDevice=localDevice)
780 except OSError as exc: 780 except OSError as exc:
838 else: 838 else:
839 dirPath, ok = QInputDialog.getText( 839 dirPath, ok = QInputDialog.getText(
840 self, 840 self,
841 self.tr("Change Directory"), 841 self.tr("Change Directory"),
842 self.tr("Enter the directory path on the device:"), 842 self.tr("Enter the directory path on the device:"),
843 QLineEdit.Normal, 843 QLineEdit.EchoMode.Normal,
844 self.deviceCwd.text()) 844 self.deviceCwd.text())
845 if ok and dirPath: 845 if ok and dirPath:
846 if not dirPath.startswith("/"): 846 if not dirPath.startswith("/"):
847 dirPath = self.deviceCwd.text() + "/" + dirPath 847 dirPath = self.deviceCwd.text() + "/" + dirPath
848 self.__fileManager.cd(dirPath) 848 self.__fileManager.cd(dirPath)
857 else: 857 else:
858 dirPath, ok = QInputDialog.getText( 858 dirPath, ok = QInputDialog.getText(
859 self, 859 self,
860 self.tr("Create Directory"), 860 self.tr("Create Directory"),
861 self.tr("Enter directory name:"), 861 self.tr("Enter directory name:"),
862 QLineEdit.Normal) 862 QLineEdit.EchoMode.Normal)
863 if ok and dirPath: 863 if ok and dirPath:
864 self.__fileManager.mkdir(dirPath) 864 self.__fileManager.mkdir(dirPath)
865 865
866 @pyqtSlot() 866 @pyqtSlot()
867 def __deleteDeviceDirectory(self): 867 def __deleteDeviceDirectory(self):
885 self, 885 self,
886 self.tr("Delete Directory"), 886 self.tr("Delete Directory"),
887 self.tr( 887 self.tr(
888 "Do you really want to delete this directory?"), 888 "Do you really want to delete this directory?"),
889 [dirname]) 889 [dirname])
890 if dlg.exec() == QDialog.Accepted: 890 if dlg.exec() == QDialog.DialogCode.Accepted:
891 self.__fileManager.rmdir(dirname) 891 self.__fileManager.rmdir(dirname)
892 892
893 @pyqtSlot() 893 @pyqtSlot()
894 def __deleteDeviceDirectoryTree(self): 894 def __deleteDeviceDirectoryTree(self):
895 """ 895 """
913 self, 913 self,
914 self.tr("Delete Directory Tree"), 914 self.tr("Delete Directory Tree"),
915 self.tr( 915 self.tr(
916 "Do you really want to delete this directory tree?"), 916 "Do you really want to delete this directory tree?"),
917 [dirname]) 917 [dirname])
918 if dlg.exec() == QDialog.Accepted: 918 if dlg.exec() == QDialog.DialogCode.Accepted:
919 self.__fileManager.rmdir(dirname, recursive=True) 919 self.__fileManager.rmdir(dirname, recursive=True)
920 920
921 @pyqtSlot() 921 @pyqtSlot()
922 def __deleteDeviceFile(self): 922 def __deleteDeviceFile(self):
923 """ 923 """
940 self, 940 self,
941 self.tr("Delete File"), 941 self.tr("Delete File"),
942 self.tr( 942 self.tr(
943 "Do you really want to delete this file?"), 943 "Do you really want to delete this file?"),
944 [filename]) 944 [filename])
945 if dlg.exec() == QDialog.Accepted: 945 if dlg.exec() == QDialog.DialogCode.Accepted:
946 self.__fileManager.delete(filename) 946 self.__fileManager.delete(filename)
947 947
948 @pyqtSlot(bool) 948 @pyqtSlot(bool)
949 def __deviceHiddenChanged(self, checked): 949 def __deviceHiddenChanged(self, checked):
950 """ 950 """

eric ide

mercurial