KRun

KDE 4.2 PyKDE API Reference

- KDE's Python API

# KRun Class Reference

`from PyKDE4.kio import *`

Inherits: QObject

## Detailed Description

## Signals
| error ()
| finished ()
## Methods
| __init__ (self, KUrl url, QWidget window, mode_t mode=0, bool isLocalFile=0, bool showProgressInfo=1, QByteArray asn=QByteArray())
| abort (self)
bool | autoDelete (self)
bool | doScanFile (self)
| error (self)
| finished (self)
| foundMimeType (self, QString type)
bool | hasError (self)
bool | hasFinished (self)
| init (self)
bool | initializeNextAction (self)
bool | isDirectory (self)
bool | isLocalFile (self)
KIO.Job | job (self)
| killJob (self)
| mimeTypeDetermined (self, QString mimeType)
mode_t | mode (self)
bool | progressInfo (self)
| scanFile (self)
| setAutoDelete (self, bool b)
| setDoScanFile (self, bool scanFile)
| setEnableExternalBrowser (self, bool b)
| setError (self, bool error)
| setFinished (self, bool finished)
| setInitializeNextAction (self, bool initialize)
| setIsDirecory (self, bool isDirectory)
| setIsLocalFile (self, bool isLocalFile)
| setJob (self, KIO.Job job)
| setMode (self, mode_t mode)
| setPreferredService (self, QString desktopEntryName)
| setProgressInfo (self, bool progressInfo)
| setRunExecutables (self, bool b)
| setSuggestedFileName (self, QString fileName)
| setUrl (self, KUrl url)
| slotScanFinished (self, KJob a0)
| slotScanMimeType (self, KIO.Job a0, QString type)
| slotStatResult (self, KJob a0)
| slotTimeout (self)
QString | suggestedFileName (self)
QTimer | timer (self)
KUrl | url (self)
## Static Methods
QString | binaryName (QString execLine, bool removePath)
bool | checkStartupNotify (QString binName, KService service, bool silent_arg, QByteArray wmclass_arg)
bool | displayOpenWithDialog (KUrl.List lst, QWidget window, bool tempFiles=0, QString suggestedFileName=QString(), QByteArray asn=QByteArray())
bool | isExecutable (QString serviceType)
bool | isExecutableFile (KUrl url, QString mimetype)
QStringList | processDesktopExec (KService _service, KUrl.List _urls, bool tempFiles=0, QString suggestedFileName=QString())
bool | run (KService service, KUrl.List urls, QWidget window, bool tempFiles=0, QString suggestedFileName=QString(), QByteArray asn=QByteArray())
bool | run (QString exec, KUrl.List urls, QWidget window, QString name=QString(), QString icon=QString(), QByteArray asn=QByteArray())
bool | runCommand (QString cmd, QWidget window)
bool | runCommand (QString cmd, QString execName, QString icon, QWidget window, QByteArray asn=QByteArray())
bool | runUrl (KUrl url, QString mimetype, QWidget window, bool tempFile=0, bool runExecutables=1, QString suggestedFileName=QString(), QByteArray asn=QByteArray())
| shellQuote (QString str)

## Method Documentation

