1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
"""Tooltips.
From:
http://stackoverflow.com/questions/34468909/how-to-make-tooltip-using-kivy
Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import os
# kivy imports
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.clock import Clock
# Cannot import kivy.core.window.Window here; Leads to a segfault.
# Doing it within the *Tooltip* class works just fine, though.
# exports
__all__ = ('Tooltip', )
## CODE ##
Builder.load_file(os.path.join(os.path.dirname(__file__), 'tooltip.kv'))
class Tooltip_Label(Label):
pass
# FIXME: Tooltip makes the whole UI *way* too slow, hence it's body is disabled
class Tooltip(object):
def set_tooltip(self, text):
pass
# if hasattr(self, '_tooltip_wx') and self._tooltip_wx is not None:
# self._tooltip_wx.text = text
# else:
# self._tooltip_wx = Tooltip_Label(text=text)
# from kivy.core.window import Window
# Window.bind(mouse_pos=self.on_mouse_pos)
#
# def on_mouse_pos(self, *args):
# if not self.get_root_window():
# return
#
# pos_x, pos_y = pos = args[1]
# from kivy.core.window import Window
# pos_x = max(0, min(pos_x, Window.width - self._tooltip_wx.width))
# pos_y = max(0, min(pos_y, Window.height - self._tooltip_wx.height))
# self._tooltip_wx.pos = (pos_x, pos_y)
#
# Clock.unschedule(self.display_tooltip) # cancel scheduled event since I moved the cursor
# self.close_tooltip() # close if it's opened
# if self.collide_point(*pos):
# Clock.schedule_once(self.display_tooltip, 1)
#
# def close_tooltip(self, *args):
# from kivy.core.window import Window
# Window.remove_widget(self._tooltip_wx)
#
# def display_tooltip(self, *args):
# from kivy.core.window import Window
# Window.add_widget(self._tooltip_wx)
## EOF ##
|