beremiz

Fix 'DoGetTextExtent - invalid DC' error

2018-06-26, Andrey Skvortsov
3c94bac4526e
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

[-------------------------------------------------------------------------------------------------------------------]
include yslt_noindent.yml2
istylesheet xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:ns="beremiz"
extension-element-prefixes="ns"
exclude-result-prefixes="ns" {
template "text()";
template "text()", mode="var_class";
template "text()", mode="var_type";
template "text()", mode="var_edit";
template "text()", mode="var_debug";
variable "project", "ns:GetProject()";
variable "stdlib", "ns:GetStdLibs()";
variable "extensions", "ns:GetExtensions()";
variable "all_types", "($project | $stdlib | $extensions)/ppx:types";
function "add_root" {
param "class";
param "type";
param "edit" > true
param "debug" > true
value "ns:SetRoot($class, $type, $edit, $debug)";
}
template "ppx:pou" {
call "add_root" {
with "class" > «@pouType»
with "type" > «@name»
}
apply "ppx:interface";
apply "ppx:actions/ppx:action | ppx:transitions/ppx:transition", mode="variable_list";
}
template "ppx:action" {
call "add_root" {
with "class" > action
}
apply "ancestor::ppx:pou/child::ppx:interface";
}
template "ppx:transition" {
call "add_root" {
with "class" > transition
}
apply "ancestor::ppx:pou/child::ppx:interface";
}
template "ppx:configuration" {
call "add_root" {
with "class" > configuration
with "debug" > false
}
apply "ppx:resource", mode="variable_list";
apply "ppx:globalVars";
}
template "ppx:resource" {
call "add_root" {
with "class" > resource
with "debug" > false
}
apply "ppx:pouInstance | ppx:task/ppx:pouInstance", mode="variable_list";
apply "ppx:globalVars";
}
function "variables_infos" {
param "var_class";
foreach "ppx:variable" {
variable "class" {
apply "ppx:type", mode="var_class" {
with "default_class" > «$var_class»
}
}
variable "type" {
apply"ppx:type", mode="var_type";
}
variable "edit" {
apply "ppx:type", mode="var_edit";
}
variable "debug" {
apply "ppx:type", mode="var_debug";
}
value "ns:AddVariable(@name, $class, $type, $edit, $debug)";
}
}
template "ppx:localVars" {
call "variables_infos" {
with "var_class" > Local
}
}
template "ppx:globalVars" {
call "variables_infos" {
with "var_class" > Global
}
}
template "ppx:externalVars" {
call "variables_infos" {
with "var_class" > External
}
}
template "ppx:tempVars" {
call "variables_infos" {
with "var_class" > Temp
}
}
template "ppx:inputVars" {
call "variables_infos" {
with "var_class" > Input
}
}
template "ppx:outputVars" {
call "variables_infos" {
with "var_class" > Output
}
}
template "ppx:inOutVars" {
call "variables_infos" {
with "var_class" > InOut
}
}
function "add_variable" {
param "name";
param "class";
param "type";
param "edit" > true
param "debug" > true
value "ns:AddVariable($name, $class, $type, $edit, $debug)";
}
template "ppx:action", mode="variable_list" {
call "add_variable" {
with "name" > «@name»
with "class" > action
}
}
template "ppx:transition", mode="variable_list" {
call "add_variable" {
with "name" > «@name»
with "class" > transition
}
}
template "ppx:resource", mode="variable_list" {
call "add_variable" {
with "name" > «@name»
with "class" > resource
with "debug" > false
}
}
template "ppx:pouInstance", mode="variable_list" {
call "add_variable" {
with "name" > «@name»
with "class" > program
with "type" > «@typeName»
}
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_class" {
param "default_class";
variable "type_name", "@name";
variable "pou_infos", "$all_types/ppx:pous/ppx:pou[@name=$type_name]";
choose {
when "$pou_infos" {
apply "$pou_infos", mode="var_class";
}
otherwise {
value "$default_class"
}
}
}
template "ppx:pou", mode="var_class" {
value "@pouType";
}
template "*[self::ppx:type or self::ppx:baseType]/*" mode="var_class" {
param "default_class";
value "$default_class";
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_type" {
> «@name»
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_type" {
> ARRAY [
foreach "ppx:dimension" {
> «@lower»..«@upper»
}
> ] OF
apply "ppx:baseType", mode="var_type";
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:string", mode="var_type" {
> STRING
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:wstring", mode="var_type" {
> WSTRING
}
template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_type" {
> «local-name()»
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_edit" {
variable "type_name", "@name";
variable "pou_infos", "$project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
choose {
when "$pou_infos" > true
otherwise > false
}
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_edit" {
apply "ppx:baseType", mode="var_edit";
}
template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_edit" {
> false
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_debug" {
variable "type_name", "@name";
variable "datatype_infos", """ \
$project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] | \
$all_types/ppx:dataTypes/ppx:dataType[@name=$type_name] \
""";
choose {
when "$datatype_infos" {
apply "$datatype_infos", mode="var_debug";
}
otherwise > false
}
}
template "ppx:pou", mode="var_debug" {
> true
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_debug" {
> false
}
template "*[self::ppx:type or self::ppx:baseType]/ppx:struct", mode="var_debug" {
> false
}
template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_debug" {
> true
}
}