ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

signal 'draw' is invalid for instance ... of type 'GtkDrawingArea'

asked 2018-07-16 13:27:28 -0500

Rodrigo Lourenço gravatar image

updated 2018-07-17 04:29:56 -0500

I don't understand the reason for this error.

After I compiled my code and run it I got the message signal 'draw' is invalid for instance (...) of type 'GtkDrawingArea'

I may have errors on my source code, but first I want to understand the reason for this problem.

Thanks in advance

Here goes my package.xml and makelists.txt

<?xml version="1.0"?>
<package>
  <name>pubsub</name>
  <version>0.0.0</version>
  <description>The pubsub package</description>

  <maintainer email="viki@todo.todo">viki</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>cv_bridge</build_depend>
  <build_depend>image_transport</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>geometry_msgs</build_depend>



  <run_depend>roscpp</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>cv_bridge</run_depend>
  <run_depend>image_transport</run_depend> 
  <run_depend>message_runtime</run_depend>
  <run_depend>geometry_msgs</run_depend>

  <export>    
  </export>
</package>

cmake_minimum_required(VERSION 2.8.3)
project(pubsub)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  cv_bridge
  actionlib
  actionlib_msgs
  image_transport
  sensor_msgs
  roslaunch
  message_generation
  geometry_msgs
)

find_package(Boost REQUIRED COMPONENTS system)
find_package(PkgConfig REQUIRED)
find_package(OpenCV)
find_package(GTK2 COMPONENTS gtk)

roslaunch_add_file_check(launch)

pkg_check_modules(gtk REQUIRED gtk+-2.0)
pkg_check_modules(OpenCV REQUIRED opencv)

add_message_files(
   FILES
   msg1.msg
   main_msg.msg
   tracks.msg
   orientations.msg
   RaposaWheels.msg
   main.msg
#   Message2.msg
 )

 add_service_files(
   FILES
   demo_srv.srv
#   Service2.srv
 )

 generate_messages(
   DEPENDENCIES
   std_msgs
   actionlib_msgs
   geometry_msgs
 )

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES myVideoImageSubscriber
  CATKIN_DEPENDS roscpp std_msgs geometry_msgs 
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${Bost_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${OpenCV_CFLAGS}
  ${GTK2_INCLUDE_DIRS}
  ${GTK2_CFLAGS}
)

add_executable(sub7 src/subscriber7.cpp)

add_dependencies(sub7 msg_pkg_generate_messages_cpp pubsub cv_bridge roscpp std_msgs sensor_msgs)

target_link_libraries(sub7
   ${catkin_LIBRARIES}
   ${Boost_LIBRARIES}
   ${OpenCV_LIBRARIES}
   ${GTK2_LIBRARIES}
)

install(TARGETS sub7
   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

I have been playing with the source code, but nothing, here is the code.

#include "ros/ros.h"
#include "std_msgs/Int16.h"
#include "std_msgs/Float64.h"
#include "std_msgs/Float32.h"
#include "pubsub/RaposaWheels.h"
#include "pubsub/main.h"
#include <geometry_msgs/Quaternion.h>
#include <std_msgs/Header.h>
#include <iostream>
#include <sstream>
#include <cairo.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define  pi  3.14159
#define draw_Wigth   180
#define draw_height  180

typedef struct orien_ang{
    float x;
    float y;
}ang;

GtkWidget* GlobalTable;
GtkWidget* darea1;
GtkWidget* darea2;
double body_roll;

ang* Gorien;

static void do_drawing(GtkWidget *widget, cairo_t *cr, gpointer user_data);
static void do_drawing2(GtkWidget *widget, cairo_t *cr, gpointer user_data);

static void do_drawing(GtkWidget *widget, cairo_t *cr, gpointer user_data)
{

    double int_x, int_y;
    double radius;
    double inset;
    double aux_ang1, aux_ang2, aux_ang3, aux_ang4;
    int i;



    int_x = draw_Wigth/2;
    int_y = draw_height/2;

    radius = draw_Wigth/3 - 5;

    cairo_set_source_rgb(cr, 0, 0, 0); //Black
    cairo_stroke(cr);

    i = 0;
    while (i < 36){
        cairo_save(cr);
        inset = (1.0/18)*radius;
        cairo_set_line_width(cr, 0.5 * cairo_get_line_width(cr));
        cairo_move_to(cr, int_x + (radius - inset)* cos(i * pi /18.0), int_y + (radius - inset)* sin(i * pi /18.0));
        cairo_line_to(cr, int_x + radius* cos(i * pi/18.0), int_y + radius* sin(i * pi/18.0));
        cairo_stroke(cr);
        cairo_restore(cr);
        i = i + 1;
    }

    i = 1;
    while ( i < 9)
    {
        cairo_save(cr);

        inset = 0.15 * radius;
        cairo_move_to(cr, int_x + (radius - inset) * cos(i * pi/4.0), int_y + (radius-inset)*sin(i ...
(more)
edit retag flag offensive close merge delete

Comments

I removed (most) of the comments from your code listing to make it easier to read.

jayess gravatar image jayess  ( 2018-07-16 13:53:52 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-07-17 13:40:48 -0500

Rodrigo Lourenço gravatar image

updated 2018-07-17 13:44:30 -0500

jayess gravatar image

Problem solve.

The main issue here is mixing GTK2.0 and GTK3.0, a few changes had to be made on this code.

1º Here we read "draw" we must have "expose-event"

2º the arguments of do_drawing not have cairo_t *cr but GdKEventExpose *event

3º create in the do_drawing the next 2 lines:

cairo_t *cr;
cr = gdk_cairo_create(widget->window);

These solved the entire problem.

Thanks.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-16 13:27:28 -0500

Seen: 945 times

Last updated: Jul 17 '18