Coverage for src/robotide/log/logwindow.py: 91%
61 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
17from wx import Colour
19from .. import widgets
20from ..widgets import RIDEDialog
21from wx.stc import StyledTextCtrl
24def message_to_string(msg, parserlog=False):
25 message = msg.message.replace('\n\t', '') if parserlog else msg.message 1bacde
26 return '%s [%s]: %s\n\n' % (msg.timestamp, msg.level, message) 1bacde
29class LogWindow(wx.Panel):
31 def __init__(self, notebook, title, log):
32 wx.Panel.__init__(self, notebook) 1a
33 self.dlg = RIDEDialog() 1a
34 self.title = title 1a
35 self._removetabs = self.title == 'Parser Log' 1a
36 self._output = StyledTextCtrl(self, wx.ID_ANY, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_NOHIDESEL) 1a
37 fore = self.dlg.color_foreground 1a
38 backg = self.dlg.color_background 1a
39 self._output.SetBackgroundColour(Colour(backg)) 1a
40 self._output.SetForegroundColour(Colour(fore)) 1a
41 self._output.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, f"fore:{fore}, back:{backg}") 1a
42 self._output.StyleSetBackground(wx.stc.STC_STYLE_DEFAULT, backg) 1a
43 self._output.Bind(wx.EVT_KEY_DOWN, self.on_key_down) 1a
44 self._log = log 1a
45 self._add_to_notebook(notebook) 1a
46 self.SetFont(widgets.Font().fixed_log) 1a
47 self.Bind(wx.EVT_SIZE, self.on_size) 1a
49 def _create_ui(self):
50 self.SetSizer(widgets.VerticalSizer()) 1a
51 self.Sizer.add_expanding(self._output) 1a
53 def _add_to_notebook(self, notebook):
54 notebook.add_tab(self, self.title, allow_closing=True) 1a
55 notebook.show_tab(self) 1a
56 self._output.SetSize(self.Size) 1a
58 def close(self, notebook):
59 self._output.Close() 1a
60 notebook.delete_tab(self) 1a
62 def update_log(self):
63 content = self._decode_log(self._log) 1a
64 text_size = len(content) 1a
65 self._output.SetReadOnly(False) 1a
66 self._output.SetText(content) 1a
67 self._output.SetStyling(text_size, wx.stc.STC_STYLE_DEFAULT) 1a
68 self._output.SetReadOnly(True) 1a
69 self._output.Refresh() 1a
71 def _decode_log(self, log):
72 result = '' 1a
73 for msg in log: 1a
74 result += message_to_string(msg, self._removetabs) 1a
75 return result 1a
77 def on_size(self, evt):
78 _ = evt 1a
79 self._output.SetSize(self.Size) 1a
81 def on_key_down(self, event):
82 keycode = event.GetKeyCode()
84 if event.ControlDown() and keycode == ord('A'):
85 self.SelectAll()
86 else:
87 event.Skip()
89 def Copy(self):
90 """ Overriden in purpose """
91 pass 1a
93 def SelectAll(self):
94 self._output.SetSelection(-1, -1) 1a