(self, pos_x, pos_y)
return Caret(mode, index, 0)
screen to caretpos
screen to caretpos
screen to caretpos
def pixel_to_caret(self, pos_x, pos_y):
        """ screen to caretpos
        """
        if self.data is None:
            return None
        # pos in offset
        if pos_x <= (self._hex_start - self._char_width):
            return None

        # pos in header
        if pos_y <= self._header_height:
            return None

        index = 0
        mode = 'hex'

        # in hex
        if pos_x <= self._ascii_start - self._col_div:
            column, row = self.pixel_to_data(pos_x - self._hex_start, pos_y)
            if column < 0 or row < 0:
                return None
            line = int(ceil(column - (column / 3)))
            index = int(
                floor(self.pos + line / 2 + row * self.bytes_per_line))
            if index > len(self.data):
                index = len(self.data)
            mode = 'hex'

        # in ascii
        if pos_x > self._ascii_start - self._col_div:
            column, row = self.pixel_to_data(pos_x - self._ascii_start, pos_y)
            if column < 0 or row < 0:
                return None
            line_index = int(ceil(column % self.bytes_per_line))
            index = int(
                floor(self.pos + line_index + row * self.bytes_per_line))
            if index > len(self.data):
                index = len(self.data)
            mode = 'ascii'

        return Caret(mode, index, 0)
def pixel_to_caret ( self , pos_x , pos_y ) : if self . data is None : return None # pos in offset if pos_x <= ( self . _hex_start - self . _char_width ) : return None # pos in header if pos_y <= self . _header_height : return None index = 0 mode = 'hex' # in hex if pos_x <= self . _ascii_start - self . _col_div : column , row = self . pixel_to_data ( pos_x - self . _hex_start , pos_y ) if column < 0 or row < 0 : return None line = int ( ceil ( column - ( column / 3 ) ) ) index = int ( floor ( self . pos + line / 2 + row * self . bytes_per_line ) ) if index > len ( self . data ) : index = len ( self . data ) mode = 'hex' # in ascii if pos_x > self . _ascii_start - self . _col_div : column , row = self . pixel_to_data ( pos_x - self . _ascii_start , pos_y ) if column < 0 or row < 0 : return None line_index = int ( ceil ( column % self . bytes_per_line ) ) index = int ( floor ( self . pos + line_index + row * self . bytes_per_line ) ) if index > len ( self . data ) : index = len ( self . data ) mode = 'ascii' return Caret ( mode , index , 0 )