Coverage for src/robotide/editor/tooltips.py: 26%
66 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
1# Copyright 2008-2015 Nokia Networks
2# Copyright 2016- Robot Framework Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16import wx 1ab
17import wx.grid 1ab
19from .popupwindow import HtmlPopupWindow 1ab
22class GridToolTips(object): 1ab
24 def __init__(self, grid): 1ab
25 self._tooltip = HtmlPopupWindow(grid, (250, 80), False, True)
26 self._information_popup = HtmlPopupWindow(grid, (450, 300))
27 self._grid = grid
28 self._tooltip_timer = wx.Timer(grid.GetGridWindow())
29 grid.GetGridWindow().Bind(wx.EVT_WINDOW_DESTROY, self.on_grid_destroy)
30 grid.GetGridWindow().Bind(wx.EVT_KILL_FOCUS, self.on_grid_focus_lost)
31 grid.GetGridWindow().Bind(wx.EVT_MOTION, self.on_mouse_motion)
32 grid.GetGridWindow().Bind(wx.EVT_TIMER, self.on_show_tool_tip)
33 grid.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.on_grid_editor_hidden)
35 def on_grid_destroy(self, event): 1ab
36 self._tooltip_timer.Stop()
37 event.Skip()
39 def on_grid_focus_lost(self, event): 1ab
40 self.on_grid_destroy(event)
42 def on_mouse_motion(self, event): 1ab
43 self._hide_tooltip()
44 if event.CmdDown():
45 self._tooltip_timer.Stop()
46 self._grid.show_cell_information()
47 else:
48 self._information_popup.hide()
49 self._start_tooltip_timer()
50 event.Skip()
52 def _start_tooltip_timer(self): 1ab
53 self._tooltip_timer.Start(1000, True)
55 def on_show_tool_tip(self, event): 1ab
56 __ = event
57 self._hide_tooltip()
58 content = self._grid.get_tooltip_content()
59 if content and self._application_has_focus():
60 self._show_tooltip_at(content, self._calculate_tooltip_position())
61 self._grid.SetFocus()
63 @staticmethod 1ab
64 def _application_has_focus(): 1ab
65 window = wx.Window.FindFocus()
66 if window is None:
67 return False
68 rect = window.GetTopLevelParent().GetScreenRect()
69 return rect.Contains(wx.GetMousePosition())
71 def on_grid_editor_hidden(self, event): 1ab
72 cell = event.Row, event.Col
73 if cell == self._grid.cell_under_cursor:
74 self._start_tooltip_timer()
76 def _show_tooltip_at(self, content, position): 1ab
77 if not self._information_popup.IsShown():
78 self._tooltip.set_content(content)
79 self._tooltip.show_at(position)
81 @staticmethod 1ab
82 def _calculate_tooltip_position(): 1ab
83 x, y = wx.GetMousePosition()
84 return x + 16, y + 16 # don't place tooltip under cursor
86 def _hide_tooltip(self): 1ab
87 self._tooltip.hide()
89 def hide_information(self): 1ab
90 self._information_popup.hide()
92 def hide(self): 1ab
93 self._hide_tooltip()
94 self.hide_information()
96 def show_info_at(self, info, title, position): 1ab
97 self._tooltip.hide()
98 self._information_popup.set_content(info, title)
99 self._information_popup.show_at(position)