Coverage for src/robotide/widgets/htmlwnd.py: 73%

54 statements  

« 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. 

15 

16import webbrowser 

17 

18import wx 

19from wx import html, Colour 

20 

21from ..preferences.settings import RideSettings 

22 

23 

24_settings = RideSettings() 

25general_settings = _settings['General'] 

26BACKGROUND_HELP = 'background help' 

27HTML_BACKGROUND = general_settings.get(BACKGROUND_HELP, '#A5F173') 

28 

29 

30class HtmlWindow(html.HtmlWindow): 

31 

32 def __init__(self, parent, size=wx.DefaultSize, text=None): 

33 html.HtmlWindow.__init__(self, parent, size=size) 1cda

34 self.SetBorders(2) 1cda

35 self.SetStandardFonts(size=9) 1cda

36 self.SetBackgroundColour(Colour(200, 222, 40)) 1cda

37 if text: 1cda

38 self.set_content(text) 1a

39 self.SetHTMLBackgroundColour(Colour(general_settings.get(BACKGROUND_HELP, '#A5F173'))) 1cda

40 self.SetForegroundColour(Colour(general_settings.get('foreground help', '#080240'))) 1cda

41 self.font = self.GetFont() 1cda

42 self.font.SetFaceName(general_settings['font face']) 1cda

43 self.font.SetPointSize(general_settings['font size']) 1cda

44 self.SetFont(self.font) 1cda

45 self.Refresh(True) 1cda

46 self.Bind(wx.EVT_KEY_DOWN, self.on_key_down) 1cda

47 

48 def set_content(self, content): 

49 background = general_settings.get(BACKGROUND_HELP, '#A5F173') 1cda

50 h = background.lstrip('#') 1cda

51 if h.upper() == background.upper(): 51 ↛ 52line 51 didn't jump to line 52 because the condition on line 51 was never true1cda

52 from wx import ColourDatabase 

53 cdb = ColourDatabase() 

54 bkng = cdb.Find(h.upper()) 

55 bkg = (bkng[0], bkng[1], bkng[2]) 

56 else: 

57 bkg = tuple(int(h[i:i + 2], 16) for i in (0, 2, 4)) 1cda

58 background = '#%02X%02X%02X' % bkg 1cda

59 _content = '<body bgcolor=%s>%s</body>' % (background, content) 1cda

60 self.SetPage(_content) 1cda

61 

62 def on_key_down(self, event): 

63 if self._is_copy(event): 

64 self._add_selection_to_clipboard() 

65 self.Parent.on_key(event) 

66 event.Skip() 

67 

68 @staticmethod 

69 def _is_copy(event): 

70 return event.GetKeyCode() == ord('C') and event.CmdDown() 

71 

72 def _add_selection_to_clipboard(self): 

73 wx.TheClipboard.Open() 

74 wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) 

75 wx.TheClipboard.Close() 

76 

77 def OnLinkClicked(self, link): # Overrides wx method 

78 webbrowser.open(link.Href) 

79 

80 def close(self): 

81 self.Show(False) 

82 

83 def clear(self): 

84 self.SetPage('')