[PyKDE] KMimeType.findByPath return value

Jim Bublitz jbublitz at nwinternet.com
Tue Dec 31 07:27:01 GMT 2002


On 30-Dec-02 Daniel Naber wrote:
> the documentaton says that KMimeType.findByURL() returns an
> instance of a  KService, I assume the same is true for
> KMimeType.findByPath(). However,  how can I simply get the
> service's name? I can print it like this:

The PyKDE documentation is incorrect, although it doesn't make a
lot of difference in this case. findByURL/findByPath return a
KMimeType instance, which should still have a usable name() method
(inherited from KServiceType).

> self.mimetype = KMimeType.findByPath(url).name()
> print "mimetype=%s" % self.mimetype
 
> Output is something like "mimetype=application/x-shellscript",
> but this is still of type 'instance' and thus cannot be used
> for  KServiceTypeProfile.preferredService(). How can I make the
> name a string?  str() around the right side of the
> self.mimetype=... leads to a crash where the KDE crash handler
> pops up (backtrace below).

name() returns a QString, so

   print self.mimetype.latin1()

should print the "appication/x-shellscript" and you should be able
to use the value of self.mimetype.latin1() as a Python string.

The type "instance" you get for self.mimetype should be a QString
instance, and since it may be Unicode you need the latin1
conversion. That may be why str() fails, although if % works I
don't see why str() would fail.
 
> I'm using the 20021122 snapshot RPMs for Suse 8.1

I haven't tested with either of those, but I don't expect it should
be a problem, especially if you can get something like
KApplication working. 

Try the latin1() conversion and if that doesn't work, repost and
I'll check into it further (can't get to it until late Wed or Thur
anyway).

Jim




More information about the PyQt mailing list