← Back to team overview

zim-wiki team mailing list archive

Re: Inserting the time with a hotkey


On Sat, Jun 9, 2012 at 11:53 AM, Adam Porter <adam@xxxxxxxxxxxxx> wrote:
> Sorry for being unclear: I didn't make a plugin.

Once you have it working I would advice to move the patch to a plugin.
Otherwise it will break everytime you upgrade to a new version of zim.

> I just edited
> pageview.py, duplicated that InsertDateDialog class, renamed it, and
> edited a few lines.  It works, except that I don't know how to call
> toggle_format_strong() to toggle bold text (assuming that's the best
> way).  How do I access that function?

There is not such function, probably you mean "toggle_format()" - see
the documentation for that function on how to call it.

A better way to do this would be to insert a "parsetree" instead of
plain text. See the "insert_parsetree_at_cursor()" method. To
construct such an object try something like:

  time = datetime.datetime.now().strftime('%H:%M')
  xml = '''<?xml version='1.0' encoding='utf-8'?>\n<zim-tree
partial="True"><strong>%s</strong> </zim-tree>''' % time
  tree = ParseTree().fromstring(xml)

This way you get an object that represents a piece of formatted text,
and you can easily insert it, without need to toggle buttons etc.