Zim

Merge lp:~blue119/zim/pyzim into lp:~jaap.karssenberg/zim/pyzim

Proposed by YPWang
Status: Merged
Merged at revision: 522
Proposed branch: lp:~blue119/zim/pyzim
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 185 lines (+167/-0)
3 files modified
data/manual/Plugins/Ditaa_Editor.txt (+29/-0)
data/manual/Plugins/Ditaa_Editor/ditaa.dia (+9/-0)
zim/plugins/ditaaeditor.py (+129/-0)
To merge this branch: bzr merge lp:~blue119/zim/pyzim
Reviewer Review Type Date Requested Status
Jaap Karssenberg Pending
Review via email: mp+96906@code.launchpad.net

Description of the change

I added a ditaa plugin for pyzim that providing to covert ASCII art to roper bitmap graphics. Could it can merge to ML ? thanks.

To post a comment you must log in.
Revision history for this message
Oliver Joos (oliver-joos) wrote :

Hoi Chris,

Good News für aafigure-User,
bad News für Mitglieder vo lp:aafigure:
http://ditaa.org

+++ Oliver

Am Sonntag, den 11.03.2012, 02:18 +0000 schrieb YPWang:
> YPWang has proposed merging lp:~blue119/zim/pyzim into lp:zim.
>
> Requested reviews:
> Jaap Karssenberg (jaap.karssenberg)
>
> I added a ditaa plugin for pyzim that providing to covert ASCII art to
> roper bitmap graphics. Could it can merge to ML ? thanks.
> --
> https://code.launchpad.net/~blue119/zim/pyzim/+merge/96906

Revision history for this message
Oliver Joos (oliver-joos) wrote :
Download full text (7.0 KiB)

Ooops!! My previous message was mis-addressed!

Here I'd like to add: I am very happy about the new plugin for Ditaa!
I did not know it yet. As a member of team lp:aafigure I planned a
similar plugin for aafigure. Now we'll see if we still do that, or we
try to enhance Ditaa with aafigure features, or both.

Anyway, great that Zim soon is able to render ASCII art!
thanks to blue119!
+++ Oliver

