8 #include <QApplication> 9 #include <QCoreApplication> 10 #include <QDesktopWidget> 17 #include <QMessageBox> 19 #include <QScrollArea> 59 Display *xDisplay = XOpenDisplay(NULL);
61 std::cerr <<
"cannot connect to X server...\n\n" 62 "Do you have an X server running?\n\n" 64 " If you are trying to run this program remotely using ssh, then " 65 "did you enable X11 forwarding?\n\n" 66 "If the possible causes cited above have been ruled out and this " 67 "problem persists, then check your X settings or contact your " 68 "system administrator.\n\n";
73 XCloseDisplay(xDisplay);
83 PvlGroup &uiPref = Preference::Preferences().findGroup(
"UserInterface");
88 setlocale(LC_ALL,
"en_US");
90 QApplication::setQuitOnLastWindowClosed(
true);
91 QApplication::setApplicationName(
FileName(argv[0]).baseName());
98 QString style = uiPref[
"GuiStyle"];
99 QApplication::setStyle(style);
104 QString fontString = uiPref[
"GuiFontName"];
105 QFont font = QFont(fontString);
108 int pointSize = uiPref[
"GuiFontSize"];
109 font.setPointSize(pointSize);
112 QApplication::setFont(font);
129 QWidget::setWindowTitle(QApplication::applicationName());
132 for(
int group = 0; group < ui.
NumGroups(); group++) {
133 for(
int param = 0; param < ui.
NumParams(group); param++) {
134 p_parameters.push_back(AddParameter(ui, group, param));
139 for(
int p = 0; p < (int)p_parameters.size(); p++) {
147 p_scrollLayout->addStretch(1);
151 p_progressBar->setMinimum(0);
152 p_progressBar->setMaximum(100);
153 p_progressBar->setValue(0);
154 p_progressBar->setMinimumWidth(200);
156 p_statusText =
new QLabel(
"Ready");
158 statusBar()->setSizeGripEnabled(
true);
159 statusBar()->addWidget(p_progressBar, 0);
160 statusBar()->addWidget(p_statusText, 3);
170 for(
unsigned int i = 0; i < p_parameters.size(); i++) {
171 delete p_parameters[i];
174 p_parameters.clear();
178 void Gui::CreateAreas() {
180 QSplitter *split =
new QSplitter(Qt::Vertical,
this);
183 p_scrollArea =
new QScrollArea();
184 p_scrollWidget =
new QWidget();
185 p_scrollLayout =
new QVBoxLayout;
186 p_scrollWidget->setLayout(p_scrollLayout);
187 p_scrollArea->setWidget(p_scrollWidget);
188 p_scrollArea->setWidgetResizable(
true);
191 int height = QApplication::desktop()->height();
195 p_log->setMinimumHeight(10);
196 p_log->resize(p_log->width(), 250);
198 split->addWidget(p_scrollArea);
199 split->addWidget(p_log);
200 split->setChildrenCollapsible(
false);
201 split->setStretchFactor(0, 3);
202 split->setStretchFactor(1, 0);
203 setCentralWidget(split);
204 resize(720, (
int)(height / 2) + 350);
207 p_processAction = CreateProcessAction();
208 p_stopAction = CreateStopAction();
209 p_exitAction = CreateExitAction();
211 p_previousHistoryAction = CreatePreviousHistoryAction();
212 p_nextHistoryAction = CreateNextHistoryAction();
213 p_resetAction = CreateResetAction();
215 p_saveLogAction = CreateSaveLogAction();
216 p_clearLogAction = CreateClearLogAction();
218 QAction *whatsThisAction = CreateWhatsThisAction();
221 QMenu *fileMenu = menuBar()->addMenu(
"&File");
222 fileMenu->addAction(p_processAction);
223 fileMenu->addAction(p_stopAction);
224 fileMenu->addAction(p_exitAction);
227 QMenu *optionsMenu = menuBar()->addMenu(
"&Options");
228 optionsMenu->addAction(p_resetAction);
229 optionsMenu->addAction(p_previousHistoryAction);
230 optionsMenu->addAction(p_nextHistoryAction);
231 optionsMenu->addAction(p_saveLogAction);
232 optionsMenu->addAction(p_clearLogAction);
235 QToolBar *tb = addToolBar(
"Controls");
236 tb->setIconSize(QSize(22, 22));
237 tb->addAction(p_processAction);
238 tb->addAction(p_stopAction);
239 tb->addAction(p_exitAction);
242 tb->addAction(p_previousHistoryAction);
243 tb->addAction(p_nextHistoryAction);
244 tb->addAction(p_resetAction);
247 tb->addAction(p_saveLogAction);
248 tb->addAction(p_clearLogAction);
251 tb->addAction(whatsThisAction);
254 showControls->setText(
"Controls");
255 showControls->setCheckable(
true);
256 connect(showControls, SIGNAL(toggled(
bool)), tb, SLOT(setVisible(
bool)));
258 tb->installEventFilter(
this);
262 addToolBar(Qt::BottomToolBarArea, tb);
263 tb->setIconSize(QSize(22, 22));
264 tb->setAllowedAreas(Qt::BottomToolBarArea);
265 p_commandLineEdit =
new QLineEdit(tb);
266 p_commandLineEdit->setReadOnly(
true);
267 tb->addWidget(p_commandLineEdit);
269 showCommandLine->setText(
"Command Line");
270 showCommandLine->setCheckable(
true);
271 connect(showCommandLine, SIGNAL(toggled(
bool)), tb, SLOT(setVisible(
bool)));
275 QMenu *viewMenu = menuBar()->addMenu(
"&View");
276 viewMenu->addAction(showControls);
277 viewMenu->addAction(showCommandLine);
278 showControls->setChecked(
true);
279 showCommandLine->setChecked(
true);
282 QMenu *helpMenu = menuBar()->addMenu(
"&Help");
283 helpMenu->addAction(whatsThisAction);
286 aboutProgram->setMenuRole(QAction::AboutRole);
287 aboutProgram->setText(
"About this program");
288 aboutProgram->setShortcut(Qt::CTRL + Qt::Key_H);
289 helpMenu->addAction(aboutProgram);
290 connect(aboutProgram, SIGNAL(triggered(
bool)),
this, SLOT(AboutProgram()));
293 aboutIsis->setMenuRole(QAction::NoRole);
294 aboutIsis->setText(
"About Isis");
295 aboutIsis->setShortcut(Qt::CTRL + Qt::Key_I);
296 helpMenu->addAction(aboutIsis);
297 connect(aboutIsis, SIGNAL(triggered(
bool)),
this, SLOT(AboutIsis()));
302 QAction *Gui::CreateProcessAction() {
304 QString baseDir = FileName(
"$BASE/icons").expanded();
305 processAction->setIcon(QPixmap(baseDir +
"/guiRun.png"));
306 processAction->setText(
"&Run");
307 processAction->setToolTip(
"Run");
308 QString processActionWhatsThisText =
"<p><b>Function: </b> \ 309 Runs the application with the current parameters</p> \ 310 <p><b>Shortcut: </b> Ctrl+R</p>";
311 processAction->setShortcut(Qt::CTRL + Qt::Key_R);
312 processAction->setWhatsThis(processActionWhatsThisText);
314 connect(processAction, SIGNAL(triggered(
bool)),
this, SLOT(
StartProcess()));
316 return processAction;
330 p_processAction->setEnabled(
false);
338 for(
int p = 0; p < (int)p_parameters.size(); p++) {
342 QString value = param.Value().simplified().trimmed();
343 if(value.length() > 0) {
355 Isis::SessionLog::TheLog(
true);
356 QApplication::setOverrideCursor(Qt::WaitCursor);
358 QApplication::restoreOverrideCursor();
362 for(
int p = 0; p < (int)p_parameters.size(); p++) {
371 QApplication::restoreOverrideCursor();
385 p_processAction->setEnabled(
true);
389 QAction *Gui::CreateExitAction() {
392 exitAction->setIcon(QPixmap(baseDir +
"/guiExit.png"));
393 exitAction->setText(
"&Exit");
394 exitAction->setToolTip(
"Exit");
395 QString exitWhatsThisText =
"<p><b>Function: </b> \ 396 Closes the program window </p> <p><b>Shortcut: </b> Ctrl+Q</p>";
397 exitAction->setWhatsThis(exitWhatsThisText);
398 exitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
399 connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
404 QAction *Gui::CreateResetAction() {
406 QString baseDir = FileName(
"$BASE/icons").expanded();
407 resetAction->setIcon(QPixmap(baseDir +
"/guiReset.png"));
408 resetAction->setText(
"&Reset");
409 resetAction->setToolTip(
"Reset parameters");
410 QString resetWhatsThisText =
"<p><b>Function: </b> \ 411 Resets the application parameters to their default values</p> \ 412 <p><b>Shortcut: </b> F3</p>";
413 resetAction->setWhatsThis(resetWhatsThisText);
414 resetAction->setShortcut(Qt::Key_F3);
415 connect(resetAction, SIGNAL(triggered()),
this, SLOT(
ResetParameters()));
421 QAction *Gui::CreateStopAction() {
423 QString baseDir = FileName(
"$BASE/icons").expanded();
424 stopAction->setIcon(QPixmap(baseDir +
"/guiStop.png"));
425 stopAction->setText(
"&Stop");
426 stopAction->setToolTip(
"Stop");
427 QString stopWhatsThisText =
"<p><b>Function: </b> \ 428 Stops the application from running</p> \ 429 <p><b>Shortcut: </b> Ctrl+E</p>";
430 stopAction->setShortcut(Qt::CTRL + Qt::Key_E);
431 stopAction->setWhatsThis(stopWhatsThisText);
432 connect(stopAction, SIGNAL(triggered()),
this, SLOT(
StopProcessing()));
438 QAction *Gui::CreateSaveLogAction() {
440 QString baseDir = FileName(
"$BASE/icons").expanded();
441 saveLogAction->setIcon(QPixmap(baseDir +
"/guiSaveLog.png"));
442 saveLogAction->setText(
"&Save Log...");
443 saveLogAction->setToolTip(
"Save log");
444 QString saveWhatsThisText =
"<p><b>Function: </b> Saves the information \ 445 currently in the log area to a file <p><b>Shortcut: </b> Ctrl+S</p>";
446 saveLogAction->setWhatsThis(saveWhatsThisText);
447 saveLogAction->setShortcut(Qt::CTRL + Qt::Key_S);
448 connect(saveLogAction, SIGNAL(triggered(
bool)), p_log, SLOT(Save()));
450 return saveLogAction;
454 QAction *Gui::CreateClearLogAction() {
456 QString baseDir = FileName(
"$BASE/icons").expanded();
457 clearlogAction->setIcon(QPixmap(baseDir +
"/guiClearLog.png"));
458 clearlogAction->setText(
"&Clear Log");
459 clearlogAction->setToolTip(
"Clear log");
460 QString clearWhatsThisText =
"<p><b>Function: </b>Clears all information \ 461 from the log area at the bottom of the application screen</p> \ 462 <p><b>Shortcut: </b> Ctrl+L</p>";
463 clearlogAction->setWhatsThis(clearWhatsThisText);
464 clearlogAction->setShortcut(Qt::CTRL + Qt::Key_L);
465 connect(clearlogAction, SIGNAL(triggered(
bool)), p_log, SLOT(Clear()));
467 return clearlogAction;
471 QAction *Gui::CreatePreviousHistoryAction() {
473 QString baseDir = FileName(
"$BASE/icons").expanded();
474 previousHistoryAction->setIcon(QPixmap(baseDir +
"/guiPrevHistory.png"));
475 previousHistoryAction->setText(
"&Previous");
476 previousHistoryAction->setToolTip(
"Previous parameters");
477 QString previousWhatsThisText =
"<p><b>Function: </b>Fills in parameter \ 478 values using the previous history entry</p> \ 479 <p><b>Shortcut: </b> F5</p>";
480 previousHistoryAction->setWhatsThis(previousWhatsThisText);
481 previousHistoryAction->setShortcut(Qt::Key_F5);
482 connect(previousHistoryAction, SIGNAL(triggered()),
this, SLOT(
PreviousHistory()));
484 return previousHistoryAction;
488 QAction *Gui::CreateNextHistoryAction() {
490 QString baseDir = FileName(
"$BASE/icons").expanded();
491 nextHistoryAction->setIcon(QPixmap(baseDir +
"/guiNextHistory.png"));
492 nextHistoryAction->setText(
"&Next");
493 nextHistoryAction->setToolTip(
"Next parameters");
494 QString nextWhatsThisText =
"<p><b>Function: </b>Fills in parameter \ 495 values using the next history entry</p> \ 496 <p><b>Shortcut: </b>F6</p>";
497 nextHistoryAction->setWhatsThis(nextWhatsThisText);
498 nextHistoryAction->setShortcut(Qt::Key_F6);
499 connect(nextHistoryAction, SIGNAL(triggered()),
this, SLOT(
NextHistory()));
501 return nextHistoryAction;
505 QAction *Gui::CreateWhatsThisAction() {
507 QString baseDir = FileName(
"$BASE/icons").expanded();
508 action->setIcon(QPixmap(baseDir +
"/contexthelp.png"));
509 action->setText(
"&What's This");
510 action->setToolTip(
"What's This");
511 QString whatsThisText =
"<p><b>Function: </b> Use this to get longer \ 512 descriptions of button functions and parameter information</p> \ 513 <p><b>Shortcut: </b> Shift+F1</p>";
514 action->setWhatsThis(whatsThisText);
515 action->setShortcut(Qt::SHIFT + Qt::Key_F1);
516 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(WhatsThis()));
524 QGridLayout *gridLayout = NULL;
525 if(!p_grids.contains(ui.
GroupName(group))) {
527 QGroupBox *groupBox =
new QGroupBox(ui.
GroupName(group));
528 p_scrollLayout->addWidget(groupBox);
529 groupBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
530 groupBox->setAlignment(Qt::AlignHCenter);
533 gridLayout =
new QGridLayout;
534 gridLayout->setColumnStretch(0, 0);
535 gridLayout->setColumnStretch(1, 0);
536 gridLayout->setColumnMinimumWidth(1, 10);
537 gridLayout->setColumnStretch(2, 10);
538 groupBox->setLayout(gridLayout);
539 p_grids[ui.
GroupName(group)] = gridLayout;
543 gridLayout = p_grids[ui.
GroupName(group)];
546 GuiParameter *p = GuiParameterFactory::Create(gridLayout, ui, group, param);
548 if (p->Type() == GuiParameter::ListWidget || p->Type() == GuiParameter::ComboWidget ||
549 p->Type() == GuiParameter::BooleanWidget) {
553 connect(p, SIGNAL(HelperTrigger(
const QString &)),
560 p_statusText->setText(text);
561 qApp->processEvents();
566 p_progressBar->setValue(percent);
567 qApp->processEvents();
582 QString m = QString(message).replace(
"\n",
"<br>");
585 if(message.contains(
"[") &&
586 message.contains(
"]") &&
587 (message.indexOf(
"[") < message.indexOf(
"]"))) {
590 while(m.indexOf(
"[", indx) != -1) {
591 m.insert(m.indexOf(
"[", indx) + 1,
"<font color=#ff0000>");
592 m.insert(m.indexOf(
"]", indx),
"</font>");
593 indx = m.indexOf(
"]", indx) + 1;
602 int status = QMessageBox::warning(
this,
605 "Ok",
"Abort",
"", 0, 1);
606 p_errorString.clear();
617 if(e->type() == QEvent::Enter) {
618 if(p_processAction->isEnabled()) {
628 if(p_processAction->isEnabled())
return;
631 switch(QMessageBox::information(
this,
633 QString(
"Program suspended, choose to ") +
634 QString(
"continue processing, stop ") +
635 QString(
"processing or exit the program"),
656 qApp->processEvents();
664 for(
int p = 0; p < (int)p_parameters.size(); p++) {
670 for(
int p = 0; p < (int)p_parameters.size(); p++) {
697 if(p_historyEntry < -1) {
699 QApplication::beep();
703 if(p_historyEntry == -1) {
715 if(!progHist.fileExists()) {
717 QApplication::beep();
724 hist.
read(progHist.expanded());
728 QString msg =
"A corrupt parameter history file [" + progHist.expanded() +
729 "] has been detected. Please fix or remove this file";
739 for(
int i = 0; i < hist.
groups(); i++) {
744 if(p_historyEntry == entries) {
745 p_historyEntry = entries - 1;
746 QApplication::beep();
750 int useEntry = entries - p_historyEntry - 1;
757 for (
int k = 0; k < up.
keywords(); k++) {
758 QString key = up[k].
name();
762 if (up[k].size() > 1) {
764 for (
int i = 0; i < up[k].size(); i++) {
765 QString newVal = up[k][i];
766 if (newVal.contains(
",")) {
767 newVal =
'"' + newVal +
'"';
769 if (i == up[k].size() - 1) {
773 val += newVal +
", ";
779 QString newVal = up[k];
786 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
793 p_historyEntry = entries - 1;
794 QApplication::beep();
804 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
810 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
812 std::vector<QString> excludeList = param.
Exclusions();
813 for(
int i = 0; i < (int)excludeList.size(); i++) {
814 for(
unsigned int e = 0; e < p_parameters.size(); e++) {
816 if(exclude.
Name() != excludeList[i])
continue;
817 exclude.
SetEnabled(
false, (param.Type()==GuiParameter::ComboWidget));
826 for(
int p = 0; p < (int)p_parameters.size(); p++) {
830 QString name = param.
Name().toLower();
833 QString value = param.Value();
834 if(param.Type() == GuiParameter::StringWidget) {
835 if(value.contains(
" ")) {
836 cline +=
"\"" + value +
"\"";
842 else if(param.Type() == GuiParameter::FileNameWidget ||
843 param.Type() == GuiParameter::CubeWidget) {
847 value = value.toLower();
852 p_commandLineEdit->setText(cline);
857 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
864 void Gui::WhatsThis() {
865 QWhatsThis::enterWhatsThisMode();
869 void Gui::AboutIsis() {
871 QString command = (QString) uig[
"GuiHelpBrowser"] +
872 " http://isis.astrogeology.usgs.gov >> /dev/null &";
877 void Gui::AboutProgram() {
879 "$ISISROOT/doc/Application/presentation/PrinterFriendly/" +
886 QString command = (QString) uig[
"GuiHelpBrowser"] +
887 (QString)
" file:" + file.expanded() +
" &";
893 p_processAction->setEnabled(
false);
898 for(
int p = 0; p < (int)p_parameters.size(); p++) {
902 QString value = param.Value().simplified().trimmed();
903 if(value.length() > 0) {
912 helper = (void ( *)())ptr;
921 p_processAction->setEnabled(
true);
int NumParams(const int &) const
Returns the number of parameters in a group.
bool eventFilter(QObject *o, QEvent *e)
Reset the Progress bar when the user moves the mouse onto the toolbar.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void NextHistory()
Goto the next history entry.
QString ProgramName() const
Returns the Program name.
void FunctionCleanup()
Cleans up after the function by writing the log, saving the history, and either sending the log to th...
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
int NumGroups() const
Returns the number of groups found in the XML.
void ProgressText(const QString &text)
Change progress text.
void InvokeHelper(const QString &funct)
Activate helper buttons.
void StopProcessing()
The user pressed the stop button ... see what they want to do.
static void checkX11()
check to see if X is available
bool ProcessEvents()
Let the event loop have some time to see if we need to cancel.
void Write(const QString &string)
Add more information to the log widget.
QString Name() const
Return the name of the parameter.
Gui(Isis::UserInterface &ui)
Constructor.
void UpdateParameters()
Update Parameters.
void PutAsString(const QString ¶mName, const QString &value)
Allows the insertion of a value for any parameter.
bool IsEnabled() const
Is the parameter enabled.
void GuiReportError(IException &e)
Loads the error message into the gui, but does not write it to the session log.
void Update()
Update the value on the GUI with the value in the UI.
void Progress(int percent)
Update the progress bar.
static Gui * p_gui
Singleton.
QString GroupName(const int &group) const
Returns the group name of group[index].
void UpdateCommandLine()
Update the command line toolbar.
void SaveHistory()
Saves the user parameter information in the history of the program for later use. ...
void ResetParameters()
Reset the parameters fields to the defaults.
QString name() const
Returns the container name.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
void PreviousHistory()
Goto the previous history entry.
void Log(const QString &text)
Write text to the gui log.
Contains multiple PvlContainers.
void UpdateHistory()
Changed the parameters based on the history pointer.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
virtual bool IsModified()
Return if the parameter value is different from the default value.
void Clear(const QString ¶mName)
Clears the value(s) in the named parameter.
Container for cube-like labels.
int FunctionError(IException &e)
Adds the error to the session log, sends the error to the parent if it has one, loads the error messa...
int Exec(void(*funct)())
Start the Gui and enter the main loop This routine only returns when the program is ready to exit...
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
PvlGroup & group(const int index)
Return the group at the specified index.
QString toString() const
Returns a string representation of this exception.
void StartProcess()
The user pressed the go button.
void LoadMessage(const QString &message)
Add more information to the error message.
Namespace for ISIS/Bullet specific routines.
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
void VerifyAll()
Verify all parameters.
Command Line and Xml loader, validation, and access.
int ShowWarning()
Show an error message and return if the user wants to continue/abort.
int groups() const
Returns the number of groups contained.
void read(const QString &file)
Loads PVL information from a stream.
void UpdateExclusions()
Grey out parameters that should be excluded for radio buttons and checkboxes.
void * GetGuiHelper(QString helper)
Reads user preferences from a data file.
Gui for Isis Applications.