Robot Framework Integrated Development Environment (RIDE)
popupwindow.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 
18 from ..context import POPUP_BACKGROUND, POPUP_FOREGROUND, IS_WINDOWS
19 from ..widgets import VerticalSizer, HtmlWindow, HtmlDialog
20 
21 
22 class _PopupWindowBase(wx.Frame):
23 
24  def __init__(self, size, detachable=True, autohide=False, color_background=POPUP_BACKGROUND,
25  color_foreground=POPUP_FOREGROUND):
26  # print("DEBUG: PopupWindow at init")
27  self.color_backgroundcolor_background = color_background
28  self.color_foregroundcolor_foreground = color_foreground
29  self.panelpanel = self._create_ui_create_ui(size)
30  if autohide:
31  self._set_auto_hiding()
32  if detachable:
33  self._set_detachable_set_detachable()
34  self.SetSize(size)
35 
36  def _create_ui(self, size):
37  panel = wx.MiniFrame(self)
38  #TODO: Make this colour dependent on colours cycle or by Library
39  panel.SetBackgroundColour(self.color_backgroundcolor_background)
40  panel.SetForegroundColour(self.color_foregroundcolor_foreground)
41  szr = VerticalSizer()
42  self._details_details = HtmlWindow(self, size=size)
43  szr.add_expanding(self._details_details)
44  # DEBUG: Grid Editor was broken on wxPython 4.2.0 with the SetSizer
45  # panel.SetSizerAndFit(szr)
46  return panel
47 
48  def _set_detachable(self):
49  self._details_details.Bind(wx.EVT_LEFT_UP, self._detach_detach)
50  self._details_details.Bind(wx.EVT_LEFT_DCLICK, self._detach_detach) # DEBUG add double-click
51 
52  def _detach(self, event):
53  self.hidehide()
54  dlg = HtmlDialog(self._detached_title_detached_title, self._current_details_current_details)
55  dlg.SetPosition((wx.GetMouseState().x, wx.GetMouseState().y))
56  dlg.Show()
57  event.Skip()
58 
59  def show_at(self, position):
60  if self.GetPosition() != position:
61  self.SetPosition(position)
62  if not self.IsShown():
63  self.Show()
64 
65  def hide(self, event=None):
66  self.Show(False)
67 
68  @property
69  screen_position = property
70 
71  def screen_position(self):
72  return self.ScreenPosition
73 
74  @property
75  size = property
76 
77  def size(self):
78  return self.Size
79 
80  def set_content(self, content, title=None):
81  if isinstance(self.color_backgroundcolor_background, tuple):
82  color = '#' + ''.join(hex(item)[2:] for item in self.color_backgroundcolor_background)
83  else:
84  color = self.color_backgroundcolor_background
85  self._current_details_current_details = '<body bgcolor=%s>%s</body>' % (color, content)
86  self._details_details.SetPage(self._current_details_current_details)
87  self._detached_title_detached_title = title
88 
89 
90 class RidePopupWindow(wx.PopupWindow, _PopupWindowBase):
91 
92  def __init__(self, parent, size):
93  wx.PopupWindow.__init__(self, parent,
94  flags=wx.CAPTION | wx.RESIZE_BORDER | wx.DEFAULT_FRAME_STYLE)
95  # _PopupWindowBase.__init__(self, size, color_background=(40,40,10), color_foreground=(255,120,0))
96  self.SetSize(size)
97 
98  def _set_auto_hiding(self):
99  # EVT_LEAVE is triggered on different components on different OSes.
100  component_to_hide = self.panelpanel if IS_WINDOWS else self
101  component_to_hide.Bind(wx.EVT_LEAVE_WINDOW, self.hidehide)
102 
103 
105 
106  def __init__(self, parent, size, detachable=True, autohide=False):
107  from ..preferences import RideSettings
108 
111  _settings = RideSettings()
112  self.general_settingsgeneral_settings = _settings['General']
113  self.color_background_helpcolor_background_help = self.general_settingsgeneral_settings['background help']
114  self.color_foreground_textcolor_foreground_text = self.general_settingsgeneral_settings['foreground text']
115  RidePopupWindow.__init__(self, parent, size)
116  _PopupWindowBase.__init__(self, size, detachable, autohide, color_background=self.color_background_helpcolor_background_help,
117  color_foreground=self.color_foreground_textcolor_foreground_text)
118 
119 
120 # TODO: See if we need to have Mac specific window
122 
123  def __init__(self, parent, size, detachable=True, autohide=False):
124  wx.MiniFrame.__init__(self, parent, style=wx.SIMPLE_BORDER
125  |wx.RESIZE_BORDER)
126  # set Left to Right direction (while we don't have localization)
127  self.SetLayoutDirection(wx.Layout_LeftToRight)
128  from ..preferences import RideSettings
129 
132  _settings = RideSettings()
133  self.general_settingsgeneral_settings = _settings['General']
134  self.color_background_helpcolor_background_help = self.general_settingsgeneral_settings['background help']
135  self.color_foreground_textcolor_foreground_text = self.general_settingsgeneral_settings['foreground text']
136  _PopupWindowBase.__init__(self, size, detachable, autohide, color_background=self.color_background_helpcolor_background_help,
137  color_foreground=self.color_foreground_textcolor_foreground_text)
138  self.hidehide()
139 
140  def _set_auto_hiding(self):
141  self._details_details.Bind(wx.EVT_MOTION, lambda evt: self.hidehide())
142 
143  def OnKey(self, *params):
144  pass
145 
146 
147 if wx.PlatformInfo[0] == '__WXMAC__':
148  RidePopupWindow = HtmlPopupWindow = MacRidePopupWindow
149 del MacRidePopupWindow
def __init__(self, parent, size, detachable=True, autohide=False)
Definition: popupwindow.py:106
def __init__(self, parent, size, detachable=True, autohide=False)
Definition: popupwindow.py:123
def set_content(self, content, title=None)
Definition: popupwindow.py:80
def __init__(self, size, detachable=True, autohide=False, color_background=POPUP_BACKGROUND, color_foreground=POPUP_FOREGROUND)
Definition: popupwindow.py:25