<commit_before>#!/usr/bin/env ruby
=begin
  tooltips.rb - Demonstrates the new tooltip API of Gtk+ 2.12;
                rg2 translation from gtk/tests/testtooltips.c.

  Copyright (c) 2007-2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

unless Gtk::Version.or_later?(3, 4, 2)
  puts "This sample requires GTK+ 3.4.2 or later: #{Gtk::Version::STRING}"
  exit
end


def treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip)
    if keyboard_tip
        # Keyboard mode
        ok,path = treeview.cursor
        if not path
            return false
        end
    else
        bin_x, bin_y = treeview.convert_widget_to_bin_window_coords(x, y)
        # Mouse mode
        ok, path = treeview.get_path_at_pos(bin_x, bin_y)
        if not path
            return false
        end
    end
    data = treeview.model.get_value(treeview.model.get_iter(path), 0)
    tooltip.markup = "<b>Path #{path}:</b> #{data}"
    return true
end

def textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag)
    if keyboard_tip
        iter = textview.buffer.get_iter_at_offset(textview.buffer.cursor_position)
    else
        bx, by = textview.window_to_buffer_coords(Gtk::TextWindowType::TEXT, x, y)
        iter, = textview.get_iter_at_position(bx, by)
    end
    if iter.has_tag?(tag)
        tooltip.text = 'Tooltip on text tag'
        return true
    else
        return false
    end
end

def drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles)
    if keyboard_tip
        return false
    end
    for r in rectangles<commit_msg>fix error in update of tooltips.rb<commit_after>#!/usr/bin/env ruby
=begin
  tooltips.rb - Demonstrates the new tooltip API of Gtk+ 2.12;
                rg2 translation from gtk/tests/testtooltips.c.

  Copyright (c) 2007-2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

unless Gtk::Version.or_later?(3, 4, 2)
  puts "This sample requires GTK+ 3.4.2 or later: #{Gtk::Version::STRING}"
  exit
end


def treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip)
    if keyboard_tip
        # Keyboard mode
        path, = treeview.cursor
        if not path
            return false
        end
    else
        bin_x, bin_y = treeview.convert_widget_to_bin_window_coords(x, y)
        # Mouse mode
        ok,path = treeview.get_path_at_pos(bin_x, bin_y)
        if not path
            return false
        end
    end
    data = treeview.model.get_value(treeview.model.get_iter(path), 0)
    tooltip.markup = "<b>Path #{path}:</b> #{data}"
    return true
end

def textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag)
    if keyboard_tip
        iter = textview.buffer.get_iter_at_offset(textview.buffer.cursor_position)
    else
        bx, by = textview.window_to_buffer_coords(Gtk::TextWindowType::TEXT, x, y)
        iter, = textview.get_iter_at_position(bx, by)
    end
    if iter.has_tag?(tag)
        tooltip.text = 'Tooltip on text tag'
        return true
    else
        return false
    end
end

def drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles)
    if keyboard_tip
        return false
    end
    for r in rectangles
{'fraction_non_alphanumeric': 0.08731617647058823, 'fraction_numerical': 0.013480392156862746, 'mean_word_length': 2.718678815489749, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '941832', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1094, 'n_words': 295}