Re: [Rhythmbox-devel] Python API question



On Mon, 2007-02-12 at 02:08 +0100, Lars Strojny wrote:
> I've did a bit more research how to construct a custom query for the
> rhythmdb but now I'm stuck again. Here is what I've got:
> 
> db = shell.get_property ('db')
> db.query_model_new(...)
> 
> The problem is, that I don't know nothing about how to specify the
> arguments for query_model_new(). I do know which parameters I want to
> supply but that's all (rhythdb.PROP_ARTIST, rhythmdb.QUERY_PROP_LIKE and
> an string for the artist).
> 
> It would be really cool if someone could show me a small snippet.

As Alex mentioned, this part of the bindings wasn't completed yet. I've
just committed most of it to SVN.


The most important new bit is the "query_append" method of
rhythmdb.RhythmDB objects. The first parameter is the rhythmdb.Query
object (created with db.query_new) that you want to append some criteria
to, and then you can pass any number of criteria tuples.

A criteria tuple is either "[rhythmdb.QUERY_DISJUNCTION]" to append a
disjunction (OR), "[rhythmdb.QUERY_SUBQUERY, query]" to append a
sub-query, or "[rhythmdb.QUERY_PROP_*, propid, value]" to do any of the
actual comparison operations.


For example, you can now do the following, which tells you if the
currently playing song is by The Living End:

db = shell.props.db
query = db.query_new()
db.query_append (query, [rhythmdb.QUERY_PROP_EQUALS,
rhythmdb.PROP_ARTIST, "The Living End"])
db.evaluate_query(query, shell.props.shell_player.get_playing_entry())



What you should be able to do is call "qm = db.query_model_new(query)"
to create a new query model with a given query. Creating it works fine
at the moment, but it doesn't actually put anything in the query model -
I'm planning to look into that tomorrow.

Sometime soon I'll probably finish the "query list collator" class I
started writing a while back, which simply returns a list of the entries
that match the query - useful for single-shot things.


If you have any suggestions for the API, particularly ways to make it
more "pythonic", please let me know.


Cheers,

James "Doc" Livingston
-- 
In God we Trust. All others must submit an X.509 certificate.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]