Coverage for src/robotide/log/logoutput.py: 86%
57 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 2024- Robot Framework Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15import wx
16from wx import Colour
18from .. import widgets
19from ..preferences import RideSettings
20from wx.stc import StyledTextCtrl
23def message_to_string(msg):
24 message = msg.replace('\t', ' ') 1a
25 return message 1a
28class LogOutput(wx.Panel):
30 def __init__(self, parent):
31 wx.Panel.__init__(self, parent) 1a
32 self._output = StyledTextCtrl(self, wx.ID_ANY, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_NOHIDESEL) 1a
33 self.SetSizer(widgets.VerticalSizer()) 1a
34 _settings = RideSettings() 1a
35 self.run_settings = _settings['Plugins']['Run Anything'] 1a
36 fore = self.run_settings.get('foreground', '#ffffff') 1a
37 backg = self.run_settings.get('background', '#241F31') 1a
38 self._output.SetBackgroundColour(Colour(backg)) 1a
39 self._output.SetForegroundColour(Colour(fore)) 1a
40 self._output.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, f"fore:{fore}, back:{backg}") 1a
41 self._output.StyleSetBackground(wx.stc.STC_STYLE_DEFAULT, backg) 1a
42 self._output.Bind(wx.EVT_KEY_DOWN, self.on_key_down) 1a
43 self._output.SetSize(self.Size) 1a
44 self.Sizer.add_expanding(self._output) 1a
45 self.SetFont(widgets.Font().fixed_log) 1a
46 self.Bind(wx.EVT_SIZE, self.on_size) 1a
47 self.Layout() 1a
48 # print(f"DEBUG: runanything.py LogOutput end init output={self._output}")
50 def close(self):
51 self._output.Close() 1a
53 def update_log(self, log=None):
54 if not log: 1a
55 return 1a
56 if isinstance(log, list): 1a
57 content = self._decode_log(log) 1a
58 else:
59 content = log 1a
60 # print(f"DEBUG: runanything.py LogOutput update_log content={content}")
61 text_size = len(content) 1a
62 self._output.SetReadOnly(False) 1a
63 self._output.SetText(content) 1a
64 self._output.SetStyling(text_size, wx.stc.STC_STYLE_DEFAULT) 1a
65 self._output.SetReadOnly(True) 1a
66 self._output.Refresh() 1a
68 @staticmethod
69 def _decode_log(log):
70 result = '' 1a
71 for msg in log: 1a
72 result += message_to_string(msg) 1a
73 return result 1a
75 def on_size(self, evt):
76 _ = evt
77 self._output.SetSize(self.Size)
79 def on_key_down(self, event):
80 keycode = event.GetKeyCode()
82 if event.ControlDown() and keycode == ord('A'):
83 self.SelectAll()
84 else:
85 event.Skip()
87 def SelectAll(self):
88 self._output.SetSelection(-1, -1)