1
# -*- coding: utf-8 -*-
3
# Copyright 2011 Greg Warner <gdwarner@gmail.com>
4
# (Pretty much copied from diagrameditor.py)
7
from zim.plugins import PluginClass
8
from zim.plugins.base.imagegenerator import ImageGeneratorPlugin, ImageGeneratorClass
10
from zim.fs import File, TmpFile
11
from zim.applications import Application, ApplicationError
14
# TODO put these commands in preferences
15
diagcmd = ('seqdiag', '-o')
18
class InsertSequenceDiagramPlugin(ImageGeneratorPlugin):
21
'name': _('Insert Sequence Diagram'), # T: plugin name
23
This plugin provides a sequence diagram editor for zim based on seqdiag.
24
It allows easy editing of sequence diagrams.
25
'''), # T: plugin description
26
'help': 'Plugins:Sequence Diagram Editor',
27
'author': 'Greg Warner',
30
object_type = 'seqdiagram'
31
short_label = _('Sequence Diagram')
32
insert_label = _('Insert Sequence Diagram')
33
edit_label = _('_Edit Sequence Diagram')
37
def check_dependencies(klass):
38
has_diagcmd = Application(diagcmd).tryexec()
39
return has_diagcmd, [("seqdiag", has_diagcmd, True)]
42
class SequenceDiagramGenerator(ImageGeneratorClass):
46
object_type = 'seqdiagram'
47
scriptname = 'seqdiagram.diag'
48
imagename = 'seqdiagram.png'
50
def __init__(self, plugin):
51
ImageGeneratorClass.__init__(self, plugin)
52
self.diagfile = TmpFile(self.scriptname)
54
self.pngfile = File(self.diagfile.path[:-5] + '.png') # len('.diag') == 5
56
def generate_image(self, text):
57
if isinstance(text, basestring):
58
text = text.splitlines(True)
61
self.diagfile.writelines(text)
65
diag = Application(diagcmd)
66
diag.run((self.pngfile, self.diagfile))
67
except ApplicationError:
68
return None, None # Sorry, no log
70
return self.pngfile, None
73
self.diagfile.remove()