__init__ | ( | self, |
|  | KUrl | url,
|  | QWidget | window,
|  | mode_t | mode=0,
|  | bool | isLocalFile=0,
|  | bool | showProgressInfo=1,
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Parameters:

  | url | the URL of the file or directory to 'run'
  | window | The top-level widget of the app that invoked this object. It is used to make sure private information like passwords are properly handled per application.
  | mode | The st_mode field of <tt>struct stat</tt>. If you don't know this set it to 0.
  | isLocalFile | If this parameter is set to false then url is examined to find out whether it is a local URL or not. This flag is just used to improve speed, since the function KUrl.isLocalFile is a bit slow.
  | showProgressInfo | Whether to show progress information when determining the type of the file (i.e. when using KIO.stat and KIO.mimetype) Before you set this to false to avoid a dialog box, think about a very slow FTP server... It is always better to provide progress info in such cases.
  | asn | Application startup notification id, if available (otherwise "").

abort | ( |  | self ) |

Abort this KRun. This kills any jobs launched by it, and leads to deletion if auto-deletion is on. This is much safer than deleting the KRun (in case it's currently showing an error dialog box, for instance)

bool autoDelete | ( |  | self ) |

Checks whether auto delete is activated. Auto-deletion causes the KRun instance to delete itself when it finished its task. By default auto deletion is on.

Returns:
  true if auto deletion is on, false otherwise

QString binaryName | ( | QString | execLine,
|  | bool | removePath
| ) |  |  |

Given a full command line (e.g. the Exec= line from a .desktop file), extract the name of the binary being run.

Parameters:

  | execLine | the full command line
  | removePath | if true, remove a (relative or absolute) path. E.g. /usr/bin/ls becomes ls.

Returns:
  the name of the binary to run

bool checkStartupNotify | ( | QString | binName,
|  | KService | service,
|  | bool | silent_arg,
|  | QByteArray | wmclass_arg
| ) |  |  |

Internal:

bool displayOpenWithDialog | ( | KUrl.List | lst,
|  | QWidget | window,
|  | bool | tempFiles=0,
|  | QString | suggestedFileName=QString(),
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Display the Open-With dialog for those URLs, and run the chosen application.

Parameters:

  | lst | the list of applications to run
  | window | The top-level widget of the app that invoked this object.
  | tempFiles | if true and lst are local files, they will be deleted when the application exits.
  | suggestedFileName | see setSuggestedFileName
  | asn | Application startup notification id, if any (otherwise "").

Returns:
  false if the dialog was canceled

bool doScanFile | ( |  | self ) |

Returns whether the file shall be scanned.

Deprecated:
  not useful in public API

error | ( |  | self ) |

Emitted when the operation had an error.

See also:
  hasError()

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

finished | ( |  | self ) |

Emitted when the operation finished.

See also:
  hasFinished()

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

foundMimeType | ( | self, |
|  | QString | type
| ) |  |  |

Called if the mimetype has been detected. The function runs the application associated with this mimetype. Reimplement this method to implement a different behavior, like opening the component for displaying the URL embedded.

bool hasError | ( |  | self ) |

Returns true if the KRun instance has an error.

Returns:
  true when an error occurred

See also:
  error()

bool hasFinished | ( |  | self ) |

Returns true if the KRun instance has finished.

Returns:
  true if the KRun instance has finished

See also:
  finished()

init | ( |  | self ) |

Initializes the krun object.

bool initializeNextAction | ( |  | self ) |

Deprecated:
  not useful in public API

bool isDirectory | ( |  | self ) |

Returns whether it is a directory.

bool isExecutable | ( | QString | serviceType
| ) |  |  |

Returns whether serviceType refers to an executable program instead of a data file.

bool isExecutableFile | ( | KUrl | url,
|  | QString | mimetype
| ) |  |  |

Returns whether the url of mimetype is executable. To be executable the file must pass the following rules:

1. Must reside on the local filesystem.
2. Must be marked as executable for the user by the filesystem.
3. The mime type must inherit application/x-executable or application/x-executable-script. To allow a script to run when the above rules are satisfied add the entry

     X-KDE-IsAlso=application/x-executable-script

to the mimetype's desktop file.

bool isLocalFile | ( |  | self ) |

Returns whether it is a local file.

KIO.Job job | ( |  | self ) |

Returns the job.

killJob | ( |  | self ) |

Kills the file scanning job.

mimeTypeDetermined | ( | self, |
|  | QString | mimeType
| ) |  |  |

Call this from subclasses when you have determined the mimetype. It will call foundMimeType, but also sets up protection against deletion during message boxes.

Since:
  4.0.2

mode_t mode | ( |  | self ) |

Returns the file mode.

QStringList processDesktopExec | ( | KService | _service,
|  | KUrl.List | _urls,
|  | bool | tempFiles=0,
|  | QString | suggestedFileName=QString()
| ) |  |  |

Processes a Exec= line as found in .desktop files.

Parameters:

  | _service | the service to extract information from.
  | _urls | The urls the service should open.
  | tempFiles | if true and urls are local files, they will be deleted when the application exits.
  | suggestedFileName | see setSuggestedFileName

Returns:
  a list of arguments suitable for KProcess.setProgram().

bool progressInfo | ( |  | self ) |

Returns whether progress information are shown.

bool run | ( | KService | service,
|  | KUrl.List | urls,
|  | QWidget | window,
|  | bool | tempFiles=0,
|  | QString | suggestedFileName=QString(),
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Open a list of URLs with a certain service (application).

Parameters:

  | service | the service to run
  | urls | the list of URLs, can be empty (app launched without argument)
  | window | The top-level widget of the app that invoked this object.
  | tempFiles | if true and urls are local files, they will be deleted when the application exits.
  | suggestedFileName | see setSuggestedFileName
  | asn | Application startup notification id, if any (otherwise "").

Returns:
  true on success, false on error

bool run | ( | QString | exec,
|  | KUrl.List | urls,
|  | QWidget | window,
|  | QString | name=QString(),
|  | QString | icon=QString(),
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Open a list of URLs with an executable.

Parameters:

  | exec | the name of the executable, for example "/usr/bin/netscape %u". Don't forget to include the %u if you know that the applications supports URLs. Otherwise, non-local urls will first be downloaded to a temp file (using kioexec).
  | urls | the list of URLs to open, can be empty (app launched without argument)
  | window | The top-level widget of the app that invoked this object.
  | name | the logical name of the application, for example "Netscape 4.06".
  | icon | the icon which should be used by the application.
  | asn | Application startup notification id, if any (otherwise "").

Returns:
  true on success, false on error

bool runCommand | ( | QString | cmd,
|  | QWidget | window
| ) |  |  |

Run the given shell command and notifies kicker of the starting of the application. If the program to be called doesn't exist, an error box will be displayed.

Use only when you know the full command line. Otherwise use the other static methods, or KRun's constructor.

cmd must be a shell command. You must not append "&" to it, since the function will do that for you.

Parameters:

  | window | The top-level widget of the app that invoked this object.

Returns:
  true on success, false on error

bool runCommand | ( | QString | cmd,
|  | QString | execName,
|  | QString | icon,
|  | QWidget | window,
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Same as the other runCommand(), but it also takes the name of the binary, to display an error message in case it couldn't find it.

Parameters:

  | cmd | must be a shell command. You must not append "&" to it, since the function will do that for you.
  | execName | the name of the executable
  | icon | icon for app starting notification
  | window | The top-level widget of the app that invoked this object.
  | asn | Application startup notification id, if any (otherwise "").

Returns:
  true on success, false on error

bool runUrl | ( | KUrl | url,
|  | QString | mimetype,
|  | QWidget | window,
|  | bool | tempFile=0,
|  | bool | runExecutables=1,
|  | QString | suggestedFileName=QString(),
|  | QByteArray | asn=QByteArray()
| ) |  |  |

Open the given URL.

This function is used after the mime type is found out. It will search for all services which can handle the mime type and call run() afterwards.

Parameters:

  | url | the URL to open
  | mimetype | the mime type of the resource
  | window | The top-level widget of the app that invoked this object.
  | tempFile | if true and url is a local file, it will be deleted when the launched application exits.
  | runExecutables | if false then local .desktop files, executables and shell scripts will not be run. See also isExecutable().
  | suggestedFileName | see setSuggestedFileName
  | asn | Application startup notification id, if any (otherwise "").

Returns:
  true on success, false on error

scanFile | ( |  | self ) |

Start scanning a file.

setAutoDelete | ( | self, |
|  | bool | b
| ) |  |  |

Enables or disabled auto deletion. Auto deletion causes the KRun instance to delete itself when it finished its task. If you allocate the KRun object on the stack you must disable auto deletion. By default auto deletion is on.

Parameters:

  | b | true to enable auto deletion, false to disable

setDoScanFile | ( | self, |
|  | bool | scanFile
| ) |  |  |

Indicate that the next action is to scan the file.

Deprecated:
  not useful in public API

setEnableExternalBrowser | ( | self, |
|  | bool | b
| ) |  |  |

Sets whether the external webbrowser setting should be honoured. This is enabled by default. This should only be disabled in webbrowser applications.

Parameters:

  | b | whether to enable the external browser or not.

setError | ( | self, |
|  | bool | error
| ) |  |  |

Sets whether an error has occurred.

setFinished | ( | self, |
|  | bool | finished
| ) |  |  |

Marks this 'KRun' instance as finished.

setInitializeNextAction | ( | self, |
|  | bool | initialize
| ) |  |  |

Deprecated:
  not useful in public API

setIsDirecory | ( | self, |
|  | bool | isDirectory
| ) |  |  |

Sets whether it is a directory.

Deprecated:
  typo in the name, and not useful as a public method

setIsLocalFile | ( | self, |
|  | bool | isLocalFile
| ) |  |  |

Sets whether it is a local file.

setJob | ( | self, |
|  | KIO.Job | job
| ) |  |  |

Sets the job.

setMode | ( | self, |
|  | mode_t | mode
| ) |  |  |

Sets the file mode.

setPreferredService | ( | self, |
|  | QString | desktopEntryName
| ) |  |  |

Set the preferred service for opening this URL, after its mimetype will have been found by KRun. IMPORTANT: the service is only used if its configuration says it can handle this mimetype. This is used for instance for the X-KDE-LastOpenedWith key, for the recent documents list.

Parameters:

  | desktopEntryName | the desktopEntryName of the service, e.g. "kate".

setProgressInfo | ( | self, |
|  | bool | progressInfo
| ) |  |  |

Sets whether progress information shall be shown.

setRunExecutables | ( | self, |
|  | bool | b
| ) |  |  |

Sets whether executables, .desktop files or shell scripts should be run by KRun. This is enabled by default.

Parameters:

  | b | whether to run executable files or not.

See also:
  isExecutable()

setSuggestedFileName | ( | self, |
|  | QString | fileName
| ) |  |  |

Sets the file name to use in the case of downloading the file to a tempfile in order to give to a non-url-aware application. Some apps rely on the extension to determine the mimetype of the file. Usually the file name comes from the URL, but in the case of the HTTP Content-Disposition header, we need to override the file name.

setUrl | ( | self, |
|  | KUrl | url
| ) |  |  |

Sets the url.

shellQuote | ( | QString | str
| ) |  |  |

Quotes a string for the shell. An empty string will not be quoted.

Deprecated:
  Use KShell.quoteArg() instead. Note that this function behaves differently for empty arguments and returns the result differently.

Parameters:

  | str | the string to quote. The quoted string will be written here

slotScanFinished | ( | self, |
|  | KJob | a0
| ) |  |  |

This slot is called when the scan job is finished.

slotScanMimeType | ( | self, |
|  | KIO.Job | a0,
|  | QString | type
| ) |  |  |

This slot is called when the scan job has found out the mime type.

slotStatResult | ( | self, |
|  | KJob | a0
| ) |  |  |

This slot is called when the 'stat' job has finished.

slotTimeout | ( |  | self ) |

This slot is called whenever the internal time has a timeout.

QString suggestedFileName | ( |  | self ) |

Suggested file name given by the server (e.g. HTTP content-disposition)

QTimer timer | ( |  | self ) |

Returns the timer object.

KUrl url | ( |  | self ) |

Returns the url.