Author: snorri
Date: 2011-09-06 21:23:56 -0700 (Tue, 06 Sep 2011)
New Revision: 365
Modified:
trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/main_window.hpp
trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/qnode.hpp
trunk/tools/eros_python_tools/templates/qt-ros/src/main_window.cpp
trunk/tools/eros_python_tools/templates/qt-ros/src/qnode.cpp
Log:
eros_python_tools : check for ros master in qt-ros template
Modified: trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/main_window.hpp
===================================================================
--- trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/main_window.hpp 2011-09-07 04:22:37 UTC (rev 364)
+++ trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/main_window.hpp 2011-09-07 04:23:56 UTC (rev 365)
@@ -39,6 +39,7 @@
void WriteSettings(); // Save qt program settings when closing
void closeEvent(QCloseEvent *event); // Overloaded function
+ void showNoMasterMessage();
public slots:
/******************************************
Modified: trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/qnode.hpp
===================================================================
--- trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/qnode.hpp 2011-09-07 04:22:37 UTC (rev 364)
+++ trunk/tools/eros_python_tools/templates/qt-ros/include/PACKAGE_NAME/qnode.hpp 2011-09-07 04:23:56 UTC (rev 365)
@@ -37,8 +37,8 @@
public:
QNode(int argc, char** argv );
~QNode();
- void init(const std::string &topic_name);
- void init(const std::string &master_url, const std::string &host_url, const std::string &topic_name);
+ bool init(const std::string &topic_name);
+ bool init(const std::string &master_url, const std::string &host_url, const std::string &topic_name);
void run();
/*********************
Modified: trunk/tools/eros_python_tools/templates/qt-ros/src/main_window.cpp
===================================================================
--- trunk/tools/eros_python_tools/templates/qt-ros/src/main_window.cpp 2011-09-07 04:22:37 UTC (rev 364)
+++ trunk/tools/eros_python_tools/templates/qt-ros/src/main_window.cpp 2011-09-07 04:23:56 UTC (rev 365)
@@ -58,25 +58,40 @@
** Implementation [Slots]
*****************************************************************************/
+void MainWindow::showNoMasterMessage() {
+ QMessageBox msgBox;
+ msgBox.setText("Couldn't find the ros master.");
+ msgBox.exec();
+ close();
+}
+
/*
* These triggers whenever the button is clicked, regardless of whether it
* is already checked or not.
*/
void MainWindow::on_button_connect_clicked(bool check ) {
- ui.button_connect->setEnabled(false);
if ( ui.checkbox_use_environment->isChecked() ) {
- qnode.init(ui.line_edit_topic->text().toStdString());
+ if ( !qnode.init(ui.line_edit_topic->text().toStdString()) ) {
+ showNoMasterMessage();
+ } else {
+ ui.button_connect->setEnabled(false);
+ }
} else {
- qnode.init(ui.line_edit_master->text().toStdString(),
+ if ( ! qnode.init(ui.line_edit_master->text().toStdString(),
ui.line_edit_host->text().toStdString(),
- ui.line_edit_topic->text().toStdString());
- ui.line_edit_master->setReadOnly(true);
- ui.line_edit_host->setReadOnly(true);
- ui.line_edit_topic->setReadOnly(true);
+ ui.line_edit_topic->text().toStdString()) ) {
+ showNoMasterMessage();
+ } else {
+ ui.button_connect->setEnabled(false);
+ ui.line_edit_master->setReadOnly(true);
+ ui.line_edit_host->setReadOnly(true);
+ ui.line_edit_topic->setReadOnly(true);
+ }
}
}
+
void MainWindow::on_checkbox_use_environment_stateChanged(int state) {
bool enabled;
if ( state == 0 ) {
Modified: trunk/tools/eros_python_tools/templates/qt-ros/src/qnode.cpp
===================================================================
--- trunk/tools/eros_python_tools/templates/qt-ros/src/qnode.cpp 2011-09-07 04:22:37 UTC (rev 364)
+++ trunk/tools/eros_python_tools/templates/qt-ros/src/qnode.cpp 2011-09-07 04:23:56 UTC (rev 365)
@@ -35,13 +35,16 @@
QNode::~QNode() {
if(ros::isStarted()) {
ros::shutdown(); // explicitly needed since we use ros::start();
+ ros::waitForShutdown();
}
- ros::waitForShutdown();
wait();
}
-void QNode::init(const std::string &topic_name) {
+bool QNode::init(const std::string &topic_name) {
ros::init(init_argc,init_argv,"%(package)s");
+ if ( ! ros::master::check() ) {
+ return false;
+ }
ros::start(); // explicitly needed since our nodehandle is going out of scope.
ros::NodeHandle n;
// Add your ros communications here.
@@ -49,11 +52,14 @@
start();
}
-void QNode::init(const std::string &master_url, const std::string &host_url, const std::string &topic_name) {
+bool QNode::init(const std::string &master_url, const std::string &host_url, const std::string &topic_name) {
std::map<std::string,std::string> remappings;
remappings["__master"] = master_url;
remappings["__hostname"] = host_url;
ros::init(remappings,"%(package)s");
+ if ( ! ros::master::check() ) {
+ return false;
+ }
ros::start(); // explicitly needed since our nodehandle is going out of scope.
ros::NodeHandle n;
// Add your ros communications here.
_______________________________________________
Eros-commits mailing list
Eros-commits@code.ros.org
https://code.ros.org/mailman/listinfo/eros-commits