Zim

Merge lp:~gdwarner/zim/sequence-diagram-plugin into lp:~jaap.karssenberg/zim/pyzim

Proposed by gdw2
Status: Merged
Merged at revision: 676
Proposed branch: lp:~gdwarner/zim/sequence-diagram-plugin
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 155 lines (+143/-0)
2 files modified
data/manual/Plugins/Sequence_Diagram_Editor.txt (+30/-0)
zim/plugins/sequencediagrameditor.py (+113/-0)
To merge this branch: bzr merge lp:~gdwarner/zim/sequence-diagram-plugin
Reviewer Review Type Date Requested Status
Jaap Karssenberg Approve
Review via email: mp+58749@code.launchpad.net

Description of the change

Added sequence diagram plugin (_heavily_ based off diagram plugin -- thanks!)

To post a comment you must log in.
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Thanks for the plugin code it looks good and usable to me but I will keep it
on hold for a bit. Reason is that we get too many similar plugins, so I'll
go and try wrapping them into bigger ones.

Essentially that will mean a patch to the diagram plugin that allows you to
switch what command is used for a specific diagram. Thus there will be a
single "insert diagram" item that supports different styles.

(Something similar can be done to merge the two insert plot plugins)

Revision history for this message
gdw2 (gdwarner) wrote :

Sounds good.
On Apr 27, 2011 12:25 PM, "Jaap Karssenberg" <email address hidden>
wrote:
> Thanks for the plugin code it looks good and usable to me but I will keep
it
> on hold for a bit. Reason is that we get too many similar plugins, so I'll
> go and try wrapping them into bigger ones.
>
> Essentially that will mean a patch to the diagram plugin that allows you
to
> switch what command is used for a specific diagram. Thus there will be a
> single "insert diagram" item that supports different styles.
>
> (Something similar can be done to merge the two insert plot plugins)
>
> --
>
https://code.launchpad.net/~gdwarner/zim/sequence-diagram-plugin/+merge/58749
> You are the owner of lp:~gdwarner/zim/sequence-diagram-plugin.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

OK, optional dependencies are in. I will be back in ~ 2 weeks and merge this code with the existing plugin.

review: Approve
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

... first of all my apologies for the 2.5 y timeout - somehow this request got burried in my inbox - sorry.

