QML/Data Engine Part 2
Eric Mesa
ericsbinaryworld at gmail.com
Wed Jan 25 01:23:39 UTC 2012
On Tuesday, January 24, 2012 17:23:03 Sebastian Kügler wrote:
> Hey,
>
> That should work asynchronously, you just do setData() when you receive it,
> and you start the download of a source by connecting to it (so basically in
> sourceRequestEvent, or its Python equivalent in your dataengine).
>
> You can start as many KIO Jobs as you want in parallel, it being async, it
> won't block, and KIO will even schedule these jobs for you so you don't clog
> the user's downlink too much.
>
> If sources become available later on, you might want to catch reference
> errors for non existing sources in your QML code, for example when
> assigning text:
>
> Text {
> [...]
> text: {
> if (typeof(viewsSource.data[mySource])) {
> return viewsSource.data[mySource][key];
> } else {
> return "";
> }
> }
> }
>
> This automatic updating is a bit peculiar, and I've seen some problematic
> cases, but this is roughly how it *should* work.
>
> Cheers,
Thanks for all the help thus far, Sebastian. Right now here's how the engine
looks:
class PyFlickrEngine(plasmascript.DataEngine):
def __init__(self,parent,args=None):
plasmascript.DataEngine.__init__(self,parent)
def init(self):
self.setMinimumPollingInterval(333)
#for flickr
views.initialize()
#adding this back in 24 jan to see if it helps
def sources(self):
sources = ["1500"]
return sources
def sourceRequestEvent(self, name):
print "source request event" #debugging
return self.updateSourceEvent(name)
def updateSourceEvent(self,group):
print "updateSourceEvent"
#grouplist = []
if group == "25":
print "i'm @ 25" #debug
grouplist = views.analyzeviews(views.views25)
#self.setData(grouplist, "Group List", QVariant.List) #original line
self.setData("25", "Group 25", grouplist)
elif group == "50":
print "i'm @ 50" #debug
grouplist = views.analyzeviews(views.views50)
self.setData("50","Group 50", grouplist)
elif group == "75":
print "i'm @ 75" #debug
grouplist = views.analyzeviews(views.views75)
self.setData("75","Group 75", grouplist)
#some stuff
elif group == "1500":
print "i'm @ 1500" #debug
grouplist = views.analyzeviews(views.views1500)
self.setData("1500","Group 1500", grouplist)
return True
def CreateDataEngine(parent):
return PyFlickrEngine(parent)
So you're saying that I need to add setData() in the sourceRequestEvent?
As far as getting data out I'm coming across a weird phenomenon. Here's my
code right now in QML:
import Qt 4.7
import "content"
import QtWebKit 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
Rectangle {
id: window
width: 360
height: 360
PlasmaCore.DataSource {
id: viewsSource
engine: "flickrviewsengine2"
interval: 0
Component.onCompleted: connectedSources = sources
onSourceAdded: connectSource(source)
}
property string currentGroup: viewsSource.data["1500"]["Group 1500"]
//"/home/ermesa/bin/qml/plasmoids/flickrviews2/contents/ui/testgrouprss6"
property string currentLocation: ""
property bool loading: feedModel.status == XmlListModel.Loading
XmlListModel{
id:feedModel
source: window.currentGroup //viewsSource.data["1500"]["Group
1500"]
query: "/photos/photo" //"/rsp/photos/photo"
XmlRole { name: "title"; query: "title/string()"}
XmlRole { name: "views"; query: "views/string()"}
XmlRole { name: "url"; query: "URL/string()"}
}
Row {
width: 360
height: 43
Rectangle{
width: window.width; height: window.height
color: "blue"
Text {
id: testtext
text: viewsSource.data["1500"]["Group 1500"]
//viewsSource.valid //timer.data["Local"]["Timezone"] //qsTr("buttons will go
here!")
}
}
}
Row {
x: 0
y: 43
width: 370
height: 317
Rectangle {
width: window.width/3+10; height: window.height
color: "#efefef"
ListView {
id: list
width: window.width/3; height: window.height
model: feedModel
delegate: ItemDelegate {}
highlight: Rectangle { color: "lightgray" }
highlightMoveSpeed: 9999999
}
}
Rectangle {
width: window.width/3*2
height: window.height
WebView {
id: webView
width: window.width/3*2
height: window.height
html: "<a href="+currentLocation+">here</a>"
}
}
}
}
Now, I know that the XML I'm generating in a string is coming across
correctly, because it appears in the text I've created
text: viewsSource.data["1500"]["Group 1500"]
I know that if I copy that into a text file and read that in as in:
property string currentGroup:
"/home/ermesa/bin/qml/plasmoids/flickrviews2/contents/ui/testgrouprss6"
, it works. So there doesn't appear to be anything wrong with the XML. BUT,
if I do as I have it now:
property string currentGroup: viewsSource.data["1500"]["Group 1500"]
It does not populate the ListView.
Here's what's in that QString:
<?xml version='1.0' encoding='iso-8859-1' ?><photos><photo>
<title>Vulnerable</title> <views>1605</views>
<URL>http://www.flickr.com/photos/ericsbinaryworld/5673784030/</URL>
</photo><photo> <title>The Triple-Breasted Whore of Eroticon Six</title>
<views>1577</views>
<URL>http://www.flickr.com/photos/ericsbinaryworld/5144657798/</URL>
</photo><photo> <title>Wanted: Adrian Lamo</title> <views>1750</views>
<URL>http://www.flickr.com/photos/ericsbinaryworld/4816607916/</URL>
</photo><photo> <title>Katy Perry's Too Tasty to Resist</title>
<views>1729</views>
<URL>http://www.flickr.com/photos/ericsbinaryworld/5141646118/</URL>
</photo><photo> <title>Wedding Ring and Anniversary Gift</title>
<views>1744</views>
<URL>http://www.flickr.com/photos/ericsbinaryworld/196460034/</URL>
</photo></photos>
Ideas?
-------------
<br>
Eric Mesa
<br>
http://www.ericsbinaryworld.com
<br>
Most of the emails from this account should be signed with my GPG key so
that you know it's me. The only exception is when I'm using gmail from
the web.
<br>
<br>
"OK, so ten out of ten for style, but minus several million
for good thinking, yeah? "
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20120124/6d7534bf/attachment.sig>
More information about the Plasma-devel
mailing list