<commit_before>#!/usr/bin/env python

from PyQt4 import QtGui, QtCore
from item import Item
import rospy
from art_msgs.msg import Touch
from desc_item import DescItem
from button_item import ButtonItem


class TouchPointItem(Item):

    def __init__(self, scene,  x,  y,  parent):

        self.pointed_item = None
        self.offset = (0, 0)
        self.last_update = rospy.Time.now()

        super(TouchPointItem, self).__init__(scene, x, y,  parent)

        self.set_poss(x,  y)

    def boundingRect(self):

        return QtCore.QRectF(-20, -20, 40, 40)

    def end_of_touch(self):

        if self.pointed_item is not None:

            rospy.logdebug("releasing pointed item: " + self.pointed_item.__class__.__name__)
            self.pointed_item.set_hover(False, self)
            self.pointed_item.cursor_release()
            self.pointed_item = None

    def set_poss(self,  x,  y):

        self.last_update = rospy.Time.now()
        self.set_pos(x, y)

        if self.pointed_item is None:

            for it in self.scene().items():

                if not isinstance(it,  Item):  # TODO skip item not derived from Item
                    continue

                if not it.isVisible():
                    continue

                # TODO what types to skip?
                if isinstance(it,  TouchTableItem) or isinstance(it,  TouchPointItem) or isinstance(it,  DescItem):
                    continue

                if self.collidesWithItem(it):

                    parent = it.parentItem()
                    if not isinstance(it,  ButtonItem) and it.fixed and parent is not None and isinstance(parent, Item) and not parent.fixed:

                        it = it.parentItem()

                    rospy.logdebug("new pointed item: " + it.__class__.__name__)

                    it.set_hover(True, self)
                    self.pointed_item = it
                    self.pointed_item.cursor_press()

                    if self.pointed_item.fixed:

                        self.pointed_item.cursor_release()

                    else:

                        my_pos = self.get_pos()
                        it_pos = self.pointed_item.get_pos()

                        self.offset = (it_pos[0]-my_pos[0], it_pos[1]-my_pos[1])

                    break

        else:

            if self.pointed_item.fixed:

                if not self.collidesWithItem(self.pointed_item):

                    self.pointed_item.set_hover(False, self)
                    self.pointed_item = None

            else:

                self.pointed_item.set_pos(x+self.offset[0], y+self.offset[1])
                self.pointed_item.item_moved()

        self.update()

    def paint(self, painter, option, widget):

        if not self.scene():
            return

        painter.setClipRect(option.exposedRect)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        if self.pointed_item is not None:
            painter.setBrush(QtCore.Qt.red)
        else:<commit_msg>art_projected_gui/touch cursor: fixed issue with unwanted double clicks on buttons<commit_after>#!/usr/bin/env python

from PyQt4 import QtGui, QtCore
from item import Item
import rospy
from art_msgs.msg import Touch
from desc_item import DescItem
from button_item import ButtonItem


class TouchPointItem(Item):

    def __init__(self, scene,  x,  y,  parent):

        self.pointed_item = None
        self.offset = (0, 0)
        self.last_update = rospy.Time.now()

        super(TouchPointItem, self).__init__(scene, x, y,  parent)

        self.set_poss(x,  y)

    def boundingRect(self):

        return QtCore.QRectF(-20, -20, 40, 40)

    def end_of_touch(self):

        if self.pointed_item is not None:

            rospy.logdebug("releasing pointed item: " + self.pointed_item.__class__.__name__)
            self.pointed_item.set_hover(False, self)
            self.pointed_item.cursor_release()
            self.pointed_item = None

    def set_poss(self,  x,  y):

        self.last_update = rospy.Time.now()
        self.set_pos(x, y)

        if self.pointed_item is None:

            for it in self.scene().items():

                if not isinstance(it,  Item):  # TODO skip item not derived from Item
                    continue

                if not it.isVisible():
                    continue

                # TODO what types to skip?
                if isinstance(it,  TouchTableItem) or isinstance(it,  TouchPointItem) or isinstance(it,  DescItem):
                    continue

                if self.collidesWithItem(it):

                    parent = it.parentItem()
                    if not isinstance(it,  ButtonItem) and it.fixed and parent is not None and isinstance(parent, Item) and not parent.fixed:

                        it = it.parentItem()

                    rospy.logdebug("new pointed item: " + it.__class__.__name__)

                    it.set_hover(True, self)
                    self.pointed_item = it
                    self.pointed_item.cursor_press()

                    my_pos = self.get_pos()
                    it_pos = self.pointed_item.get_pos()

                    self.offset = (it_pos[0]-my_pos[0], it_pos[1]-my_pos[1])

                    break

        else:

            if self.pointed_item.fixed:

                if not self.collidesWithItem(self.pointed_item):

                    self.pointed_item.set_hover(False, self)
                    self.pointed_item = None

            else:

                self.pointed_item.set_pos(x+self.offset[0], y+self.offset[1])
                self.pointed_item.item_moved()

        self.update()

    def paint(self, painter, option, widget):

        if not self.scene():
            return

        painter.setClipRect(option.exposedRect)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        if self.pointed_item is not None:
            painter.setBrush(QtCore.Qt.red)
        else:
{'fraction_non_alphanumeric': 0.0880715370339126, 'fraction_numerical': 0.005736460266576683, 'mean_word_length': 1.7019143117593436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7659907', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1680, 'n_words': 392}