// At this point we may or may not have a valid working directory in that the // selected directory may exist and we haven't confirmed if the user wants to // overwrite it. void ProcessMonitor::submitJob2() { if (!m_pendingProcess) { qDebug() << "ProcessMonitor::submitJob2() called with no pending process"; return; } ServerTask::Base* task = qobject_cast<ServerTask::Base*>(sender()); if (!task) { delete m_pendingProcess; m_pendingProcess = 0; return; } QString errorMessage(task->errorMessage()); task->deleteLater(); Server* server = ServerRegistry::instance().get(m_pendingProcess->serverName()); if (errorMessage.contains("Working directory exists")) { if (QMsgBox::question(0, "IQmol", "Directory exists, overwrite?") == QMessageBox::Ok) { m_pendingProcess->jobInfo()->promptOnOverwrite(false); }else if (!server->getWorkingDirectoryFromUser(m_pendingProcess)) { delete m_pendingProcess; m_pendingProcess = 0; return; } task = server->setup(m_pendingProcess); connect(task, SIGNAL(finished()), this, SLOT(submitJob2())); task->start(); return; } if (!errorMessage.isEmpty()) { QString msg("Problem setting up Job:\n"); msg += errorMessage; QMsgBox::warning(this, "IQmol", msg); delete m_pendingProcess; m_pendingProcess = 0; return; } // We now have a valid working directory postStatusMessage("Configuring options..."); if (server->configureJob(m_pendingProcess)) { postStatusMessage("Submitting job..."); task = server->submit(m_pendingProcess); connect(task, SIGNAL(finished()), this, SLOT(jobSubmitted())); task->start(); }else { delete m_pendingProcess; m_pendingProcess = 0; return; } }
void GraphEditor::load(void) { auto fileName = this->getCurrentFilePath().toStdString(); if (fileName.empty()) { _stateManager->resetToDefault(); handleStateChange(GraphState("document-new", tr("Create new topology"))); _stateManager->saveCurrent(); this->render(); return; } try { poco_information_f1(Poco::Logger::get("PothosGui.GraphEditor.load"), "Loading %s from file", fileName); postStatusMessage(tr("Loading %1").arg(QString::fromStdString(fileName))); std::ifstream inFile(fileName.c_str()); this->loadState(inFile); } catch (const std::exception &ex) { poco_error_f2(Poco::Logger::get("PothosGui.GraphEditor.load"), "Error loading %s: %s", fileName, std::string(ex.what())); } _stateManager->resetToDefault(); handleStateChange(GraphState("document-new", tr("Load topology from file"))); _stateManager->saveCurrent(); this->updateGraphEditorMenus(); this->render(); }
void ProcessMonitor::submitJob(IQmol::JobInfo* jobInfo) { if (m_pendingProcess) { QString msg("Job submission pending, cannot submit additional jobs"); QMsgBox::warning(this, "IQmol", msg); return; } // Because we need to thread the network stuff, we break the job submission // process up into several bits (ServerTasks) and connect these via signals // and slots. First we need to make sure the server is connected and tested. // Note that because the connection process is potentially interactive, we // don't bother threading it. QString serverName(jobInfo->get(JobInfo::ServerName)); Server* server = ServerRegistry::instance().get(serverName); if (!server) { QMsgBox::warning(this, "IQmol", "Invalid server"); return; } if (!server->isConnected()) { postStatusMessage("Connecting to server..."); try { QLOG_DEBUG() << "Attempting to connect to server " << server->name(); if (!server->connectServer()) throw Server::Exception("Connection failed"); QLOG_DEBUG() << "Connection established: " << server->isConnected(); postStatusMessage("Testing configuration..."); } catch (std::exception& err) { QString msg("Failed to connect to server "); msg += serverName + ":\n"; msg += err.what(); QMsgBox::warning(this, "IQmol", msg); return; } } // This is a bit untidy, but we need to tell the next slot in the submission // thread chain what job we are dealing with. m_pendingProcess = new Process(jobInfo); ServerTask::Base* task = server->testConfiguration(); if (task) { connect(task, SIGNAL(finished()), this, SLOT(submitJob1())); task->start(); } }
// At this point the server is connected and tested, but we still need to check // if the test was successful. If it is, then we can go ahead with the setup // which starts with obtaining the working directory. void ProcessMonitor::submitJob1() { if (!m_pendingProcess) { qDebug() << "ProcessMonitor::submitJob1() called with no pending process"; return; } ServerTask::Base* task = qobject_cast<ServerTask::Base*>(sender()); if (!task) { delete m_pendingProcess; m_pendingProcess = 0; return; } QString errorMessage(task->errorMessage()); task->deleteLater(); if (!errorMessage.isEmpty()) { QString msg("Problem submitting job:\n"); msg += errorMessage; QMsgBox::warning(this, "IQmol", msg); delete m_pendingProcess; m_pendingProcess = 0; return; } postStatusMessage("Determining working directory..."); Server* server = ServerRegistry::instance().get(m_pendingProcess->serverName()); if (server->getWorkingDirectoryFromUser(m_pendingProcess)) { task = server->setup(m_pendingProcess); connect(task, SIGNAL(finished()), this, SLOT(submitJob2())); task->start(); }else { delete m_pendingProcess; m_pendingProcess = 0; } }
int main(int argc, char **argv) { MyScopedSyslogListener syslogListener; //did the user specified files on the command line? //stash the files so they are loaded into the editor //this replaces the currently stored file list QStringList files; for (int i = 1; i < argc; i++) { QString file(argv[i]); if (file.isEmpty()) continue; files.push_back(file); } if (not files.isEmpty()) getSettings().setValue("GraphEditorTabs/files", files); //create the entry point to the GUI QApplication app(argc, argv); app.setOrganizationName("PothosWare"); app.setApplicationName("Pothos"); //create splash screen getSplashScreen()->show(); //setup the application icon app.setWindowIcon(QIcon(makeIconPath("PothosGui.png"))); //perform library initialization with graphical error message on failure Pothos::RemoteServer server; try { //try to talk to the server on localhost, if not there, spawn a custom one //make a server and node that is temporary with this process postStatusMessage("Launching scratch process..."); try { Pothos::RemoteClient client("tcp://"+Pothos::Util::getLoopbackAddr()); } catch (const Pothos::RemoteClientError &) { server = Pothos::RemoteServer("tcp://"+Pothos::Util::getLoopbackAddr(Pothos::RemoteServer::getLocatorPort())); //TODO make server background so it does not close with process Pothos::RemoteClient client("tcp://"+Pothos::Util::getLoopbackAddr()); //now it should connect to the new server } } catch (const Pothos::Exception &ex) { QMessageBox msgBox(QMessageBox::Critical, "Pothos Initialization Error", QString::fromStdString(ex.displayText())); msgBox.exec(); return EXIT_FAILURE; } POTHOS_EXCEPTION_TRY { postStatusMessage("Initializing Pothos plugins..."); Pothos::ScopedInit init; //create the main window for the GUI std::unique_ptr<QWidget> mainWindow(new PothosGuiMainWindow(nullptr)); mainWindow->show(); getSplashScreen()->finish(mainWindow.get()); getSettings().setParent(mainWindow.get()); //begin application execution return app.exec(); } POTHOS_EXCEPTION_CATCH (const Pothos::Exception &ex) { QMessageBox msgBox(QMessageBox::Critical, "PothosGui Application Error", QString::fromStdString(ex.displayText())); msgBox.exec(); return EXIT_FAILURE; }