diff --git a/files/ZAZLaTex2SVG_v0.2.0.oxt b/files/ZAZLaTex2SVG_v0.2.0.oxt index 5c35328..68ed380 100644 Binary files a/files/ZAZLaTex2SVG_v0.2.0.oxt and b/files/ZAZLaTex2SVG_v0.2.0.oxt differ diff --git a/source/ZAZLaTex2SVG.py b/source/ZAZLaTex2SVG.py index 462ab86..5f67048 100644 --- a/source/ZAZLaTex2SVG.py +++ b/source/ZAZLaTex2SVG.py @@ -10,50 +10,7 @@ ID_EXTENSION = 'net.elmau.zaz.latex2svg' SERVICE = ('com.sun.star.task.Job',) -class Controllers(object): - - def __init__(self, dlg): - self.d = dlg - self._path = '' - - def cmd_close_action(self, event): - self.d.close() - return - - def cmd_preview_action(self, event): - code = self.d.text.value - if not code: - msg = _('Write some code') - app.errorbox(msg) - return - - self._path = _latex_to_svg(code) - self.d.image.url = self._path - return - - def cmd_insert_action(self, event): - if not self._path: - msg = _('First, generate preview') - app.errorbox(msg) - return - - attr = {} - sel = app.selection - if hasattr(sel, 'anchor'): - attr = sel.size - anchor = sel.anchor - anchor.dp.remove(sel) - sel = anchor - - image = sel.insert_image(self._path, attr) - image.description = self.d.text.value - self.d.close() - return - - - class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): - NAME = 'temp' def __init__(self, ctx): self.ctx = ctx @@ -63,97 +20,6 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): main.run(args, __file__) return - def _dlg(self): - dlg = self._create_dialog() - sel = app.selection - if hasattr(sel, 'description'): - dlg.text.value = sel.description - dlg.open() - return - - def _create_dialog(self): - args = { - 'Name': 'dialog', - 'Title': TITLE, - 'Width': 270, - 'Height': 250, - } - dlg = app.create_dialog(args) - dlg.id = ID_EXTENSION - dlg.events = Controllers - - args = { - 'Type': 'Label', - 'Name': 'lbl_code', - 'Label': _('Latex code'), - 'Width': 70, - 'Height': 10, - 'X': 10, - 'Y': 5, - 'VerticalAlign': 1, - } - dlg.add_control(args) - - args = { - 'Type': 'Text', - 'Name': 'text', - 'Width': 250, - 'Height': 75, - 'MultiLine': True, - 'VScroll': True, - } - dlg.add_control(args) - - args = { - 'Type': 'Button', - 'Name': 'cmd_preview', - 'Label': _('Preview'), - 'Width': 70, - 'Height': 15, - 'ImageURL': 'view.png', - 'ImagePosition': 1, - } - dlg.add_control(args) - - args = { - 'Type': 'Image', - 'Name': 'image', - 'Width': 250, - 'Height': 100, - } - dlg.add_control(args) - - args = { - 'Type': 'Button', - 'Name': 'cmd_insert', - 'Label': _('Insert'), - 'Width': 70, - 'Height': 15, - 'ImageURL': 'insert.png', - 'ImagePosition': 1, - } - dlg.add_control(args) - args = { - 'Type': 'Button', - 'Name': 'cmd_close', - 'Label': _('Close'), - 'Width': 70, - 'Height': 15, - 'ImageURL': 'close.png', - 'ImagePosition': 1, - } - dlg.add_control(args) - - dlg.text.move(dlg.lbl_code) - dlg.cmd_preview.move(dlg.text, center=True) - dlg.image.move(dlg.cmd_preview, center=True) - dlg.cmd_insert.move(dlg.image) - dlg.cmd_close.move(dlg.image) - controls = (dlg.cmd_insert, dlg.cmd_close) - dlg.center(controls) - - return dlg - g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(ZAZLaTex2SVG, ID_EXTENSION, SERVICE) diff --git a/source/pythonpath/main.py b/source/pythonpath/main.py index d84e85a..2bf31b1 100644 --- a/source/pythonpath/main.py +++ b/source/pythonpath/main.py @@ -6,7 +6,6 @@ import easymacro as app ID_EXTENSION = '' TITLE = 'ZAZ Latex2SVG' _ = None - TEMPLATE = """\documentclass{{article}} \\usepackage[a5paper, landscape]{{geometry}} \\usepackage{{xcolor}} @@ -24,6 +23,47 @@ TEMPLATE = """\documentclass{{article}} """ +class Controllers(object): + + def __init__(self, dlg): + self.d = dlg + self._path = '' + + def cmd_close_action(self, event): + self.d.close() + return + + def cmd_preview_action(self, event): + code = self.d.text.value + if not code: + msg = _('Write some code') + app.errorbox(msg) + return + + self._path = _latex_to_svg(code) + self.d.image.url = self._path + return + + def cmd_insert_action(self, event): + if not self._path: + msg = _('First, generate preview') + app.errorbox(msg) + return + + attr = {} + sel = app.selection + if hasattr(sel, 'anchor'): + attr = sel.size + anchor = sel.anchor + anchor.dp.remove(sel) + sel = anchor + + image = sel.insert_image(self._path, attr) + image.description = self.d.text.value + self.d.close() + return + + def validate_app(): msg1 = _('Not found') msg2 = _('Found') @@ -87,8 +127,96 @@ def from_selection(): return +def _create_dialog(): + args = { + 'Name': 'dialog', + 'Title': TITLE, + 'Width': 270, + 'Height': 250, + } + dlg = app.create_dialog(args) + dlg.id = ID_EXTENSION + dlg.events = Controllers + + args = { + 'Type': 'Label', + 'Name': 'lbl_code', + 'Label': _('Latex code'), + 'Width': 70, + 'Height': 10, + 'X': 10, + 'Y': 5, + 'VerticalAlign': 1, + } + dlg.add_control(args) + + args = { + 'Type': 'Text', + 'Name': 'text', + 'Width': 250, + 'Height': 75, + 'MultiLine': True, + 'VScroll': True, + } + dlg.add_control(args) + + args = { + 'Type': 'Button', + 'Name': 'cmd_preview', + 'Label': _('Preview'), + 'Width': 70, + 'Height': 15, + 'ImageURL': 'view.png', + 'ImagePosition': 1, + } + dlg.add_control(args) + + args = { + 'Type': 'Image', + 'Name': 'image', + 'Width': 250, + 'Height': 100, + } + dlg.add_control(args) + + args = { + 'Type': 'Button', + 'Name': 'cmd_insert', + 'Label': _('Insert'), + 'Width': 70, + 'Height': 15, + 'ImageURL': 'insert.png', + 'ImagePosition': 1, + } + dlg.add_control(args) + args = { + 'Type': 'Button', + 'Name': 'cmd_close', + 'Label': _('Close'), + 'Width': 70, + 'Height': 15, + 'ImageURL': 'close.png', + 'ImagePosition': 1, + } + dlg.add_control(args) + + dlg.text.move(dlg.lbl_code) + dlg.cmd_preview.move(dlg.text, center=True) + dlg.image.move(dlg.cmd_preview, center=True) + dlg.cmd_insert.move(dlg.image) + dlg.cmd_close.move(dlg.image) + controls = (dlg.cmd_insert, dlg.cmd_close) + dlg.center(controls) + + return dlg + + def from_dialog(): - app.debug('From dialog') + dlg = _create_dialog() + sel = app.selection + if hasattr(sel, 'description'): + dlg.text.value = sel.description + dlg.open() return