38 SaveFileEnsureExtensionMode = 3 |
38 SaveFileEnsureExtensionMode = 3 |
39 DirectoryMode = 4 |
39 DirectoryMode = 4 |
40 CustomMode = 99 |
40 CustomMode = 99 |
41 NoMode = 100 |
41 NoMode = 100 |
42 |
42 |
43 # TODO: Refactor the classes using a base class with common functions |
43 |
44 |
44 class E5PathPickerBase(QWidget): |
45 |
45 """ |
46 class E5PathPicker(QWidget): |
46 Class implementing the base of a path picker widget consisting of a |
47 """ |
47 line edit or combo box and a tool button to open a file dialog. |
48 Class implementing a path picker widget consisting of a line edit and a |
|
49 tool button to open a file dialog. |
|
50 |
48 |
51 @signal textChanged(path) emitted when the entered path has changed |
49 @signal textChanged(path) emitted when the entered path has changed |
|
50 (line edit based widget) |
|
51 @signal editTextChanged(path) emitted when the entered path has changed |
|
52 (combo box based widget) |
52 @signal pathSelected(path) emitted after a path has been selected via the |
53 @signal pathSelected(path) emitted after a path has been selected via the |
53 file dialog |
54 file dialog |
54 @signal aboutToShowPathPickerDialog emitted before the file dialog is shown |
55 @signal aboutToShowPathPickerDialog emitted before the file dialog is shown |
55 @signal pickerButtonClicked emitted when the picker button was pressed and |
56 @signal pickerButtonClicked emitted when the picker button was pressed and |
56 the widget mode is custom |
57 the widget mode is custom |
57 """ |
58 """ |
58 DefaultMode = E5PathPickerModes.NoMode |
59 DefaultMode = E5PathPickerModes.NoMode |
59 |
60 |
60 textChanged = pyqtSignal(str) |
61 textChanged = pyqtSignal(str) |
|
62 editTextChanged = pyqtSignal(str) |
61 pathSelected = pyqtSignal(str) |
63 pathSelected = pyqtSignal(str) |
62 aboutToShowPathPickerDialog = pyqtSignal() |
64 aboutToShowPathPickerDialog = pyqtSignal() |
63 pickerButtonClicked = pyqtSignal() |
65 pickerButtonClicked = pyqtSignal() |
64 |
66 |
65 def __init__(self, parent=None): |
67 def __init__(self, parent=None, useLineEdit=True): |
66 """ |
68 """ |
67 Constructor |
69 Constructor |
68 |
70 |
69 @param parent reference to the parent widget |
71 @param parent reference to the parent widget |
70 @type QWidget |
72 @type QWidget |
71 """ |
73 @param useLineEdit flag indicating the use of a line edit |
72 super(E5PathPicker, self).__init__(parent) |
74 @type bool |
|
75 """ |
|
76 super(E5PathPickerBase, self).__init__(parent) |
|
77 |
|
78 self.__lineEditKind = useLineEdit |
73 |
79 |
74 self.__mode = E5PathPicker.DefaultMode |
80 self.__mode = E5PathPicker.DefaultMode |
75 self.__editorEnabled = True |
81 self.__editorEnabled = True |
76 |
82 |
77 self.__completer = None |
83 self._completer = None |
78 self.__filters = "" |
84 self.__filters = "" |
79 self.__defaultDirectory = "" |
85 self.__defaultDirectory = "" |
80 self.__windowTitle = "" |
86 self.__windowTitle = "" |
81 |
87 |
82 self.__layout = QHBoxLayout() |
88 self.__layout = QHBoxLayout() |
83 self.__layout.setSpacing(0) |
89 self.__layout.setSpacing(0) |
84 self.__layout.setContentsMargins(0, 0, 0, 0) |
90 self.__layout.setContentsMargins(0, 0, 0, 0) |
85 self.setLayout(self.__layout) |
91 self.setLayout(self.__layout) |
86 |
92 |
87 self.__editor = E5ClearableLineEdit(self, self.tr("Enter Path Name")) |
93 if useLineEdit: |
|
94 self._editor = E5ClearableLineEdit( |
|
95 self, self.tr("Enter Path Name")) |
|
96 else: |
|
97 self._editor = E5ClearableComboBox( |
|
98 self, self.tr("Enter Path Name")) |
88 |
99 |
89 self.__button = QToolButton(self) |
100 self.__button = QToolButton(self) |
90 self.__button.setToolButtonStyle(Qt.ToolButtonIconOnly) |
101 self.__button.setToolButtonStyle(Qt.ToolButtonIconOnly) |
91 self.__button.setIcon(UI.PixmapCache.getIcon("open.png")) |
102 self.__button.setIcon(UI.PixmapCache.getIcon("open.png")) |
92 |
103 |
93 self.__layout.addWidget(self.__editor) |
104 self.__layout.addWidget(self._editor) |
94 self.__layout.addWidget(self.__button) |
105 self.__layout.addWidget(self.__button) |
95 |
106 |
96 self.__button.clicked.connect(self.__showPathPickerDialog) |
107 self.__button.clicked.connect(self.__showPathPickerDialog) |
97 self.__editor.textEdited.connect(self.__pathEdited) |
108 if useLineEdit: |
98 self.__editor.textChanged.connect(self.textChanged) |
109 self._editor.textEdited.connect(self.__pathEdited) |
99 |
110 self._editor.textChanged.connect(self.textChanged) |
100 self.setFocusProxy(self.__editor) |
111 else: |
|
112 self._editor.editTextChanged.connect(self.editTextChanged) |
|
113 |
|
114 self.setFocusProxy(self._editor) |
101 self.setFocusPolicy(Qt.StrongFocus) |
115 self.setFocusPolicy(Qt.StrongFocus) |
102 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
116 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
103 |
117 |
104 self.__button.setEnabled(self.__mode != E5PathPickerModes.NoMode) |
118 self.__button.setEnabled(self.__mode != E5PathPickerModes.NoMode) |
105 |
119 |
469 path = Utilities.toNativeSeparators(path) |
528 path = Utilities.toNativeSeparators(path) |
470 while path.endswith(os.sep): |
529 while path.endswith(os.sep): |
471 path = path[:-1] |
530 path = path[:-1] |
472 |
531 |
473 if path: |
532 if path: |
474 self.__editor.setText(path) |
533 self._setEditorText(path) |
475 self.pathSelected.emit(path) |
534 self.pathSelected.emit(path) |
476 |
535 |
477 |
536 ################################################################## |
478 class E5ComboPathPicker(QWidget): |
537 ## Methods below emulate some of the QComboBox API |
|
538 ################################################################## |
|
539 |
|
540 def addItems(self, pathsList): |
|
541 """ |
|
542 Public method to add paths to the current list. |
|
543 |
|
544 @param pathsList list of paths to add |
|
545 @type list of str |
|
546 """ |
|
547 self._editor.addItems(pathsList) |
|
548 |
|
549 def addItem(self, path): |
|
550 """ |
|
551 Public method to add a paths to the current list. |
|
552 |
|
553 @param path path to add |
|
554 @type str |
|
555 """ |
|
556 self._editor.addItem(path) |
|
557 |
|
558 def setPathsList(self, pathsList): |
|
559 """ |
|
560 Public method to set the paths list. |
|
561 |
|
562 @param pathsList list of paths |
|
563 @type list of str |
|
564 """ |
|
565 self.clear() |
|
566 self.addItems(pathsList) |
|
567 |
|
568 def setCurrentIndex(self, index): |
|
569 """ |
|
570 Public slot to set the current index. |
|
571 |
|
572 @param index index of the item to set current |
|
573 @type int |
|
574 """ |
|
575 self._editor.setCurrentIndex(index) |
|
576 |
|
577 def setInsertPolicy(self, policy): |
|
578 """ |
|
579 Public method to set the insertion policy of the combo box. |
|
580 |
|
581 @param policy insertion policy |
|
582 @type QComboBox.InsertPolicy |
|
583 """ |
|
584 self._editor.setInsertPolicy(policy) |
|
585 |
|
586 def setSizeAdjustPolicy(self, policy): |
|
587 """ |
|
588 Public method to set the size adjust policy of the combo box. |
|
589 |
|
590 @param policy size adjust policy |
|
591 @type QComboBox.SizeAdjustPolicy |
|
592 """ |
|
593 self._editor.setSizeAdjustPolicy(policy) |
|
594 |
|
595 |
|
596 class E5PathPicker(E5PathPickerBase): |
|
597 """ |
|
598 Class implementing a path picker widget consisting of a line edit and a |
|
599 tool button to open a file dialog. |
|
600 |
|
601 @signal textChanged(path) emitted when the entered path has changed |
|
602 @signal pathSelected(path) emitted after a path has been selected via the |
|
603 file dialog |
|
604 @signal aboutToShowPathPickerDialog emitted before the file dialog is shown |
|
605 @signal pickerButtonClicked emitted when the picker button was pressed and |
|
606 the widget mode is custom |
|
607 """ |
|
608 def __init__(self, parent=None): |
|
609 """ |
|
610 Constructor |
|
611 |
|
612 @param parent reference to the parent widget |
|
613 @type QWidget |
|
614 """ |
|
615 super(E5PathPicker, self).__init__(parent, useLineEdit=True) |
|
616 |
|
617 |
|
618 class E5ComboPathPicker(E5PathPickerBase): |
479 """ |
619 """ |
480 Class implementing a path picker widget consisting of a combobox and a |
620 Class implementing a path picker widget consisting of a combobox and a |
481 tool button to open a file dialog. |
621 tool button to open a file dialog. |
482 |
622 |
483 @signal editTextChanged(path) emitted when the entered path has changed |
623 @signal editTextChanged(path) emitted when the entered path has changed |
485 file dialog |
625 file dialog |
486 @signal aboutToShowPathPickerDialog emitted before the file dialog is shown |
626 @signal aboutToShowPathPickerDialog emitted before the file dialog is shown |
487 @signal pickerButtonClicked emitted when the picker button was pressed and |
627 @signal pickerButtonClicked emitted when the picker button was pressed and |
488 the widget mode is custom |
628 the widget mode is custom |
489 """ |
629 """ |
490 DefaultMode = E5PathPickerModes.NoMode |
|
491 |
|
492 editTextChanged = pyqtSignal(str) |
|
493 pathSelected = pyqtSignal(str) |
|
494 aboutToShowPathPickerDialog = pyqtSignal() |
|
495 pickerButtonClicked = pyqtSignal() |
|
496 |
|
497 def __init__(self, parent=None): |
630 def __init__(self, parent=None): |
498 """ |
631 """ |
499 Constructor |
632 Constructor |
500 |
633 |
501 @param parent reference to the parent widget |
634 @param parent reference to the parent widget |
502 @type QWidget |
635 @type QWidget |
503 """ |
636 """ |
504 super(E5ComboPathPicker, self).__init__(parent) |
637 super(E5ComboPathPicker, self).__init__(parent, useLineEdit=False) |
505 |
|
506 self.__mode = E5PathPicker.DefaultMode |
|
507 self.__editorEnabled = True |
|
508 |
|
509 self.__filters = "" |
|
510 self.__defaultDirectory = "" |
|
511 self.__windowTitle = "" |
|
512 |
|
513 self.__layout = QHBoxLayout() |
|
514 self.__layout.setSpacing(0) |
|
515 self.__layout.setContentsMargins(0, 0, 0, 0) |
|
516 self.setLayout(self.__layout) |
|
517 |
|
518 self.__editor = E5ClearableComboBox(self, self.tr("Enter Path Name")) |
|
519 |
|
520 self.__button = QToolButton(self) |
|
521 self.__button.setToolButtonStyle(Qt.ToolButtonIconOnly) |
|
522 self.__button.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
523 |
|
524 self.__layout.addWidget(self.__editor) |
|
525 self.__layout.addWidget(self.__button) |
|
526 |
|
527 self.__button.clicked.connect(self.__showPathPickerDialog) |
|
528 self.__editor.editTextChanged.connect(self.editTextChanged) |
|
529 |
|
530 self.setFocusProxy(self.__editor) |
|
531 self.setFocusPolicy(Qt.StrongFocus) |
|
532 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
|
533 |
|
534 self.__button.setEnabled(self.__mode != E5PathPickerModes.NoMode) |
|
535 |
|
536 def setMode(self, mode): |
|
537 """ |
|
538 Public method to set the path picker mode. |
|
539 |
|
540 @param mode picker mode |
|
541 @type E5PathPickerModes |
|
542 """ |
|
543 assert mode in E5PathPickerModes |
|
544 |
|
545 oldMode = self.__mode |
|
546 self.__mode = mode |
|
547 |
|
548 if mode != oldMode: |
|
549 if mode != E5PathPickerModes.NoMode: |
|
550 # set inactive text |
|
551 if mode == E5PathPickerModes.OpenFilesMode: |
|
552 self.__editor.setInactiveText( |
|
553 self.tr("Enter Path Names separated by ';'")) |
|
554 else: |
|
555 self.__editor.setInactiveText( |
|
556 self.tr("Enter Path Name")) |
|
557 self.__button.setEnabled(self.__mode != E5PathPickerModes.NoMode) |
|
558 |
|
559 def mode(self): |
|
560 """ |
|
561 Public method to get the path picker mode. |
|
562 |
|
563 @return path picker mode |
|
564 @rtype E5PathPickerModes |
|
565 """ |
|
566 return self.__mode |
|
567 |
|
568 def setPickerEnabled(self, enable): |
|
569 """ |
|
570 Public method to set the enabled state of the file dialog button. |
|
571 |
|
572 @param enable flag indicating the enabled state |
|
573 @type bool |
|
574 """ |
|
575 self.__button.setEnabled(enable) |
|
576 |
|
577 def isPickerEnabled(self): |
|
578 """ |
|
579 Public method to get the file dialog button enabled state. |
|
580 |
|
581 @return flag indicating the enabled state |
|
582 @rtype bool |
|
583 """ |
|
584 return self.__button.isEnabled() |
|
585 |
|
586 def clear(self): |
|
587 """ |
|
588 Public method to clear the list of paths. |
|
589 """ |
|
590 self.__editor.clear() |
|
591 |
|
592 def clearEditText(self): |
|
593 """ |
|
594 Public method to clear the current path. |
|
595 """ |
|
596 self.__editor.clearEditText() |
|
597 |
|
598 def setEditText(self, path): |
|
599 """ |
|
600 Public method to set the current path. |
|
601 |
|
602 @param path path to be set |
|
603 @type str |
|
604 """ |
|
605 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
606 self.__editor.setEditText(path) |
|
607 else: |
|
608 self.__editor.setEditText(Utilities.toNativeSeparators(path)) |
|
609 |
|
610 def currentText(self): |
|
611 """ |
|
612 Public method to get the current path. |
|
613 |
|
614 @return current path |
|
615 @rtype str |
|
616 """ |
|
617 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
618 return ";".join( |
|
619 [Utilities.toNativeSeparators(path) |
|
620 for path in self.__editor.currentText().split(";")]) |
|
621 else: |
|
622 return os.path.expanduser( |
|
623 Utilities.toNativeSeparators(self.__editor.currentText())) |
|
624 |
|
625 def setPath(self, path): |
|
626 """ |
|
627 Public method to set the current path. |
|
628 |
|
629 @param path path to be set |
|
630 @type str |
|
631 """ |
|
632 self.setEditText(path) |
|
633 |
|
634 def path(self): |
|
635 """ |
|
636 Public method to get the current path. |
|
637 |
|
638 @return current path |
|
639 @rtype str |
|
640 """ |
|
641 return self.currentText() |
|
642 |
|
643 def paths(self): |
|
644 """ |
|
645 Public method to get the list of entered paths. |
|
646 |
|
647 @return entered paths |
|
648 @rtype list of str |
|
649 """ |
|
650 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
651 return self.path().split(";") |
|
652 else: |
|
653 return [self.path()] |
|
654 |
|
655 def firstPath(self): |
|
656 """ |
|
657 Public method to get the first path of a list of entered paths. |
|
658 |
|
659 @return first path |
|
660 @rtype str |
|
661 """ |
|
662 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
663 return self.path().split(";")[0] |
|
664 else: |
|
665 return self.path() |
|
666 |
|
667 def lastPath(self): |
|
668 """ |
|
669 Public method to get the last path of a list of entered paths. |
|
670 |
|
671 @return first path |
|
672 @rtype str |
|
673 """ |
|
674 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
675 return self.path().split(";")[-1] |
|
676 else: |
|
677 return self.path() |
|
678 |
|
679 def addItems(self, pathsList): |
|
680 """ |
|
681 Public method to add paths to the current list. |
|
682 |
|
683 @param pathsList list of paths to add |
|
684 @type list of str |
|
685 """ |
|
686 self.__editor.addItems(pathsList) |
|
687 |
|
688 def addItem(self, path): |
|
689 """ |
|
690 Public method to add a paths to the current list. |
|
691 |
|
692 @param path path to add |
|
693 @type str |
|
694 """ |
|
695 self.__editor.addItem(path) |
|
696 |
|
697 def setPathsList(self, pathsList): |
|
698 """ |
|
699 Public method to set the paths list. |
|
700 |
|
701 @param pathsList list of paths |
|
702 @type list of str |
|
703 """ |
|
704 self.clear() |
|
705 self.addItems(pathsList) |
|
706 |
|
707 def setCurrentIndex(self, index): |
|
708 """ |
|
709 Public slot to set the current index. |
|
710 |
|
711 @param index index of the item to set current |
|
712 @type int |
|
713 """ |
|
714 self.__editor.setCurrentIndex(index) |
|
715 |
|
716 def setEditorEnabled(self, enable): |
|
717 """ |
|
718 Public method to set the path editor's enabled state. |
|
719 |
|
720 @param enable flag indicating the enable state |
|
721 @type bool |
|
722 """ |
|
723 if enable != self.__editorEnabled: |
|
724 self.__editorEnabled = enable |
|
725 self.__editor.setEnabled(enable) |
|
726 |
|
727 def editorEnabled(self): |
|
728 """ |
|
729 Public method to get the path editor's enabled state. |
|
730 |
|
731 @return flag indicating the enabled state |
|
732 @rtype bool |
|
733 """ |
|
734 return self.__editorEnabled |
|
735 |
|
736 def setDefaultDirectory(self, directory): |
|
737 """ |
|
738 Public method to set the default directory. |
|
739 |
|
740 @param directory default directory |
|
741 @type str |
|
742 """ |
|
743 self.__defaultDirectory = directory |
|
744 |
|
745 def defaultDirectory(self): |
|
746 """ |
|
747 Public method to get the default directory. |
|
748 |
|
749 @return default directory |
|
750 @rtype str |
|
751 """ |
|
752 return self.__defaultDirectory |
|
753 |
|
754 def setWindowTitle(self, title): |
|
755 """ |
|
756 Public method to set the path picker dialog window title. |
|
757 |
|
758 @param title window title |
|
759 @type str |
|
760 """ |
|
761 self.__windowTitle = title |
|
762 |
|
763 def windowTitle(self): |
|
764 """ |
|
765 Public method to get the path picker dialog's window title. |
|
766 |
|
767 @return window title |
|
768 @rtype str |
|
769 """ |
|
770 return self.__windowTitle |
|
771 |
|
772 def setFilters(self, filters): |
|
773 """ |
|
774 Public method to set the filters for the path picker dialog. |
|
775 |
|
776 Note: Multiple filters must be separated by ';;'. |
|
777 |
|
778 @param filters string containing the file filters |
|
779 @type str |
|
780 """ |
|
781 self.__filters = filters |
|
782 |
|
783 def filters(self): |
|
784 """ |
|
785 Public methods to get the filter string. |
|
786 |
|
787 @return filter string |
|
788 @rtype str |
|
789 """ |
|
790 return self.__filters |
|
791 |
|
792 def setButtonToolTip(self, tooltip): |
|
793 """ |
|
794 Public method to set the tool button tool tip. |
|
795 |
|
796 @param tooltip text to be set as a tool tip |
|
797 @type str |
|
798 """ |
|
799 self.__button.setToolTip(tooltip) |
|
800 |
|
801 def buttonToolTip(self): |
|
802 """ |
|
803 Public method to get the tool button tool tip. |
|
804 |
|
805 @return tool tip text |
|
806 @rtype str |
|
807 """ |
|
808 return self.__button.toolTip() |
|
809 |
|
810 def setEditorToolTip(self, tooltip): |
|
811 """ |
|
812 Public method to set the editor tool tip. |
|
813 |
|
814 @param tooltip text to be set as a tool tip |
|
815 @type str |
|
816 """ |
|
817 self.__editor.setToolTip(tooltip) |
|
818 |
|
819 def editorToolTip(self): |
|
820 """ |
|
821 Public method to get the editor tool tip. |
|
822 |
|
823 @return tool tip text |
|
824 @rtype str |
|
825 """ |
|
826 return self.__editor.toolTip() |
|
827 |
|
828 def setInsertPolicy(self, policy): |
|
829 """ |
|
830 Public method to set the insertion policy of the combo box. |
|
831 |
|
832 @param policy insertion policy |
|
833 @type QComboBox.InsertPolicy |
|
834 """ |
|
835 self.__editor.setInsertPolicy(policy) |
|
836 |
|
837 def setSizeAdjustPolicy(self, policy): |
|
838 """ |
|
839 Public method to set the size adjust policy of the combo box. |
|
840 |
|
841 @param policy size adjust policy |
|
842 @type QComboBox.SizeAdjustPolicy |
|
843 """ |
|
844 self.__editor.setSizeAdjustPolicy(policy) |
|
845 |
|
846 def __showPathPickerDialog(self): |
|
847 """ |
|
848 Private slot to show the path picker dialog. |
|
849 """ |
|
850 if self.__mode == E5PathPickerModes.NoMode: |
|
851 return |
|
852 |
|
853 if self.__mode == E5PathPickerModes.CustomMode: |
|
854 self.pickerButtonClicked.emit() |
|
855 return |
|
856 |
|
857 self.aboutToShowPathPickerDialog.emit() |
|
858 |
|
859 windowTitle = self.__windowTitle |
|
860 if not windowTitle: |
|
861 if self.__mode == E5PathPickerModes.OpenFileMode: |
|
862 windowTitle = self.tr("Choose a file to open") |
|
863 elif self.__mode == E5PathPickerModes.OpenFilesMode: |
|
864 windowTitle = self.tr("Choose files to open") |
|
865 elif self.__mode == E5PathPickerModes.SaveFileMode: |
|
866 windowTitle = self.tr("Choose a file to save") |
|
867 elif self.__mode == E5PathPickerModes.DirectoryMode: |
|
868 windowTitle = self.tr("Choose a directory") |
|
869 |
|
870 directory = self.__editor.currentText() |
|
871 if not directory and self.__defaultDirectory: |
|
872 directory = self.__defaultDirectory |
|
873 if self.__mode == E5PathPickerModes.OpenFilesMode: |
|
874 directory = os.path.expanduser(directory.split(";")[0]) |
|
875 else: |
|
876 directory = os.path.expanduser(directory) |
|
877 if not os.path.isabs(directory) and self.__defaultDirectory: |
|
878 directory = os.path.join(self.__defaultDirectory, directory) |
|
879 directory = Utilities.fromNativeSeparators(directory) |
|
880 |
|
881 if self.__mode == E5PathPickerModes.OpenFileMode: |
|
882 path = E5FileDialog.getOpenFileName( |
|
883 self, |
|
884 windowTitle, |
|
885 directory, |
|
886 self.__filters) |
|
887 path = Utilities.toNativeSeparators(path) |
|
888 elif self.__mode == E5PathPickerModes.OpenFilesMode: |
|
889 paths = E5FileDialog.getOpenFileNames( |
|
890 self, |
|
891 windowTitle, |
|
892 directory, |
|
893 self.__filters) |
|
894 path = ";".join([Utilities.toNativeSeparators(path) |
|
895 for path in paths]) |
|
896 elif self.__mode == E5PathPickerModes.SaveFileMode: |
|
897 path = E5FileDialog.getSaveFileName( |
|
898 self, |
|
899 windowTitle, |
|
900 directory, |
|
901 self.__filters, |
|
902 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
903 path = Utilities.toNativeSeparators(path) |
|
904 elif self.__mode == E5PathPickerModes.SaveFileEnsureExtensionMode: |
|
905 path, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
|
906 self, |
|
907 windowTitle, |
|
908 directory, |
|
909 self.__filters, |
|
910 None, |
|
911 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
912 path = Utilities.toNativeSeparators(path) |
|
913 if path: |
|
914 ext = QFileInfo(path).suffix() |
|
915 if not ext: |
|
916 ex = selectedFilter.split("(*")[1].split(")")[0] |
|
917 if ex: |
|
918 path += ex |
|
919 elif self.__mode == E5PathPickerModes.DirectoryMode: |
|
920 path = E5FileDialog.getExistingDirectory( |
|
921 self, |
|
922 windowTitle, |
|
923 directory, |
|
924 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
925 path = Utilities.toNativeSeparators(path) |
|
926 while path.endswith(os.sep): |
|
927 path = path[:-1] |
|
928 |
|
929 if path: |
|
930 self.__editor.setEditText(path) |
|
931 self.pathSelected.emit(path) |
|