From 0b60755eb7c38ae2995690f57ce405b5f0052f0f Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 7 Aug 2025 14:37:02 -0400 Subject: Add macondo tab, run process --- .gitignore | 1 + quacker/CMakeLists.txt | 2 ++ quacker/macondo.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ quacker/macondo.h | 20 ++++++++++++++++++++ quacker/quacker.cpp | 4 +++- quacker/quacker.h | 4 +++- 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 quacker/macondo.cpp create mode 100644 quacker/macondo.h diff --git a/.gitignore b/.gitignore index 49b3592..f62fff4 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ dawginput.raw playabilities.raw smaller.raw DerivedData +compile_commands.json diff --git a/quacker/CMakeLists.txt b/quacker/CMakeLists.txt index 123ee1a..ac60a7d 100644 --- a/quacker/CMakeLists.txt +++ b/quacker/CMakeLists.txt @@ -39,6 +39,7 @@ set(QUACKLE_SOURCES letterboxsettings.cpp lexicondialog.cpp lister.cpp + macondo.cpp main.cpp movebox.cpp newgame.cpp @@ -72,6 +73,7 @@ set(QUACKLE_HEADERS letterboxsettings.h lexicondialog.h lister.h + macondo.h movebox.h newgame.h noteeditor.h diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp new file mode 100644 index 0000000..476d41b --- /dev/null +++ b/quacker/macondo.cpp @@ -0,0 +1,45 @@ +#include "macondo.h" +#include "quacker.h" + +#include +#include +#include +#include + +Macondo::Macondo(QWidget *parent) : QWidget(parent) { + m_updateTimer = new QTimer(this); + QGridLayout *layout = new QGridLayout(this); + m_runButton = new QPushButton(tr("Run")); + layout->addWidget(m_runButton, 0, 0); + layout->setAlignment(Qt::AlignTop); + const char *home = getenv("HOME"); + // TODO: configurable path + m_execPath = home ? home : "/"; + m_execPath += "/apps/macondo/macondo"; + connect(m_runButton, SIGNAL(clicked()), this, SLOT(run())); + connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateResults())); + m_updateTimer->setInterval(100); +} + +void Macondo::run() { + if (m_process) return; + printf("running macondo %s\n", m_execPath.c_str()); + m_process = new QProcess; + QStringList args; + m_process->start(m_execPath.c_str(), args); + connect(m_process, SIGNAL(started()), this, SLOT(processStarted())); +} + +void Macondo::processStarted() { + m_updateTimer->start(); + m_process->write("help\n"); +} + +void Macondo::updateResults() { + QProcess::ProcessState state = m_process->state(); + QByteArray data = m_process->readAllStandardError(); + printf("%s",data.constData()); + data = m_process->readAllStandardOutput(); + printf("%s", data.constData()); + fflush(stdout); +} diff --git a/quacker/macondo.h b/quacker/macondo.h new file mode 100644 index 0000000..e6eb749 --- /dev/null +++ b/quacker/macondo.h @@ -0,0 +1,20 @@ +#include + +class QPushButton; +class QProcess; +class QTimer; + +class Macondo : public QWidget { +Q_OBJECT +public: + explicit Macondo(QWidget *parent = 0); +public slots: + void run(); + void updateResults(); + void processStarted(); +private: + QPushButton *m_runButton; + QTimer *m_updateTimer; + std::string m_execPath; + QProcess *m_process = nullptr; +}; diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index 17b982e..0270302 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -42,6 +42,7 @@ #include "lister.h" #include "letterbox.h" #include "lexiconparameters.h" +#include "macondo.h" #include "movebox.h" #include "noteeditor.h" #include "newgame.h" @@ -67,7 +68,7 @@ TopLevel::TopLevel(QWidget *parent) qRegisterMetaType("OppoThread*"); m_quackerSettings = new QuackerSettings; - + m_macondo = new Macondo; m_settings = new Settings; m_settings->preInitialize(); m_settings->createGUI(); @@ -2005,6 +2006,7 @@ void TopLevel::createWidgets() m_tabWidget->addTab(m_history, tr("Histor&y")); m_tabWidget->addTab(m_choicesWidget, tr("&Choices")); m_tabWidget->addTab(m_settings, tr("Se&ttings")); + m_tabWidget->addTab(m_macondo, tr("&Macondo")); GraphicalFactory factory; m_brb = new BRB(&factory); diff --git a/quacker/quacker.h b/quacker/quacker.h index 83813c7..cb47023 100644 --- a/quacker/quacker.h +++ b/quacker/quacker.h @@ -70,6 +70,7 @@ class QuackerSettings; class Settings; class SimViewer; class View; +class Macondo; class TopLevel : public QMainWindow { @@ -313,7 +314,7 @@ private: QVBoxLayout *m_leftSideLayout; - enum TabIndex { HistoryTabIndex = 0, ChoicesTabIndex = 1, SettingsTabIndex = 2}; + enum TabIndex { HistoryTabIndex = 0, ChoicesTabIndex = 1, SettingsTabIndex = 2, MacondoTabIndex = 3 }; QTabWidget *m_tabWidget; HistoryView *m_history; @@ -325,6 +326,7 @@ private: QFrame *m_frameWidget; Settings *m_settings; + Macondo *m_macondo; ListerDialog *m_listerDialog; void updateListerDialogWithRack(); -- cgit v1.2.3