[PyKDE] PyKDE: bug with KRecentFilesAction?
Serge Weinstock
sweinst at ukonline.co.uk
Fri Jul 7 23:01:52 BST 2006
Jim Bublitz wrote:
> On Friday 07 July 2006 12:06, Serge Weinstock wrote:
>
>> Is there a bug with KRecentFilesAction?
>>
>> I'm creating a KRecentFilesAction like this:
>>
>> class MyMainWindow(KMainWindow)
>> ...
>> def initActions(self):
>> ...
>> self.openRecentFilesAction = KRecentFilesAction(i18n("Open
>> &Recent File"), KShortcut(),
>> self.openURL, acts, "openRecentFilesAction")
>>
>> ...
>>
>> def openURL(self, url):
>> ...
>>
>> When I select an entry in the recent file list, I got a:
>>
>> TypeError: openURL() takes exactly 2 arguments (1 given)
>>
>> The documentation says that the slot signature should be
>> urlSelected(const KURL &)
>>
>> I get the same if I do a:
>> self.connect(self.openRecentFilesAction,
>> SIGNAL("urlSelected(const KURL &)"), self.openURL)
>>
>>
>> Is it a bug or have I done something wrong?
>>
>
>
> It looks like a bug. The PyKDE code all looks correct, as does your code and
> the sip-generated C++ code, so unless I've overlooked something, it appears
> sip isn't handling the signal correctly or there's a bug in KDE itself.
>
> I don't think it'll make a difference, but could you try changing the slot
> name to something different, like open_URL - there are KDE methods with that
> name (openURL), but they're in different classes, so there shouldn't be a
> name clash, but there shouldn't be a bug either.
>
> It would help if you could post a short but complete program that fails this
> way so either Phil or I can look into this further.
>
> Jim
>
>
Thanks,
I tried to rename the slot but it doesn't change anything.
I wrote a short example, I hope it can help.
--------------------------------- test.py
-----------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from kdecore import *
from kdeui import *
from kfile import *
class KdeApp(KMainWindow):
def __init__(self):
KMainWindow.__init__(self,None,"test")
KStdAction.open(self.fileOpen, self.actionCollection())
self.openRecentFilesAction = KRecentFilesAction(i18n("Open
&Recent File"), KShortcut(),
self.openURL, self.actionCollection(), "openRecentFilesAction")
self.openRecentFilesAction.loadEntries(KApplication.kApplication().config(),
"RecentFiles")
KStdAction.quit(self.close, self.actionCollection())
self.createGUI(os.path.abspath(os.path.join(os.path.dirname(__file__),
"testui.rc")), 0)
def fileOpen(self):
urls = KFileDialog.getOpenURLs(None, None, self, None)
if not urls: return
for url in urls: self.openURL(url)
def openURL(self, url):
print "opening", url.prettyURL()
self.openRecentFilesAction.addURL(url)
def queryClose(self):
self.openRecentFilesAction.saveEntries(KApplication.kApplication().config(),
"RecentFiles")
return True
aboutdata = KAboutData(
"kdeapp", "KdeApp", "1.0", "description",
KAboutData.License_GPL, "(C)", None, None, "your at email.com"
)
KCmdLineArgs.init(sys.argv,aboutdata)
kapp = KApplication()
widget = KdeApp()
widget.show()
kapp.exec_loop()
--------------------------------- test.py
-----------------------------------------------
--------------------------------- testui.rc
-----------------------------------------------
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" >
<kpartgui name="test" version="1">
<MenuBar>
<Menu name="file"><text>&File</text>
<Action name="openAction"/>
<Action name="openRecentFilesAction"/>
<Separator/>
<Action name="quitAction"/>
</Menu>
</MenuBar>
</kpartgui>
--------------------------------- testui.rc
-----------------------------------------------
Serge
More information about the PyQt
mailing list