~jaap.karssenberg/zim/pyzim-gtk3

« back to all changes in this revision

Viewing changes to zim/plugins/linkmap.py

  • Committer: Jaap Karssenberg
  • Date: 2014-03-08 11:47:43 UTC
  • mfrom: (668.1.49 pyzim-refactor)
  • Revision ID: jaap.karssenberg@gmail.com-20140308114743-fero6uvy9zirbb4o
Merge branch with refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
'''Plugin showing a map of links between pages based on GraphViz'''
6
6
 
7
 
from zim.plugins import PluginClass
 
7
import gtk
 
8
 
 
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
 
17
 
 
18
 
11
19
 
12
20
class LinkMapPlugin(PluginClass):
13
21
 
25
33
                'help': 'Plugins:Link Map',
26
34
        }
27
35
 
28
 
        def __init__(self, ui):
29
 
                PluginClass.__init__(self, ui)
30
 
                if self.ui.ui_type == 'gtk':
31
 
                        import gui
32
 
                        self.gui = gui.GtkLinkMap(self.ui)
33
 
                else:
34
 
                        self.gui = False
35
 
 
36
36
        @classmethod
37
37
        def check_dependencies(klass):
38
38
                has_graphviz = Application(('fdp',)).tryexec()
97
97
                return '\n'.join(dotcode)+'\n'
98
98
 
99
99
 
 
100
 
 
101
@extends('MainWindow')
 
102
class MainWindowExtension(WindowExtension):
 
103
 
 
104
        uimanager_xml = '''
 
105
        <ui>
 
106
                <menubar name='menubar'>
 
107
                        <menu action='view_menu'>
 
108
                                <placeholder name='plugin_items'>
 
109
                                        <menuitem action='show_linkmap'/>
 
110
                                </placeholder>
 
111
                        </menu>
 
112
                </menubar>
 
113
        </ui>
 
114
        '''
 
115
 
 
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())
 
120
                dialog.show_all()
 
121
 
 
122
 
 
123
class LinkMapDialog(Dialog):
 
124
 
 
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
 
129
                self.opener = opener
 
130
 
 
131
                hbox = gtk.HBox(spacing=5)
 
132
                self.vbox.add(hbox)
 
133
 
 
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)
 
139
 
 
140
                vbox = gtk.VBox()
 
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),
 
147
                ):
 
148
                        button = IconButton(stock)
 
149
                        button.connect('clicked', method)
 
150
                        vbox.pack_start(button, False)
 
151
 
 
152
        def on_node_clicked(self, widget, name, event):
 
153
                self.opener.open_page(Path(name))
 
154
 
100
155
# And a bit of debug code...
101
156
 
102
157
if __name__ == '__main__':
104
159
        import zim
105
160
        import zim.notebook
106
161
        import gui
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()
113
167
        dialog.run()