53 @type QWidget |
53 @type QWidget |
54 """ |
54 """ |
55 super(MicroPythonFileManagerWidget, self).__init__(parent) |
55 super(MicroPythonFileManagerWidget, self).__init__(parent) |
56 self.setupUi(self) |
56 self.setupUi(self) |
57 |
57 |
|
58 self.__repl = parent |
|
59 |
58 self.syncButton.setIcon(UI.PixmapCache.getIcon("2rightarrow")) |
60 self.syncButton.setIcon(UI.PixmapCache.getIcon("2rightarrow")) |
59 self.putButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) |
61 self.putButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) |
|
62 self.putAsButton.setIcon(UI.PixmapCache.getIcon("putAs")) |
60 self.getButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) |
63 self.getButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) |
|
64 self.getAsButton.setIcon(UI.PixmapCache.getIcon("getAs")) |
61 self.localUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
65 self.localUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
62 self.localReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) |
66 self.localReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) |
63 self.deviceUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
67 self.deviceUpButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
64 self.deviceReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) |
68 self.deviceReloadButton.setIcon(UI.PixmapCache.getIcon("reload")) |
65 |
69 |
|
70 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit()) |
|
71 |
66 self.putButton.setEnabled(False) |
72 self.putButton.setEnabled(False) |
|
73 self.putAsButton.setEnabled(False) |
67 self.getButton.setEnabled(False) |
74 self.getButton.setEnabled(False) |
|
75 self.getAsButton.setEnabled(False) |
68 |
76 |
69 self.localFileTreeWidget.header().setSortIndicator( |
77 self.localFileTreeWidget.header().setSortIndicator( |
70 0, Qt.AscendingOrder) |
78 0, Qt.AscendingOrder) |
71 self.deviceFileTreeWidget.header().setSortIndicator( |
79 self.deviceFileTreeWidget.header().setSortIndicator( |
72 0, Qt.AscendingOrder) |
80 0, Qt.AscendingOrder) |
107 self.__localMenu.addSeparator() |
115 self.__localMenu.addSeparator() |
108 self.__localMenu.addAction( |
116 self.__localMenu.addAction( |
109 self.tr("Show Time"), self.__showLocalTime) |
117 self.tr("Show Time"), self.__showLocalTime) |
110 |
118 |
111 self.__deviceMenu = QMenu(self) |
119 self.__deviceMenu = QMenu(self) |
112 self.__deviceMenu.addAction( |
120 if not self.__repl.isMicrobit(): |
113 self.tr("Change Directory"), self.__changeDeviceDirectory) |
121 self.__deviceMenu.addAction( |
114 self.__deviceMenu.addAction( |
122 self.tr("Change Directory"), self.__changeDeviceDirectory) |
115 self.tr("Create Directory"), self.__createDeviceDirectory) |
123 self.__deviceMenu.addAction( |
116 self.__devDelDirAct = self.__deviceMenu.addAction( |
124 self.tr("Create Directory"), self.__createDeviceDirectory) |
117 self.tr("Delete Directory"), self.__deleteDeviceDirectory) |
125 self.__devDelDirAct = self.__deviceMenu.addAction( |
118 self.__devDelDirTreeAct = self.__deviceMenu.addAction( |
126 self.tr("Delete Directory"), self.__deleteDeviceDirectory) |
119 self.tr("Delete Directory Tree"), self.__deleteDeviceDirectoryTree) |
127 self.__devDelDirTreeAct = self.__deviceMenu.addAction( |
120 self.__deviceMenu.addSeparator() |
128 self.tr("Delete Directory Tree"), |
|
129 self.__deleteDeviceDirectoryTree) |
|
130 self.__deviceMenu.addSeparator() |
121 self.__devDelFileAct = self.__deviceMenu.addAction( |
131 self.__devDelFileAct = self.__deviceMenu.addAction( |
122 self.tr("Delete File"), self.__deleteDeviceFile) |
132 self.tr("Delete File"), self.__deleteDeviceFile) |
123 self.__deviceMenu.addSeparator() |
133 if not parent.isMicrobit(): |
124 self.__deviceMenu.addAction( |
134 self.__deviceMenu.addSeparator() |
125 self.tr("Show Filesystem Info"), self.__showFileSystemInfo) |
135 self.__deviceMenu.addAction( |
|
136 self.tr("Show Filesystem Info"), self.__showFileSystemInfo) |
126 |
137 |
127 def start(self): |
138 def start(self): |
128 """ |
139 """ |
129 Public method to start the widget. |
140 Public method to start the widget. |
130 """ |
141 """ |
336 return True |
349 return True |
337 |
350 |
338 return False |
351 return False |
339 |
352 |
340 @pyqtSlot() |
353 @pyqtSlot() |
341 def on_putButton_clicked(self): |
354 def on_putButton_clicked(self, putAs=False): |
342 """ |
355 """ |
343 Private slot to copy the selected file to the connected device. |
356 Private slot to copy the selected file to the connected device. |
|
357 |
|
358 @param putAs flag indicating to give it a new name |
|
359 @type bool |
344 """ |
360 """ |
345 selectedItems = self.localFileTreeWidget.selectedItems() |
361 selectedItems = self.localFileTreeWidget.selectedItems() |
346 if selectedItems: |
362 if selectedItems: |
347 filename = selectedItems[0].text(0).strip() |
363 filename = selectedItems[0].text(0).strip() |
348 if not filename.endswith("/"): |
364 if not filename.endswith("/"): |
349 # it is really a file |
365 # it is really a file |
350 if self.__isFileInList(filename, self.deviceFileTreeWidget): |
366 if putAs: |
|
367 deviceFilename, ok = QInputDialog.getText( |
|
368 self, |
|
369 self.tr("Put File As"), |
|
370 self.tr("Enter a new name for the file"), |
|
371 QLineEdit.Normal, |
|
372 filename) |
|
373 if not ok or not filename: |
|
374 return |
|
375 else: |
|
376 deviceFilename = filename |
|
377 |
|
378 if self.__isFileInList(deviceFilename, |
|
379 self.deviceFileTreeWidget): |
351 # ask for overwrite permission |
380 # ask for overwrite permission |
352 action, resultFilename = confirmOverwrite( |
381 action, resultFilename = confirmOverwrite( |
353 filename, self.tr("Copy File to Device"), |
382 deviceFilename, self.tr("Copy File to Device"), |
354 self.tr("The given file exists already" |
383 self.tr("The given file exists already" |
355 " (Enter file name only)."), |
384 " (Enter file name only)."), |
356 False, self) |
385 False, self) |
357 if action == "cancel": |
386 if action == "cancel": |
358 return |
387 return |
359 elif action == "rename": |
388 elif action == "rename": |
360 deviceFilename = os.path.basename(resultFilename) |
389 deviceFilename = os.path.basename(resultFilename) |
361 else: |
|
362 deviceFilename = filename |
|
363 else: |
|
364 deviceFilename = filename |
|
365 |
390 |
|
391 deviceCwd = self.deviceCwd.text() |
|
392 if deviceCwd: |
|
393 deviceFilename = deviceCwd + "/" + deviceFilename |
366 self.__fileManager.put( |
394 self.__fileManager.put( |
367 os.path.join(self.localCwd.text(), filename), |
395 os.path.join(self.localCwd.text(), filename), |
368 os.path.join(self.deviceCwd.text(), deviceFilename) |
396 deviceFilename |
369 ) |
397 ) |
370 |
398 |
371 @pyqtSlot() |
399 @pyqtSlot() |
372 def on_getButton_clicked(self): |
400 def on_putAsButton_clicked(self): |
|
401 """ |
|
402 Private slot to copy the selected file to the connected device |
|
403 with a different name. |
|
404 """ |
|
405 self.on_putButton_clicked(putAs=True) |
|
406 |
|
407 @pyqtSlot() |
|
408 def on_getButton_clicked(self, getAs=False): |
373 """ |
409 """ |
374 Private slot to copy the selected file from the connected device. |
410 Private slot to copy the selected file from the connected device. |
|
411 |
|
412 @param getAs flag indicating to give it a new name |
|
413 @type bool |
375 """ |
414 """ |
376 selectedItems = self.deviceFileTreeWidget.selectedItems() |
415 selectedItems = self.deviceFileTreeWidget.selectedItems() |
377 if selectedItems: |
416 if selectedItems: |
378 filename = selectedItems[0].text(0).strip() |
417 filename = selectedItems[0].text(0).strip() |
379 if not filename.endswith("/"): |
418 if not filename.endswith("/"): |
380 # it is really a file |
419 # it is really a file |
381 if self.__isFileInList(filename, self.localFileTreeWidget): |
420 if getAs: |
|
421 localFilename, ok = QInputDialog.getText( |
|
422 self, |
|
423 self.tr("Get File As"), |
|
424 self.tr("Enter a new name for the file"), |
|
425 QLineEdit.Normal, |
|
426 filename) |
|
427 if not ok or not filename: |
|
428 return |
|
429 else: |
|
430 localFilename = filename |
|
431 |
|
432 if self.__isFileInList(localFilename, |
|
433 self.localFileTreeWidget): |
382 # ask for overwrite permission |
434 # ask for overwrite permission |
383 action, resultFilename = confirmOverwrite( |
435 action, resultFilename = confirmOverwrite( |
384 filename, self.tr("Copy File from Device"), |
436 localFilename, self.tr("Copy File from Device"), |
385 self.tr("The given file exists already."), |
437 self.tr("The given file exists already."), |
386 True, self) |
438 True, self) |
387 if action == "cancel": |
439 if action == "cancel": |
388 return |
440 return |
389 elif action == "rename": |
441 elif action == "rename": |
390 localFilename = resultFilename |
442 localFilename = resultFilename |
391 else: |
|
392 localFilename = filename |
|
393 else: |
|
394 localFilename = filename |
|
395 |
443 |
|
444 deviceCwd = self.deviceCwd.text() |
|
445 if deviceCwd: |
|
446 filename = deviceCwd + "/" + filename |
396 if not os.path.isabs(localFilename): |
447 if not os.path.isabs(localFilename): |
397 localFilename = os.path.join(self.localCwd.text(), |
448 localFilename = os.path.join(self.localCwd.text(), |
398 localFilename) |
449 localFilename) |
399 self.__fileManager.get( |
450 self.__fileManager.get( |
400 os.path.join(self.deviceCwd.text(), filename), |
451 filename, |
401 localFilename |
452 localFilename |
402 ) |
453 ) |
|
454 |
|
455 @pyqtSlot() |
|
456 def on_getAsButton_clicked(self): |
|
457 """ |
|
458 Private slot to copy the selected file from the connected device |
|
459 with a different name. |
|
460 """ |
|
461 self.on_getButton_clicked(getAs=True) |
403 |
462 |
404 @pyqtSlot(str, str) |
463 @pyqtSlot(str, str) |
405 def __handleGetDone(self, deviceFile, localFile): |
464 def __handleGetDone(self, deviceFile, localFile): |
406 """ |
465 """ |
407 Private slot handling a successful copy of a file from the device. |
466 Private slot handling a successful copy of a file from the device. |