This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[python] File transfer with KIOSlaves

Tags: None
(comma "," separated)
User avatar
bubble
Registered Member
Posts
6
Karma
0
Hi

I simply want to write a python program that copy a file to another location.
I try with:
Code: Select all
KIO.file_copy(KUrl("thepathofthesourcefile"), KUrl("thepathofthedestfile"), -1)
with no luck.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Does your python application have a instance of QCoreApplication, QApplication or KApplication? ( note that it needs to have been started, ie. exec() called on it )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
bubble
Registered Member
Posts
6
Karma
0
No it doesn't have them. I learned on IRC that there are these needs, but I don't know how to use it.
On internet I didn't find any sort of information about that, with the exception of some examples, but nothing useful for my situation.

Maybe with api.kde.org online I can find a solution, but now I don't have any ideas this is my first program that use Qt and KDE libraries I'm a completely newbie :P

edit: api.kde.org is now online :)
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please see http://techbase.kde.org/Development/Lan ... ng_PyKDE_4 for help in preparing KApplication.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
bubble
Registered Member
Posts
6
Karma
0
ok thanks solved with that code:
Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs
from PyKDE4.kdeui import KApplication

from PyKDE4.kio import KIO
from PyKDE4.kdecore import KUrl

appName     = "KIOSLAVES_attempt"
catalog     = ""
programName = ki18n ("KApplication")
version     = "1.0"
description = ki18n ("KApplication/KMainWindow/KAboutData example")
license     = KAboutData.License_GPL
copyright   = ki18n ("(c) 2010 kiroken")
text        = ki18n ("none")
homePage    = "www.itdoesntexist.none"
bugEmail    = "none@none.it"

aboutData   = KAboutData (appName, catalog, programName, version, description,
license, copyright, text, homePage, bugEmail)


KCmdLineArgs.init (sys.argv, aboutData)

app = KApplication ()

tr = KIO.file_copy(KUrl("file:///path/file1.txt"), KUrl("file:///path/file2.txt"), -1)
tr.start()

app.exec_()
I had just need some documentation to do it


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]