KDE 4.2 PyKDE API Reference

- KDE's Python API

# KDirOperator Class Reference

`from PyKDE4.kio import *`

Inherits: QWidget → QObject

## Detailed Description

## Enumerations

ActionType | { SortActions, ViewActions, NavActions, FileActions, AllActions }

## Signals

| completion (QString a0)
| contextMenuAboutToShow (KFileItem item, QMenu menu)
| currentIconSizeChanged (int size)
| dirActivated (KFileItem item)
| dropped (KFileItem item, QDropEvent event, KUrl.List urls)
| fileHighlighted (KFileItem item)
| fileSelected (KFileItem item)
| finishedLoading ()
| updateInformation (int files, int dirs)
| urlEntered (KUrl a0)
| viewChanged (QAbstractItemView newView)

## Methods

| __init__ (self, KUrl urlName=KUrl(), QWidget parent=0)
KActionCollection | actionCollection (self)
| activatedMenu (self, KFileItem item, QPoint pos)
| back (self)
| cdUp (self)
| changeEvent (self, QEvent event)
bool | checkPreviewSupport (self)
| clearFilter (self)
| clearHistory (self)
| close (self)
| completion (self, QString a0)
KCompletion | completionObject (self)
| contextMenuAboutToShow (self, KFileItem item, QMenu menu)
QAbstractItemView | createView (self, QWidget parent, KFile.FileView viewKind)
| currentIconSizeChanged (self, int size)
KIO.DeleteJob | del_ (self, KFileItemList items, QWidget parent=0, bool ask=1, bool showProgress=1)
| deleteSelected (self)
| dirActivated (self, KFileItem item)
KCompletion | dirCompletionObject (self)
bool | dirHighlighting (self)
KDirLister | dirLister (self)
bool | dirOnlyMode (self)
| dropped (self, KFileItem item, QDropEvent event, KUrl.List urls)
bool | eventFilter (self, QObject watched, QEvent event)
| fileHighlighted (self, KFileItem item)
| fileSelected (self, KFileItem item)
| finishedLoading (self)
| forward (self)
| highlightFile (self, KFileItem item)
| home (self)
int | iconsZoom (self)
bool | isInlinePreviewShown (self)
bool | isRoot (self)
bool | isSaving (self)
bool | isSelected (self, KFileItem item)
QString | makeCompletion (self, QString a0)
QString | makeDirCompletion (self, QString a0)
QStringList | mimeFilter (self)
bool | mkdir (self, QString directory, bool enterDirectory=1)
| mkdir (self)
KFile.Modes | mode (self)
QString | nameFilter (self)
int | numDirs (self)
int | numFiles (self)
bool | onlyDoubleClickSelectsFiles (self)
| pathChanged (self)
| prepareCompletionObjects (self)
KFilePreviewGenerator | previewGenerator (self)
QProgressBar | progressBar (self)
| readConfig (self, KConfigGroup configGroup)
| rereadDir (self)
| resetCursor (self)
| resizeEvent (self, QResizeEvent event)
| selectDir (self, KFileItem item)
| selectFile (self, KFileItem item)
KFileItemList | selectedItems (self)
| setAcceptDrops (self, bool b)
| setCurrentItem (self, QString url)
| setCurrentItem (self, KFileItem item)
| setCurrentItems (self, QStringList urls)
| setCurrentItems (self, KFileItemList items)
| setDirLister (self, KDirLister lister)
| setDropOptions (self, int options)
| setEnableDirHighlighting (self, bool enable)
| setIconsZoom (self, int value)
| setInlinePreviewShown (self, bool show)
| setIsSaving (self, bool isSaving)
| setMimeFilter (self, QStringList mimetypes)
| setMode (self, KFile.Modes m)
| setNameFilter (self, QString filter)
| setOnlyDoubleClickSelectsFiles (self, bool enable)
| setPreviewWidget (self, KPreviewWidgetBase w)
| setShowHiddenFiles (self, bool s)
| setSorting (self, QDir.SortFlags a0)
| setUrl (self, KUrl url, bool clearforward)
| setView (self, QAbstractItemView view)
| setView (self, KFile.FileView viewKind)
| setViewConfig (self, KConfigGroup configGroup)
| setupActions (self)
| setupMenu (self, int whichActions)
| setupMenu (self)
bool | showHiddenFiles (self)
| slotCompletionMatch (self, QString match)
| sortByDate (self)
| sortByName (self)
| sortBySize (self)
| sortByType (self)
| sortReversed (self)
QDir.SortFlags | sorting (self)
| toggleDirsFirst (self)
| toggleIgnoreCase (self)
KIO.CopyJob | trash (self, KFileItemList items, QWidget parent, bool ask=1, bool showProgress=1)
| trashSelected (self)
| updateDir (self)
| updateInformation (self, int files, int dirs)
| updateSelectionDependentActions (self)
| updateSortActions (self)
| updateViewActions (self)
KUrl | url (self)
| urlEntered (self, KUrl a0)
QAbstractItemView | view (self)
| viewChanged (self, QAbstractItemView newView)
KConfigGroup | viewConfigGroup (self)
| writeConfig (self, KConfigGroup configGroup)

