26 from ..
import context
27 from ..
import widgets
28 from ..pluginapi
import Plugin
29 from ..action
import ActionInfo
30 from ..publish.messages
import RideParserLogMessage
31 from ..widgets
import RIDEDialog
34 return '%s [%s]: %s\n\n' % (msg.timestamp, msg.level, msg.message.replace(
'\n\t',
''))
41 Plugin.__init__(self, app, default_settings={
42 'log_to_console':
False,
48 tempfile.gettempdir(),
'{}-ride_parser.log'.format(uuid.uuid4()))
51 atexit.register(self.
_close_close)
54 if self.
_outfile_outfile
is not None:
58 for fname
in glob.glob(
59 os.path.join(tempfile.gettempdir(),
'*-ride_parser.log')):
62 except OSError
or IOError
or PermissionError
as e:
63 sys.stderr.write(f
"Removing old *-ride_parser.log files failed with: {repr(e)}\n")
72 self.
_outfile_outfile = io.open(self.
_path_path,
'w', encoding=
'utf8')
77 self.subscribe(self.
_log_message_log_message, RideParserLogMessage)
80 self.unsubscribe_all()
81 self.unregister_actions()
83 self.
_panel_panel.close(self.notebook)
86 self.unregister_actions()
88 'Tools',
'View Parser Log', self.
OnViewLogOnViewLog, position=83))
91 self.
_log_log.append(message)
93 self.
_panel_panel.update_log()
94 if self.log_to_console:
99 if message.notify_user:
100 font_size = 13
if context.IS_MAC
else -1
102 padding=10, font_size=font_size).Show()
103 self.
OnViewLogOnViewLog(message, show_tab=
False)
108 self.notebook.SetPageTextColour(self.notebook.GetPageCount()-1, wx.Colour(255, 165, 0))
109 self.
_panel_panel.update_log()
110 self.register_shortcut(
'CtrlCmd-C',
lambda e: self.
_panel_panel.Copy())
112 self.notebook.show_tab(self.
_panel_panel)
118 wx.Panel.__init__(self, notebook)
119 self.
dlgdlg = RIDEDialog()
120 self.
_output_output = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_NOHIDESEL)
121 self.
_output_output.SetBackgroundColour(Colour(self.
dlgdlg.color_background))
122 self.
_output_output.SetForegroundColour(Colour(self.
dlgdlg.color_foreground))
128 self.Bind(wx.EVT_SIZE, self.
OnSizeOnSize)
131 notebook.add_tab(self,
'Parser Log', allow_closing=
True)
132 self.
_output_output.SetSize(self.Size)
135 notebook.delete_tab(self)
139 self.Sizer.add_expanding(self.
_output_output)
151 self.
_output_output.SetSize(self.Size)
154 keycode = event.GetKeyCode()
156 if event.ControlDown()
and keycode == ord(
'A'):
165 self._output.SetSelection(-1, -1)
Used to create menu entries, keyboard shortcuts and/or toolbar buttons.
Viewer for internal log messages.
def _log_message(self, message)
def _remove_old_log_files(self)
def OnViewLog(self, event, show_tab=True)
def _decode_log(self, log)
def _add_to_notebook(self, notebook)
def __init__(self, notebook, log)
def close(self, notebook)
def OnKeyDown(self, event)
def write(msg, level='INFO', html=False)
Writes the message to the log file using the given level.
def _message_to_string(msg)