Merged in pyzim-refactor using new plugin framework, will be merged in trunk for next release.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/manual/Plugins/Sequence_Diagram_Editor'
2=== added file 'data/manual/Plugins/Sequence_Diagram_Editor.txt'
3--- data/manual/Plugins/Sequence_Diagram_Editor.txt 1970-01-01 00:00:00 +0000
4+++ data/manual/Plugins/Sequence_Diagram_Editor.txt 2011-04-21 20:37:52 +0000
5@@ -0,0 +1,30 @@
6+Content-Type: text/x-zim-wiki
7+Wiki-Format: zim 0.4
8+
9+====== Diagram Editor ======
10+
11+The sequence diagram editor allows you to insert and edit diagrams based on seqdiag. Seqdiag uses a basic script language to define diagrams. This plugin adds a dialog where one can define a diagram in this script. The dialog shows a preview of the rendered diagram and when the diagram is finished it can be inserted in a zim page as an image. You can always edit it later again by selecting "Edit Diagram" from the context menu (right-mouse-click on the diagram will show the context menu).
12+
13+**Dependencies:** This plugin requires seqdiag to be installed and available in the system path.
14+
15+===== Example =====
16+
17+For example a diagram like:
18+
19+{{./diagram.png}}
20+
21+Can be created by entering the following definition in the dialog:
22+
23+'''
24+diagram {
25+ browser -> webserver [label = "GET /index.html"];
26+ browser <-- webserver;
27+ browser -> webserver [label = "POST /blog/comment"];
28+ webserver -> database [label = "INSERT comment"];
29+ webserver <-- database;
30+ browser <-- webserver;
31+}
32+'''
33+
34+For full documentation of the script language see: http://tk0miya.bitbucket.org/seqdiag/build/html/index.html
35+
36
37=== added file 'data/manual/Plugins/Sequence_Diagram_Editor/diagram.png'
38Binary files data/manual/Plugins/Sequence_Diagram_Editor/diagram.png 1970-01-01 00:00:00 +0000 and data/manual/Plugins/Sequence_Diagram_Editor/diagram.png 2011-04-21 20:37:52 +0000 differ
39=== added file 'zim/plugins/sequencediagrameditor.py'
40--- zim/plugins/sequencediagrameditor.py 1970-01-01 00:00:00 +0000
41+++ zim/plugins/sequencediagrameditor.py 2011-04-21 20:37:52 +0000
42@@ -0,0 +1,113 @@
43+# -*- coding: utf-8 -*-
44+
45+# Copyright 2011 Greg Warner <gdwarner@gmail.com>
46+# (Pretty much copied from diagrameditor.py)
47+
48+import gtk
49+
50+from zim.fs import File, TmpFile
51+from zim.plugins import PluginClass
52+from zim.config import data_file
53+from zim.applications import Application
54+from zim.gui.imagegeneratordialog import ImageGeneratorDialog
55+
56+# TODO put these commands in preferences
57+diagcmd = ('seqdiag', '-o')
58+
59+ui_xml = '''
60+<ui>
61+ <menubar name='menubar'>
62+ <menu action='insert_menu'>
63+ <placeholder name='plugin_items'>
64+ <menuitem action='insert_seqdiagram'/>
65+ </placeholder>
66+ </menu>
67+ </menubar>
68+</ui>
69+'''
70+
71+ui_actions = (
72+ # name, stock id, label, accelerator, tooltip, read only
73+ ('insert_seqdiagram', None, _('Se_quence Diagram...'), '', _('Insert sequence diagram'), False),
74+ # T: menu item for insert diagram plugin
75+)
76+
77+
78+class InsertSequenceDiagramPlugin(PluginClass):
79+
80+ plugin_info = {
81+ 'name': _('Insert Sequence Diagram'), # T: plugin name
82+ 'description': _('''\
83+This plugin provides a sequence diagram editor for zim based on seqdiag.
84+
85+This is not a core plugin shipping with zim.
86+'''), # T: plugin description
87+ 'help': ':Plugins:Sequence Diagram Editor',
88+ 'author': 'Greg Warner',
89+ }
90+
91+ @classmethod
92+ def check_dependencies(klass):
93+ return [("seqdiag",Application(diagcmd).tryexec())]
94+
95+ def __init__(self, ui):
96+ PluginClass.__init__(self, ui)
97+ if self.ui.ui_type == 'gtk':
98+ self.ui.add_actions(ui_actions, self)
99+ self.ui.add_ui(ui_xml, self)
100+ self.register_image_generator_plugin('seqdiagram')
101+
102+ def insert_seqdiagram(self):
103+ dialog = InsertSequenceDiagramDialog.unique(self, self.ui)
104+ dialog.show_all()
105+
106+ def edit_object(self, buffer, iter, image):
107+ dialog = InsertSequenceDiagramDialog(self.ui, image=image)
108+ dialog.show_all()
109+
110+ def do_populate_popup(self, menu, buffer, iter, image):
111+ menu.prepend(gtk.SeparatorMenuItem())
112+
113+ item = gtk.MenuItem(_('_Edit Sequence Diagram')) # T: menu item in context menu
114+ item.connect('activate',
115+ lambda o: self.edit_object(buffer, iter, image))
116+ menu.prepend(item)
117+
118+
119+
120+class InsertSequenceDiagramDialog(ImageGeneratorDialog):
121+
122+ def __init__(self, ui, image=None):
123+ generator = SequenceDiagramGenerator()
124+ ImageGeneratorDialog.__init__(self, ui, _('Insert Sequence Diagram'), # T: dialog title
125+ generator, image, help=':Plugins:Sequence Diagram Editor')
126+
127+
128+class SequenceDiagramGenerator(object):
129+
130+ # TODO: generic base class for image generators
131+
132+ type = 'seqdiagram'
133+ basename = 'seqdiagram.diag'
134+
135+ def __init__(self):
136+ self.diagfile = TmpFile('diagram-editor.diag')
137+ self.diagfile.touch()
138+ self.pngfile = File(self.diagfile.path[:-5] + '.png') # len('.diag') == 5
139+
140+ def generate_image(self, text):
141+ if isinstance(text, basestring):
142+ text = text.splitlines(True)
143+
144+ # Write to tmp file
145+ self.diagfile.writelines(text)
146+
147+ # Call seqdiag
148+ diag = Application(diagcmd)
149+ diag.run((self.pngfile, self.diagfile))
150+
151+ return self.pngfile, None
152+
153+ def cleanup(self):
154+ self.diagfile.remove()
155+ self.pngfile.remove()