Bookmarks plugin

jaap-karssenberg edited this page Sep 26, 2015 · 5 revisions
Clone this wiki locally

As of zim 0.64 there is a default bookmarks plugin in zim.

Information below may be aut of date

This plugin targets fast access to 10 configurable bookmarks. Configuration takes place in the plugin itself, so user has to copy a present location of a page and paste it in the configuration to a corresponding bookmark number. These bookmarks are accessible from a menu "Go" and by key-bindings (Alt+[0-9]).

Note: This plugin no longer works in ZIM 0.62, at least in Windows 7. For similar functionality, one option is using the Tags plugin that comes included with ZIM - and then use a tag such as @bookmark - tagged pages will show in the Left Panel (other options are also available)

Folder to install custom plugins (.py files) in windows: %APPDATA%\zim\data\zim\plugins\

TODO: The present version doesn't update the labels in a "Go" menu after changes in a configuration of the plugin (changes are applied with a restart of application).

Copy the code and paste in a file (located in your plugin folder)

# -*- coding: utf-8 -*-

# Copyright 2011 NorfCran <>

import gtk
import time

from zim.notebook import Path
from zim.plugins import PluginClass
from zim.gui.widgets import ui_environment

class BookmarksPlugin(PluginClass):

    plugin_info = {
        'name': _('Bookmarks'), # T: plugin name
        'description': _('''\
This plugin allows definition of 10 bookmarks. The bookmarks are accessed through Alt+(0-9) and from a menubar (Go).

Default plugin values:
Bookmark number ==> Page
'''), # T: plugin description
        'author': 'NorfCran',
        'help': 'Plugins:Bookmarks',

    plugin_preferences = (
               ('bookmark_0', 'string', 'Bookmark 0', ':home'),
               ('bookmark_1', 'string', 'Bookmark 1', ':home'),
               ('bookmark_2', 'string', 'Bookmark 2', ':home'),
               ('bookmark_3', 'string', 'Bookmark 3', ':home'),
               ('bookmark_4', 'string', 'Bookmark 4', ':home'),
               ('bookmark_5', 'string', 'Bookmark 5', ':home'),
               ('bookmark_6', 'string', 'Bookmark 6', ':home'),
               ('bookmark_7', 'string', 'Bookmark 7', ':home'),
               ('bookmark_8', 'string', 'Bookmark 8', ':home'),
               ('bookmark_9', 'string', 'Bookmark 9', ':home'),

    def __init__(self, ui):
        PluginClass.__init__(self, ui)

    def generate_ui_xml(self):
        ui_xml_template = '''
        <menubar name='menubar'>
                <menu action='go_menu'>
                        <placeholder name='plugin_items'>
                                <menuitem action='bookmark_%i'/>
        ui_xml = ""
        for i in range(10):
            ui_xml += ui_xml_template % i
        ui_xml = "<ui>\n" + ui_xml + "\n</ui>"
        return ui_xml

    def generate_ui_actions(self):
            # in oder to provide dynamic key binding assignment the initiation is made in the plugin class --> DONE
        ui_actions = ()
        for i in range(10):
            label = self.preferences['bookmark_%i'%i]
            ui_actions +=  ('bookmark_%i'%i, None, _('%s'%label), '<Alt>%i'%i, '', False),
        return ui_actions

    def initialize_ui(self, ui):
        if self.ui.ui_type == 'gtk':
            ui_actions = self.generate_ui_actions()
            self.ui.add_actions(ui_actions, self)
            ui_xml = self.generate_ui_xml()
            self.ui.add_ui(ui_xml, self)

    def do_preferences_changed(self):
                if self.ui.ui_type == 'gtk':
                        ui_xml = self.generate_ui_xml()
                        self.ui.add_ui(ui_xml, self)    

        def bookmark_0(self):

        def bookmark_1(self):

        def bookmark_2(self):

        def bookmark_3(self):

        def bookmark_4(self):

        def bookmark_5(self):

        def bookmark_6(self):

        def bookmark_7(self):

        def bookmark_8(self):

        def bookmark_9(self):

    def go_to_bookmark(self, page):