Merge lp:~alexwolf/stellarium/scripts-output into lp:stellarium
- scripts-output
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 6946 |
Proposed branch: | lp:~alexwolf/stellarium/scripts-output |
Merge into: | lp:stellarium |
Diff against target: |
600 lines (+273/-61) 11 files modified
src/CMakeLists.txt (+2/-0) src/gui/ScriptConsole.cpp (+17/-2) src/gui/ScriptConsole.hpp (+1/-0) src/gui/scriptConsole.ui (+70/-5) src/main.cpp (+11/-0) src/scripting/StelMainScriptAPI.cpp (+59/-52) src/scripting/StelMainScriptAPI.hpp (+4/-0) src/scripting/StelScriptMgr.cpp (+7/-0) src/scripting/StelScriptMgr.hpp (+8/-2) src/scripting/StelScriptOutput.cpp (+44/-0) src/scripting/StelScriptOutput.hpp (+50/-0) |
To merge this branch: | bzr merge lp:~alexwolf/stellarium/scripts-output |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
gzotti | Approve | ||
Fabien Chéreau | Pending | ||
Stellarium | Pending | ||
Review via email: mp+230235@code.launchpad.net |
Commit message
Description of the change
Added new feature to scripting engine: support of output data into a separate file from scripts
Alexander Wolf (alexwolf) wrote : | # |
A long time the only way getting tabulated data from scripts for using outside Stellarium was using debug mode: e.g. core.debug("some text"); Now I introduce second output channel from scripts - core.output("some text");. You can use within scripts core.debug() for debugging messages and core.output() for data.
Typical case for the new feature - getting table coordinates of celestial body as function of time.
gzotti (georg-zotti) wrote : | # |
Sounds good. But can you maybe add a practical example, e.g. scripts/
In the source file I see the output goes into <USERDIR>
Alexander Wolf (alexwolf) wrote : | # |
Just put it into script console and run :)
core.setDate(
core.output(
for(i=0;i<365;i++)
{
data = core.getObjectI
core.output(
core.setDate(
core.wait(0.1);
}
Alexander Wolf (alexwolf) wrote : | # |
Or:
core.setJDay(
core.output(
core.output(
for(i=0;i<500;i++)
{
core.output(
core.setJDay(
core.wait(0.1);
}
Alexander Wolf (alexwolf) wrote : | # |
output file name is hard coded for security reason
gzotti (georg-zotti) wrote : | # |
OK, I get syntax errors in the scripts. Just the one line with "output" works, though, that was the main point.
Another suggestion if creating with filename not possible: As I see it, the file gets reset on every start. Maybe make it configurable to allow appending? This would be useful for intermittent work on long observation lists, ephemerides etc, which one would like to collect for later use. Catastrophic for those users if file gets reset just with a restart of Stellarium.
- 6945. By Alexander Wolf
-
introduced new option - main/use_
separate_ output_ file
Alexander Wolf (alexwolf) wrote : | # |
I introduce new config option - main/use_
By default main/use_
gzotti (georg-zotti) wrote : | # |
OK, also a good solution!
Preview Diff
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2014-07-26 13:16:21 +0000 |
3 | +++ src/CMakeLists.txt 2014-08-12 09:52:27 +0000 |
4 | @@ -252,6 +252,8 @@ |
5 | |
6 | IF(ENABLE_SCRIPTING) |
7 | SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} |
8 | + scripting/StelScriptOutput.hpp |
9 | + scripting/StelScriptOutput.cpp |
10 | scripting/StelScriptMgr.cpp |
11 | scripting/StratoscriptPreprocessor.cpp |
12 | scripting/StelScriptMgr.hpp |
13 | |
14 | === modified file 'src/gui/ScriptConsole.cpp' |
15 | --- src/gui/ScriptConsole.cpp 2014-04-19 12:01:08 +0000 |
16 | +++ src/gui/ScriptConsole.cpp 2014-08-12 09:52:27 +0000 |
17 | @@ -89,6 +89,7 @@ |
18 | connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(quickRun(int))); |
19 | connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped()), this, SLOT(scriptEnded())); |
20 | connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(const QString&)), this, SLOT(appendLogLine(const QString&))); |
21 | + connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptOutput(const QString&)), this, SLOT(appendOutputLine(const QString&))); |
22 | #ifndef ENABLE_STRATOSCRIPT_COMPAT |
23 | ui->preprocessSTSButton->setHidden(true); |
24 | #else |
25 | @@ -140,6 +141,8 @@ |
26 | if (ui->tabs->currentIndex() == 0) |
27 | ui->scriptEdit->clear(); |
28 | else if (ui->tabs->currentIndex() == 1) |
29 | + ui->logBrowser->clear(); |
30 | + else if (ui->tabs->currentIndex() == 2) |
31 | ui->outputBrowser->clear(); |
32 | } |
33 | |
34 | @@ -179,7 +182,7 @@ |
35 | void ScriptConsole::runScript() |
36 | { |
37 | ui->tabs->setCurrentIndex(1); |
38 | - ui->outputBrowser->setHtml(""); |
39 | + ui->logBrowser->setHtml(""); |
40 | QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); |
41 | QString fileName; |
42 | if (file.open()) { |
43 | @@ -221,7 +224,7 @@ |
44 | void ScriptConsole::scriptEnded() |
45 | { |
46 | qDebug() << "ScriptConsole::scriptEnded"; |
47 | - QString html = ui->outputBrowser->toHtml(); |
48 | + QString html = ui->logBrowser->toHtml(); |
49 | appendLogLine(QString("Script finished at %1").arg(QDateTime::currentDateTime().toString())); |
50 | ui->runButton->setEnabled(true); |
51 | ui->stopButton->setEnabled(false); |
52 | @@ -229,6 +232,17 @@ |
53 | |
54 | void ScriptConsole::appendLogLine(const QString& s) |
55 | { |
56 | + QString html = ui->logBrowser->toHtml(); |
57 | + html.replace(QRegExp("^\\s+"), ""); |
58 | + // if (html!="") |
59 | + // html += "<br />"; |
60 | + |
61 | + html += s; |
62 | + ui->logBrowser->setHtml(html); |
63 | +} |
64 | + |
65 | +void ScriptConsole::appendOutputLine(const QString& s) |
66 | +{ |
67 | QString html = ui->outputBrowser->toHtml(); |
68 | html.replace(QRegExp("^\\s+"), ""); |
69 | // if (html!="") |
70 | @@ -238,6 +252,7 @@ |
71 | ui->outputBrowser->setHtml(html); |
72 | } |
73 | |
74 | + |
75 | void ScriptConsole::includeBrowse() |
76 | { |
77 | ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMainView::getInstance(), |
78 | |
79 | === modified file 'src/gui/ScriptConsole.hpp' |
80 | --- src/gui/ScriptConsole.hpp 2012-02-13 18:59:16 +0000 |
81 | +++ src/gui/ScriptConsole.hpp 2014-08-12 09:52:27 +0000 |
82 | @@ -44,6 +44,7 @@ |
83 | void preprocessScript(); |
84 | void scriptEnded(); |
85 | void appendLogLine(const QString& s); |
86 | + void appendOutputLine(const QString& s); |
87 | void includeBrowse(); |
88 | void quickRun(int idx); |
89 | void rowColumnChanged(); |
90 | |
91 | === modified file 'src/gui/scriptConsole.ui' |
92 | --- src/gui/scriptConsole.ui 2012-02-20 10:28:26 +0000 |
93 | +++ src/gui/scriptConsole.ui 2014-08-12 09:52:27 +0000 |
94 | @@ -17,7 +17,16 @@ |
95 | <property name="spacing"> |
96 | <number>0</number> |
97 | </property> |
98 | - <property name="margin"> |
99 | + <property name="leftMargin"> |
100 | + <number>0</number> |
101 | + </property> |
102 | + <property name="topMargin"> |
103 | + <number>0</number> |
104 | + </property> |
105 | + <property name="rightMargin"> |
106 | + <number>0</number> |
107 | + </property> |
108 | + <property name="bottomMargin"> |
109 | <number>0</number> |
110 | </property> |
111 | <item> |
112 | @@ -139,7 +148,16 @@ |
113 | <property name="spacing"> |
114 | <number>0</number> |
115 | </property> |
116 | - <property name="margin"> |
117 | + <property name="leftMargin"> |
118 | + <number>0</number> |
119 | + </property> |
120 | + <property name="topMargin"> |
121 | + <number>0</number> |
122 | + </property> |
123 | + <property name="rightMargin"> |
124 | + <number>0</number> |
125 | + </property> |
126 | + <property name="bottomMargin"> |
127 | <number>0</number> |
128 | </property> |
129 | <item> |
130 | @@ -220,7 +238,7 @@ |
131 | </size> |
132 | </property> |
133 | <property name="toolTip"> |
134 | - <string>clear script</string> |
135 | + <string>clear</string> |
136 | </property> |
137 | <property name="text"> |
138 | <string/> |
139 | @@ -372,7 +390,16 @@ |
140 | <string>Script</string> |
141 | </attribute> |
142 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
143 | - <property name="margin"> |
144 | + <property name="leftMargin"> |
145 | + <number>0</number> |
146 | + </property> |
147 | + <property name="topMargin"> |
148 | + <number>0</number> |
149 | + </property> |
150 | + <property name="rightMargin"> |
151 | + <number>0</number> |
152 | + </property> |
153 | + <property name="bottomMargin"> |
154 | <number>0</number> |
155 | </property> |
156 | <item> |
157 | @@ -396,12 +423,50 @@ |
158 | </item> |
159 | </layout> |
160 | </widget> |
161 | + <widget class="QWidget" name="logTab"> |
162 | + <attribute name="title"> |
163 | + <string>Log</string> |
164 | + </attribute> |
165 | + <layout class="QVBoxLayout" name="verticalLayout_5"> |
166 | + <property name="leftMargin"> |
167 | + <number>0</number> |
168 | + </property> |
169 | + <property name="topMargin"> |
170 | + <number>0</number> |
171 | + </property> |
172 | + <property name="rightMargin"> |
173 | + <number>0</number> |
174 | + </property> |
175 | + <property name="bottomMargin"> |
176 | + <number>0</number> |
177 | + </property> |
178 | + <item> |
179 | + <widget class="QTextBrowser" name="logBrowser"> |
180 | + <property name="font"> |
181 | + <font> |
182 | + <family>DejaVu Sans Mono</family> |
183 | + <pointsize>8</pointsize> |
184 | + </font> |
185 | + </property> |
186 | + </widget> |
187 | + </item> |
188 | + </layout> |
189 | + </widget> |
190 | <widget class="QWidget" name="outputTab"> |
191 | <attribute name="title"> |
192 | <string>Output</string> |
193 | </attribute> |
194 | <layout class="QVBoxLayout" name="verticalLayout_4"> |
195 | - <property name="margin"> |
196 | + <property name="leftMargin"> |
197 | + <number>0</number> |
198 | + </property> |
199 | + <property name="topMargin"> |
200 | + <number>0</number> |
201 | + </property> |
202 | + <property name="rightMargin"> |
203 | + <number>0</number> |
204 | + </property> |
205 | + <property name="bottomMargin"> |
206 | <number>0</number> |
207 | </property> |
208 | <item> |
209 | |
210 | === modified file 'src/main.cpp' |
211 | --- src/main.cpp 2014-08-01 18:48:38 +0000 |
212 | +++ src/main.cpp 2014-08-12 09:52:27 +0000 |
213 | @@ -25,6 +25,9 @@ |
214 | #include "CLIProcessor.hpp" |
215 | #include "StelIniParser.hpp" |
216 | #include "StelUtils.hpp" |
217 | +#ifndef DISABLE_SCRIPTING |
218 | +#include "StelScriptOutput.hpp" |
219 | +#endif |
220 | |
221 | #include <QDebug> |
222 | |
223 | @@ -289,6 +292,14 @@ |
224 | Q_ASSERT(confSettings); |
225 | qDebug() << "Config file is: " << QDir::toNativeSeparators(configFileFullPath); |
226 | |
227 | + #ifndef DISABLE_SCRIPTING |
228 | + QString outputFile = StelFileMgr::getUserDir()+"/output.txt"; |
229 | + if (confSettings->value("main/use_separate_output_file", false).toBool()) |
230 | + outputFile = StelFileMgr::getUserDir()+"/output-"+QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss")+".txt"; |
231 | + StelScriptOutput::init(outputFile); |
232 | + #endif |
233 | + |
234 | + |
235 | // Override config file values from CLI. |
236 | CLIProcessor::parseCLIArgsPostConfig(argList, confSettings); |
237 | |
238 | |
239 | === modified file 'src/scripting/StelMainScriptAPI.cpp' |
240 | --- src/scripting/StelMainScriptAPI.cpp 2014-01-15 07:13:40 +0000 |
241 | +++ src/scripting/StelMainScriptAPI.cpp 2014-08-12 09:52:27 +0000 |
242 | @@ -361,34 +361,34 @@ |
243 | } |
244 | |
245 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
246 | - double ra0, double dec0, |
247 | - double ra1, double dec1, |
248 | - double ra2, double dec2, |
249 | - double ra3, double dec3, |
250 | - double minRes, double maxBright, bool visible) |
251 | + double ra0, double dec0, |
252 | + double ra1, double dec1, |
253 | + double ra2, double dec2, |
254 | + double ra3, double dec3, |
255 | + double minRes, double maxBright, bool visible) |
256 | { |
257 | QString path = "scripts/" + filename; |
258 | emit(requestLoadSkyImage(id, path, ra0, dec0, ra1, dec1, ra2, dec2, ra3, dec3, minRes, maxBright, visible)); |
259 | } |
260 | |
261 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
262 | - const QString& ra0, const QString& dec0, |
263 | - const QString& ra1, const QString& dec1, |
264 | - const QString& ra2, const QString& dec2, |
265 | - const QString& ra3, const QString& dec3, |
266 | - double minRes, double maxBright, bool visible) |
267 | + const QString& ra0, const QString& dec0, |
268 | + const QString& ra1, const QString& dec1, |
269 | + const QString& ra2, const QString& dec2, |
270 | + const QString& ra3, const QString& dec3, |
271 | + double minRes, double maxBright, bool visible) |
272 | { |
273 | loadSkyImage(id, filename, |
274 | - StelUtils::getDecAngle(ra0) *180./M_PI, StelUtils::getDecAngle(dec0)*180./M_PI, |
275 | - StelUtils::getDecAngle(ra1) *180./M_PI, StelUtils::getDecAngle(dec1)*180./M_PI, |
276 | - StelUtils::getDecAngle(ra2) *180./M_PI, StelUtils::getDecAngle(dec2)*180./M_PI, |
277 | - StelUtils::getDecAngle(ra3) *180./M_PI, StelUtils::getDecAngle(dec3)*180./M_PI, |
278 | - minRes, maxBright, visible); |
279 | + StelUtils::getDecAngle(ra0) *180./M_PI, StelUtils::getDecAngle(dec0)*180./M_PI, |
280 | + StelUtils::getDecAngle(ra1) *180./M_PI, StelUtils::getDecAngle(dec1)*180./M_PI, |
281 | + StelUtils::getDecAngle(ra2) *180./M_PI, StelUtils::getDecAngle(dec2)*180./M_PI, |
282 | + StelUtils::getDecAngle(ra3) *180./M_PI, StelUtils::getDecAngle(dec3)*180./M_PI, |
283 | + minRes, maxBright, visible); |
284 | } |
285 | |
286 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
287 | - double ra, double dec, double angSize, double rotation, |
288 | - double minRes, double maxBright, bool visible) |
289 | + double ra, double dec, double angSize, double rotation, |
290 | + double minRes, double maxBright, bool visible) |
291 | { |
292 | Vec3f XYZ; |
293 | static const float RADIUS_NEB = 1.; |
294 | @@ -396,15 +396,15 @@ |
295 | XYZ*=RADIUS_NEB; |
296 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); |
297 | Mat4f matPrecomp = Mat4f::translation(XYZ) * |
298 | - Mat4f::zrotation(ra*M_PI/180.) * |
299 | - Mat4f::yrotation(-dec*M_PI/180.) * |
300 | - Mat4f::xrotation(rotation*M_PI/180.); |
301 | + Mat4f::zrotation(ra*M_PI/180.) * |
302 | + Mat4f::yrotation(-dec*M_PI/180.) * |
303 | + Mat4f::xrotation(rotation*M_PI/180.); |
304 | |
305 | Vec3f corners[4]; |
306 | - corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
307 | - corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
308 | - corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
309 | - corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
310 | + corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
311 | + corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
312 | + corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
313 | + corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
314 | |
315 | // convert back to ra/dec (radians) |
316 | Vec3f cornersRaDec[4]; |
317 | @@ -412,38 +412,40 @@ |
318 | StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]); |
319 | |
320 | loadSkyImage(id, filename, |
321 | - cornersRaDec[0][0]*180./M_PI, cornersRaDec[0][1]*180./M_PI, |
322 | - cornersRaDec[1][0]*180./M_PI, cornersRaDec[1][1]*180./M_PI, |
323 | - cornersRaDec[3][0]*180./M_PI, cornersRaDec[3][1]*180./M_PI, |
324 | - cornersRaDec[2][0]*180./M_PI, cornersRaDec[2][1]*180./M_PI, |
325 | - minRes, maxBright, visible); |
326 | + cornersRaDec[0][0]*180./M_PI, cornersRaDec[0][1]*180./M_PI, |
327 | + cornersRaDec[1][0]*180./M_PI, cornersRaDec[1][1]*180./M_PI, |
328 | + cornersRaDec[3][0]*180./M_PI, cornersRaDec[3][1]*180./M_PI, |
329 | + cornersRaDec[2][0]*180./M_PI, cornersRaDec[2][1]*180./M_PI, |
330 | + minRes, maxBright, visible); |
331 | } |
332 | |
333 | |
334 | |
335 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
336 | - const QString& ra, const QString& dec, double angSize, double rotation, |
337 | - double minRes, double maxBright, bool visible) |
338 | + const QString& ra, const QString& dec, |
339 | + double angSize, double rotation, |
340 | + double minRes, double maxBright, bool visible) |
341 | { |
342 | loadSkyImage(id, filename, StelUtils::getDecAngle(ra)*180./M_PI, |
343 | - StelUtils::getDecAngle(dec)*180./M_PI, angSize, |
344 | - rotation, minRes, maxBright, visible); |
345 | + StelUtils::getDecAngle(dec)*180./M_PI, angSize, |
346 | + rotation, minRes, maxBright, visible); |
347 | } |
348 | |
349 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, |
350 | - double alt0, double azi0, |
351 | - double alt1, double azi1, |
352 | - double alt2, double azi2, |
353 | - double alt3, double azi3, |
354 | - double minRes, double maxBright, bool visible) |
355 | + double alt0, double azi0, |
356 | + double alt1, double azi1, |
357 | + double alt2, double azi2, |
358 | + double alt3, double azi3, |
359 | + double minRes, double maxBright, bool visible) |
360 | { |
361 | QString path = "scripts/" + filename; |
362 | emit(requestLoadSkyImageAltAz(id, path, alt0, azi0, alt1, azi1, alt2, azi2, alt3, azi3, minRes, maxBright, visible)); |
363 | } |
364 | |
365 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, |
366 | - double alt, double azi, double angSize, double rotation, |
367 | - double minRes, double maxBright, bool visible) |
368 | + double alt, double azi, |
369 | + double angSize, double rotation, |
370 | + double minRes, double maxBright, bool visible) |
371 | { |
372 | Vec3f XYZ; |
373 | static const float RADIUS_NEB = 1.; |
374 | @@ -452,15 +454,15 @@ |
375 | XYZ*=RADIUS_NEB; |
376 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); |
377 | Mat4f matPrecomp = Mat4f::translation(XYZ) * |
378 | - Mat4f::zrotation((180-azi)*M_PI/180.) * |
379 | - Mat4f::yrotation(-alt*M_PI/180.) * |
380 | - Mat4f::xrotation((rotation+90)*M_PI/180.); |
381 | + Mat4f::zrotation((180-azi)*M_PI/180.) * |
382 | + Mat4f::yrotation(-alt*M_PI/180.) * |
383 | + Mat4f::xrotation((rotation+90)*M_PI/180.); |
384 | |
385 | Vec3f corners[4]; |
386 | - corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
387 | - corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
388 | - corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
389 | - corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
390 | + corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
391 | + corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
392 | + corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
393 | + corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
394 | |
395 | // convert back to alt/azi (radians) |
396 | Vec3f cornersAltAz[4]; |
397 | @@ -468,11 +470,11 @@ |
398 | StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]); |
399 | |
400 | loadSkyImageAltAz(id, filename, |
401 | - cornersAltAz[0][0]*180./M_PI, cornersAltAz[0][1]*180./M_PI, |
402 | - cornersAltAz[1][0]*180./M_PI, cornersAltAz[1][1]*180./M_PI, |
403 | - cornersAltAz[3][0]*180./M_PI, cornersAltAz[3][1]*180./M_PI, |
404 | - cornersAltAz[2][0]*180./M_PI, cornersAltAz[2][1]*180./M_PI, |
405 | - minRes, maxBright, visible); |
406 | + cornersAltAz[0][0]*180./M_PI, cornersAltAz[0][1]*180./M_PI, |
407 | + cornersAltAz[1][0]*180./M_PI, cornersAltAz[1][1]*180./M_PI, |
408 | + cornersAltAz[3][0]*180./M_PI, cornersAltAz[3][1]*180./M_PI, |
409 | + cornersAltAz[2][0]*180./M_PI, cornersAltAz[2][1]*180./M_PI, |
410 | + minRes, maxBright, visible); |
411 | } |
412 | |
413 | void StelMainScriptAPI::removeSkyImage(const QString& id) |
414 | @@ -622,6 +624,11 @@ |
415 | StelApp::getInstance().getScriptMgr().debug(s); |
416 | } |
417 | |
418 | +void StelMainScriptAPI::output(const QString &s) |
419 | +{ |
420 | + StelApp::getInstance().getScriptMgr().output(s); |
421 | +} |
422 | + |
423 | double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec) |
424 | { |
425 | StelCore *core = StelApp::getInstance().getCore(); |
426 | |
427 | === modified file 'src/scripting/StelMainScriptAPI.hpp' |
428 | --- src/scripting/StelMainScriptAPI.hpp 2013-08-04 06:13:29 +0000 |
429 | +++ src/scripting/StelMainScriptAPI.hpp 2014-08-12 09:52:27 +0000 |
430 | @@ -614,6 +614,10 @@ |
431 | //! @param s the message to be displayed on the console. |
432 | void debug(const QString& s); |
433 | |
434 | + //! print an output message from script |
435 | + //! @param s the message to be displayed on the output file. |
436 | + void output(const QString& s); |
437 | + |
438 | //! Get the current application language. |
439 | //! @return two letter language code, e.g. "en", or "de" and so on. |
440 | QString getAppLanguage(); |
441 | |
442 | === modified file 'src/scripting/StelScriptMgr.cpp' |
443 | --- src/scripting/StelScriptMgr.cpp 2014-07-13 05:52:52 +0000 |
444 | +++ src/scripting/StelScriptMgr.cpp 2014-08-12 09:52:27 +0000 |
445 | @@ -19,6 +19,7 @@ |
446 | */ |
447 | |
448 | |
449 | +#include "StelScriptOutput.hpp" |
450 | #include "StelScriptMgr.hpp" |
451 | #include "StelMainScriptAPI.hpp" |
452 | #include "StelModuleMgr.hpp" |
453 | @@ -423,6 +424,12 @@ |
454 | emit(scriptDebug(msg)); |
455 | } |
456 | |
457 | +void StelScriptMgr::output(const QString &msg) |
458 | +{ |
459 | + StelScriptOutput::writeLog(msg); |
460 | + emit(scriptOutput(msg)); |
461 | +} |
462 | + |
463 | void StelScriptMgr::scriptEnded() |
464 | { |
465 | if (engine.hasUncaughtException()) |
466 | |
467 | === modified file 'src/scripting/StelScriptMgr.hpp' |
468 | --- src/scripting/StelScriptMgr.hpp 2014-04-10 02:47:02 +0000 |
469 | +++ src/scripting/StelScriptMgr.hpp 2014-08-12 09:52:27 +0000 |
470 | @@ -136,10 +136,14 @@ |
471 | //! execution rate. |
472 | double getScriptRate(); |
473 | |
474 | - //! cause the emission of the scriptDebug signal. This is so that functions in |
475 | + //! cause the emission of the scriptDebug signal. This is so that functions in |
476 | //! StelMainScriptAPI can explicitly send information to the ScriptConsole |
477 | void debug(const QString& msg); |
478 | |
479 | + //! cause the emission of the scriptOutput signal. This is so that functions in |
480 | + //! StelMainScriptAPI can explicitly send information to the ScriptConsole |
481 | + void output(const QString& msg); |
482 | + |
483 | //! Pause a running script. |
484 | void pauseScript(); |
485 | |
486 | @@ -155,7 +159,9 @@ |
487 | //! Notification when a script has stopped running |
488 | void scriptStopped(); |
489 | //! Notification of a script event - warnings, current execution line etc. |
490 | - void scriptDebug(const QString&); |
491 | + void scriptDebug(const QString&); |
492 | + //! Notification of a script event - output line. |
493 | + void scriptOutput(const QString&); |
494 | |
495 | private: |
496 | // Utility functions for preprocessor |
497 | |
498 | === added file 'src/scripting/StelScriptOutput.cpp' |
499 | --- src/scripting/StelScriptOutput.cpp 1970-01-01 00:00:00 +0000 |
500 | +++ src/scripting/StelScriptOutput.cpp 2014-08-12 09:52:27 +0000 |
501 | @@ -0,0 +1,44 @@ |
502 | +/* |
503 | + * Stellarium |
504 | + * Copyright (C) 2014 Alexander Wolf |
505 | + * |
506 | + * This program is free software; you can redistribute it and/or |
507 | + * modify it under the terms of the GNU General Public License |
508 | + * as published by the Free Software Foundation; either version 2 |
509 | + * of the License, or (at your option) any later version. |
510 | + * |
511 | + * This program is distributed in the hope that it will be useful, |
512 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
513 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
514 | + * GNU General Public License for more details. |
515 | + * |
516 | + * You should have received a copy of the GNU General Public License |
517 | + * along with this program; if not, write to the Free Software |
518 | + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. |
519 | + */ |
520 | + |
521 | +#include "StelScriptOutput.hpp" |
522 | +#include <QDebug> |
523 | + |
524 | +// Init statics variables. |
525 | +QFile StelScriptOutput::outputFile; |
526 | +QString StelScriptOutput::outputText; |
527 | + |
528 | +void StelScriptOutput::init(const QString& outputFilePath) |
529 | +{ |
530 | + outputFile.setFileName(outputFilePath); |
531 | + if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text | QIODevice::Unbuffered)) |
532 | + qDebug() << "ERROR: Cannot open output.txt file"; |
533 | +} |
534 | + |
535 | +void StelScriptOutput::deinit() |
536 | +{ |
537 | + outputFile.close(); |
538 | +} |
539 | + |
540 | +void StelScriptOutput::writeLog(QString msg) |
541 | +{ |
542 | + msg += "\n"; |
543 | + outputFile.write(qPrintable(msg), msg.size()); |
544 | + outputText += msg; |
545 | +} |
546 | |
547 | === added file 'src/scripting/StelScriptOutput.hpp' |
548 | --- src/scripting/StelScriptOutput.hpp 1970-01-01 00:00:00 +0000 |
549 | +++ src/scripting/StelScriptOutput.hpp 2014-08-12 09:52:27 +0000 |
550 | @@ -0,0 +1,50 @@ |
551 | +/* |
552 | + * Stellarium |
553 | + * Copyright (C) 2014 Alexander Wolf |
554 | + * |
555 | + * This program is free software; you can redistribute it and/or |
556 | + * modify it under the terms of the GNU General Public License |
557 | + * as published by the Free Software Foundation; either version 2 |
558 | + * of the License, or (at your option) any later version. |
559 | + * |
560 | + * This program is distributed in the hope that it will be useful, |
561 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
562 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
563 | + * GNU General Public License for more details. |
564 | + * |
565 | + * You should have received a copy of the GNU General Public License |
566 | + * along with this program; if not, write to the Free Software |
567 | + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. |
568 | + */ |
569 | + |
570 | +#ifndef STELSCRIPTOUTPUT_HPP |
571 | +#define STELSCRIPTOUTPUT_HPP |
572 | + |
573 | +#include "config.h" |
574 | + |
575 | +#include <QString> |
576 | +#include <QFile> |
577 | + |
578 | +//! @class StelScriptOutput |
579 | +//! Class wit only static members used to manage output for Stellarium scripts. |
580 | +class StelScriptOutput |
581 | +{ |
582 | +public: |
583 | + //! Create and initialize the log file. |
584 | + //! Prepend system information before any output. |
585 | + static void init(const QString& outputFilePath); |
586 | + |
587 | + //! Deinitialize the output file. |
588 | + //! Must be called after init() was called. |
589 | + static void deinit(); |
590 | + |
591 | + //! Write the message plus a newline to the output file at $USERDIR/output.txt. |
592 | + //! @param msg message to write. |
593 | + static void writeLog(QString msg); |
594 | + |
595 | +private: |
596 | + static QFile outputFile; |
597 | + static QString outputText; |
598 | +}; |
599 | + |
600 | +#endif // STELSCRIPTOUTPUT_HPP |
I rarely have used the script console (not lack of interest - it's a great feature, just not for me currently...). What shall I test? Any test script included that uses the new feature and shows usage syntax?