5
5
'''Plugin showing a map of links between pages based on GraphViz'''
7
from zim.plugins import PluginClass
9
from zim.plugins import PluginClass, extends, WindowExtension
10
from zim.actions import action
11
from zim.notebook import Path
8
12
from zim.index import LINK_DIR_BOTH
9
13
from zim.applications import Application
10
14
from zim.fs import Dir
15
from zim.gui.widgets import ui_environment, Dialog, IconButton
16
from zim.inc import xdot
12
20
class LinkMapPlugin(PluginClass):
25
33
'help': 'Plugins:Link Map',
28
def __init__(self, ui):
29
PluginClass.__init__(self, ui)
30
if self.ui.ui_type == 'gtk':
32
self.gui = gui.GtkLinkMap(self.ui)
37
37
def check_dependencies(klass):
38
38
has_graphviz = Application(('fdp',)).tryexec()
97
97
return '\n'.join(dotcode)+'\n'
101
@extends('MainWindow')
102
class MainWindowExtension(WindowExtension):
106
<menubar name='menubar'>
107
<menu action='view_menu'>
108
<placeholder name='plugin_items'>
109
<menuitem action='show_linkmap'/>
116
@action(_('Show Link Map'), stock='zim-linkmap')
117
def show_linkmap(self):
118
linkmap = LinkMap(self.window.ui.notebook, self.window.ui.page) # XXX
119
dialog = LinkMapDialog(self.window, linkmap, self.window.get_resource_opener())
123
class LinkMapDialog(Dialog):
125
def __init__(self, ui, linkmap, opener):
126
Dialog.__init__(self, ui, 'LinkMap',
127
defaultwindowsize=(400, 400), buttons=gtk.BUTTONS_CLOSE)
128
self.linkmap = linkmap
131
hbox = gtk.HBox(spacing=5)
134
self.xdotview = xdot.DotWidget()
135
self.xdotview.set_filter('fdp')
136
self.xdotview.set_dotcode(linkmap.get_dotcode())
137
self.xdotview.connect('clicked', self.on_node_clicked)
138
hbox.add(self.xdotview)
141
hbox.pack_start(vbox, False)
142
for stock, method in (
143
(gtk.STOCK_ZOOM_IN, self.xdotview.on_zoom_in ),
144
(gtk.STOCK_ZOOM_OUT, self.xdotview.on_zoom_out),
145
(gtk.STOCK_ZOOM_FIT, self.xdotview.on_zoom_fit),
146
(gtk.STOCK_ZOOM_100, self.xdotview.on_zoom_100),
148
button = IconButton(stock)
149
button.connect('clicked', method)
150
vbox.pack_start(button, False)
152
def on_node_clicked(self, widget, name, event):
153
self.opener.open_page(Path(name))
100
155
# And a bit of debug code...
102
157
if __name__ == '__main__':
105
160
import zim.notebook
107
notebook = zim.notebook.get_notebook(Dir(sys.argv[1]))
162
notebook = zim.notebook.build_notebook(Dir(sys.argv[1]))
108
163
path = notebook.resolve_path(sys.argv[2])
109
ui = zim.NotebookInterface(notebook)
110
164
linkmap = LinkMap(notebook, path)
111
dialog = gui.LinkMapDialog(ui, linkmap)
165
dialog = LinkMapDialog(None, linkmap, None)
112
166
dialog.show_all()