[Kst] branches/work/kst/portto4/kst

Barth Netterfield netterfield at astro.utoronto.ca
Tue Sep 27 15:38:46 UTC 2011


SVN commit 1255859 by netterfield:

Re-arrange where the script server lives, so that documents can be cleared 
without borking the script server.

Add a clear() function to scripting to clear the current session from a script.


 M  +3 -1      pyKst/pykst.py  
 M  +0 -3      src/libkstapp/cartesianrenderitem.cpp  
 M  +2 -2      src/libkstapp/datawizard.cpp  
 M  +0 -3      src/libkstapp/document.cpp  
 M  +0 -2      src/libkstapp/document.h  
 M  +13 -3     src/libkstapp/mainwindow.cpp  
 M  +3 -1      src/libkstapp/mainwindow.h  
 M  +11 -2     src/libkstapp/scriptserver.cpp  
 M  +4 -0      src/libkstapp/scriptserver.h  


--- branches/work/kst/portto4/kst/pyKst/pykst.py #1255858:1255859
@@ -33,7 +33,6 @@
         self.ls.connectToServer(serverName)
         self.ls.waitForConnected(300)
         self.serverName=serverName
-        sleep(1)
     
   def send(self,command):
     """ Sends a command to kst and returns a response. You should never use this directly, as there is no guarantee that the internal command
@@ -59,6 +58,9 @@
     get_matrix(ret,self.serverName,command)
     return ret
     
+  def clear(self):
+    """ Equivalent to file->close from the menubar inside kst.  Clears all objects from kst."""
+    self.send("clear()")
   def screenBack(self):
     """ Equivalent to "Range>Back One Screen" from the menubar inside kst. """
     self.send("screenBack()")
--- branches/work/kst/portto4/kst/src/libkstapp/cartesianrenderitem.cpp #1255858:1255859
@@ -52,9 +52,6 @@
     context.foregroundColor = painter->pen().color();
     context.backgroundColor = painter->brush().color();
 
-    //FIXME rename these methods in kstvcurve
-    //FIXME Completely refactor KstCurveRenderContext now that we know what these are
-
     //Set the projection box...
     context.XMin = projectionRect().left();
     context.XMax = projectionRect().right();
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1255858:1255859
@@ -569,7 +569,6 @@
 
   _FFTOptions->GroupBoxFFTOptions->setCheckable(true);
   _FFTOptions->GroupBoxFFTOptions->setTitle(i18n("Create S&pectra Plots. Set FFT options below:"));
-  _FFTOptions->GroupBoxFFTOptions->setChecked(false); // fixme: use persistant defaults
 
   _FFTOptions->GroupBoxFFTOptions->setChecked(_dialogDefaults->value("wizard/doPSD",false).toBool());
   _xAxisGroup->setChecked(_dialogDefaults->value("wizard/doXY",true).toBool());
@@ -695,7 +694,8 @@
   if (MainWindow *mw = qobject_cast<MainWindow*>(parent)) {
     _document = mw->document();
   } else {
-    // FIXME: we need a document
+    // we need a document
+    // not sure that this can ever happen.
     qFatal("ERROR: can't construct a DataWizard without a document");
   }
 
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #1255858:1255859
@@ -24,7 +24,6 @@
 #include <commandlineparser.h>
 #include "objectstore.h"
 #include "updatemanager.h"
-#include "scriptserver.h"
 
 #include <QDebug>
 #include <QFile>
@@ -36,7 +35,6 @@
 Document::Document(MainWindow *window)
 : CoreDocument(), _win(window), _dirty(false), _isOpen(false) {
   _session = new SessionModel(objectStore());
-  _scriptServer = new ScriptServer(objectStore());
 
   _fileName.clear();
   UpdateManager::self()->setStore(objectStore());
@@ -45,7 +43,6 @@
 
 Document::~Document() {
   delete _session;
-  delete _scriptServer;
   _session = 0;
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/document.h #1255858:1255859
@@ -25,7 +25,6 @@
 class View;
 class ViewItem;
 class CommandLineParser;
-class ScriptServer;
 
 class Document : public CoreDocument {
   public:
@@ -52,7 +51,6 @@
     View *currentView() const;
 
   private:
-    ScriptServer* _scriptServer;
     QPointer<MainWindow> _win;
     SessionModel *_session;
     bool _dirty;
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1255858:1255859
@@ -58,6 +58,7 @@
 #include "dialogdefaults.h"
 
 #include "dialoglauncher.h"
+#include "scriptserver.h"
 
 #include <QSvgGenerator>
 #include <QUndoGroup>
@@ -87,6 +88,8 @@
     _highlightPoint(false) 
 {
   _doc = new Document(this);
+  _scriptServer = new ScriptServer(_doc->objectStore());
+
   _tabWidget = new TabWidget(this);
   _undoGroup = new QUndoGroup(this);
   _debugDialog = new DebugDialog(this);
@@ -121,6 +124,8 @@
   _dataManager = 0;
   delete _doc;
   _doc = 0;
+  delete _scriptServer;
+  _scriptServer = 0;
 }
 
 
@@ -242,10 +247,11 @@
   updateRecentKstFiles(fn);
 }
 
-
-void MainWindow::newDoc() {
+void MainWindow::newDoc(bool force) {
   bool clearApproved = false;
-  if (_doc->isChanged()) {
+  if (force) {
+    clearApproved = true;
+  } else if (_doc->isChanged()) {
     clearApproved = promptSave();
   } else {
     int rc = QMessageBox::warning(this, tr("Kst"), tr("Delete everything?"), QMessageBox::Ok, QMessageBox::Cancel);
@@ -257,6 +263,7 @@
     _dataManager = 0;
     delete _doc;
     _doc = new Document(this);
+    _scriptServer->setStore(_doc->objectStore());
   } else {
     return;
   }
@@ -386,6 +393,7 @@
 bool MainWindow::initFromCommandLine() {
   delete _doc;
   _doc = new Document(this);
+  _scriptServer->setStore(_doc->objectStore());
 
   CommandLineParser P(_doc, this);
 
@@ -414,6 +422,7 @@
   _dataManager = 0;
   delete _doc;
   _doc = new Document(this);
+  _scriptServer->setStore(_doc->objectStore());
 
   bool ok = _doc->open(file);
   QApplication::restoreOverrideCursor();
@@ -424,6 +433,7 @@
            "Maybe it is a Kst 1 file which could not be read by Kst 2.").arg(file, _doc->lastError()));
     delete _doc;
     _doc = new Document(this);
+    _scriptServer->setStore(_doc->objectStore());
   }
 
   setWindowTitle("Kst - " + file);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #1255858:1255859
@@ -41,6 +41,7 @@
 class AboutDialog;
 class TabWidget;
 class View;
+class ScriptServer;
 
 
 class MainWindow : public QMainWindow
@@ -93,7 +94,7 @@
     void save();
     void saveAs();
     void open();
-    void newDoc();
+    void newDoc(bool force=false);
     void openFile(const QString &file);
     void print();
     void setPrinterDefaults(QPrinter *printer);
@@ -175,6 +176,7 @@
     Document *_doc;
     TabWidget *_tabWidget;
     QUndoGroup *_undoGroup;
+    ScriptServer* _scriptServer;
 
     DataManager *_dataManager;
     DebugDialog *_debugDialog;
--- branches/work/kst/portto4/kst/src/libkstapp/scriptserver.cpp #1255858:1255859
@@ -87,7 +87,7 @@
         socket.disconnectFromServer();
         connectTo=initial+QString::number(connectTo.remove(initial).toInt()+1);
     }
-    //qDebug()<<"Created script server with name "<<connectTo;
+    qDebug()<<"Created script server with name "<<connectTo;
     connect(_server,SIGNAL(newConnection()),this,SLOT(procConnection()));
 
     //setup _map={QByteArray->ScriptMemberFn}
@@ -175,7 +175,8 @@
     _fnMap.insert("eliminate()",&ScriptServer::eliminate);
     _fnMap.insert("endEdit()",&ScriptServer::endEdit);
 
-    _fnMap.insert("done()",&ScriptServer::beginEdit);
+    _fnMap.insert("done()",&ScriptServer::done);
+    _fnMap.insert("clear()",&ScriptServer::clear);
 
     _fnMap.insert("tabCount()",&ScriptServer::tabCount);
     _fnMap.insert("newTab()",&ScriptServer::newTab);
@@ -1055,6 +1056,14 @@
     return "Bye.";
 }
 
+
+QByteArray ScriptServer::clear(QByteArray&, QLocalSocket* s,ObjectStore*,const int&ifMode,
+                              const QByteArray&ifEqual,IfSI*& _if,VarSI*var) {
+  kstApp->mainWindow()->newDoc(true);
+  return handleResponse("Done",s,ifMode,ifEqual,_if,var);
+}
+
+
 QByteArray ScriptServer::tabCount(QByteArray&, QLocalSocket* s,ObjectStore*,const int&ifMode,
                                   const QByteArray&ifEqual,IfSI*& _if,VarSI*var) {
     return handleResponse(QByteArray::number(kstApp->mainWindow()->tabWidget()->count()),s,ifMode,ifEqual,_if,var);
--- branches/work/kst/portto4/kst/src/libkstapp/scriptserver.h #1255858:1255859
@@ -48,6 +48,7 @@
     ScriptServer(ObjectStore*obj);
     ~ScriptServer();
     QByteArray checkPrimatives(QByteArray&command,QLocalSocket* s);
+    void setStore(ObjectStore *obj) { _store = obj;}
 public slots:
     void procConnection();
     void readSomething();
@@ -146,6 +147,9 @@
     // Quit:
     QByteArray done(QByteArray& command, QLocalSocket* s,ObjectStore*_store,const int&ifMode, const QByteArray&ifString,IfSI*& ifStat,VarSI*var);
 
+    // Clear:
+    QByteArray clear(QByteArray& command, QLocalSocket* s,ObjectStore*_store,const int&ifMode, const QByteArray&ifString,IfSI*& ifStat,VarSI*var);
+
     // Destruction is much easier than construction.
     QByteArray eliminate(QByteArray& command, QLocalSocket* s,ObjectStore*_store,const int&ifMode, const QByteArray&ifString,IfSI*& ifStat,VarSI*var);
 


More information about the Kst mailing list