# HG changeset patch # User Andrey Skvortsov # Date 1530023655 -10800 # Node ID 3c94bac4526e8754d383de9319f9c3e753f6d66e # Parent 12cb48823b8c474c853ef9ef3117153b89fe4fd5 Fix 'DoGetTextExtent - invalid DC' error most likely this error happens only on certain wx backends. GTK3+ on GNU/Linux is apparently one of them. The problem is described in wxWidgets issue tracker. http://trac.wxwidgets.org/ticket/12486 [-------------------------------------------------------------------------------------------------------------------] platform: Linux-4.16.0-2-rt-amd64-x86_64-with-debian-buster-sid python-version: 2.7.15 traceback: File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 1605, in DispatchDebugValuesProc self.CallWeakcallables("__tick__", "NewDataAvailable", debug_ticks) File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 1585, in CallWeakcallables function(*cargs) File "/home/developer/WorkData/PLC/beremiz/beremiz/editors/Viewer.py", line 1217, in NewDataAvailable refresh_rect.Union(element.GetRedrawRect()) File "/home/developer/WorkData/PLC/beremiz/beremiz/graphics/GraphicCommons.py", line 1609, in GetRedrawRect self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) File "/home/developer/WorkData/PLC/beremiz/beremiz/editors/Viewer.py", line 932, in GetMiniTextExtent return self.MiniTextDC.GetTextExtent(text) File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk3/wx/_gdi.py", line 4127, in GetTextExtent return _gdi_.DC_GetTextExtent(*args, **kwargs) : C++ assertion "m_graphicContext" failed at ../src/common/dcgraph.cpp(1160) in DoGetTextExtent(): wxGCDC(cg)::DoGetTextExtent - invalid DC wx-platform: __WXGTK__ wx-version: 3.0.2.0 [-------------------------------------------------------------------------------------------------------------------] traceback: File "/home/developer/WorkData/PLC/beremiz/beremiz/controls/LogViewer.py", line 740, in OnMessageToolTipTimer self.MessageToolTip.SetFont(self.Font) File "/home/developer/WorkData/PLC/beremiz/beremiz/controls/CustomToolTip.py", line 75, in SetFont self.RefreshTip() File "/home/developer/WorkData/PLC/beremiz/beremiz/controls/CustomToolTip.py", line 158, in RefreshTip self.SetClientSize(self.GetToolTipSize()) File "/home/developer/WorkData/PLC/beremiz/beremiz/controls/CustomToolTip.py", line 145, in GetToolTipSize w, h = dc.GetTextExtent(line) File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk3/wx/_gdi.py", line 4127, in GetTextExtent return _gdi_.DC_GetTextExtent(*args, **kwargs) : C++ assertion "m_graphicContext" failed at ../src/common/dcgraph.cpp(1160) in DoGetTextExtent(): wxGCDC(cg)::DoGetTextExtent - invalid DC [-------------------------------------------------------------------------------------------------------------------] diff -r 12cb48823b8c -r 3c94bac4526e controls/CustomToolTip.py --- a/controls/CustomToolTip.py Tue Jun 26 14:48:44 2018 +0300 +++ b/controls/CustomToolTip.py Tue Jun 26 17:34:15 2018 +0300 @@ -137,7 +137,7 @@ max_width = max_height = 0 # Create a memory DC for calculating text extent - dc = wx.MemoryDC() + dc = wx.MemoryDC(wx.EmptyBitmap(1, 1)) dc.SetFont(self.Font) # Compute max tip text size diff -r 12cb48823b8c -r 3c94bac4526e editors/Viewer.py --- a/editors/Viewer.py Tue Jun 26 14:48:44 2018 +0300 +++ b/editors/Viewer.py Tue Jun 26 17:34:15 2018 +0300 @@ -770,7 +770,7 @@ dc.SetFont(font) width, _height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") self.SetFont(font) - self.MiniTextDC = wx.MemoryDC() + self.MiniTextDC = wx.MemoryDC(wx.EmptyBitmap(1, 1)) self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["helv"])) self.CurrentScale = None