KDirOperator Class Reference
from PyKDE4.kio import *
Detailed Description
This widget works as a network transparent filebrowser. You specify a URL to display and this url will be loaded via KDirLister. The user can browse through directories, highlight and select files, delete or rename files.
It supports different views, e.g. a detailed view (see KFileDetailView), a simple icon view (see KFileIconView), a combination of two views, separating directories and files ( KCombiView).
Additionally, a preview view is available (see KFilePreview), which can show either a simple or detailed view and additionally a preview widget (see setPreviewWidget()). KImageFilePreview is one implementation of a preview widget, that displays previews for all supported filetypes utilizing KIO.PreviewJob.
Currently, those classes don't support Drag&Drop out of the box -- there you have to use your own view-classes. You can use some DnD-aware views from Björn Sahlström <bjorn@kbear.org> until they will be integrated into this library. See http://devel-home.kde.org/~pfeiffer/DnD-classes.tar.gz
This widget is the one used in the KFileDialog.
Basic usage is like this:
KDirOperator *op = new KDirOperator( KUrl( "file:/home/gis" ), this ); // some signals you might be interested in connect(op, SIGNAL(urlEntered(const KUrl&)), SLOT(urlEntered(const KUrl&))); connect(op, SIGNAL(fileHighlighted(const KFileItem &)), SLOT(fileHighlighted(const KFileItem &))); connect(op, SIGNAL(fileSelected(const KFileItem &)), SLOT(fileSelected(const KFileItem &))); connect(op, SIGNAL(finishedLoading()), SLOT(slotLoadingFinished())); KConfigGroup grp(KGlobal.config(),"Your KDiroperator ConfigGroup" ); op->readConfig( &grp); op->setView(KFile.Default);
This will create a childwidget of 'this' showing the directory contents of /home/gis in the default-view. The view is determined by the readConfig() call, which will read the KDirOperator settings, the user left your program with (and which you saved with op->writeConfig()).
A widget for displaying files and browsing directories.
Signal Documentation
completion | ( | QString | a0 | |
) |
- Signal syntax:
QObject.connect(source, SIGNAL("completion(const QString&)"), target_slot)
Emitted just before the context menu is shown, allows users to extend the menu with custom actions.
- Parameters:
-
item the file on which the context menu was invoked menu the context menu, pre-populated with the file-management actions
- Since:
- 4.2
- Signal syntax:
QObject.connect(source, SIGNAL("contextMenuAboutToShow(const KFileItem&, QMenu*)"), target_slot)
currentIconSizeChanged | ( | int | size | |
) |
Will notify that the icon size has changed. Since we save the icon size depending on the view type (list view or a different kind of view), a call to setView() can trigger this signal to be emitted.
- Since:
- 4.2
- Signal syntax:
QObject.connect(source, SIGNAL("currentIconSizeChanged(int)"), target_slot)
dirActivated | ( | KFileItem | item | |
) |
- Signal syntax:
QObject.connect(source, SIGNAL("dirActivated(const KFileItem&)"), target_slot)
dropped | ( | KFileItem | item, | |
QDropEvent | event, | |||
KUrl.List | urls | |||
) |
Emitted when files are dropped. Dropping files is disabled by default. You need to enable it with setAcceptDrops()
- Parameters:
-
item the item on which the drop occurred or 0. event the drop event itself. urls the urls that where dropped.
- Signal syntax:
QObject.connect(source, SIGNAL("dropped(const KFileItem&, QDropEvent*, const KUrl::List&)"), target_slot)
fileHighlighted | ( | KFileItem | item | |
) |
Emitted when a file is highlighted or generally the selection changes in multiselection mode. In the latter case, item is 0L. You can access the selected items with selectedItems().
- Signal syntax:
QObject.connect(source, SIGNAL("fileHighlighted(const KFileItem&)"), target_slot)
fileSelected | ( | KFileItem | item | |
) |
- Signal syntax:
QObject.connect(source, SIGNAL("fileSelected(const KFileItem&)"), target_slot)
finishedLoading | ( | ) |
- Signal syntax:
QObject.connect(source, SIGNAL("finishedLoading()"), target_slot)
updateInformation | ( | int | files, | |
int | dirs | |||
) |
- Signal syntax:
QObject.connect(source, SIGNAL("updateInformation(int, int)"), target_slot)
urlEntered | ( | KUrl | a0 | |
) |
- Signal syntax:
QObject.connect(source, SIGNAL("urlEntered(const KUrl&)"), target_slot)
viewChanged | ( | QAbstractItemView | newView | |
) |
Emitted whenever the current fileview is changed, either by an explicit call to setView() or by the user selecting a different view thru the GUI.
- Signal syntax:
QObject.connect(source, SIGNAL("viewChanged(QAbstractItemView*)"), target_slot)
Method Documentation
Constructs the KDirOperator with no initial view. As the views are configurable, call readConfig() to load the user's configuration and then setView to explicitly set a view.
This constructor doesn't start loading the url, setView will do it.
KActionCollection actionCollection | ( | self ) |
an accessor to a collection of all available Actions. The actions are static, they will be there all the time (no need to connect to the signals KActionCollection.inserted() or removed().
There are the following actions:
The short and detailed view are in an exclusive group. The sort-by actions are in an exclusive group as well. Also the "separate dirs", "preview" and "single" actions are in an exclusive group.
You can e.g. use
actionCollection()->action( "up" )->plug( someToolBar );to add a button into a toolbar, which makes the dirOperator change to its parent directory.
- Returns:
- all available Actions
Called upon right-click to activate the popupmenu.
back | ( | self ) |
Goes one step back in the history and opens that url.
cdUp | ( | self ) |
Goes one directory up from the current url.
changeEvent | ( | self, | ||
QEvent | event | |||
) |
bool checkPreviewSupport | ( | self ) |
Checks if there support from KIO.PreviewJob for the currently shown files, taking mimeFilter() and nameFilter() into account Enables/disables the preview-action accordingly.
clearFilter | ( | self ) |
Clears both the namefilter and mimetype filter, so that all files and directories will be shown. Call updateDir() to apply it.
- See also:
- setMimeFilter
- See also:
- setNameFilter
clearHistory | ( | self ) |
Clears the forward and backward history.
close | ( | self ) |
Stops loading immediately. You don't need to call this, usually.
KCompletion completionObject | ( | self ) |
- Returns:
- a KCompletion object, containing all filenames and directories of the current directory/URL. You can use it to insert it into a KLineEdit or KComboBox Note: it will only contain files, after prepareCompletionObjects() has been called. It will be implicitly called from makeCompletion() or makeDirCompletion()
QAbstractItemView createView | ( | self, | ||
QWidget | parent, | |||
KFile.FileView | viewKind | |||
) |
A view factory for creating predefined fileviews. Called internally by setView, but you can also call it directly. Reimplement this if you depend on self defined fileviews.
- Parameters:
-
parent is the QWidget to be set as parent viewKind is the predefined view to be set, note: this can be several ones OR:ed together
- Returns:
- the created view
- See also:
- KFile.FileView
- See also:
- setView
QStyleOptionViewItem.Position decorationPosition | ( | self ) |
Returns the position where icons are shown relative to the labels of file items in the icon view.
- Since:
- 4.2.3
KIO.DeleteJob del_ | ( | self, | ||
KFileItemList | items, | |||
QWidget | parent=0, | |||
bool | ask=1, | |||
bool | showProgress=1 | |||
) |
Starts and returns a KIO.DeleteJob to delete the given items.
- Parameters:
-
items the list of items to be deleted parent the parent widget used for the confirmation dialog ask specifies whether a confirmation dialog should be shown showProgress passed to the DeleteJob to show a progress dialog
deleteSelected | ( | self ) |
Deletes the currently selected files/directories.
KCompletion dirCompletionObject | ( | self ) |
- Returns:
- a KCompletion object, containing only all directories of the current directory/URL. You can use it to insert it into a KLineEdit or KComboBox Note: it will only contain directories, after prepareCompletionObjects() has been called. It will be implicitly called from makeCompletion() or makeDirCompletion()
bool dirHighlighting | ( | self ) |
- Returns:
- whether the last directory will be made the current item when going up in the directory hierarchy.
Default is false.
KDirLister dirLister | ( | self ) |
- Returns:
- the object listing the directory
bool dirOnlyMode | ( | self ) |
- Returns:
- true if we are in directory-only mode, that is, no files are shown.
forward | ( | self ) |
Goes one step forward in the history and opens that url.
highlightFile | ( | self, | ||
KFileItem | item | |||
) |
Emits fileHighlighted(item)
home | ( | self ) |
Enters the home directory.
int iconsZoom | ( | self ) |
Returns the icon zoom.
- Since:
- 4.2
bool isInlinePreviewShown | ( | self ) |
Returns whether the inline previews are shown or not.
- Since:
- 4.2
bool isRoot | ( | self ) |
- Returns:
- true if we are displaying the root directory of the current url
bool isSaving | ( | self ) |
Returns whether KDirOperator will force a double click to accept.
- Note:
- this is false by default
- Since:
- 4.2
bool isSelected | ( | self, | ||
KFileItem | item | |||
) |
- Returns:
- true if item is currently selected, or false otherwise.
keyPressEvent | ( | self, | ||
QKeyEvent | event | |||
) |
Tries to complete the given string (only completes files).
Tries to complete the given string (only completes directores).
QStringList mimeFilter | ( | self ) |
- Returns:
- the current mime filter.
bool mkdir | ( | self, | ||
QString | directory, | |||
bool | enterDirectory=1 | |||
) |
Opens a dialog to create a new directory.
mkdir | ( | self ) |
Opens a dialog to create a new directory.
KFile.Modes mode | ( | self ) |
- Returns:
- the listing/selection mode.
QString nameFilter | ( | self ) |
- Returns:
- the current namefilter.
- See also:
- setNameFilter
QStringList newFileMenuSupportedMimeTypes | ( | self ) |
- Returns:
- the current Supported Mimes Types.
- Since:
- 4.5
int numDirs | ( | self ) |
- Returns:
- the number of directories in the currently listed url. Returns 0 if there is no view.
int numFiles | ( | self ) |
- Returns:
- the number of files in the currently listed url. Returns 0 if there is no view.
bool onlyDoubleClickSelectsFiles | ( | self ) |
- Returns:
- whether files (not directories) should only be select()ed by double-clicks.
- See also:
- setOnlyDoubleClickSelectsFiles
pathChanged | ( | self ) |
Called after setUrl() to load the directory, update the history, etc.
prepareCompletionObjects | ( | self ) |
Synchronizes the completion objects with the entries of the currently listed url.
Automatically called from makeCompletion() and makeDirCompletion()
KFilePreviewGenerator previewGenerator | ( | self ) |
Returns the preview generator for the current view.
- Since:
- 4.2
QProgressBar progressBar | ( | self ) |
- Returns:
- the progress widget, that is shown during directory listing. You can for example reparent() it to put it into a statusbar.
readConfig | ( | self, | ||
KConfigGroup | configGroup | |||
) |
Reads the default settings for a view, i.e. the default KFile.FileView. Also reads the sorting and whether hidden files should be shown. Note: the default view will not be set - you have to call
setView( KFile.Default )to apply it.
- See also:
- setView
- See also:
- setViewConfig
- See also:
- writeConfig
rereadDir | ( | self ) |
Re-reads the current url.
resetCursor | ( | self ) |
Restores the normal cursor after showing the busy-cursor. Also hides the progressbar.
resizeEvent | ( | self, | ||
QResizeEvent | event | |||
) |
selectDir | ( | self, | ||
KFileItem | item | |||
) |
Enters the directory specified by the given item.
selectFile | ( | self, | ||
KFileItem | item | |||
) |
Emits fileSelected( item )
KFileItemList selectedItems | ( | self ) |
- Returns:
- a list of all currently selected items. If there is no view, or there are no selected items, an empty list is returned.
setAcceptDrops | ( | self, | ||
bool | b | |||
) |
Reimplemented - allow dropping of files if b is true
- Parameters:
-
b true if the widget should allow dropping of files
setCurrentItem | ( | self, | ||
QString | url | |||
) |
Clears the current selection and attempts to set item as the current item.
setCurrentItem | ( | self, | ||
KFileItem | item | |||
) |
Clears the current selection and attempts to set item as the current item.
setCurrentItems | ( | self, | ||
QStringList | urls | |||
) |
Clears the current selection and attempts to set items as the current items.
- Since:
- 4.2
setCurrentItems | ( | self, | ||
KFileItemList | items | |||
) |
Clears the current selection and attempts to set items as the current items.
- Since:
- 4.2
setDecorationPosition | ( | self, | ||
QStyleOptionViewItem.Position | position | |||
) |
Sets the position where icons shall be shown relative to the labels of file items in the icon view.
- Since:
- 4.2.3
setDirLister | ( | self, | ||
KDirLister | lister | |||
) |
Sets a custom KDirLister to list directories. The KDirOperator takes ownership of the given KDirLister.
setDropOptions | ( | self, | ||
int | options | |||
) |
Sets the options for dropping files. CURRENTLY NOT IMPLEMENTED
setEnableDirHighlighting | ( | self, | ||
bool | enable | |||
) |
When going up in the directory hierarchy, KDirOperator can highlight the directory that was just left.
I.e. when you go from /home/gis/src to /home/gis, the item "src" will be made the current item.
Default is off.
setIconsZoom | ( | self, | ||
int | value | |||
) |
Notifies that the icons size should change. value is an int ranged from 0 to 100. 100 means KIconLoader.SizeEnormous.
- Since:
- 4.2
setInlinePreviewShown | ( | self, | ||
bool | show | |||
) |
Forces the inline previews to be shown or hidden, depending on show.
- Parameters:
-
show Whether to show inline previews or not.
- Since:
- 4.2
setIsSaving | ( | self, | ||
bool | isSaving | |||
) |
If the system is set up to trigger items on single click, if isSaving is true, we will force to double click to accept.
- Note:
- this is false by default
- Since:
- 4.2
setMimeFilter | ( | self, | ||
QStringList | mimetypes | |||
) |
Sets a list of mimetypes as filter. Only files of those mimetypes will be shown.
Example:
QStringList filter; filter << "text/html" << "image/png" << "inode/directory"; dirOperator->setMimefilter( filter );
Node: Without the mimetype inode/directory, only files would be shown. Call updateDir() to apply it.
- See also:
- KDirLister.setMimeFilter
- See also:
- mimeFilter
setMode | ( | self, | ||
KFile.Modes | m | |||
) |
Sets the listing/selection mode for the views, an OR'ed combination of
You cannot mix File and Files of course, as the former means single-selection mode, the latter multi-selection.
setNameFilter | ( | self, | ||
QString | filter | |||
) |
Sets a filter like "*.cpp *.h *.o". Only files matching that filter will be shown.
- See also:
- KDirLister.setNameFilter
- See also:
- nameFilter
setNewFileMenuSupportedMimeTypes | ( | self, | ||
QStringList | mime | |||
) |
Only show the files in a given set of mimetypes. This is useful in specialized applications (while file managers, on the other hand, want to show all mimetypes). Internally uses KNewFileMenu.setSupportedMimeTypes
Example:
QStringList mimeTypes; mimeTypes << "text/html" << "inode/directory"; dirOperator->setNewFileMenuSupportedMimeTypes(mimeTypes);
Note: If the list is empty, all options will be shown. Otherwise, without the mimetype inode/directory, only file options will be shown.
- See also:
- KNewFileMenu.setSupportedMimeTypes
- See also:
- newFileMenuSupportedMimeTypes
- Since:
- 4.5
setOnlyDoubleClickSelectsFiles | ( | self, | ||
bool | enable | |||
) |
This toggles between double/single click file and directory selection mode. When argument is true, files and directories are highlighted with single click and selected (executed) with double click.
The default follows the signle/double click system setting.
setPreviewWidget | ( | self, | ||
KPreviewWidgetBase | w | |||
) |
Sets a preview-widget to be shown next to the file-view. The ownership of w is transferred to KDirOperator, so don't delete it yourself!
setShowHiddenFiles | ( | self, | ||
bool | s | |||
) |
Enables/disables showing hidden files.
setSorting | ( | self, | ||
QDir.SortFlags | a0 | |||
) |
Sets the way to sort files and directories.
setUrl | ( | self, | ||
KUrl | url, | |||
bool | clearforward | |||
) |
Sets a new url to list.
- Parameters:
-
clearforward specifies whether the "forward" history should be cleared. url the URL to set
setView | ( | self, | ||
QAbstractItemView | view | |||
) |
Sets one of the predefined fileviews.
- See also:
- KFile.FileView
setView | ( | self, | ||
KFile.FileView | viewKind | |||
) |
Sets one of the predefined fileviews.
- See also:
- KFile.FileView
setViewConfig | ( | self, | ||
KConfigGroup | configGroup | |||
) |
Sets the config object and the to be used group in KDirOperator. This will be used to store the view's configuration. If you don't set this, the views cannot save and restore their configuration.
Usually you call this right after KDirOperator creation so that the view instantiation can make use of it already.
Note that KDirOperator does NOT take ownership of that object (typically it's KGlobal.config() anyway.
You must not delete the KConfig or KConfigGroup object (and master config object) before either deleting the KDirOperator or calling setViewConfig(0); or something like that
- See also:
- viewConfig
- See also:
- viewConfigGroup
setupActions | ( | self ) |
Sets up all the actions. Called from the constructor, you usually better not call this.
setupMenu | ( | self, | ||
int | whichActions | |||
) |
Sets up the context-menu with all the necessary actions. Called from the constructor, you usually don't need to call this.
setupMenu | ( | self ) |
Sets up the context-menu with all the necessary actions. Called from the constructor, you usually don't need to call this.
bool showHiddenFiles | ( | self ) |
- Returns:
- true when hidden files are shown or false otherwise.
slotCompletionMatch | ( | self, | ||
QString | match | |||
) |
Tries to make the given match as current item in the view and emits completion( match )
sortByDate | ( | self ) |
Changes sorting to sort by date
sortByName | ( | self ) |
Changes sorting to sort by name
sortBySize | ( | self ) |
Changes sorting to sort by size
sortByType | ( | self ) |
Changes sorting to sort by date
sortReversed | ( | self ) |
Changes sorting to reverse sorting
QDir.SortFlags sorting | ( | self ) |
- Returns:
- the current way of sorting files and directories
toggleDirsFirst | ( | self ) |
Toggles showing directories first / having them sorted like files.
toggleIgnoreCase | ( | self ) |
Toggles case sensitive / case insensitive sorting
KIO.CopyJob trash | ( | self, | ||
KFileItemList | items, | |||
QWidget | parent, | |||
bool | ask=1, | |||
bool | showProgress=1 | |||
) |
Starts and returns a KIO.CopyJob to trash the given items.
- Parameters:
-
items the list of items to be trashed parent the parent widget used for the confirmation dialog ask specifies whether a confirmation dialog should be shown showProgress passed to the CopyJob to show a progress dialog
trashSelected | ( | self ) |
Trashes the currently selected files/directories.
This function used to take activation reason and keyboard modifiers, in order to call deleteSelected() if the user wanted to delete. Instead, call deleteSelected().
FIXME KAction Port: link deleteSelected() up correctly
updateDir | ( | self ) |
to update the view after changing the settings
updateSelectionDependentActions | ( | self ) |
Enables/disables actions that are selection dependent. Call this e.g. when you are about to show a popup menu using some of KDirOperators actions.
updateSortActions | ( | self ) |
Updates the sorting-related actions to comply with the current sorting
- See also:
- sorting
updateViewActions | ( | self ) |
Updates the view-related actions to comply with the current KFile.FileView
KUrl url | ( | self ) |
- Returns:
- the current url
QAbstractItemView view | ( | self ) |
- Returns:
- the currently used view.
- See also:
- setView
KConfigGroup viewConfigGroup | ( | self ) |
writeConfig | ( | self, | ||
KConfigGroup | configGroup | |||
) |
Saves the current settings like sorting, simple or detailed view.
- See also:
- readConfig
- See also:
- setViewConfig
Static Method Documentation
bool dirOnlyMode | ( | long | mode | |
) |
- Returns:
- true if we are in directory-only mode, that is, no files are shown.
Enumeration Documentation
ActionType |
The various action types. These values can be or'd together
- Enumerator:
-
SortActions = 1 ViewActions = 2 NavActions = 4 FileActions = 8 AllActions = 15