OpenMS
Loading...
Searching...
No Matches
ExternalProcessMBox Class Reference

A wrapper around ExternalProcess to conveniently show a MessageBox when an error occurs. More...

#include <OpenMS/VISUAL/MISC/ExternalProcessMBox.h>

Collaboration diagram for ExternalProcessMBox:
[legend]

Public Member Functions

 ExternalProcessMBox ()
 default Ctor; callbacks for stdout/stderr are empty
 
 ExternalProcessMBox (std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
 set the callback functions to process stdout and stderr output when the external process generates it
 
 ~ExternalProcessMBox ()
 D'tor.
 
void setCallbacks (std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
 re-wire the callbacks used using run()
 
ExternalProcess::RETURNSTATE run (QWidget *parent, const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose, String &error_msg)
 Runs a program by calling ExternalProcess::run and shows any error reported in error_msg as a MessageBox before this function returns.
 
ExternalProcess::RETURNSTATE run (QWidget *parent, const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose)
 Same as other overload, just without a returned error message.
 

Private Attributes

ExternalProcess ep_
 

Detailed Description

A wrapper around ExternalProcess to conveniently show a MessageBox when an error occurs.

Use the custom Ctor to provide callback functions for stdout/stderr output or set them via setCallbacks().

Running an external program blocks the caller, so do not use this in a main GUI thread (unless you have some other means to tell the user that no interaction is possible at the moment).

Constructor & Destructor Documentation

◆ ExternalProcessMBox() [1/2]

default Ctor; callbacks for stdout/stderr are empty

◆ ExternalProcessMBox() [2/2]

ExternalProcessMBox ( std::function< void(const String &)>  callbackStdOut,
std::function< void(const String &)>  callbackStdErr 
)

set the callback functions to process stdout and stderr output when the external process generates it

◆ ~ExternalProcessMBox()

D'tor.

Member Function Documentation

◆ run() [1/2]

ExternalProcess::RETURNSTATE run ( QWidget parent,
const QString &  exe,
const QStringList &  args,
const QString &  working_dir,
const bool  verbose 
)

Same as other overload, just without a returned error message.

◆ run() [2/2]

ExternalProcess::RETURNSTATE run ( QWidget parent,
const QString &  exe,
const QStringList &  args,
const QString &  working_dir,
const bool  verbose,
String error_msg 
)

Runs a program by calling ExternalProcess::run and shows any error reported in error_msg as a MessageBox before this function returns.

Parameters
[in]parentOptional parent widget, used to position QMesssageBoxes above the parent
[in]exeThe program to call (can contain spaces in path, no problem)
[in]argsA list of extra arguments (can be empty)
[in,out]working_dirExecute the external process in the given directory (relevant when relative input/output paths are given). Leave empty to use the current working directory.
[in]verboseReport the call command and errors via the callbacks (default: false)
[out]error_msgMessage to display to the user or log somewhere if something went wrong (if return != SUCCESS)
Returns
Did the external program succeed (SUCCESS) or did something go wrong?

◆ setCallbacks()

void setCallbacks ( std::function< void(const String &)>  callbackStdOut,
std::function< void(const String &)>  callbackStdErr 
)

re-wire the callbacks used using run()

Member Data Documentation

◆ ep_

ExternalProcess ep_
private