Re: Python extension manipulating bookmarks



On Fri, Oct 14, 2005 at 03:03:12PM +0100, Magnus Therning wrote:
>On Fri, Oct 14, 2005 at 12:17:20PM +0100, Magnus Therning wrote:
>[snip]
>>>EphyNode is undocumented, so you'll probably want to have
>>>epiphany/lib/ephy-node.h open to get a vague idea of what functions you
>>>need. In essence, once you've got an EphyNode representing the bookmark
>>>you want to delete, you should be able to call
>>>"bms.get_bookmarks().remove_child(b)".
>>
>>Now that you mention it it does sound like a logical solution. The only
>>reason I might have been thrown off before was the lack of a
>>`remove_bookmark()` function (while `remove_keyword()` is there, why the
>>asymmetry?).
>>
>>>I'm not 100% sure of this. I've never used EphyNode from Python, and
>>>more critically, I've never really understood EphyNode all that well
>>>even in C (which is why it's undocumented :P). Let us know if it works
>>>out or if you need more help.
>>
>>I'm having some problems with Epiphany dying on me when removing a
>>bookmark. Since I don't have an Epiphany with debugging symbols I
>>suspect bug-buddy won't be very useful. I'll try to put together a
>>minimal app that shows the same behaviour later on today... stay tuned
>>:-)
>
>My Epiphany dies after executing the following code:
>
>    import epiphany
>    bms = epiphany.ephy_shell_get_default().get_bookmarks()
>    bmnode = bms.find_bookmark('http://packages.ubuntu.com/')
>    bms.get_bookmarks().remove_child(bmnode)
>
>It doesn't happen *all* the time. E.g. it seems that removing a bookmark
>that has no keywords works just fine, so my next problem is how do I
>(easily) find a bookmark's all keywords?

It seems the easiest way to remove a bookmark is to remove *all* its
keywords (include the automatic ones like 'All' etc). 

I haven't found an easy way of getting the keywords for a specific
bookmark. `get_property_string(epiphany.NODE_BMK_KEYWORDS)` returns a
string containing all keywords separated by a single space. This is
useful for matching text against (I guess it's used for the address bar)
but it's not very useful for finding the EphyNodes of the keywords
(keywords with spaces don't get special treatment).

There seems to be no negative side to removing a keyword the bookmark
doesn't have and since it's fatal to miss a single keyword (Epiphany
dies then) it's what I've settled on. The following code works for me:

    import epiphany
    bms = epiphany.ephy_shell_get_default().get_bookmarks()
    bm_node = bms.find_bookmark('http://packages.ubuntu.com/')
    for kw_node in bms.get_keywords().get_children():
        bms.unset_keyword(kw_node, bm_node)

/M

-- 
Magnus Therning                    (OpenPGP: 0xAB4DFBA4)
magnus therning org
http://therning.org/magnus

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

Few false ideas have more firmly gripped the minds of so many
intelligent men than the one that, if they just tried, they could
invent a cipher that no one could break.
      -- David Kahn

Attachment: pgpXIqaN6GqfN.pgp
Description: PGP signature



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