Skip to content

Commit c821413

Browse files
docs(tree): improved typings and docs (#459)
1 parent d75345b commit c821413

5 files changed

Lines changed: 303 additions & 76 deletions

File tree

libs/pyTermTk/TermTk/TTkCore/constant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class InsertPolicy(int):
231231
# InsertAlphabetically = 0x06
232232
# '''The string is inserted in the alphabetic order in the combobox.'''
233233

234-
class DragDropMode(int):
234+
class DragDropMode(IntEnum):
235235
'''Specifies the Drag and Drop mode allowed by this widget
236236
237237
.. autosummary::

libs/pyTermTk/TermTk/TTkWidgets/TTkModelView/filetree.py

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
__all__ = ['TTkFileTree']
2424

25+
from typing import List,Optional
26+
2527
from TermTk.TTkCore.constant import TTkK
2628
from TermTk.TTkCore.string import TTkString
2729
from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal
@@ -204,49 +206,68 @@ def folderActivated(self) -> pyTTkSignal:
204206
:type folder: :py:class:`TTkFileTreeWidgetItem`
205207
'''
206208
return self._fileTreeWidget.folderActivated
207-
def setHeaderLabels(self, labels:TTkString) -> None:
209+
def setHeaderLabels(self, labels:List[TTkString]) -> None:
208210
'''
209211
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.setHeaderLabels`
210212
211-
setHeaderLabels
213+
Adds a column in the header for each item in the labels list, and sets the label for each column.
214+
215+
:param labels: the list of labels
216+
:type labels: List[:py:class:`TTkString`]
212217
'''
213218
return self._fileTreeWidget.setHeaderLabels(labels=labels)
214219
def setColumnWidth(self, column:int, width: int) -> None:
215220
'''
216221
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.setColumnWidth`
217222
218-
setColumnWidth
223+
Set the width of the column requested
224+
225+
:param column: the column position
226+
:type column: int
227+
228+
:rtype: int
219229
'''
220230
return self._fileTreeWidget.setColumnWidth(column=column, width=width)
221231
def resizeColumnToContents(self, column:int) -> None:
222232
'''
223233
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.resizeColumnToContents`
224234
225-
resizeColumnToContents
235+
rwsize the width of the column requestedto its content
236+
237+
:param column: the column position
238+
:type column: int
226239
'''
227240
return self._fileTreeWidget.resizeColumnToContents(column=column)
228-
def sortColumn(self):
241+
def sortColumn(self) -> int:
229242
'''
230243
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.sortColumn`
231244
232245
Returns the column used to sort the contents of the widget.
246+
-1 in case no column sort is used
247+
248+
:rtype: int
233249
'''
234250
return self._fileTreeWidget.sortColumn()
235251
def sortItems(self, col:int, order:TTkK.SortOrder) -> None:
236252
'''
237253
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.sortItems`
238254
239255
Sorts the items in the widget in the specified order by the values in the given column.
256+
257+
:param col: the column used as reference for the sorting
258+
:type col: int
259+
:param order: the sorting order
260+
:type order: :py:class:`TTkK.SortOrder`
240261
'''
241262
return self._fileTreeWidget.sortItems(col=col, order=order)
242-
def dragDropMode(self):
263+
def dragDropMode(self) -> TTkK.DragDropMode:
243264
'''
244265
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.dragDropMode`
245266
246267
dragDropMode
247268
'''
248269
return self._fileTreeWidget.dragDropMode()
249-
def setDragDropMode(self, dndMode):
270+
def setDragDropMode(self, dndMode:TTkK.DragDropMode):
250271
'''
251272
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.setDragDropMode`
252273
@@ -258,64 +279,98 @@ def expandAll(self) -> None:
258279
'''
259280
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.expandAll`
260281
261-
expandAll
282+
Expands all expandable items.
262283
'''
263284
return self._fileTreeWidget.expandAll()
264285
@pyTTkSlot()
265286
def collapseAll(self) -> None:
266287
'''
267288
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.collapseAll`
268289
269-
collapseAll
290+
Collapse all collapsable items.
270291
'''
271292
return self._fileTreeWidget.collapseAll()
293+
def invisibleRootItem(self) -> TTkTreeWidgetItem:
294+
'''
295+
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.invisibleRootItem`
296+
297+
Returns the tree widget's invisible root item.
298+
299+
The invisible root item provides access to the tree widget's top-level items through the :py:class:`TTkTreeWidgetItem` API,
300+
making it possible to write functions that can treat top-level items and their children in a uniform way;
301+
for example, recursive functions.
302+
303+
:return: the root Item
304+
:rtype: :py:class:`TTkTreeWidgetItem`
305+
'''
306+
return self._fileTreeWidget.invisibleRootItem()
272307
def addTopLevelItem(self, item:TTkTreeWidgetItem) -> None:
273308
'''
274309
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.addTopLevelItem`
275310
276-
addTopLevelItem
311+
Appends the item as a top-level item in the widget.
312+
313+
:param item: the item to be added.
314+
:type item: :py:class:`TTkTreeWidgetItem`
277315
'''
278316
return self._fileTreeWidget.addTopLevelItem(item=item)
279-
def addTopLevelItems(self, items:TTkTreeWidgetItem) -> None:
317+
def addTopLevelItems(self, items:List[TTkTreeWidgetItem]) -> None:
280318
'''
281319
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.addTopLevelItems`
282320
283-
addTopLevelItems
321+
Appends the list of items as a top-level items in the widget.
322+
323+
:param item: the item to be added.
324+
:type item: List[:py:class:`TTkTreeWidgetItem`]
284325
'''
285326
return self._fileTreeWidget.addTopLevelItems(items=items)
286-
def takeTopLevelItem(self, index) -> None:
327+
def takeTopLevelItem(self, index:int) -> Optional[TTkTreeWidgetItem]:
287328
'''
288329
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.takeTopLevelItem`
289330
290-
takeTopLevelItem
331+
Removes the top-level item at the given index in the tree and returns it, otherwise returns None;
332+
333+
:param index: the index of the item
334+
:type index: int
335+
336+
:rtype: Optional[:py:class:`TTkTreeWidgetItem`]
291337
'''
292338
return self._fileTreeWidget.takeTopLevelItem(index=index)
293-
def topLevelItem(self, index) -> TTkTreeWidgetItem:
339+
def topLevelItem(self, index) -> Optional[TTkTreeWidgetItem]:
294340
'''
295341
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.topLevelItem`
296342
297-
topLevelItem
343+
Returns the top level item at the given index, or None if the item does not exist.
344+
345+
:param index: the index of the item
346+
:type index: int
347+
348+
:rtype: Optional[:py:class:`TTkTreeWidgetItem`]
298349
'''
299350
return self._fileTreeWidget.topLevelItem(index=index)
300351
def indexOfTopLevelItem(self, item:TTkTreeWidgetItem) -> int:
301352
'''
302353
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.indexOfTopLevelItem`
303354
304-
indexOfTopLevelItem
355+
Returns the index of the given top-level item, or -1 if the item cannot be found.
356+
357+
:rtype: int
305358
'''
306359
return self._fileTreeWidget.indexOfTopLevelItem(item=item)
307-
def selectedItems(self) -> list[TTkTreeWidgetItem]:
360+
def selectedItems(self) -> List[TTkTreeWidgetItem]:
308361
'''
309362
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.selectedItems`
310363
311-
selectedItems
364+
Returns a list of all selected non-hidden items.
365+
366+
:rtype: List[:py:class:`TTkTreeWidgetItem`]
312367
'''
313368
return self._fileTreeWidget.selectedItems()
314369
def clear(self) -> None:
315370
'''
316371
.. seealso:: this method is forwarded to :py:meth:`TTkFileTreeWidget.clear`
317372
318-
clear
373+
Clears the tree widget by removing all of its items and selections.
319374
'''
320375
return self._fileTreeWidget.clear()
321376
def openPath(self, path):

0 commit comments

Comments
 (0)