Insert with dialog
This commit is contained in:
parent
5c1c45b069
commit
412ad7056f
|
@ -42,6 +42,7 @@ sudo apt install texlive-extra-utils
|
||||||
sudo apt install pdf2svg
|
sudo apt install pdf2svg
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
* For OSx
|
* For OSx
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Binary file not shown.
|
@ -19,9 +19,12 @@ TEMPLATE = """\documentclass{{article}}
|
||||||
\\usepackage{{amsmath}}
|
\\usepackage{{amsmath}}
|
||||||
\pagestyle{{empty}}
|
\pagestyle{{empty}}
|
||||||
\\begin{{document}}
|
\\begin{{document}}
|
||||||
|
\\begingroup
|
||||||
|
\huge
|
||||||
|
|
||||||
\[ {} \]
|
\[ {} \]
|
||||||
|
|
||||||
|
\endgroup
|
||||||
\end{{document}}
|
\end{{document}}
|
||||||
"""
|
"""
|
||||||
# ~ TEMPLATE = """\documentclass{{standalone}}
|
# ~ TEMPLATE = """\documentclass{{standalone}}
|
||||||
|
@ -51,19 +54,22 @@ class Controllers(object):
|
||||||
|
|
||||||
def __init__(self, dlg):
|
def __init__(self, dlg):
|
||||||
self.d = dlg
|
self.d = dlg
|
||||||
|
self._path = ''
|
||||||
|
|
||||||
def cmd_close_action(self, event):
|
def cmd_close_action(self, event):
|
||||||
self.d.close()
|
self.d.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@app.catch_exception
|
||||||
def cmd_preview_action(self, event):
|
def cmd_preview_action(self, event):
|
||||||
data = self.d.text.value
|
code = self.d.text.value
|
||||||
if not data:
|
if not code:
|
||||||
msg = _('Write some code')
|
msg = _('Write some code')
|
||||||
app.errorbox(msg)
|
app.errorbox(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
app.msgbox(data)
|
self._path = _latex_to_svg(code)
|
||||||
|
self.d.image.value = self._path
|
||||||
return
|
return
|
||||||
|
|
||||||
def cmd_insert_action(self, event):
|
def cmd_insert_action(self, event):
|
||||||
|
@ -77,10 +83,33 @@ class Controllers(object):
|
||||||
if not app.question(msg):
|
if not app.question(msg):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
app.selection.insert_image(self._path, {})
|
||||||
self.d.close()
|
self.d.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _latex_to_svg(code):
|
||||||
|
NAME = 'temp'
|
||||||
|
data = TEMPLATE.format(code)
|
||||||
|
dt = app.paths.dir_tmp()
|
||||||
|
path_tex = app._P.join(dt.name, f'{NAME}.tex')
|
||||||
|
path_pdf = app._P.join(dt.name, f'{NAME}.pdf')
|
||||||
|
path_svg = app._P.join(app._P.temp_dir, f'{NAME}.svg')
|
||||||
|
|
||||||
|
app.paths.save(path_tex, data)
|
||||||
|
cmd = f'pdflatex --interaction=batchmode -output-directory="{dt.name}" "{path_tex}"'
|
||||||
|
app.run(cmd)
|
||||||
|
cmd = f'pdfcrop "{path_pdf}" "{path_pdf}"'
|
||||||
|
app.run(cmd)
|
||||||
|
cmd = f'pdf2svg "{path_pdf}" "{path_svg}"'
|
||||||
|
app.run(cmd)
|
||||||
|
|
||||||
|
if not app.paths.exists(path_svg):
|
||||||
|
path_svg = ''
|
||||||
|
dt.cleanup()
|
||||||
|
return path_svg
|
||||||
|
|
||||||
|
|
||||||
class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
NAME = 'temp'
|
NAME = 'temp'
|
||||||
_msg1 = _('Not found')
|
_msg1 = _('Not found')
|
||||||
|
@ -122,7 +151,6 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
app.msgbox(msg)
|
app.msgbox(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
@app.catch_exception
|
|
||||||
def _dlg(self):
|
def _dlg(self):
|
||||||
dlg = self._create_dialog()
|
dlg = self._create_dialog()
|
||||||
dlg.open()
|
dlg.open()
|
||||||
|
@ -144,7 +172,7 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
'Name': 'lbl_code',
|
'Name': 'lbl_code',
|
||||||
'Label': _('Latex code'),
|
'Label': _('Latex code'),
|
||||||
'Width': 70,
|
'Width': 70,
|
||||||
'Height': 15,
|
'Height': 10,
|
||||||
'X': 10,
|
'X': 10,
|
||||||
'Y': 5,
|
'Y': 5,
|
||||||
'VerticalAlign': 1,
|
'VerticalAlign': 1,
|
||||||
|
@ -172,6 +200,14 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
}
|
}
|
||||||
dlg.add_control(args)
|
dlg.add_control(args)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'Type': 'Image',
|
||||||
|
'Name': 'image',
|
||||||
|
'Width': 250,
|
||||||
|
'Height': 100,
|
||||||
|
}
|
||||||
|
dlg.add_control(args)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'Type': 'Button',
|
'Type': 'Button',
|
||||||
'Name': 'cmd_insert',
|
'Name': 'cmd_insert',
|
||||||
|
@ -195,8 +231,9 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
|
|
||||||
dlg.text.move(dlg.lbl_code)
|
dlg.text.move(dlg.lbl_code)
|
||||||
dlg.cmd_preview.move(dlg.text, center=True)
|
dlg.cmd_preview.move(dlg.text, center=True)
|
||||||
dlg.cmd_insert.move(dlg.cmd_preview)
|
dlg.image.move(dlg.cmd_preview, center=True)
|
||||||
dlg.cmd_close.move(dlg.cmd_preview)
|
dlg.cmd_insert.move(dlg.image)
|
||||||
|
dlg.cmd_close.move(dlg.image)
|
||||||
controls = (dlg.cmd_insert, dlg.cmd_close)
|
controls = (dlg.cmd_insert, dlg.cmd_close)
|
||||||
dlg.center(controls)
|
dlg.center(controls)
|
||||||
|
|
||||||
|
|
|
@ -2633,6 +2633,24 @@ class UnoText(UnoBaseObject):
|
||||||
self.model.Text = value
|
self.model.Text = value
|
||||||
|
|
||||||
|
|
||||||
|
class UnoImage(UnoBaseObject):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return 'image'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
return self.m.ImageURL
|
||||||
|
@value.setter
|
||||||
|
def value(self, value):
|
||||||
|
self.m.ImageURL = None
|
||||||
|
self.m.ImageURL = _P.to_url(value)
|
||||||
|
|
||||||
|
|
||||||
UNO_CLASSES = {
|
UNO_CLASSES = {
|
||||||
'label': UnoLabel,
|
'label': UnoLabel,
|
||||||
'link': UnoLabelLink,
|
'link': UnoLabelLink,
|
||||||
|
@ -2640,6 +2658,7 @@ UNO_CLASSES = {
|
||||||
'radio': UnoRadio,
|
'radio': UnoRadio,
|
||||||
'check': UnoCheck,
|
'check': UnoCheck,
|
||||||
'text': UnoText,
|
'text': UnoText,
|
||||||
|
'image': UnoImage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2652,13 +2671,13 @@ class LODialog(object):
|
||||||
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
|
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
|
||||||
'check': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
'check': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
||||||
'text': 'com.sun.star.awt.UnoControlEditModel',
|
'text': 'com.sun.star.awt.UnoControlEditModel',
|
||||||
|
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||||
# ~ 'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
# ~ 'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
||||||
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||||
# ~ 'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
# ~ 'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||||
# ~ 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
# ~ 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
||||||
# ~ 'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
# ~ 'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
||||||
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||||
# ~ 'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
|
||||||
# ~ 'pages': 'com.sun.star.awt.UnoMultiPageModel',
|
# ~ 'pages': 'com.sun.star.awt.UnoMultiPageModel',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue