9#include <QHyodaX11Mathematica.h>
15QHyodaX11Mathematica::QHyodaX11Mathematica(QWidget *tabWidgetParent,
17 QHyodaX11(tabWidgetParent,fInfo.fileName()),
18 fileInfo(QFileInfo(fInfo)),
19 cmdMathematica(QString(
"xterm")),
21 argsMathematica(QStringList()),
22 cmdXwininfo(QString(
"xwininfo")),
23 argsXwininfo(QStringList()),
27 argsMathematica<<
"-T" <<
"xtermMath";
30 argsXwininfo<<
"-name" <<
"xtermMath";
33 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica] "<<cmdMathematica << argsMathematica<<
"␛[0m";
34 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica] "<<cmdXwininfo << argsXwininfo<<
"␛[0m";
37 X11Process.append(
new QProcess());
38 X11Process.last()->setProcessChannelMode(QProcess::MergedChannels);
39 connect(X11Process.last(),SIGNAL(finished(
int,QProcess::ExitStatus)),
this,SLOT(mathFinished(
int,QProcess::ExitStatus)));
40 connect(X11Process.last(),SIGNAL(readyReadStandardOutput()),
this,SLOT(mathReadyReadStandardOutput()));
41 X11Process.last()->start(cmdMathematica, argsMathematica);
42 if (!X11Process.last()->waitForStarted())
43 qFatal(
"␛[1;36mQHyodaX11Mathematica::mathematica NOT started!␛[0m");
46 X11Process.append(
new QProcess());
47 X11Process.last()->setProcessChannelMode(QProcess::MergedChannels);
48 connect(X11Process.last(),SIGNAL(readyReadStandardOutput()),
this,SLOT(xwinReadyReadStandardOutput()));
49 X11Process.last()->start(cmdXwininfo, argsXwininfo);
50 if (!X11Process.last()->waitForStarted())
51 qFatal(
"QHyodaX11Mathematica::xlsclients NOT started!");
53 layout->addWidget(
this);
61QHyodaX11Mathematica::~QHyodaX11Mathematica(
void){
62 qDebug() <<
"␛[1;36m~QHyodaX11Mathematica"<<
"␛[0m";
63 qDebug()<<
"␛[1;36m~QHyodaX11Mathematica clossing X11Process x"<<X11Process.count()<<
"␛[0m";
66 QString pkill_cmd(
"/usr/bin/pkill");
67 QStringList pkill_args=QStringList()<<
"-SIGKILL" <<
"'Math.*'";
68 qDebug()<<pkill_cmd<<pkill_args;
69 pkill.start(pkill_cmd, pkill_args);
70 if (!pkill.waitForStarted())
71 qFatal(
"QHyodaX11Mathematica::mathFinished pkill not started!");
73 if (pkill.waitForFinished())
74 qFatal(
"pkill could not be closed!");
76 foreach(QProcess *prcs, X11Process){
77 qDebug()<<
"␛[1;36m~QHyodaX11Mathematica clossing "<<prcs<<
"␛[0m";
79 if (prcs->waitForFinished()) qFatal(
"A process could not be closed!");
86void QHyodaX11Mathematica::clientIsEmbedded(){
87 qDebug()<<
"␛[1;36m[QHyodaX11Mathematica::clientIsEmbedded]"<<
"␛[0m";
93void QHyodaX11Mathematica::clientClosed(){
94 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica::embedClosed] Container clientClosed!"<<
"␛[0m";
108void QHyodaX11Mathematica::launch(QWidget *widget){
110 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica::launch] Now launching...␛[0m";
116 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica::launch] Launched!␛[0m";
127void QHyodaX11Mathematica::mathFinished(
int exitCode,
128 QProcess::ExitStatus exitStatus){
129 qDebug() <<
"␛[1;36m[QHyodaX11Mathematica::mathFinished] mathematica has finished with exitCode="<<exitCode<<
", and exitStatus="<<exitStatus<<
"␛[0m";
153void QHyodaX11Mathematica::mathReadyReadStandardOutput(
void){
154 qDebug()<<
"␛[1;36mmathReadyReadStandardOutput␛[0m";
162void QHyodaX11Mathematica::xwinReadyReadStandardOutput(
void){
163 qDebug()<<
"␛[1;36mxwinReadyReadStandardOutput"<<
"␛[0m";
164 const QStringList lines=QString(X11Process.last()->readAllStandardOutput()).split(QRegExp(
"\\s+"));
169 qDebug()<<
"␛[1;36m[xwinReadyReadStandardOutput] winId!=0, returning!"<<
"␛[0m";
174 if (lines.at(4).startsWith(
"0x")){
176 winId = lines.at(4).toLong(&ok, 16);
177 qDebug()<<
"␛[1;36m[xwinReadyReadStandardOutput] winId="<<winId<<
"␛[0m";
178 if (!ok) qFatal(
"Could not play with WinID");
180 QWindow *math_win=QWindow::fromWinId(winId);
181 QWidget *container=QWidget::createWindowContainer(math_win);
184 layout->addWidget(container);
192 X11Process.last()->close();
193 if (X11Process.last()->waitForFinished()) qFatal(
"xwininfo NOT closed!");
195 X11Process.last()->start(cmdXwininfo, argsXwininfo);
196 if (!X11Process.last()->waitForStarted())
197 qFatal(
"QHyodaX11Mathematica::xwininfo NOT started!");