Am Sonntag, den 11.03.2012, 02:18 +0000 schrieb YPWang:
> YPWang has proposed merging lp:~blue119/zim/pyzim into lp:zim.
>
> Requested reviews:
> Jaap Karssenberg (jaap.karssenberg)
>
> For more details, see:
> https://code.launchpad.net/~blue119/zim/pyzim/+merge/96906
>
> I added a ditaa plugin for pyzim that providing to covert ASCII art to roper bitmap graphics. Could it can merge to ML ? thanks.
> Unterschiede zwischen Dateien-Anlage (review-diff.txt)
> === added directory 'data/manual/Plugins/Ditaa_Editor'
> === added file 'data/manual/Plugins/Ditaa_Editor.txt'
> --- data/manual/Plugins/Ditaa_Editor.txt 1970-01-01 00:00:00 +0000
> +++ data/manual/Plugins/Ditaa_Editor.txt 2012-03-11 02:17:18 +0000
> @@ -0,0 +1,29 @@
> +Content-Type: text/x-zim-wiki
> +Wiki-Format: zim 0.4
> +Creation-Date: 2012-03-11T09:47:20+08:00
> +
> +====== Ditaa Editor ======
> +Created Sunday 11 March 2012
> +
> +ditaa is a small command-line utility written in Java, that can convert diagrams drawn using ascii art ('drawings' that contain characters that resemble lines like | / - ), into proper bitmap graphics. This is best illustrated by the following example -- which also illustrates the benefits of using ditaa in comparison to other methods :)
> +
> +===== Example =====
> +'''
> ++--------+ +-------+ +-------+
> +| | --+ ditaa +--> | |
> +| Text | +-------+ |diagram|
> +|Document| |!magic!| | |
> +| {d}| | | | |
> ++---+----+ +-------+ +-------+
> + : ^
> + | Lots of work |
> + +-------------------------+
> +'''
> +
> +
> +After conversion using ditaa, the above file becomes:
> +{{./ditaa.png?type=ditaa}}
> +ditaa interprets ascci art as a series of open and closed shapes, but it also uses special markup syntax to increase the possibilities of shapes and symbols that can be rendered.
> +ditaa is open source and free software (free as in free speech), since it is released under the GPL license.
> +
> +See http://ditaa.sourceforge.net/ for more information about gnuplot
>
> === added file 'data/manual/Plugins/Ditaa_Editor/ditaa.dia'
> --- data/manual/Plugins/Ditaa_Editor/ditaa.dia 1970-01-01 00:00:00 +0000
> +++ data/manual/Plugins/Ditaa_Editor/ditaa.dia 2012-03-11 02:17:18 +0000
> @@ -0,0 +1,9 @@
> + +--------+ +-------+ +-------+
> + | | --+ ditaa +--> | |
> + | Text | +-------+ |diagram|
> + |Document| |!magic!| | |
> + | {d}| | | | |
> + +---+----+ +-------+ +-------+
> + : ^
> + | Lots of work |
> + +-------------------------+
> \ No newline at end of file
>
> === added file 'data/manual/Plugins/Ditaa_Editor/ditaa.png'
> B...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/manual/Plugins/Ditaa_Editor'
2=== added file 'data/manual/Plugins/Ditaa_Editor.txt'
3--- data/manual/Plugins/Ditaa_Editor.txt 1970-01-01 00:00:00 +0000
4+++ data/manual/Plugins/Ditaa_Editor.txt 2012-03-11 02:17:18 +0000
5@@ -0,0 +1,29 @@
6+Content-Type: text/x-zim-wiki
7+Wiki-Format: zim 0.4
8+Creation-Date: 2012-03-11T09:47:20+08:00
9+
10+====== Ditaa Editor ======
11+Created Sunday 11 March 2012
12+
13+ditaa is a small command-line utility written in Java, that can convert diagrams drawn using ascii art ('drawings' that contain characters that resemble lines like | / - ), into proper bitmap graphics. This is best illustrated by the following example -- which also illustrates the benefits of using ditaa in comparison to other methods :)
14+
15+===== Example =====
16+'''
17++--------+ +-------+ +-------+
18+| | --+ ditaa +--> | |
19+| Text | +-------+ |diagram|
20+|Document| |!magic!| | |
21+| {d}| | | | |
22++---+----+ +-------+ +-------+
23+ : ^
24+ | Lots of work |
25+ +-------------------------+
26+'''
27+
28+
29+After conversion using ditaa, the above file becomes:
30+{{./ditaa.png?type=ditaa}}
31+ditaa interprets ascci art as a series of open and closed shapes, but it also uses special markup syntax to increase the possibilities of shapes and symbols that can be rendered.
32+ditaa is open source and free software (free as in free speech), since it is released under the GPL license.
33+
34+See http://ditaa.sourceforge.net/ for more information about gnuplot
35
36=== added file 'data/manual/Plugins/Ditaa_Editor/ditaa.dia'
37--- data/manual/Plugins/Ditaa_Editor/ditaa.dia 1970-01-01 00:00:00 +0000
38+++ data/manual/Plugins/Ditaa_Editor/ditaa.dia 2012-03-11 02:17:18 +0000
39@@ -0,0 +1,9 @@
40+ +--------+ +-------+ +-------+
41+ | | --+ ditaa +--> | |
42+ | Text | +-------+ |diagram|
43+ |Document| |!magic!| | |
44+ | {d}| | | | |
45+ +---+----+ +-------+ +-------+
46+ : ^
47+ | Lots of work |
48+ +-------------------------+
49\ No newline at end of file
50
51=== added file 'data/manual/Plugins/Ditaa_Editor/ditaa.png'
52Binary files data/manual/Plugins/Ditaa_Editor/ditaa.png 1970-01-01 00:00:00 +0000 and data/manual/Plugins/Ditaa_Editor/ditaa.png 2012-03-11 02:17:18 +0000 differ
53=== added file 'zim/plugins/ditaaeditor.py'
54--- zim/plugins/ditaaeditor.py 1970-01-01 00:00:00 +0000
55+++ zim/plugins/ditaaeditor.py 2012-03-11 02:17:18 +0000
56@@ -0,0 +1,129 @@
57+# -*- coding: utf-8 -*-
58+#
59+# ditaaeditor.py
60+#
61+# This is a plugin for Zim, which allows coverting ASCII art into proper bitmap
62+# graphics.
63+#
64+#
65+# Author: Yao-Po Wang <blue119@gmail.com>
66+# Date: 2012-03-11
67+# Copyright (c) 2012, released under the GNU GPL v2 or higher
68+#
69+#
70+
71+import gtk
72+
73+from zim.fs import File, TmpFile
74+from zim.plugins import PluginClass
75+from zim.config import data_file
76+from zim.applications import Application, ApplicationError
77+from zim.gui.imagegeneratordialog import ImageGeneratorClass, ImageGeneratorDialog
78+from zim.gui.widgets import populate_popup_add_separator
79+
80+# TODO put these commands in preferences
81+dotcmd = ('ditaa')
82+
83+ui_xml = '''
84+<ui>
85+ <menubar name='menubar'>
86+ <menu action='insert_menu'>
87+ <placeholder name='plugin_items'>
88+ <menuitem action='insert_ditaa'/>
89+ </placeholder>
90+ </menu>
91+ </menubar>
92+</ui>
93+'''
94+
95+ui_actions = (
96+ # name, stock id, label, accelerator, tooltip, read only
97+ ('insert_ditaa', None, _('Ditaa...'), '', _('Insert ditaa'), False),
98+ # T: menu item for insert diagram plugin
99+)
100+
101+
102+class InsertDitaaPlugin(PluginClass):
103+
104+ plugin_info = {
105+ 'name': _('Insert Ditaa'), # T: plugin name
106+ 'description': _('''\
107+This plugin provides a diagram editor for zim based on Ditaa.
108+
109+This is a core plugin shipping with zim.
110+'''), # T: plugin description
111+ 'help': ':Plugins:Ditaa Editor',
112+ 'author': 'Yao-Po Wang',
113+ }
114+
115+ @classmethod
116+ def check_dependencies(klass):
117+ has_dotcmd = Application(dotcmd).tryexec()
118+ return has_dotcmd, [("Ditaa", has_dotcmd, True)]
119+
120+ def __init__(self, ui):
121+ PluginClass.__init__(self, ui)
122+ if self.ui.ui_type == 'gtk':
123+ self.ui.add_actions(ui_actions, self)
124+ self.ui.add_ui(ui_xml, self)
125+ self.register_image_generator_plugin('diagram')
126+
127+ def insert_ditaa(self):
128+ dialog = InsertDitaaDialog.unique(self, self.ui)
129+ dialog.show_all()
130+
131+ def edit_object(self, buffer, iter, image):
132+ dialog = InsertDitaaDialog(self.ui, image=image)
133+ dialog.show_all()
134+
135+ def do_populate_popup(self, menu, buffer, iter, image):
136+ populate_popup_add_separator(prepend=True)
137+
138+ item = gtk.MenuItem(_('_Edit Ditaa')) # T: menu item in context menu
139+ item.connect('activate',
140+ lambda o: self.edit_object(buffer, iter, image))
141+ menu.prepend(item)
142+
143+
144+
145+class InsertDitaaDialog(ImageGeneratorDialog):
146+
147+ def __init__(self, ui, image=None):
148+ generator = DitaaGenerator()
149+ ImageGeneratorDialog.__init__(self, ui, _('Insert Ditaa'), # T: dialog title
150+ generator, image, help=':Plugins:Ditaa Editor' )
151+
152+
153+class DitaaGenerator(ImageGeneratorClass):
154+
155+ uses_log_file = False
156+
157+ type = 'ditaa'
158+ scriptname = 'ditaa.dia'
159+ imagename = 'ditaa.png'
160+
161+ def __init__(self):
162+ self.dotfile = TmpFile(self.scriptname)
163+ self.dotfile.touch()
164+ self.pngfile = File(self.dotfile.path[:-4] + '.png') # len('.dot') == 4
165+
166+ def generate_image(self, text):
167+ if isinstance(text, basestring):
168+ text = text.splitlines(True)
169+
170+ # Write to tmp file
171+ self.dotfile.writelines(text)
172+
173+ # Call GraphViz
174+ try:
175+ dot = Application(dotcmd)
176+ dot.run((self.dotfile, '-o', self.pngfile))
177+ except ApplicationError:
178+ return None, None # Sorry, no log
179+ else:
180+ return self.pngfile, None
181+
182+ def cleanup(self):
183+ self.dotfile.remove()
184+ self.pngfile.remove()
185+