Re: [Zim-wiki] path link checking plugin

2016-04-04 Thread Jaap Karssenberg
Hi Nathaniel,

Sorry for responding so late. Afraid that what you try to do can not be
implemented as a pure plugin. You will need to patch the core code of the
pageview to accomplish this.

The reason is that the gtk.TextTag is private within the editor widget. The
parsetree only passes on the content of the page, but indeed does not
contain the widget objects.

So to implement this feature the parsetree needs to be updated to contain a
link attribute whether or not the target exists, plus the widget should be
updated to understand this attribute and render the link differently.

Regards,

Jaap


On Tue, Feb 9, 2016 at 2:48 AM, Nathaniel Beaver  wrote:

> I've written a plugin to check that the target of a file link exists (see
> prototype attached).
>
> However, I'd like to turn the broken links a different color by accessing
> the gtk.TextTag corresponding to the link and changing the style with
> something like
>
> tag.set_property('foreground', 'red')
>
> Unfortunately, I am having some difficulty finding the actual TextTags in
> the parse tree. Right now I am using tree.findall(zim.formats.LINK) to get
> all the links, but the node.tag property is just a string, not a TextTag.
>
> Any suggestions?
>
> Nathaniel Beaver
>
> P.S. Here is the GitHub page if it helps:
>
> https://github.com/nbeaver/zim-pathchecker-plugin
>
> and here is the relevant bug report:
>
> https://bugs.launchpad.net/zim/+bug/1419531
>
> ___
> Mailing list: https://launchpad.net/~zim-wiki
> Post to : zim-wiki@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~zim-wiki
> More help   : https://help.launchpad.net/ListHelp
>
>
___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp


[Zim-wiki] path link checking plugin

2016-02-08 Thread Nathaniel Beaver
I've written a plugin to check that the target of a file link exists 
(see prototype attached).


However, I'd like to turn the broken links a different color by 
accessing the gtk.TextTag corresponding to the link and changing the 
style with something like


tag.set_property('foreground', 'red')

Unfortunately, I am having some difficulty finding the actual TextTags 
in the parse tree. Right now I am using tree.findall(zim.formats.LINK) 
to get all the links, but the node.tag property is just a string, not a 
TextTag.


Any suggestions?

Nathaniel Beaver

P.S. Here is the GitHub page if it helps:

https://github.com/nbeaver/zim-pathchecker-plugin

and here is the relevant bug report:

https://bugs.launchpad.net/zim/+bug/1419531
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''Path check plugin based on zeitgeist-logger plugin.'''

import sys
import os.path
import urlparse

from zim.plugins import PluginClass, ObjectExtension, extends
from zim.signals import SIGNAL_AFTER
import zim.formats
import zim.parsing
import logging

import inspect

logger = logging.getLogger('zim.plugins.pathcheck')

class PathChecker(PluginClass):

	plugin_info = {
		'name': "Path Checker", # T: plugin name
		'description': "Checks for broken paths in links.", # T: plugin description
		'author': "Nathaniel Beaver",
	}

@extends('PageView')
class PageViewExtension(ObjectExtension):

	def __init__(self, plugin, pageview):
		self.plugin = plugin
		self.connectto(obj=pageview.ui, signal='open-page', handler=self.on_open_page, order=SIGNAL_AFTER)

	def yield_link_nodes(self, page):
		tree = page.get_parsetree()
		if tree:
			for node in tree.findall(zim.formats.LINK):
href = node.attrib.pop('href')
link_type = zim.parsing.link_type(href)
yield link_type, href, node

	def on_open_page(self, ui, page, path):
		logger.debug("Opened page: %s", page.name)
		for link_type, href, node in self.yield_link_nodes(page):

			if link_type == 'file':
if href.startswith('file://'):
	path = urlparse.urlparse(href).path
else:
	path = os.path.expanduser(href)
if not os.path.exists(path):
	logger.debug("Broken path: %s", path)
___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp