Mercurial > hg > octave-terminal
changeset 13390:ee41454753d4
Added dockable variable and history widget.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sun, 10 Apr 2011 23:26:38 +0200 |
parents | 6bdfa6012e77 |
children | d5d56d353278 |
files | gui//Quint.pro gui//src/HistoryDockWidget.cpp gui//src/HistoryDockWidget.h gui//src/MainWindow.cpp gui//src/MainWindow.h gui//src/OctaveTerminal.cpp gui//src/OctaveTerminal.h gui//src/VariablesDockWidget.cpp gui//src/VariablesDockWidget.h |
diffstat | 9 files changed, 288 insertions(+), 224 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//Quint.pro +++ b/gui//Quint.pro @@ -39,7 +39,9 @@ src/Quint.cpp \ src/OctaveLink.cpp \ src/ProcessInfo.cpp \ - src/OctaveTerminal.cpp + src/OctaveTerminal.cpp \ + src/VariablesDockWidget.cpp \ + src/HistoryDockWidget.cpp HEADERS += \ src/TerminalCharacterDecoder.h \ @@ -75,7 +77,9 @@ src/ProcessInfo.h \ src/kpty_export.h \ src/kdecore_export.h \ - src/OctaveTerminal.h + src/OctaveTerminal.h \ + src/VariablesDockWidget.h \ + src/HistoryDockWidget.h INCFLAGS = -g3 $$system(mkoctfile -p INCFLAGS) LFLAGS = $$system(mkoctfile -p LFLAGS) \
new file mode 100644 --- /dev/null +++ b/gui//src/HistoryDockWidget.cpp @@ -0,0 +1,34 @@ +#include "HistoryDockWidget.h" +#include <QHBoxLayout> + +HistoryDockWidget::HistoryDockWidget(QWidget *parent) + : QDockWidget(parent) { + construct(); +} + +void HistoryDockWidget::construct() { + m_historyListModel = new QStringListModel(); + m_historyListView = new QListView(this); + m_historyListView->setModel(m_historyListModel); + + QHBoxLayout *layout = new QHBoxLayout(); + + setWindowTitle("History"); + setWidget(new QWidget()); + + layout->addWidget(m_historyListView); + layout->setMargin(2); + + widget()->setLayout(layout); +} + + +void HistoryDockWidget::updateHistory(string_vector historyEntries) { + QStringList stringList = m_historyListModel->stringList(); + for(size_t i = 0; i < historyEntries.length(); i++) { + QString command(historyEntries[i].c_str()); + if(!command.startsWith("#")) + stringList.push_front(QString("%1: ").arg(stringList.size() + 1) + command); + } + m_historyListModel->setStringList(stringList); +}
new file mode 100644 --- /dev/null +++ b/gui//src/HistoryDockWidget.h @@ -0,0 +1,48 @@ +#ifndef HISTORYDOCKWIDGET_H +#define HISTORYDOCKWIDGET_H + +#include <QDockWidget> +#include <QListView> +#include <QStringListModel> + +// Octave includes +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef PACKAGE_URL +#include "octave/config.h" + +#include "octave/debug.h" +#include "octave/octave.h" +#include "octave/symtab.h" +#include "octave/parse.h" +#include "octave/unwind-prot.h" +#include "octave/toplev.h" +#include "octave/load-path.h" +#include "octave/error.h" +#include "octave/quit.h" +#include "octave/variables.h" +#include "octave/sighandlers.h" +#include "octave/sysdep.h" +#include "octave/str-vec.h" +#include "octave/cmd-hist.h" +#include "octave/cmd-edit.h" +#include "octave/oct-env.h" +#include "octave/symtab.h" +#include "cmd-edit.h" + +class HistoryDockWidget : public QDockWidget +{ +public: + HistoryDockWidget(QWidget *parent = 0); + void updateHistory(string_vector historyEntries); + +private: + void construct(); + QListView *m_historyListView; + QStringListModel *m_historyListModel; +}; + +#endif // HISTORYDOCKWIDGET_H
--- a/gui//src/MainWindow.cpp +++ b/gui//src/MainWindow.cpp @@ -22,13 +22,13 @@ #include <QtWebKit/QWebView> #include "MainWindow.h" -#include "OctaveTerminal.h" - MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) { + : QMainWindow(parent), + isRunning(true) { + resize(1000, 600); constructWindow(); - showMaximized(); + establishOctaveLink(); } MainWindow::~MainWindow() { @@ -36,6 +36,94 @@ void MainWindow::constructWindow() { m_octaveTerminal = new OctaveTerminal(this); + m_variablesDockWidget = new VariablesDockWidget(this); + m_historyDockWidget = new HistoryDockWidget(this); setWindowTitle("Quint"); setCentralWidget(m_octaveTerminal); + + addDockWidget(Qt::LeftDockWidgetArea, m_variablesDockWidget); + addDockWidget(Qt::LeftDockWidgetArea, m_historyDockWidget); } + +void MainWindow::establishOctaveLink() { + //QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Establishing Octave link.."))); + m_octaveLink = new OctaveLink(); + pthread_create(&m_octaveThread, 0, MainWindow::octaveMainWrapper, this); + pthread_create(&m_octaveCallbackThread, 0, MainWindow::octaveCallback, this); + command_editor::add_event_hook(server_rl_event_hook_function); + + int fdm, fds; + if(openpty(&fdm, &fds, 0, 0, 0) < 0) { + assert(0); + } + dup2 (fds, 0); + dup2 (fds, 1); + dup2 (fds, 2); + m_octaveTerminal->openTeletype(fdm); +} + +void* MainWindow::octaveMainWrapper(void *widget) { + //MainWindow *mainWindow = (MainWindow*)ptr; + + int argc = 3; + const char* argv[] = {"octave", "--interactive", "--line-editing"}; + octave_main(argc, (char**)argv,1); + switch_to_buffer(create_buffer(get_input_from_stdin())); + main_loop(); + clean_up_and_exit(0); + return 0; +} + +void* MainWindow::octaveCallback(void *widget) { + MainWindow *mainWindow = (MainWindow*)widget; + + while(mainWindow->isRunning) { + + // Get a full variable list. + std::vector<OctaveLink::VariableMetaData> variables = oct_octave_server.variableInfoList(); + if(variables.size()) { + // TODO: Update variables view. + } + + // Check whether any requested variables have been returned. + std::vector<OctaveLink::RequestedVariable> reqVars = oct_octave_server.requestedVariables(); + for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); + it != reqVars.end(); it++ ) { + // TODO: Process requested variables. + } + + // Collect history list. + string_vector historyList = oct_octave_server.getHistoryList(); + if(historyList.length()) { + mainWindow->m_historyDockWidget->updateHistory(historyList); + } + + // Put a marker in each buffer at the proper location. + int status = 0; + std::vector<OctaveLink::BreakPoint> breakPoints = oct_octave_server.breakPointList(status); + if(status==0) { + //MEditor::GetInstance()->process_breakpoint_list (bps); + } + + // Find out if a breakpoint is hit + static bool lineNumber = -1; + bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); + if((status==0) && hitBreakPoint) { + std::vector<OctaveLink::BreakPoint> hit_breakpoint = oct_octave_server.reachedBreakpoint(); + + if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); + lineNumber = hit_breakpoint[0].lineNumber; + } + } + else if((status==0) && lineNumber>0) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + lineNumber = -1; + } + + usleep(100000); + } + + return 0; +}
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -21,7 +21,52 @@ #include <QtGui/QMainWindow> #include "OctaveTerminal.h" +#include "OctaveLink.h" +#include "VariablesDockWidget.h" +#include "HistoryDockWidget.h" +// Octave includes +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef PACKAGE_URL +#include "octave/config.h" + +#include "octave/debug.h" +#include "octave/octave.h" +#include "octave/symtab.h" +#include "octave/parse.h" +#include "octave/unwind-prot.h" +#include "octave/toplev.h" +#include "octave/load-path.h" +#include "octave/error.h" +#include "octave/quit.h" +#include "octave/variables.h" +#include "octave/sighandlers.h" +#include "octave/sysdep.h" +#include "octave/str-vec.h" +#include "octave/cmd-hist.h" +#include "octave/cmd-edit.h" +#include "octave/oct-env.h" +#include "octave/symtab.h" +#include "cmd-edit.h" + +typedef struct yy_buffer_state *YY_BUFFER_STATE; +extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); +extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); +extern OCTINTERP_API FILE *get_input_from_stdin (void); + +// System +#include <termios.h> +#include <sys/types.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <iostream> +#include <vector> +#include "pty.h" /** * \class MainWindow * @@ -31,13 +76,25 @@ { Q_OBJECT public: + static void* octaveMainWrapper(void *widget); + static void* octaveCallback(void *widget); + MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: private: void constructWindow(); + void establishOctaveLink(); OctaveTerminal *m_octaveTerminal; + VariablesDockWidget *m_variablesDockWidget; + HistoryDockWidget *m_historyDockWidget; + + // Threads for running octave and managing the data interaction. + OctaveLink *m_octaveLink; + pthread_t m_octaveThread; + pthread_t m_octaveCallbackThread; + bool isRunning; }; #endif // MAINWINDOW_H
--- a/gui//src/OctaveTerminal.cpp +++ b/gui//src/OctaveTerminal.cpp @@ -23,155 +23,15 @@ #include <QStringList> OctaveTerminal::OctaveTerminal(QWidget *parent) - : QWidget(parent), - m_terminalWidget(0), - isRunning(true) { - constructWindow(); - establishOctaveLink(); + : QTerminalWidget(0, parent) { + construct(); } OctaveTerminal::~OctaveTerminal() { - delete m_octaveLink; - isRunning = false; -} - -void OctaveTerminal::setStatus(QString message) { - m_statusBar->showMessage(message, 1000); -} - -void OctaveTerminal::establishOctaveLink() { - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Establishing Octave link.."))); - m_octaveLink = new OctaveLink(); - pthread_create(&m_octaveThread, 0, OctaveTerminal::octaveMainWrapper, this); - pthread_create(&m_octaveCallbackThread, 0, OctaveTerminal::octaveCallback, this); - command_editor::add_event_hook(server_rl_event_hook_function); - - int fdm, fds; - if(openpty(&fdm, &fds, 0, 0, 0) < 0) { - assert(0); - } - dup2 (fds, 0); - dup2 (fds, 1); - dup2 (fds, 2); - m_terminalWidget->openTeletype(fdm); -} - -void OctaveTerminal::constructWindow() { - QVBoxLayout *vBoxLayout = new QVBoxLayout(); - - QWidget *hWidget = new QWidget(); - QHBoxLayout *hBoxLayout = new QHBoxLayout(); - - m_terminalWidget = new QTerminalWidget(0, hWidget); - m_terminalWidget->setScrollBarPosition(QTerminalWidget::ScrollBarRight); - m_terminalWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QWidget *hvWidget = new QWidget(); - QVBoxLayout *hvBoxLayout = new QVBoxLayout(); - m_variableView = new QTreeView(hWidget); - m_commandHistoryView = new QListView(hWidget); - m_commandHistoryView->setModel(new QStringListModel()); - hvWidget->setMaximumWidth(300); - hvBoxLayout->addWidget(new QLabel("Variables", hWidget)); - hvBoxLayout->addWidget(m_variableView); - hvBoxLayout->addWidget(new QLabel("Command History", hWidget)); - hvBoxLayout->addWidget(m_commandHistoryView); - hvBoxLayout->setMargin(1); - hvWidget->setLayout(hvBoxLayout); - - hBoxLayout->addWidget(m_terminalWidget); - hBoxLayout->addWidget(hvWidget); - hBoxLayout->setMargin(2); - hWidget->setLayout(hBoxLayout); - - m_statusBar = new QStatusBar(); - - vBoxLayout->addWidget(hWidget); - vBoxLayout->addWidget(m_statusBar); - vBoxLayout->setMargin(2); - setLayout(vBoxLayout); } -void OctaveTerminal::updateHistory(string_vector historyEntries) { - QStringListModel * model = dynamic_cast<QStringListModel*>(m_commandHistoryView->model()); - if(!model) - return; - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating history.."))); - QStringList stringList = model->stringList(); - for(size_t i = 0; i < historyEntries.length(); i++) { - QString command(historyEntries[i].c_str()); - if(!command.startsWith("#")) - stringList.push_front(QString("%1: ").arg(stringList.size() + 1) + command); - } - model->setStringList(stringList); -} - -void OctaveTerminal::updateVariables(std::vector<OctaveLink::VariableMetaData> variables) { - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating variables.."))); - // TODO: Update variable view. -} - -void* OctaveTerminal::octaveMainWrapper(void *widget) { - //MainWindow *mainWindow = (MainWindow*)ptr; - - int argc = 3; - const char* argv[] = {"octave", "--interactive", "--line-editing"}; - octave_main(argc, (char**)argv,1); - switch_to_buffer(create_buffer(get_input_from_stdin())); - main_loop(); - clean_up_and_exit(0); - return 0; +void OctaveTerminal::construct() { + setScrollBarPosition(QTerminalWidget::ScrollBarRight); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } -void* OctaveTerminal::octaveCallback(void *widget) { - OctaveTerminal* terminalWindow = (OctaveTerminal*)widget; - - while(terminalWindow->isRunning) { - - // Get a full variable list. - std::vector<OctaveLink::VariableMetaData> variables = oct_octave_server.variableInfoList(); - if(variables.size()) - terminalWindow->updateVariables(variables); - - // Check whether any requested variables have been returned. - std::vector<OctaveLink::RequestedVariable> reqVars = oct_octave_server.requestedVariables(); - for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); - it != reqVars.end(); it++ ) { - // TODO: Process requested variables. - } - - // Collect history list. - string_vector historyList = oct_octave_server.getHistoryList(); - if(historyList.length()) { - terminalWindow->updateHistory(historyList); - } - - // Put a marker in each buffer at the proper location. - int status = 0; - std::vector<OctaveLink::BreakPoint> breakPoints = oct_octave_server.breakPointList(status); - if(status==0) { - //MEditor::GetInstance()->process_breakpoint_list (bps); - } - - // Find out if a breakpoint is hit - static bool lineNumber = -1; - bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); - if((status==0) && hitBreakPoint) { - std::vector<OctaveLink::BreakPoint> hit_breakpoint = oct_octave_server.reachedBreakpoint(); - - if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); - lineNumber = hit_breakpoint[0].lineNumber; - } - } - else if((status==0) && lineNumber>0) { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - lineNumber = -1; - } - - usleep(100000); - } - - return 0; -}
--- a/gui//src/OctaveTerminal.h +++ b/gui//src/OctaveTerminal.h @@ -16,85 +16,20 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef TERMINALMDISUBWINDOW_H -#define TERMINALMDISUBWINDOW_H - -#include <QMdiSubWindow> -#include <QTreeView> -#include <QListView> -#include <QStatusBar> -#include "QTerminalWidget.h" -#include "OctaveLink.h" - -// Octave includes -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#undef PACKAGE_URL -#include "octave/config.h" +#ifndef OCTAVETERMINAL_H +#define OCTAVETERMINAL_H -#include "octave/debug.h" -#include "octave/octave.h" -#include "octave/symtab.h" -#include "octave/parse.h" -#include "octave/unwind-prot.h" -#include "octave/toplev.h" -#include "octave/load-path.h" -#include "octave/error.h" -#include "octave/quit.h" -#include "octave/variables.h" -#include "octave/sighandlers.h" -#include "octave/sysdep.h" -#include "octave/str-vec.h" -#include "octave/cmd-hist.h" -#include "octave/cmd-edit.h" -#include "octave/oct-env.h" -#include "octave/symtab.h" -#include "cmd-edit.h" +#include "QTerminalWidget.h" -typedef struct yy_buffer_state *YY_BUFFER_STATE; -extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); -extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); -extern OCTINTERP_API FILE *get_input_from_stdin (void); -// System -#include <termios.h> -#include <sys/types.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <iostream> -#include <vector> -#include "pty.h" - -class OctaveTerminal : public QWidget { +class OctaveTerminal : public QTerminalWidget { Q_OBJECT public: - static void* octaveMainWrapper(void *widget); - static void* octaveCallback(void *widget); - - void updateHistory(string_vector historyEntries); - void updateVariables(std::vector<OctaveLink::VariableMetaData> variables); OctaveTerminal(QWidget *parent = 0); ~OctaveTerminal(); -public slots: - void setStatus(QString message); +private: + void construct(); +}; -private: - void establishOctaveLink(); - void constructWindow(); - QTerminalWidget *m_terminalWidget; - QTreeView *m_variableView; - QListView *m_commandHistoryView; - QStatusBar *m_statusBar; - OctaveLink *m_octaveLink; - - // Threads for running octave and managing the data interaction. - pthread_t m_octaveThread; - pthread_t m_octaveCallbackThread; - bool isRunning; -}; -#endif // TERMINALMDISUBWINDOW_H +#endif // OCTAVETERMINAL_H
new file mode 100644 --- /dev/null +++ b/gui//src/VariablesDockWidget.cpp @@ -0,0 +1,21 @@ +#include "VariablesDockWidget.h" +#include <QHBoxLayout> + +VariablesDockWidget::VariablesDockWidget(QWidget *parent) + : QDockWidget(parent) { + construct(); +} + +void VariablesDockWidget::construct() { + m_variablesTreeView = new QTreeView(this); + + QHBoxLayout *layout = new QHBoxLayout(); + + setWindowTitle("Variables"); + setWidget(new QWidget()); + + layout->addWidget(m_variablesTreeView); + layout->setMargin(2); + + widget()->setLayout(layout); +}
new file mode 100644 --- /dev/null +++ b/gui//src/VariablesDockWidget.h @@ -0,0 +1,17 @@ +#ifndef VARIABLESDOCKWIDGET_H +#define VARIABLESDOCKWIDGET_H + +#include <QDockWidget> +#include <QTreeView> + +class VariablesDockWidget : public QDockWidget +{ +public: + VariablesDockWidget(QWidget *parent = 0); +private: + void construct(); + + QTreeView *m_variablesTreeView; +}; + +#endif // VARIABLESDOCKWIDGET_H