lazy initialization of highlight pens and brushes for DebugVariableViewer
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 19:01:31 +0300
changeset 1807 5562f34f2fc2
parent 1806 6b4d0f4f2fbc
child 1808 b4764ebb352d
lazy initialization of highlight pens and brushes for DebugVariableViewer

Constructors wx.Pen() and wx.Brush() require wx.App to exist already.
That causes crash during import of the control,
because import is done before calling main application code.
controls/DebugVariablePanel/DebugVariableViewer.py
--- a/controls/DebugVariablePanel/DebugVariableViewer.py	Fri Sep 15 18:57:20 2017 +0300
+++ b/controls/DebugVariablePanel/DebugVariableViewer.py	Fri Sep 15 19:01:31 2017 +0300
@@ -41,10 +41,10 @@
  HIGHLIGHT_RESIZE] = range(6)
 
 # Viewer highlight styles
-HIGHLIGHT_DROP_PEN = wx.Pen(wx.Colour(0, 128, 255))
-HIGHLIGHT_DROP_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128))
-HIGHLIGHT_RESIZE_PEN = wx.Pen(wx.Colour(200, 200, 200))
-HIGHLIGHT_RESIZE_BRUSH = wx.Brush(wx.Colour(200, 200, 200))
+HIGHLIGHT_DROP_PEN = None
+HIGHLIGHT_DROP_BRUSH = None
+HIGHLIGHT_RESIZE_PEN = None
+HIGHLIGHT_RESIZE_BRUSH = None
 
 # -------------------------------------------------------------------------------
 #                        Base Debug Variable Viewer Class
@@ -72,6 +72,7 @@
         self.Highlight = HIGHLIGHT_NONE
         # List of buttons
         self.Buttons = []
+        self.InitHighlightPensBrushes()
 
     def __del__(self):
         """
@@ -80,6 +81,16 @@
         # Remove reference to Debug Variable Panel
         self.ParentWindow = None
 
+    def InitHighlightPensBrushes(self):
+        """
+        Init global pens and brushes
+        """
+        if HIGHLIGHT_DROP_PEN is None:
+            HIGHLIGHT_DROP_PEN = wx.Pen(wx.Colour(0, 128, 255))
+            HIGHLIGHT_DROP_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128))
+            HIGHLIGHT_RESIZE_PEN = wx.Pen(wx.Colour(200, 200, 200))
+            HIGHLIGHT_RESIZE_BRUSH = wx.Brush(wx.Colour(200, 200, 200))
+
     def GetIndex(self):
         """
         Return position of Viewer in Debug Variable Panel