Robot Framework Integrated Development Environment (RIDE)
tooltips.py
Go to the documentation of this file.
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.
15 
16 import wx
17 import wx.grid
18 
19 from .popupwindow import HtmlPopupWindow
20 
21 
22 class GridToolTips():
23 
24  def __init__(self, grid):
25  self._tooltip_tooltip = HtmlPopupWindow(grid, (250, 80), False, True)
26  self._information_popup_information_popup = HtmlPopupWindow(grid, (450, 300))
27  self._grid_grid = grid
28  self._tooltip_timer_tooltip_timer = wx.Timer(grid.GetGridWindow())
29  grid.GetGridWindow().Bind(wx.EVT_WINDOW_DESTROY, self.OnGridDestroyOnGridDestroy)
30  grid.GetGridWindow().Bind(wx.EVT_KILL_FOCUS, self.OnGridFocusLostOnGridFocusLost)
31  grid.GetGridWindow().Bind(wx.EVT_MOTION, self.OnMouseMotionOnMouseMotion)
32  grid.GetGridWindow().Bind(wx.EVT_TIMER, self.OnShowToolTipOnShowToolTip)
33  grid.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnGridEditorHiddenOnGridEditorHidden)
34 
35  def OnGridDestroy(self, event):
36  self._tooltip_timer_tooltip_timer.Stop()
37  event.Skip()
38 
39  def OnGridFocusLost(self, event):
40  self._tooltip_timer_tooltip_timer.Stop()
41  event.Skip()
42 
43  def OnMouseMotion(self, event):
44  self._hide_tooltip_hide_tooltip()
45  if event.CmdDown():
46  self._tooltip_timer_tooltip_timer.Stop()
47  self._grid_grid.show_cell_information()
48  else:
49  self._information_popup_information_popup.hide()
50  self._start_tooltip_timer_start_tooltip_timer()
51  event.Skip()
52 
54  self._tooltip_timer_tooltip_timer.Start(1000, True)
55 
56  def OnShowToolTip(self, event):
57  self._hide_tooltip_hide_tooltip()
58  content = self._grid_grid.get_tooltip_content()
59  if content and self._application_has_focus_application_has_focus():
60  self._show_tooltip_at_show_tooltip_at(content, self._calculate_tooltip_position_calculate_tooltip_position())
61  self._grid_grid.SetFocus()
62 
64  window = wx.Window.FindFocus()
65  if window is None:
66  return False
67  rect = window.GetTopLevelParent().GetScreenRect()
68  return rect.Contains(wx.GetMousePosition())
69 
70  def OnGridEditorHidden(self, event):
71  cell = event.Row, event.Col
72  if cell == self._grid_grid.cell_under_cursor:
73  self._start_tooltip_timer_start_tooltip_timer()
74 
75  def _show_tooltip_at(self, content, position):
76  if not self._information_popup_information_popup.IsShown():
77  self._tooltip_tooltip.set_content(content)
78  self._tooltip_tooltip.show_at(position)
79 
81  x, y = wx.GetMousePosition()
82  return x + 16, y + 16 # don't place tooltip under cursor
83 
84  def _hide_tooltip(self):
85  self._tooltip_tooltip.hide()
86 
87  def hide_information(self):
88  self._information_popup_information_popup.hide()
89 
90  def hide(self):
91  self._hide_tooltip_hide_tooltip()
92  self.hide_informationhide_information()
93 
94  def show_info_at(self, info, title, position):
95  self._tooltip_tooltip.hide()
96  self._information_popup_information_popup.set_content(info, title)
97  self._information_popup_information_popup.show_at(position)
def _show_tooltip_at(self, content, position)
Definition: tooltips.py:75
def OnGridEditorHidden(self, event)
Definition: tooltips.py:70
def show_info_at(self, info, title, position)
Definition: tooltips.py:94