Sat, 16 Jul 2022 18:14:30 +0200
EricPathPicker, EricPathPickerDialog
- added/changed code to work with pathlib.Path objects next to string paths
--- a/src/eric7/APIs/Python3/eric7.api Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/APIs/Python3/eric7.api Sat Jul 16 18:14:30 2022 +0200 @@ -1497,6 +1497,7 @@ eric7.EricWidgets.EricPasswordMeter.EricPasswordMeter.setValue?4(value) eric7.EricWidgets.EricPasswordMeter.EricPasswordMeter?1(parent=None) eric7.EricWidgets.EricPathPicker.EricComboPathPicker.getPathItems?4() +eric7.EricWidgets.EricPathPicker.EricComboPathPicker.getPathLibItems?4() eric7.EricWidgets.EricPathPicker.EricComboPathPicker?1(parent=None) eric7.EricWidgets.EricPathPicker.EricPathPicker?1(parent=None) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.DefaultMode?7 @@ -1510,21 +1511,23 @@ eric7.EricWidgets.EricPathPicker.EricPathPickerBase.clearEditText?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.currentText?4(toNative=True) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.defaultDirectory?4() +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.defaultDirectoryPath?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.editTextChanged?7 eric7.EricWidgets.EricPathPicker.EricPathPickerBase.editorEnabled?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.editorToolTip?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.filters?4() -eric7.EricWidgets.EricPathPicker.EricPathPickerBase.firstPath?4(toNative=True) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.firstPath?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.isPickerEnabled?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.isReadOnly?4() -eric7.EricWidgets.EricPathPicker.EricPathPickerBase.lastPath?4(toNative=True) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.lastPath?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.mode?4() -eric7.EricWidgets.EricPathPicker.EricPathPickerBase.path?4(toNative=True) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.path?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.pathSelected?7 -eric7.EricWidgets.EricPathPicker.EricPathPickerBase.paths?4(toNative=True) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.paths?4() eric7.EricWidgets.EricPathPicker.EricPathPickerBase.pickerButtonClicked?7 eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setButtonToolTip?4(tooltip) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setCurrentIndex?4(index) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setCurrentPath?4(fpath) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setCurrentText?4(text) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setDefaultDirectory?4(directory) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setEditText?4(fpath, toNative=True) @@ -1534,7 +1537,7 @@ eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setInsertPolicy?4(policy) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setMode?4(mode) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setNameFilters?4(filters) -eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setPath?4(fpath, toNative=True) +eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setPath?4(fpath) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setPathsList?4(pathsList) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setPickerEnabled?4(enable) eric7.EricWidgets.EricPathPicker.EricPathPickerBase.setReadOnly?4(readOnly) @@ -1556,14 +1559,16 @@ eric7.EricWidgets.EricPathPicker.EricPathPickerModes.SAVE_FILE_MODE?7 eric7.EricWidgets.EricPathPicker.EricPathPickerModes.SAVE_FILE_OVERWRITE_MODE?7 eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.getPath?4() +eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.getText?4() eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setDefaultDirectory?4(directory) eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setLabelText?4(text) eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setPickerFilters?4(filters) eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setPickerMode?4(mode) -eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setPickerPath?4(path) +eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setPickerPath?4(fpath) eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog.setTitle?4(title) eric7.EricWidgets.EricPathPickerDialog.EricPathPickerDialog?1(parent=None) -eric7.EricWidgets.EricPathPickerDialog.getPath?4(parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, path="", defaultDirectory="", filters=None, ) +eric7.EricWidgets.EricPathPickerDialog.getPath?4(parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, pathlibPath=None, defaultDirectory=None, filters=None, ) +eric7.EricWidgets.EricPathPickerDialog.getStrPath?4(parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, strPath=None, defaultDirectory=None, filters=None, ) eric7.EricWidgets.EricPlainTextDialog.EricPlainTextDialog.on_copyButton_clicked?4() eric7.EricWidgets.EricPlainTextDialog.EricPlainTextDialog.toPlainText?4() eric7.EricWidgets.EricPlainTextDialog.EricPlainTextDialog?1(title="", text="", readOnly=True, parent=None)
--- a/src/eric7/DataViews/PyCoverageDialog.py Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/DataViews/PyCoverageDialog.py Sat Jul 16 18:14:30 2022 +0200 @@ -420,12 +420,12 @@ from EricWidgets import EricPathPickerDialog from EricWidgets.EricPathPicker import EricPathPickerModes - filename, ok = EricPathPickerDialog.getPath( + filename, ok = EricPathPickerDialog.getStrPath( self, self.tr("LCOV Report"), self.tr("Enter the path of the output file:"), mode=EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE, - path=os.path.join(os.path.dirname(self.cfn), "coverage.lcov"), + strPath=os.path.join(os.path.dirname(self.cfn), "coverage.lcov"), defaultDirectory=os.path.dirname(self.cfn), filters=self.tr("LCOV Files (*.lcov);;All Files (*)"), )
--- a/src/eric7/Documentation/Help/source.qhp Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/Documentation/Help/source.qhp Sat Jul 16 18:14:30 2022 +0200 @@ -4927,6 +4927,7 @@ <keyword name="EricComboPathPicker" id="EricComboPathPicker" ref="eric7.EricWidgets.EricPathPicker.html#EricComboPathPicker" /> <keyword name="EricComboPathPicker (Constructor)" id="EricComboPathPicker (Constructor)" ref="eric7.EricWidgets.EricPathPicker.html#EricComboPathPicker.__init__" /> <keyword name="EricComboPathPicker.getPathItems" id="EricComboPathPicker.getPathItems" ref="eric7.EricWidgets.EricPathPicker.html#EricComboPathPicker.getPathItems" /> + <keyword name="EricComboPathPicker.getPathLibItems" id="EricComboPathPicker.getPathLibItems" ref="eric7.EricWidgets.EricPathPicker.html#EricComboPathPicker.getPathLibItems" /> <keyword name="EricComboSelectionDialog" id="EricComboSelectionDialog" ref="eric7.EricWidgets.EricComboSelectionDialog.html#EricComboSelectionDialog" /> <keyword name="EricComboSelectionDialog (Constructor)" id="EricComboSelectionDialog (Constructor)" ref="eric7.EricWidgets.EricComboSelectionDialog.html#EricComboSelectionDialog.__init__" /> <keyword name="EricComboSelectionDialog (Module)" id="EricComboSelectionDialog (Module)" ref="eric7.EricWidgets.EricComboSelectionDialog.html" /> @@ -5339,6 +5340,7 @@ <keyword name="EricPathPickerBase.clearEditText" id="EricPathPickerBase.clearEditText" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.clearEditText" /> <keyword name="EricPathPickerBase.currentText" id="EricPathPickerBase.currentText" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.currentText" /> <keyword name="EricPathPickerBase.defaultDirectory" id="EricPathPickerBase.defaultDirectory" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.defaultDirectory" /> + <keyword name="EricPathPickerBase.defaultDirectoryPath" id="EricPathPickerBase.defaultDirectoryPath" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.defaultDirectoryPath" /> <keyword name="EricPathPickerBase.editorEnabled" id="EricPathPickerBase.editorEnabled" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.editorEnabled" /> <keyword name="EricPathPickerBase.editorToolTip" id="EricPathPickerBase.editorToolTip" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.editorToolTip" /> <keyword name="EricPathPickerBase.filters" id="EricPathPickerBase.filters" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.filters" /> @@ -5351,6 +5353,7 @@ <keyword name="EricPathPickerBase.paths" id="EricPathPickerBase.paths" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.paths" /> <keyword name="EricPathPickerBase.setButtonToolTip" id="EricPathPickerBase.setButtonToolTip" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setButtonToolTip" /> <keyword name="EricPathPickerBase.setCurrentIndex" id="EricPathPickerBase.setCurrentIndex" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setCurrentIndex" /> + <keyword name="EricPathPickerBase.setCurrentPath" id="EricPathPickerBase.setCurrentPath" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setCurrentPath" /> <keyword name="EricPathPickerBase.setCurrentText" id="EricPathPickerBase.setCurrentText" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setCurrentText" /> <keyword name="EricPathPickerBase.setDefaultDirectory" id="EricPathPickerBase.setDefaultDirectory" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setDefaultDirectory" /> <keyword name="EricPathPickerBase.setEditText" id="EricPathPickerBase.setEditText" ref="eric7.EricWidgets.EricPathPicker.html#EricPathPickerBase.setEditText" /> @@ -5373,6 +5376,7 @@ <keyword name="EricPathPickerDialog (Constructor)" id="EricPathPickerDialog (Constructor)" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.__init__" /> <keyword name="EricPathPickerDialog (Module)" id="EricPathPickerDialog (Module)" ref="eric7.EricWidgets.EricPathPickerDialog.html" /> <keyword name="EricPathPickerDialog.getPath" id="EricPathPickerDialog.getPath" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.getPath" /> + <keyword name="EricPathPickerDialog.getText" id="EricPathPickerDialog.getText" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.getText" /> <keyword name="EricPathPickerDialog.setDefaultDirectory" id="EricPathPickerDialog.setDefaultDirectory" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.setDefaultDirectory" /> <keyword name="EricPathPickerDialog.setLabelText" id="EricPathPickerDialog.setLabelText" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.setLabelText" /> <keyword name="EricPathPickerDialog.setPickerFilters" id="EricPathPickerDialog.setPickerFilters" ref="eric7.EricWidgets.EricPathPickerDialog.html#EricPathPickerDialog.setPickerFilters" /> @@ -18802,6 +18806,7 @@ <keyword name="getServersPath" id="getServersPath" ref="eric7.Plugins.VcsPlugins.vcsSubversion.SvnUtilities.html#getServersPath" /> <keyword name="getSettings" id="getSettings" ref="eric7.Preferences.__init__.html#getSettings" /> <keyword name="getShell" id="getShell" ref="eric7.Preferences.__init__.html#getShell" /> + <keyword name="getStrPath" id="getStrPath" ref="eric7.EricWidgets.EricPathPickerDialog.html#getStrPath" /> <keyword name="getSupportedApiLanguages" id="getSupportedApiLanguages" ref="eric7.QScintilla.Lexers.__init__.html#getSupportedApiLanguages" /> <keyword name="getSupportedDevices" id="getSupportedDevices" ref="eric7.MicroPython.MicroPythonDevices.html#getSupportedDevices" /> <keyword name="getSupportedDocstringTypes" id="getSupportedDocstringTypes" ref="eric7.QScintilla.DocstringGenerator.__init__.html#getSupportedDocstringTypes" />
--- a/src/eric7/Documentation/Source/eric7.EricWidgets.EricPathPicker.html Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/Documentation/Source/eric7.EricWidgets.EricPathPicker.html Sat Jul 16 18:14:30 2022 +0200 @@ -75,6 +75,10 @@ <td><a href="#EricComboPathPicker.getPathItems">getPathItems</a></td> <td>Public method to get the list of remembered paths.</td> </tr> +<tr> +<td><a href="#EricComboPathPicker.getPathLibItems">getPathLibItems</a></td> +<td>Public method to get the list of remembered paths.</td> +</tr> </table> <h3>Static Methods</h3> @@ -106,7 +110,7 @@ <dl> <dt>Return:</dt> <dd> -list od remembered paths +list of remembered paths </dd> </dl> <dl> @@ -115,6 +119,25 @@ list of str </dd> </dl> +<a NAME="EricComboPathPicker.getPathLibItems" ID="EricComboPathPicker.getPathLibItems"></a> +<h4>EricComboPathPicker.getPathLibItems</h4> +<b>getPathLibItems</b>(<i></i>) + +<p> + Public method to get the list of remembered paths. +</p> +<dl> +<dt>Return:</dt> +<dd> +list of remembered paths +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +list of pathlib.Path +</dd> +</dl> <div align="right"><a href="#top">Up</a></div> <hr /> <hr /> @@ -269,6 +292,10 @@ <td>Public method to get the default directory.</td> </tr> <tr> +<td><a href="#EricPathPickerBase.defaultDirectoryPath">defaultDirectoryPath</a></td> +<td>Public method to get the default directory as a pathlib.Path object.</td> +</tr> +<tr> <td><a href="#EricPathPickerBase.editorEnabled">editorEnabled</a></td> <td>Public method to get the path editor's enabled state.</td> </tr> @@ -317,6 +344,10 @@ <td>Public slot to set the current index.</td> </tr> <tr> +<td><a href="#EricPathPickerBase.setCurrentPath">setCurrentPath</a></td> +<td>Public method to set the current path.</td> +</tr> +<tr> <td><a href="#EricPathPickerBase.setCurrentText">setCurrentText</a></td> <td>Public slot to set the current text.</td> </tr> @@ -476,7 +507,7 @@ </p> <dl> -<dt><i>fpath</i> (str)</dt> +<dt><i>fpath</i> (str or pathlib.Path)</dt> <dd> path to add </dd> @@ -490,9 +521,9 @@ </p> <dl> -<dt><i>pathsList</i> (list of str)</dt> +<dt><i>pathsList</i> (list of str or pathlib.Path)</dt> <dd> -list of paths to add +list of paths </dd> </dl> <a NAME="EricPathPickerBase.buttonToolTip" ID="EricPathPickerBase.buttonToolTip"></a> @@ -574,6 +605,25 @@ str </dd> </dl> +<a NAME="EricPathPickerBase.defaultDirectoryPath" ID="EricPathPickerBase.defaultDirectoryPath"></a> +<h4>EricPathPickerBase.defaultDirectoryPath</h4> +<b>defaultDirectoryPath</b>(<i></i>) + +<p> + Public method to get the default directory as a pathlib.Path object. +</p> +<dl> +<dt>Return:</dt> +<dd> +default directory +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +pathlib.Path +</dd> +</dl> <a NAME="EricPathPickerBase.editorEnabled" ID="EricPathPickerBase.editorEnabled"></a> <h4>EricPathPickerBase.editorEnabled</h4> <b>editorEnabled</b>(<i></i>) @@ -633,20 +683,12 @@ </dl> <a NAME="EricPathPickerBase.firstPath" ID="EricPathPickerBase.firstPath"></a> <h4>EricPathPickerBase.firstPath</h4> -<b>firstPath</b>(<i>toNative=True</i>) +<b>firstPath</b>(<i></i>) <p> Public method to get the first path of a list of entered paths. </p> <dl> - -<dt><i>toNative</i> (bool)</dt> -<dd> -flag indicating to convert the path into - a native format -</dd> -</dl> -<dl> <dt>Return:</dt> <dd> first path @@ -655,7 +697,7 @@ <dl> <dt>Return Type:</dt> <dd> -str +pathlib.Path </dd> </dl> <a NAME="EricPathPickerBase.isPickerEnabled" ID="EricPathPickerBase.isPickerEnabled"></a> @@ -698,20 +740,12 @@ </dl> <a NAME="EricPathPickerBase.lastPath" ID="EricPathPickerBase.lastPath"></a> <h4>EricPathPickerBase.lastPath</h4> -<b>lastPath</b>(<i>toNative=True</i>) +<b>lastPath</b>(<i></i>) <p> Public method to get the last path of a list of entered paths. </p> <dl> - -<dt><i>toNative</i> (bool)</dt> -<dd> -flag indicating to convert the path into - a native format -</dd> -</dl> -<dl> <dt>Return:</dt> <dd> last path @@ -720,7 +754,7 @@ <dl> <dt>Return Type:</dt> <dd> -str +pathlib.Path </dd> </dl> <a NAME="EricPathPickerBase.mode" ID="EricPathPickerBase.mode"></a> @@ -744,20 +778,12 @@ </dl> <a NAME="EricPathPickerBase.path" ID="EricPathPickerBase.path"></a> <h4>EricPathPickerBase.path</h4> -<b>path</b>(<i>toNative=True</i>) +<b>path</b>(<i></i>) <p> Public method to get the current path. </p> <dl> - -<dt><i>toNative</i> (bool)</dt> -<dd> -flag indicating to convert the path into - a native format -</dd> -</dl> -<dl> <dt>Return:</dt> <dd> current path @@ -766,25 +792,17 @@ <dl> <dt>Return Type:</dt> <dd> -str +pathlib.Path </dd> </dl> <a NAME="EricPathPickerBase.paths" ID="EricPathPickerBase.paths"></a> <h4>EricPathPickerBase.paths</h4> -<b>paths</b>(<i>toNative=True</i>) +<b>paths</b>(<i></i>) <p> Public method to get the list of entered paths. </p> <dl> - -<dt><i>toNative</i> (bool)</dt> -<dd> -flag indicating to convert the path into - a native format -</dd> -</dl> -<dl> <dt>Return:</dt> <dd> entered paths @@ -793,7 +811,7 @@ <dl> <dt>Return Type:</dt> <dd> -list of str +list of pathlib.Path </dd> </dl> <a NAME="EricPathPickerBase.setButtonToolTip" ID="EricPathPickerBase.setButtonToolTip"></a> @@ -824,6 +842,20 @@ index of the item to set current </dd> </dl> +<a NAME="EricPathPickerBase.setCurrentPath" ID="EricPathPickerBase.setCurrentPath"></a> +<h4>EricPathPickerBase.setCurrentPath</h4> +<b>setCurrentPath</b>(<i>fpath</i>) + +<p> + Public method to set the current path. +</p> +<dl> + +<dt><i>fpath</i> (pathlib.Path)</dt> +<dd> +current path +</dd> +</dl> <a NAME="EricPathPickerBase.setCurrentText" ID="EricPathPickerBase.setCurrentText"></a> <h4>EricPathPickerBase.setCurrentText</h4> <b>setCurrentText</b>(<i>text</i>) @@ -847,7 +879,7 @@ </p> <dl> -<dt><i>directory</i> (str)</dt> +<dt><i>directory</i> (str or pathlib.Path)</dt> <dd> default directory </dd> @@ -967,22 +999,17 @@ </dl> <a NAME="EricPathPickerBase.setPath" ID="EricPathPickerBase.setPath"></a> <h4>EricPathPickerBase.setPath</h4> -<b>setPath</b>(<i>fpath, toNative=True</i>) +<b>setPath</b>(<i>fpath</i>) <p> Public method to set the current path. </p> <dl> -<dt><i>fpath</i> (str)</dt> +<dt><i>fpath</i> (str or pathlib.Path)</dt> <dd> path to be set </dd> -<dt><i>toNative</i> (bool)</dt> -<dd> -flag indicating to convert the path into - a native format -</dd> </dl> <a NAME="EricPathPickerBase.setPathsList" ID="EricPathPickerBase.setPathsList"></a> <h4>EricPathPickerBase.setPathsList</h4> @@ -993,7 +1020,7 @@ </p> <dl> -<dt><i>pathsList</i> (list of str)</dt> +<dt><i>pathsList</i> (list of str or pathlib.Path)</dt> <dd> list of paths </dd>
--- a/src/eric7/Documentation/Source/eric7.EricWidgets.EricPathPickerDialog.html Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/Documentation/Source/eric7.EricWidgets.EricPathPickerDialog.html Sat Jul 16 18:14:30 2022 +0200 @@ -33,6 +33,10 @@ <td><a href="#getPath">getPath</a></td> <td>Function to get a file or directory path from the user.</td> </tr> +<tr> +<td><a href="#getStrPath">getStrPath</a></td> +<td>Function to get a file or directory path from the user.</td> +</tr> </table> <hr /> <hr /> @@ -65,7 +69,11 @@ </tr> <tr> <td><a href="#EricPathPickerDialog.getPath">getPath</a></td> -<td>Public method to get the current path.</td> +<td>Public method to get the current path as a pathlib.Path object.</td> +</tr> +<tr> +<td><a href="#EricPathPickerDialog.getText">getText</a></td> +<td>Public method to get the current path as text.</td> </tr> <tr> <td><a href="#EricPathPickerDialog.setDefaultDirectory">setDefaultDirectory</a></td> @@ -117,7 +125,26 @@ <b>getPath</b>(<i></i>) <p> - Public method to get the current path. + Public method to get the current path as a pathlib.Path object. +</p> +<dl> +<dt>Return:</dt> +<dd> +current path +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +pathlib.Path +</dd> +</dl> +<a NAME="EricPathPickerDialog.getText" ID="EricPathPickerDialog.getText"></a> +<h4>EricPathPickerDialog.getText</h4> +<b>getText</b>(<i></i>) + +<p> + Public method to get the current path as text. </p> <dl> <dt>Return:</dt> @@ -140,7 +167,7 @@ </p> <dl> -<dt><i>directory</i> (str)</dt> +<dt><i>directory</i> (str or pathlib.Path)</dt> <dd> default directory </dd> @@ -192,14 +219,14 @@ </dl> <a NAME="EricPathPickerDialog.setPickerPath" ID="EricPathPickerDialog.setPickerPath"></a> <h4>EricPathPickerDialog.setPickerPath</h4> -<b>setPickerPath</b>(<i>path</i>) +<b>setPickerPath</b>(<i>fpath</i>) <p> Public method to set the path of the path picker. </p> <dl> -<dt><i>path</i> (str)</dt> +<dt><i>fpath</i> (str or pathlib.Path)</dt> <dd> path to be set </dd> @@ -223,7 +250,7 @@ <hr /> <a NAME="getPath" ID="getPath"></a> <h2>getPath</h2> -<b>getPath</b>(<i>parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, path="", defaultDirectory="", filters=None, </i>) +<b>getPath</b>(<i>parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, pathlibPath=None, defaultDirectory=None, filters=None, </i>) <p> Function to get a file or directory path from the user. @@ -242,22 +269,77 @@ <dd> text to be shown above the path picker </dd> -<dt><i>mode</i> (EricPathPickerModes)</dt> +<dt><i>mode</i> (EricPathPickerModes (optional))</dt> <dd> -mode of the path picker +mode of the path picker (defaults to EricPathPickerModes.OPEN_FILE_MODE) </dd> -<dt><i>path</i> (str)</dt> +<dt><i>pathlibPath</i> (pathlib.Path (optional))</dt> <dd> -initial path to be shown +initial path to be shown (defaults to None) </dd> -<dt><i>defaultDirectory</i> (str)</dt> +<dt><i>defaultDirectory</i> (pathlib.Path (optional))</dt> <dd> default directory of the path picker selection - dialog + dialog (defaults to None) +</dd> +<dt><i>filters</i> (list of str (optional))</dt> +<dd> +list of file filters (defaults to None) +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +tuple containing the entered path and a flag indicating that the + user pressed the OK button +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +tuple of (pathlib.Path, bool) </dd> -<dt><i>filters</i> (list of str)</dt> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="getStrPath" ID="getStrPath"></a> +<h2>getStrPath</h2> +<b>getStrPath</b>(<i>parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, strPath=None, defaultDirectory=None, filters=None, </i>) + +<p> + Function to get a file or directory path from the user. +</p> +<dl> + +<dt><i>parent</i> (QWidget)</dt> +<dd> +reference to the parent widget +</dd> +<dt><i>title</i> (str)</dt> <dd> -list of file filters +title of the dialog +</dd> +<dt><i>label</i> (str)</dt> +<dd> +text to be shown above the path picker +</dd> +<dt><i>mode</i> (EricPathPickerModes (optional))</dt> +<dd> +mode of the path picker (defaults to EricPathPickerModes.OPEN_FILE_MODE) +</dd> +<dt><i>strPath</i> (str (optional))</dt> +<dd> +initial path to be shown (defaults to None) +</dd> +<dt><i>defaultDirectory</i> (str (optional))</dt> +<dd> +default directory of the path picker selection + dialog (defaults to None) +</dd> +<dt><i>filters</i> (list of str (optional))</dt> +<dd> +list of file filters (defaults to None) </dd> </dl> <dl>
--- 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
--- a/src/eric7/EricWidgets/EricPathPickerDialog.py Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/EricWidgets/EricPathPickerDialog.py Sat Jul 16 18:14:30 2022 +0200 @@ -75,24 +75,6 @@ """ self.__pathPicker.setMode(mode) - def setPickerPath(self, path): - """ - Public method to set the path of the path picker. - - @param path path to be set - @type str - """ - self.__pathPicker.setPath(path) - - def setDefaultDirectory(self, directory): - """ - Public method to set the default directory of the path picker. - - @param directory default directory - @type str - """ - self.__pathPicker.setDefaultDirectory(directory) - def setPickerFilters(self, filters): """ Public method to set the filters of the path picker. @@ -104,23 +86,50 @@ """ self.__pathPicker.setFilters(filters) - def getPath(self): + def setPickerPath(self, fpath): + """ + Public method to set the path of the path picker. + + @param fpath path to be set + @type str or pathlib.Path + """ + self.__pathPicker.setText(str(fpath)) + + def setDefaultDirectory(self, directory): """ - Public method to get the current path. + Public method to set the default directory of the path picker. + + @param directory default directory + @type str or pathlib.Path + """ + self.__pathPicker.setDefaultDirectory(str(directory)) + + def getText(self): + """ + Public method to get the current path as text. @return current path @rtype str """ + return self.__pathPicker.text() + + def getPath(self): + """ + Public method to get the current path as a pathlib.Path object. + + @return current path + @rtype pathlib.Path + """ return self.__pathPicker.path() -def getPath( +def getStrPath( parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, - path="", - defaultDirectory="", + strPath=None, + defaultDirectory=None, filters=None, ): """ @@ -132,15 +141,15 @@ @type str @param label text to be shown above the path picker @type str - @param mode mode of the path picker - @type EricPathPickerModes - @param path initial path to be shown - @type str + @param mode mode of the path picker (defaults to EricPathPickerModes.OPEN_FILE_MODE) + @type EricPathPickerModes (optional) + @param strPath initial path to be shown (defaults to None) + @type str (optional) @param defaultDirectory default directory of the path picker selection - dialog - @type str - @param filters list of file filters - @type list of str + dialog (defaults to None) + @type str (optional) + @param filters list of file filters (defaults to None) + @type list of str (optional) @return tuple containing the entered path and a flag indicating that the user pressed the OK button @rtype tuple of (str, bool) @@ -152,8 +161,8 @@ if label: dlg.setLabelText(label) dlg.setPickerMode(mode) - if path: - dlg.setPickerPath(path) + if strPath: + dlg.setPickerPath(strPath) if defaultDirectory: dlg.setDefaultDirectory(defaultDirectory) if filters is not None and len(filters) > 0: @@ -162,10 +171,67 @@ # step 2: show the dialog and get the result if dlg.exec() == QDialog.DialogCode.Accepted: ok = True - path = dlg.getPath().strip() + fpath = dlg.getText().strip() else: ok = False - path = "" + fpath = "" # step 3: return the result - return path, ok + return fpath, ok + + +def getPath( + parent, + title, + label, + mode=EricPathPickerModes.OPEN_FILE_MODE, + pathlibPath=None, + defaultDirectory=None, + filters=None, +): + """ + Function to get a file or directory path from the user. + + @param parent reference to the parent widget + @type QWidget + @param title title of the dialog + @type str + @param label text to be shown above the path picker + @type str + @param mode mode of the path picker (defaults to EricPathPickerModes.OPEN_FILE_MODE) + @type EricPathPickerModes (optional) + @param pathlibPath initial path to be shown (defaults to None) + @type pathlib.Path (optional) + @param defaultDirectory default directory of the path picker selection + dialog (defaults to None) + @type pathlib.Path (optional) + @param filters list of file filters (defaults to None) + @type list of str (optional) + @return tuple containing the entered path and a flag indicating that the + user pressed the OK button + @rtype tuple of (pathlib.Path, bool) + """ + # step 1: setup of the dialog + dlg = EricPathPickerDialog(parent) + if title: + dlg.setTitle(title) + if label: + dlg.setLabelText(label) + dlg.setPickerMode(mode) + if pathlibPath: + dlg.setPickerPath(pathlibPath) + if defaultDirectory: + dlg.setDefaultDirectory(defaultDirectory) + if filters is not None and len(filters) > 0: + dlg.setPickerFilters(";;".join(filters)) + + # step 2: show the dialog and get the result + if dlg.exec() == QDialog.DialogCode.Accepted: + ok = True + fpath = dlg.getText().strip() + else: + ok = False + fpath = "" + + # step 3: return the result + return fpath, ok
--- a/src/eric7/MicroPython/MicroPythonFileManagerWidget.py Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/MicroPython/MicroPythonFileManagerWidget.py Sat Jul 16 18:14:30 2022 +0200 @@ -690,12 +690,12 @@ """ cwdWidget = self.deviceCwd if localDevice else self.localCwd - dirPath, ok = EricPathPickerDialog.getPath( + dirPath, ok = EricPathPickerDialog.getStrPath( self, self.tr("Change Directory"), self.tr("Select Directory"), EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, - path=cwdWidget.text(), + strPath=cwdWidget.text(), defaultDirectory=cwdWidget.text(), ) if ok and dirPath:
--- a/src/eric7/MultiProject/MultiProject.py Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/MultiProject/MultiProject.py Sat Jul 16 18:14:30 2022 +0200 @@ -363,14 +363,14 @@ startdir = Preferences.getMultiProject("Workspace") srcProject = self.__projects[uid] srcProjectDirectory = os.path.dirname(srcProject["file"]) - dstProjectDirectory, ok = EricPathPickerDialog.getPath( + dstProjectDirectory, ok = EricPathPickerDialog.getStrPath( self.parent(), self.tr("Copy Project"), self.tr( "Enter directory for the new project (must not exist" " already):" ), mode=EricPathPickerModes.DIRECTORY_MODE, - path=srcProjectDirectory, + strPath=srcProjectDirectory, defaultDirectory=startdir, ) if ok and dstProjectDirectory and not os.path.exists(dstProjectDirectory):
--- a/src/eric7/Project/IdlCompilerOptionsDialog.py Sat Jul 16 18:09:30 2022 +0200 +++ b/src/eric7/Project/IdlCompilerOptionsDialog.py Sat Jul 16 18:14:30 2022 +0200 @@ -136,7 +136,7 @@ Private slot to add an 'Include Directory'. """ defaultDirectory = self.__project.getProjectPath() if self.__project else "" - path, ok = EricPathPickerDialog.getPath( + path, ok = EricPathPickerDialog.getStrPath( self, self.tr("Include Directory"), self.tr("Select Include Directory"), @@ -173,12 +173,12 @@ else: path = itm.text() defaultDirectory = "" - path, ok = EricPathPickerDialog.getPath( + path, ok = EricPathPickerDialog.getStrPath( self, self.tr("Include Directory"), self.tr("Select Include Directory"), EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, - path=path, + strPath=path, defaultDirectory=defaultDirectory, ) if ok and path: