QML/Data Engine Part 2

Sebastian Kügler sebas at kde.org
Tue Jan 24 16:23:03 UTC 2012


Hey,

> Sorry it was late and I was a little out of it.
> 
> Basically, in my data Engine - which is written in Python, if I add in that
> block, then when my plasmoid runs it will cause the data Engine to get that
> data.  When I'm back home I'll have to match up this email and your
> previous email with my code to see what I'm doing.  (Because I think I
> already have the dataSource.connectSource(bla))
> 
> Actually, if I can look into what I sent the mailing list recently....
> 
> here's the engine part of what I have right now in the QML part of my code:
> 
> PlasmaCore.DataSource {
> 
> id: viewsSource
> 
> engine: "flickrviewsengine"
> 
> interval: 0
> 
> Component.onCompleted: connectedSources = sources
> 
> onSourceAdded: connectSource(source)
> 
> }
> 
> 
> So is that not enough to connect to the source?
> 
> To try and clarify things as much as possible - because I was posting as I
> was debugging things in a mad fit of inspiration at 0200 local time - let
> me try and sum up here.
> 
> If you remove the python code that's in this email chain from the data
> engine code, but leave everything else about my QML the same, then my
> plasmoid connects to the dataEngine, but there's no data inside.  I know
> it's connected because viewsSource.valid gives true.
> 
> Now, I add that python code, uninstall and reinstall the engine.  When I
> run my plasmoid THIS time, I can see all the debug statements that I've put
> into my engine code.  I see the engine is working and then I get data out.
> I know this because I did a
> 
> text: viewsSource.data["1500"]["Group 1500"]
> 
> And I can see the contents of my data Engine.
> 
> So it works!  yay!  So why come to the mailing list?  Because I want to
> make sure I'm doing this correctly since adding in all my sources would
> cause this plasmoid to take forever to load.  It takes 15 minutes or more
> for all the data to be pulled off the internet and put into the engine for
> all the data sources.  If it has to be that way, then it has to be that
> way.  But I was hoping that by using a data engine I could have the data
> engine just grab the sources in parallel.  Then, in the plasmoid, you could
> click on buttons for each of the sources - 25, 50, 1500, etc and whichever
> ones already have data in them would allow you to interact with them while
> the other ones downloaded.

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,
-- 
sebas

http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9


More information about the Plasma-devel mailing list