src/eric7/EricWidgets/EricPathPicker.py

branch
eric7
changeset 9238
a7cbf3d61498
parent 9221
bf71ee032bb4
child 9259
66167d4d0407
--- a/src/eric7/EricWidgets/EricPathPicker.py	Sat Jul 16 18:09:30 2022 +0200
+++ b/src/eric7/EricWidgets/EricPathPicker.py	Sat Jul 16 18:14:30 2022 +0200
@@ -319,71 +319,56 @@
         """
         return self.text(toNative=toNative)
 
-    def setPath(self, fpath, toNative=True):
+    def setPath(self, fpath):
         """
         Public method to set the current path.
 
         @param fpath path to be set
-        @type str
-        @param toNative flag indicating to convert the path into
-            a native format
-        @type bool
+        @type str or pathlib.Path
         """
-        self.setText(fpath, toNative=toNative)
+        self.setText(str(fpath), toNative=True)
 
-    def path(self, toNative=True):
+    def path(self):
         """
         Public method to get the current path.
 
-        @param toNative flag indicating to convert the path into
-            a native format
-        @type bool
         @return current path
-        @rtype str
+        @rtype pathlib.Path
         """
-        return self.text(toNative=toNative)
+        return self.paths()[0]
 
-    def paths(self, toNative=True):
+    def paths(self):
         """
         Public method to get the list of entered paths.
 
-        @param toNative flag indicating to convert the path into
-            a native format
-        @type bool
         @return entered paths
-        @rtype list of str
+        @rtype list of pathlib.Path
         """
         if self.__mode in (
             EricPathPickerModes.OPEN_FILES_MODE,
             EricPathPickerModes.OPEN_FILES_AND_DIRS_MODE,
         ):
-            return self.path(toNative=toNative).split(";")
+            return [pathlib.Path(t) for t in self.text().split(";")]
         else:
-            return [self.path(toNative=toNative)]
+            return [pathlib.Path(self.text)]
 
-    def firstPath(self, toNative=True):
+    def firstPath(self):
         """
         Public method to get the first path of a list of entered paths.
 
-        @param toNative flag indicating to convert the path into
-            a native format
-        @type bool
         @return first path
-        @rtype str
+        @rtype pathlib.Path
         """
-        return self.paths(toNative=toNative)[0]
+        return self.paths()[0]
 
-    def lastPath(self, toNative=True):
+    def lastPath(self):
         """
         Public method to get the last path of a list of entered paths.
 
-        @param toNative flag indicating to convert the path into
-            a native format
-        @type bool
         @return last path
-        @rtype str
+        @rtype pathlib.Path
         """
-        return self.paths(toNative=toNative)[-1]
+        return self.paths()[-1]
 
     def setEditorEnabled(self, enable):
         """
@@ -410,9 +395,9 @@
         Public method to set the default directory.
 
         @param directory default directory
-        @type str
+        @type str or pathlib.Path
         """
-        self.__defaultDirectory = directory
+        self.__defaultDirectory = str(directory)
 
     def defaultDirectory(self):
         """
@@ -423,6 +408,15 @@
         """
         return self.__defaultDirectory
 
+    def defaultDirectoryPath(self):
+        """
+        Public method to get the default directory as a pathlib.Path object.
+
+        @return default directory
+        @rtype pathlib.Path
+        """
+        return pathlib.Path(self.__defaultDirectory)
+
     def setWindowTitle(self, title):
         """
         Public method to set the path picker dialog window title.
@@ -648,26 +642,26 @@
         """
         Public method to add paths to the current list.
 
-        @param pathsList list of paths to add
-        @type list of str
+        @param pathsList list of paths
+        @type list of str or pathlib.Path
         """
-        self._editor.addItems(pathsList)
+        self._editor.addItems(str(f) for f in pathsList)
 
     def addItem(self, fpath):
         """
         Public method to add a paths to the current list.
 
         @param fpath path to add
-        @type str
+        @type str or pathlib.Path
         """
-        self._editor.addItem(fpath)
+        self._editor.addItem(str(fpath))
 
     def setPathsList(self, pathsList):
         """
         Public method to set the paths list.
 
         @param pathsList list of paths
-        @type list of str
+        @type list of str or pathlib.Path
         """
         self.clear()
         self.addItems(pathsList)
@@ -690,6 +684,15 @@
         """
         self._editor.setCurrentText(text)
 
+    def setCurrentPath(self, fpath):
+        """
+        Public method to set the current path.
+
+        @param fpath current path
+        @type pathlib.Path
+        """
+        self._editor.setCurrentText(str(fpath))
+
     def setInsertPolicy(self, policy):
         """
         Public method to set the insertion policy of the combo box.
@@ -744,10 +747,22 @@
         """
         Public method to get the list of remembered paths.
 
-        @return list od remembered paths
+        @return list of remembered paths
         @rtype list of str
         """
         paths = []
         for index in range(self._editor.count()):
             paths.append(self._editor.itemText(index))
         return paths
+
+    def getPathLibItems(self):
+        """
+        Public method to get the list of remembered paths.
+
+        @return list of remembered paths
+        @rtype list of pathlib.Path
+        """
+        paths = []
+        for index in range(self._editor.count()):
+            paths.append(pathlib.Path(self._editor.itemText(index)))
+        return paths

eric ide

mercurial