Re: QML/Data Engine Part 2

2012-01-24 Thread Sebastian Kügler
On Tuesday, January 24, 2012 08:43:49 Eric Mesa wrote:
  Here's an interesting little tidbit that might make this all finally work
 correctly.
 
 If I add this in:
 
 def sources(self):
 sources = [1500]
 return sources
 
 to my engine - then whenever it's connected to, it grabs the data into the
 engine.  So it looks like the data was empty otherwise, even if I used
 plasmaengineexplorer to make sure data was in there first.  The question
 is - is this the right thing to do?  Or is there a way of telling it to
 grab the data as it's requested by my plasmoid?  When I add i the rest of
 my sources it will take a while for the data to be available.

plasmaengineexplorer starts a different process, so what happens in there 
doesn't happen in your plasmoid, they're entirely different things. You have 
to populate the dataengine from your plasmoid, using 
dataSource.connectSource(bla).
-- 
sebas

http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: QML/Data Engine Part 2

2012-01-24 Thread Sebastian Kügler
On Tuesday, January 24, 2012 09:46:21 Sebastian Kügler wrote:
 On Tuesday, January 24, 2012 08:43:49 Eric Mesa wrote:
   Here's an interesting little tidbit that might make this all finally
   work
  
  correctly.
  
  If I add this in:
  
  def sources(self):
  sources = [1500]
  return sources

That looks a lot like Python syntax... :)

sources() is just an accessor though, instead use setData(...) or 
addSource(...) if you want to put data into your engine.

  to my engine - then whenever it's connected to, it grabs the data into
  the engine.  So it looks like the data was empty otherwise, even if I
  used plasmaengineexplorer to make sure data was in there first.  The
  question is - is this the right thing to do?  Or is there a way of
  telling it to grab the data as it's requested by my plasmoid?  When I
  add i the rest of my sources it will take a while for the data to be
  available.
 
 plasmaengineexplorer starts a different process, so what happens in there
 doesn't happen in your plasmoid, they're entirely different things. You
 have to populate the dataengine from your plasmoid, using
 dataSource.connectSource(bla).

Also useful, in order to debug in your code:

if (dataSource[mysource]) { print(dataSource[mysource]); }

or if (typeof(dataSource[mySource]) ...

You can also check what you're connected to:

or print(dataSource.connectedSources)

In your DataSource:

DataSource {
id: ds
 [...]
onNewData: {
print(source, data);
}
}

this should make it a bit easier to do basic print-level debugging.

Cheers,
-- 
sebas

http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: QML/Data Engine Part 2

2012-01-24 Thread Eric Mesa
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.
--
Eric Mesa
http://www.ericsbinaryworld.com


On Tue, Jan 24, 2012 at 5:20 AM, Sebastian Kügler se...@kde.org wrote:

 On Tuesday, January 24, 2012 09:46:21 Sebastian Kügler wrote:
  On Tuesday, January 24, 2012 08:43:49 Eric Mesa wrote:
Here's an interesting little tidbit that might make this all finally
work
  
   correctly.
  
   If I add this in:
  
   def sources(self):
   sources = [1500]
   return sources

 That looks a lot like Python syntax... :)

 sources() is just an accessor though, instead use setData(...) or
 addSource(...) if you want to put data into your engine.

   to my engine - then whenever it's connected to, it grabs the data into
   the engine.  So it looks like the data was empty otherwise, even if I
   used plasmaengineexplorer to make sure data was in there first.  The
   question is - is this the right thing to do?  Or is there a way of
   telling it to grab the data as it's requested by my plasmoid?  When I
   add i the rest of my sources it will take a while for the data to be
   available.
 
  plasmaengineexplorer starts a different process, so what happens in there
  doesn't happen in your plasmoid, they're entirely different things. You
  have to populate the dataengine from your plasmoid, using
  dataSource.connectSource(bla).

 Also useful, in order to debug in your code:

 if (dataSource[mysource]) { print(dataSource[mysource]); }

 or if (typeof(dataSource[mySource]) ...

 You can also check what you're connected to:

 or print(dataSource.connectedSources)

 In your DataSource:

 DataSource {
id: ds
 [...]
onNewData: {
print(source, data);
}
 }

 this should make it a bit easier to do basic print-level debugging.

 Cheers,
 --
 sebas

 http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
 ___
 Plasma-devel mailing list
 Plasma-devel@kde.org
 https://mail.kde.org/mailman/listinfo/plasma-devel

___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: Re: QML/Data Engine Part 2

2012-01-24 Thread Sebastian Kügler
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
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: QML/Data Engine Part 2

2012-01-24 Thread Eric Mesa
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: 999
}

}

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 

Re: QML/Data Engine Part 2

2012-01-24 Thread Eric Mesa
As to the second half of my previous post - turns out it was a quirk of the 
XmlListModel.  I was using source: changed that to xml: and it worked!
-
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
Rome wasn't burned in a day. 


signature.asc
Description: This is a digitally signed message part.
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel