Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tikz_editor/controllers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _createActions(self):
self.actions[actions.SAVE] = ActionFactory.createAction(self, "Save", "Save the document", QKeySequence.Save, self.save)
self.actions[actions.SAVE_ALL] = ActionFactory.createAction(self, "Save All", "Save all documents", None, self.saveAll)
self.actions[actions.SAVE_AS] = ActionFactory.createAction(self, "Save As...", "Save the document as...", QKeySequence.SaveAs, self.saveAs)
self.actions[actions.EXPORT] = ActionFactory.createAction(self, "Export", "Export document as PDF", None, self.export)
self.actions[actions.UNDO] = ActionFactory.createAction(self, "Undo", "Undo last action", QKeySequence.Undo, self.undo)

def _createMenuBar(self):
Expand All @@ -84,6 +85,7 @@ def _createFileMenu(self):
self.actions[actions.SAVE],
self.actions[actions.SAVE_AS],
self.actions[actions.SAVE_ALL],
self.actions[actions.EXPORT],
None,
self.actions[actions.PREVIEW],
None,
Expand Down Expand Up @@ -274,6 +276,15 @@ def saveAs(self):
except Exception as e:
Dialogs.showError(e)

def export(self):
try:
if self.documentHasFocus():
self.focused_document.export()
else:
QApplication.beep()
except Exception as e:
Dialogs.showError(e)

def undo(self):
self._doActionOnFocusedWidget("undo")

Expand Down
7 changes: 7 additions & 0 deletions tikz_editor/controllers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from PyQt5.QtCore import *

from tikz_editor.tools import File
from tikz_editor.tools import TemporaryDirectory
from tikz_editor.tools.latex2image import Converter


class DocumentController(QObject):
Expand Down Expand Up @@ -84,6 +86,11 @@ def saveAs(self):
self.model.file_path = file_path
self.model.save()

def export(self):
file_path = File.showSaveFileDialog(self.view, "%s.pdf" % self.model.title)
if file_path:
self.model.export(file_path, self.preview_controller.latex2image_converter)

def _getDocumentFileName(self):
file_name = self.model.file_path
if not file_name:
Expand Down
1 change: 1 addition & 0 deletions tikz_editor/globals/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
SAVE = "save"
SAVE_ALL = "saveAll"
SAVE_AS = "saveAs"
EXPORT = "export"
SHOW_ERRORS = "showErrors"
SHOW_LOGS = "showLogs"
SHOW_PREAMBLE = "showPreamble"
Expand Down
16 changes: 16 additions & 0 deletions tikz_editor/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

import shutil

from PyQt5.QtCore import *
from PyQt5.QtGui import *

Expand Down Expand Up @@ -76,6 +78,20 @@ def save(self):
except Exception as e:
raise DocumentError("The document cannot be saved: %s" % str(e))

def export(self, file_path, converter):
"""
To export the document as PDF, the source is converted using the
latex2image converter.
"""
try:
template = Preferences.getPreviewTemplate()
source = documentIO.buildFileContentFromDocument(template, self)
converter.convertLatexToImage(source)
converter.waitForFinished()
shutil.copyfile(converter.pdf_file_path, file_path)
except Exception as e:
raise DocumentError("The document cannot be exported: %s" % str(e))

@property
def file_path(self):
return self._file_path
Expand Down
4 changes: 4 additions & 0 deletions tikz_editor/tools/latex2image/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def _initProcesses(self):
self._convert_process.error.connect(self._pdfToImageConversionError)
self._convert_process.finished.connect(self._pdfToImageConversionFinished)

def waitForFinished(self):
self._latex_process.waitForFinished()
self._convert_process.waitForFinished()

def stopConversion(self):
self._stopping_conversion = True
self._killProcesses()
Expand Down