Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
QHyodaX11Mathematica.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7//#include <QHyoda.h>
8#include <unistd.h>
9#include <QHyodaX11Mathematica.h>
10
11
12// ****************************************************************************
13// * QHyodaX11Mathematica
14// ****************************************************************************
15QHyodaX11Mathematica::QHyodaX11Mathematica(QWidget *tabWidgetParent,
16 QFileInfo fInfo):
17 QHyodaX11(tabWidgetParent,fInfo.fileName()),
18 fileInfo(QFileInfo(fInfo)),
19 cmdMathematica(QString("xterm")),
20 //cmdMathematica(QString("mathematica")),
21 argsMathematica(QStringList()),
22 cmdXwininfo(QString("xwininfo")),
23 argsXwininfo(QStringList()),
24 winId(0)
25{
26 //qDebug() << "␛[1;36m[QHyodaX11Mathematica] NEW␛[0m";
27 argsMathematica<< "-T" << "xtermMath";
28 //argsMathematica << "/tmp/110308-Laplace.nb";
29 //<< "--singlelaunch" << fInfo.absoluteFilePath();
30 argsXwininfo<< "-name" << "xtermMath";
31 //argsXwininfo<< "-name" << fileInfo.fileName().append(" - Wolfram Mathematica 10.0");
32 //argsXwininfo << "-name" << "/tmp/110308-Laplace.nb - Wolfram Mathematica 10.0";
33 qDebug() << "␛[1;36m[QHyodaX11Mathematica] "<<cmdMathematica << argsMathematica<<"␛[0m";
34 qDebug() << "␛[1;36m[QHyodaX11Mathematica] "<<cmdXwininfo << argsXwininfo<<"␛[0m";
35
36 // Process Mathematica
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");
44
45 // Process xwin pour récupérer l'ID de la fenêtre
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!");
52
53 layout->addWidget(this);
54}
55
56// ****************************************************************************
57// * ~QHyodaX11Mathematica
58// * pgrep -u camierjs -P 15507 -l '.*'
59// * pkill -SIGKILL 'Math.*'
60// ****************************************************************************
61QHyodaX11Mathematica::~QHyodaX11Mathematica(void){
62 qDebug() << "␛[1;36m~QHyodaX11Mathematica"<<"␛[0m";
63 qDebug()<< "␛[1;36m~QHyodaX11Mathematica clossing X11Process x"<<X11Process.count()<<"␛[0m";
64 {
65 QProcess pkill(this);
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!");
72 pkill.close();
73 if (pkill.waitForFinished())
74 qFatal("pkill could not be closed!");
75 }
76 foreach(QProcess *prcs, X11Process){
77 qDebug()<< "␛[1;36m~QHyodaX11Mathematica clossing "<<prcs<<"␛[0m";
78 prcs->close();
79 if (prcs->waitForFinished()) qFatal("A process could not be closed!");
80 }
81}
82
83// ****************************************************************************
84// * embedIsEmbedded
85// ****************************************************************************
86void QHyodaX11Mathematica::clientIsEmbedded(){
87 qDebug()<<"␛[1;36m[QHyodaX11Mathematica::clientIsEmbedded]"<<"␛[0m";
88}
89
90// ****************************************************************************
91// * embedClosed
92// ****************************************************************************
93void QHyodaX11Mathematica::clientClosed(){
94 qDebug() << "␛[1;36m[QHyodaX11Mathematica::embedClosed] Container clientClosed!"<<"␛[0m";
95}
96
97// ****************************************************************************
98// * error
99// ****************************************************************************
100/*void QHyodaX11Mathematica::error(QX11EmbedContainer::Error error){
101 qDebug() << "␛[1;36m[QHyodaX11Mathematica::error] Container error:"<<error<<"␛[0m";
102 }*/
103
104
105// ****************************************************************************
106// * launchMathematicaInWindow
107// ****************************************************************************
108void QHyodaX11Mathematica::launch(QWidget *widget){
109 //tabParent=widget;
110 qDebug() << "␛[1;36m[QHyodaX11Mathematica::launch] Now launching...␛[0m";
111 //X11Container.append(new QHyodaX11Embed(widget, this));
112 //splitter->addWidget(this);
113
114
115
116 qDebug() << "␛[1;36m[QHyodaX11Mathematica::launch] Launched!␛[0m";
117
118 //qDebug() << "␛[1;36m[QHyodaX11Mathematica::launch] Launched, waitting for winId!␛[0m";
119 //while (winId==0) usleep(100);
120 //qDebug() << "␛[1;36m[QHyodaX11Mathematica::launch] Got IT!␛[0m";
121}
122
123
124// ****************************************************************************
125// * mathFinished
126// ****************************************************************************
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";
130 // On enlève le tab s'il existe: on arrive avec le CTRL-Q alors qu'il est deleté!
131 //int idx=tabParent->indexOf(this);
132 //qDebug() << "[QHyodaX11Mathematica] idx="<<idx;
133 //if (idx!=-1) tabParent->removeTab(idx);
134
135 // exitStatus à 0 pour le CTRL-D ou destructeur
136 // exitStatus à 1 depuis la croix
137/* if (exitStatus==0){
138 qDebug() << "[QHyodaX11Mathematica] From CTRL-D ou destructeur!";
139 delete mathematica; mathematica=NULL;
140 delete layout; layout=NULL;
141 delete mathematicaContainer; mathematicaContainer=NULL;
142 }
143 if (exitStatus==1){
144 qDebug() << "[QHyodaX11Mathematica] From X tab!";
145 }
146*/
147}
148
149
150// ****************************************************************************
151// * mathReadyReadStandardOutput
152// ****************************************************************************
153void QHyodaX11Mathematica::mathReadyReadStandardOutput(void){
154 qDebug()<<"␛[1;36mmathReadyReadStandardOutput␛[0m";
155 //qDebug()<<X11Process.last()->readAllStandardOutput();
156}
157
158
159// ****************************************************************************
160// * xwinReadyReadStandardOutput
161// ****************************************************************************
162void QHyodaX11Mathematica::xwinReadyReadStandardOutput(void){
163 qDebug()<<"␛[1;36mxwinReadyReadStandardOutput"<<"␛[0m";
164 const QStringList lines=QString(X11Process.last()->readAllStandardOutput()).split(QRegExp("\\s+"));
165 //foreach(QString line, lines) qDebug()<<line;
166
167 // Si on a déjà récupéré l'id de la fenêtre, il n'y a plus rien à faire
168 if (winId!=0) {
169 qDebug()<<"␛[1;36m[xwinReadyReadStandardOutput] winId!=0, returning!"<<"␛[0m";
170 return;
171 }
172
173 // On scrute le retour pour voir si l'on peut récupérer l'id
174 if (lines.at(4).startsWith("0x")){
175 bool ok;
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");
179
180 QWindow *math_win=QWindow::fromWinId(winId);
181 QWidget *container=QWidget::createWindowContainer(math_win);//,this,Qt::FramelessWindowHint);
182 //math_win->setParent(tabParent->windowHandle());
183 //math_win->setFlags(Qt::FramelessWindowHint);
184 layout->addWidget(container);
185 //show();
186 //math_win->setParent(parentWidget->windowHandle());
187 //layout->addWidget(container);
188 return;
189 }
190
191 // Sinon, on ferme pour recommencer
192 X11Process.last()->close();
193 if (X11Process.last()->waitForFinished()) qFatal("xwininfo NOT closed!");
194 usleep(100ul);
195 X11Process.last()->start(cmdXwininfo, argsXwininfo);
196 if (!X11Process.last()->waitForStarted())
197 qFatal("QHyodaX11Mathematica::xwininfo NOT started!");
198}
199