Verified Commit 57c9b60e authored by ita1024's avatar ita1024

Improve document creation from the command-line

parent 9027ef44
Semantik 1.0.6
--------------
* Improve the document export from the command-line
Semantik 1.0.5
--------------
* Highlight code snippets in beamer presentations/pdflatex using Minted
......
......@@ -1122,19 +1122,20 @@ int sem_mediator::num_children(int i_iParent)
return l_iCnt;
}
void sem_mediator::generate_docs(const QString &i_oFile, const QString &i_sDirName, const QString &i_sLocation)
int sem_mediator::generate_docs(const QString &i_oFile, const QString &i_sDirName, const QString &i_sLocation)
{
if (choose_root() == NO_ITEM)
{
//qDebug()<<"root is -1";
return;
qDebug()<<"Missing root item";
emit sig_message(trUtf8("Code generation failed: no root item"), 5000);
return 21;
}
QFile l_o2(i_oFile);
if (!l_o2.open(QIODevice::ReadOnly))
{
emit sig_message(trUtf8("Code generation failed: missing file %1").arg(i_oFile), 5000);
return;
return 22;
}
QByteArray l_oBa = l_o2.readAll();
......@@ -1168,17 +1169,18 @@ void sem_mediator::generate_docs(const QString &i_oFile, const QString &i_sDirNa
if (!init_py())
{
emit sig_message(trUtf8("Missing bindings for opening files"), 5000);
return;
return 23;
}
int ret = PyRun_SimpleString(l_oBa.constData());
if (ret != 0)
{
emit sig_message(trUtf8("Document generation failed, check the output folder"), 50000);
return;
return 24;
}
emit sig_message(trUtf8("Document generation completed successfully"), 5000);
emit sig_preview();
return 0;
}
int sem_mediator::choose_root()
......
......@@ -194,7 +194,7 @@ class sem_mediator: public QObject
bool save_and_load_picture(const QUrl& i_sPath, int id);
bool m_bIsDiagram;
void generate_docs(const QString &i_oFile, const QString &i_sName, const QString &i_sLocation);
int generate_docs(const QString &i_oFile, const QString &i_sName, const QString &i_sLocation);
int m_iTimerValue;
int parent_of(int i_iId);
......
......@@ -1636,10 +1636,9 @@ int canvas_view::batch_print_map(const QUrl& i_oUrl, QPair<int, int> & p) {
l_oGenerator.setFileName(url);
l_oGenerator.setSize(QSize(l_oR.width(), l_oR.height()));
l_oGenerator.setViewBox(l_oR);
l_oGenerator.setResolution(QApplication::desktop()->physicalDpiX());
l_oGenerator.setResolution(96);
l_oGenerator.setTitle(trUtf8("Semantik map"));
QPainter l_oP;
l_oP.begin(&l_oGenerator);
l_oP.setRenderHints(QPainter::Antialiasing);
......
......@@ -603,7 +603,7 @@ void box_view::notify_export_item(int id)
l_oGenerator.setFileName(QString(m_oMediator->m_sTempDir + QString("/") + QString("diag-%1.svg")).arg(QString::number(m_iId)));
l_oGenerator.setSize(QSize(l_oR.width(), l_oR.height()));
l_oGenerator.setViewBox(l_oR);
l_oGenerator.setResolution(QApplication::desktop()->physicalDpiX());
l_oGenerator.setResolution(96);
l_oGenerator.setTitle(trUtf8("Semantik diagram"));
QPainter l_oSvg;
......@@ -1946,7 +1946,7 @@ int box_view::batch_print_map(const QUrl& i_oUrl, QPair<int, int> & p)
l_oGenerator.setSize(QSize(l_oR.width(), l_oR.height()));
l_oGenerator.setViewBox(l_oR);
l_oGenerator.setTitle(trUtf8("Semantik diagram"));
l_oGenerator.setResolution(QApplication::desktop()->physicalDpiX());
l_oGenerator.setResolution(96);
QPainter l_oP;
l_oP.begin(&l_oGenerator);
......
......@@ -7,6 +7,8 @@
#include <QCommandLineParser>
#include "con.h"
#include "semantik.h"
#include "sem_mediator.h"
#include "sembind.h"
#include <stdlib.h>
#include <iostream>
......@@ -29,6 +31,8 @@ int main(int i_iArgc, char **i_iArgv)
KCmdLineOptions options;
options.add("+[url]", ki18n("A file to open on startup"));
options.add("o <file>", ki18n("Batch export as svg/pdf/png"));
options.add("d <folder>", ki18n("Batch document creation into the given folder (absolute path)"));
options.add("t <type>", ki18n("Batch document creation template pdflatex/beamer/html/s5/odp/odt"));
K4AboutData l_o("semantik", 0, ki18n("Semantik"), version, ki18n(description),
K4AboutData::License_GPL_V3, ki18n("(C) 2007-2018 Thomas Nagy"), KLocalizedString());
l_o.setBugAddress("https://gitlab.com/ita1024/semantik/issues");
......@@ -43,21 +47,65 @@ int main(int i_iArgc, char **i_iArgv)
semantik_win *l_oMainWin = new semantik_win;
const KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (!args->getOption("o").isEmpty()) {
if (!args->getOption("o").isEmpty())
{
if (args->count()) {
if (args->url(0).isEmpty()) {
qDebug()<<"a file requires a url";
qDebug()<<"Image export requires an input document (url)";
return 1;
} else {
QUrl l_oUrl(args->getOption("o"));
if (!l_oUrl.isValid()) return 2;
QString l_o = args->getOption("o");
if (!QDir::isAbsolutePath(l_o))
{
l_o = QDir::currentPath() + "/" + l_o;
}
l_oMainWin->slot_recent(args->url(0));
QPair<int, int> p;
return l_oMainWin->print_to_file(l_oUrl, p);
return l_oMainWin->print_to_file(l_o, p);
}
}
} else {
}
else if (!args->getOption("d").isEmpty() && !args->getOption("t").isEmpty())
{
QUrl l_oInput = args->url(0);
if (!l_oInput.isValid())
{
qDebug()<<"Batch document export requires an input document (url)";
return 1;
}
l_oMainWin->slot_recent(args->url(0));
QString l_oTemplate = QString("%1/%2.sem.py").arg(bind_node::get_var(notr("template_dir")), args->getOption("t"));
if (!QFile::exists(l_oTemplate))
{
qDebug()<<"Document export requires a readable input template"<<l_oTemplate;
return 2;
}
QDir l_oDir = QDir(args->getOption("d"));
if (!l_oDir.isAbsolute())
{
qDebug()<<"Document export requires an absolute path for the target folder";
return 3;
}
QString l_oTargetName = l_oDir.dirName();
l_oDir.cdUp();
QString l_oBaseFolder = l_oDir.absolutePath();
// "/home/user/" "tc_infra" "Beamer presentation"
// "/usr/share/semantik/templates/beamer.sem.py" "tc_infra" "/home/user/"
/*l_oMainWin->m_oMediator->m_sOutDir = l_oGen.m_oLocation->text();
l_oMainWin->m_oMediator->m_sOutProject = l_oGen.m_oName->text();
--l_oMainWin->m_oMediator->m_sOutTemplate = l_oGen.m_sShortName;*/
l_oMainWin->m_oMediator->m_sOutDir = l_oBaseFolder;
l_oMainWin->m_oMediator->m_sOutProject = l_oTargetName;
return l_oMainWin->m_oMediator->generate_docs(l_oTemplate, l_oTargetName, l_oBaseFolder);
}
else
{
l_oMainWin->show();
if (args->count() && !args->url(0).isEmpty()) {
l_oMainWin->slot_recent(args->url(0));
......
......@@ -2,6 +2,7 @@
#include <QtGui>
#include <QFile>
# include <QDir>
#include <QTextBrowser>
#include <QProgressDialog>
#include <KDE/KStatusBar>
......@@ -391,7 +392,7 @@ void semantik_win::read_config()
move(l_oConfig.readEntry(notr("winpos"), QPoint(0, 0)));
m_oCanvas->setBackgroundBrush(QColor(l_oConfig.readEntry(notr("bgcolor"), notr("#FFFDE8"))));
m_oMediator->m_sOutDir = l_oConfig.readEntry(notr("outdir"), notr("/tmp/"));
m_oMediator->m_sOutDir = l_oConfig.readEntry(notr("outdir"), QDir::homePath());
bind_node::set_var(notr("outdir"), m_oMediator->m_sOutDir);
QString l_oGuidString = l_oConfig.readEntry(notr("guid"));
......
......@@ -204,19 +204,22 @@ def print_figure_slides(node, recurse=False):
print_figure_slides(node.child_num(i))
#print_figure_slides(root, recurse=False)
# 0. all nodes result in some text being output
# 1. unless explicitly stated, figures only result
# 2. top-level nodes always make a section
def print_nodes(node, niv):
num = node.child_count()
for i in range(num):
subtree = node.child_num(i)
#print_nodes(node.child_num(i), niv+1)
title = tex_convert(subtree.get_val('summary'))
sm = tex_convert(subtree.get_val('summary'))
num = subtree.child_count()
if niv == 0 and num >= 1:
out('\\section{%s}\n' % sm)
elif niv == 1 and num >= 1:
out('\\subsection{%s}\n' % sm)
if niv == 0:
out('%% %s\n' % ('=' * 79))
out('\\section{%s}\n' % title)
#elif niv == 1 and num >= 1:
# out('\\subsection{%s}\n' % title)
if subtree.child_count() >= 0:
if int(subtree.get_val('tree_size')) < 16:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment