def mouseMoveEvent(self, e): msg = MouseEvent() msg.header.stamp = rospy.Time.now() msg.type = MouseEvent.MOUSE_MOVE msg.x, msg.y = self.mousePosition(e) msg.width = self.label.pixmap().width() msg.height = self.label.pixmap().height() if self.event_pub: self.event_pub.publish(msg)
def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.left_button_clicked = False msg = MouseEvent() msg.header.stamp = rospy.Time.now() msg.width = self.label.pixmap().width() msg.height = self.label.pixmap().height() msg.type = MouseEvent.MOUSE_LEFT_UP msg.x, msg.y = self.mousePosition(e) self.event_pub.publish(msg)
def main(): pub_plus = rospy.Publisher('~plus_rect_event', MouseEvent, queue_size=1) pub_minus = rospy.Publisher('~minus_rect_event', MouseEvent, queue_size=1) width = rospy.get_param('~image_width') height = rospy.get_param('~image_height') plus_events = [ MouseEvent(type=3, x=width/4, y=height/4, width=width, height=height), MouseEvent(type=4, x=width/2, y=height/2, width=width, height=height), MouseEvent(type=2, x=3*width/4, y=3*height/4, width=width, height=height), ] minus_events = [ MouseEvent(type=3, x=3*width/4, y=3*height/4, width=width, height=height), MouseEvent(type=4, x=width/2, y=height/2, width=width, height=height), MouseEvent(type=2, x=width/4, y=height/4, width=width, height=height), ] rate = rospy.Rate(10) while not rospy.is_shutdown(): for e in plus_events: e.header.stamp = rospy.get_rostime() pub_plus.publish(e) rate.sleep() for e in minus_events: e.header.stamp = rospy.get_rostime() pub_minus.publish(e) rate.sleep()
def mousePressEvent(self, e): msg = MouseEvent() msg.header.stamp = rospy.Time.now() if e.button() == Qt.LeftButton: msg.type = MouseEvent.MOUSE_LEFT_DOWN self.left_button_clicked = True elif msg.type == Qt.RightButton: msg.type = MouseEvent.MOUSE_RIGHT_DOWN msg.width = self.label.pixmap().width() msg.height = self.label.pixmap().height() msg.x, msg.y = self.mousePosition(e) self.event_pub.publish(msg)