## Static Methods

bool | dirOnlyMode (long mode)

## Method Documentation

__init__ | ( | self, |
|  | KUrl | urlName=KUrl(),
|  | QWidget | parent=0
| ) |  |  |

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:

- popupMenu : an ActionMenu presenting a popupmenu with all actions
- up : changes to the parent directory
- back : goes back to the previous directory
- forward : goes forward in the history
- home : changes to the user's home directory
- reload : reloads the current directory
- mkdir : opens a dialog box to create a directory
- delete : deletes the selected files/directories
- sorting menu : an ActionMenu containing all sort-options
- by name : sorts by name
- by size : sorts by size
- by date : sorts by date
- by type : sorts by type
- descending : reverses the sort order
- view menu : an ActionMenu containing all actions concerning the view
- short view : shows a simple fileview
- detailed view : shows a detailed fileview (dates, permissions ,...)
- show hidden : shows hidden files
- preview : shows a preview next to the fileview
- properties : shows a KPropertiesDialog for the selected files

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

activatedMenu | ( | self, |
|  | KFileItem | item,
|  | QPoint | pos
| ) |  |  |

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.

completion | ( | self, |
|  | QString | a0
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("completion(const QString&)"), target_slot)`

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()

contextMenuAboutToShow | ( | self, |
|  | KFileItem | item,
|  | QMenu | menu
| ) |  |  |

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)`

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

currentIconSizeChanged | ( | self, |
|  | 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)`

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.

dirActivated | ( | self, |
|  | KFileItem | item
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("dirActivated(const KFileItem&)"), target_slot)`

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.

bool dirOnlyMode | ( | long | mode
| ) |  |  |

dropped | ( | self, |
|  | 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 List&)"), target_slot)`

bool eventFilter | ( | self, |
|  | QObject | watched,
|  | QEvent | event
| ) |  |  |

fileHighlighted | ( | self, |
|  | KFileItem | item
| ) |  |  |

Emitted when a file is highlighted or generally the selection changes in multiselection mode. In the latter case, item is 0. You can access the selected items with selectedItems().

Signal syntax:
  `QObject.connect(source, SIGNAL("fileHighlighted(const KFileItem&)"), target_slot)`

fileSelected | ( | self, |
|  | KFileItem | item
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("fileSelected(const KFileItem&)"), target_slot)`

finishedLoading | ( |  | self ) |

Signal syntax:
  `QObject.connect(source, SIGNAL("finishedLoading()"), target_slot)`

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.

QString makeCompletion | ( | self, |
|  | QString | a0
| ) |  |  |

Tries to complete the given string (only completes files).

QString makeDirCompletion | ( | self, |
|  | QString | a0
| ) |  |  |

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
| ) |  |  |

Creates the given directory/url. If it is a relative path, it will be completed with the current directory. If enterDirectory is true, the directory will be entered after a successful operation. If unsuccessful, a messagebox will be presented to the user.

Returns:
  true if the directory could be created.

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

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 url the current url file. Note that urls can be relative or absolute.

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 urls the current url files. Note that urls can be relative or absolute.

Since:
  4.2

setCurrentItems | ( | self, |
|  | KFileItemList | items
| ) |  |  |

Clears the current selection and attempts to set items as the current items.

Since:
  4.2

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

- File
- Directory
- Files
- ExistingOnly
- LocalOnly

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

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 a new view to be used for showing and browsing files. Note: this will read the current url() to fill the view.

See also:
  KFileTreeView

See also:
  view

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 action menu.

Parameters:

  | whichActions | is an value of OR'd ActionTypes that controls which actions to show in the action menu

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

updateInformation | ( | self, |
|  | int | files,
|  | int | dirs
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("updateInformation(int, int)"), target_slot)`

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

urlEntered | ( | self, |
|  | KUrl | a0
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("urlEntered(const KUrl&)"), target_slot)`

QAbstractItemView view | ( |  | self ) |

Returns:
  the currently used view.

See also:
  setView

viewChanged | ( | self, |
|  | 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)`

KConfigGroup viewConfigGroup | ( |  | self ) |

writeConfig | ( | self, |
|  | KConfigGroup | configGroup
| ) |  |  |

Saves the current settings like sorting, simple or detailed view.

See also:
  readConfig

See also:
  setViewConfig

## 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 |