← Back to team overview

zim-wiki team mailing list archive

Bookmarks packed in a plugin (an extra feature for ZIM)


Good evening ZIM users and developers,

I would like to share a plugin, which is capable of a fast access to any
page through defined bookmarks. The plugin binds page to short cuts
Alt+(0-9) and it is also accessible from "Go" in a menu.

Enjoy, best regards, JK!

P.S. Great thanks to all developers and contributors, the ZIM simply rocks
:D !
# -*- coding: utf-8 -*-

# Copyright 2011 NorfCran <norfcran@xxxxxxxxx>

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>"
		print ui_xml
		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),
		print ui_actions
		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 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):