Avoid usage of localized strings before initialization during import in many modules
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 29 Aug 2018 18:53:02 +0300
changeset 2301 5b8a7dd43f9f
parent 2300 f19788028d99
child 2302 69fefac5760e
Avoid usage of localized strings before initialization during import in many modules

This happens if import is done before i18n setup
(InstallLocalRessources()).
This affects PLCOpenEditor mostly. Beremiz IDE is free from this issue, but moving
initialization from import should make modules more robust.
Otherwise execution result depends on where and when import was done
and this is not a good thing.

Some modules (ConfigTreeNode, features, CodeFileEditor related
classes) still have this, but they are used only in Beremiz.
Most problems result in non-working internatialization.
In some cases (VariablePanel) there is backtrace, because localized
key is not found in non-localized dictionary.
IDEFrame.py
controls/DebugVariablePanel/DebugVariablePanel.py
controls/VariablePanel.py
dialogs/BrowseLocationsDialog.py
dialogs/DurationEditorDialog.py
dialogs/FBDVariableDialog.py
dialogs/PouActionDialog.py
dialogs/PouTransitionDialog.py
editors/FileManagementPanel.py
editors/ResourceEditor.py
editors/Viewer.py
--- a/IDEFrame.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/IDEFrame.py	Wed Aug 29 18:53:02 2018 +0300
@@ -93,106 +93,6 @@
 ] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
 
 
-# Define behaviour of each Toolbar item according to current POU body type
-# Informations meaning are in this order:
-#  - Item is toggled
-#  - PLCOpenEditor mode where item is displayed (could be more then one)
-#  - Item id
-#  - Item callback function name
-#  - Item icon filename
-#  - Item tooltip text
-EditorToolBarItems = {
-    "FBD":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
-               "move", _("Move the view")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
-               "add_comment", _("Create a new comment")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
-               "add_variable", _("Create a new variable")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
-               "add_block", _("Create a new block")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
-               "add_connection", _("Create a new connection"))],
-    "LD":    [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
-               "move", _("Move the view")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
-               "add_comment", _("Create a new comment")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
-               "add_powerrail", _("Create a new power rail")),
-              (False, DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool",
-               "add_rung", _("Create a new rung")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool",
-               "add_coil", _("Create a new coil")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
-               "add_contact", _("Create a new contact")),
-              (False, DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool",
-               "add_branch", _("Create a new branch")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
-               "add_variable", _("Create a new variable")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
-               "add_block", _("Create a new block")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
-               "add_connection", _("Create a new connection"))],
-    "SFC":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
-               "move", _("Move the view")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
-               "add_comment", _("Create a new comment")),
-              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool",
-               "add_initial_step", _("Create a new initial step")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool",
-               "add_step", _("Create a new step")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool",
-               "add_transition", _("Create a new transition")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool",
-               "add_action", _("Create a new action block")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool",
-               "add_divergence", _("Create a new divergence")),
-              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool",
-               "add_jump", _("Create a new jump")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
-               "add_variable", _("Create a new variable")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
-               "add_block", _("Create a new block")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
-               "add_connection", _("Create a new connection")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
-               "add_powerrail", _("Create a new power rail")),
-              (True, FREEDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
-               "add_contact", _("Create a new contact"))],
-    "ST":    [],
-    "IL":    [],
-    "debug": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
-               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
-               "move", _("Move the view"))],
-}
-
 # -------------------------------------------------------------------------------
 #                               Helper Functions
 # -------------------------------------------------------------------------------
@@ -331,12 +231,114 @@
     return tabs
 
 
-UNEDITABLE_NAMES_DICT = dict([(_(n), n) for n in UNEDITABLE_NAMES])
-
-
 class IDEFrame(wx.Frame):
     """IDEFrame Base Class"""
 
+    def InitEditorToolbarItems(self):
+        """
+        Initialize dictionary with lists of elements that need to be shown
+        if POU in particular programming language is edited.
+        """
+        # Define behaviour of each Toolbar item according to current POU body type
+        # Informations meaning are in this order:
+        #  - Item is toggled
+        #  - PLCOpenEditor mode where item is displayed (could be more then one)
+        #  - Item id
+        #  - Item callback function name
+        #  - Item icon filename
+        #  - Item tooltip text
+        self.EditorToolBarItems = {
+            "FBD":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
+                       "move", _("Move the view")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
+                       "add_comment", _("Create a new comment")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
+                       "add_variable", _("Create a new variable")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
+                       "add_block", _("Create a new block")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
+                       "add_connection", _("Create a new connection"))],
+            "LD":    [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
+                       "move", _("Move the view")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
+                       "add_comment", _("Create a new comment")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
+                       "add_powerrail", _("Create a new power rail")),
+                      (False, DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool",
+                       "add_rung", _("Create a new rung")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool",
+                       "add_coil", _("Create a new coil")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
+                       "add_contact", _("Create a new contact")),
+                      (False, DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool",
+                       "add_branch", _("Create a new branch")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
+                       "add_variable", _("Create a new variable")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
+                       "add_block", _("Create a new block")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
+                       "add_connection", _("Create a new connection"))],
+            "SFC":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
+                       "move", _("Move the view")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
+                       "add_comment", _("Create a new comment")),
+                      (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool",
+                       "add_initial_step", _("Create a new initial step")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool",
+                       "add_step", _("Create a new step")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool",
+                       "add_transition", _("Create a new transition")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool",
+                       "add_action", _("Create a new action block")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool",
+                       "add_divergence", _("Create a new divergence")),
+                      (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool",
+                       "add_jump", _("Create a new jump")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
+                       "add_variable", _("Create a new variable")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
+                       "add_block", _("Create a new block")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
+                       "add_connection", _("Create a new connection")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
+                       "add_powerrail", _("Create a new power rail")),
+                      (True, FREEDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
+                       "add_contact", _("Create a new contact"))],
+            "ST":    [],
+            "IL":    [],
+            "debug": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
+                       ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
+                       "move", _("Move the view"))],
+        }
+
     def _init_coll_MenuBar_Menus(self, parent):
         parent.Append(menu=self.FileMenu, title=_(u'&File'))
         parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
@@ -672,10 +674,13 @@
                           size=wx.Size(1000, 600),
                           style=wx.DEFAULT_FRAME_STYLE)
 
+        self.UNEDITABLE_NAMES_DICT = dict([(_(n), n) for n in UNEDITABLE_NAMES])
+
         self.Controler = None
         self.Config = wx.ConfigBase.Get()
         self.EnableDebug = enable_debug
 
+        self.InitEditorToolbarItems()
         self._init_ctrls(parent)
 
         # Define Tree item icon list
@@ -1891,7 +1896,7 @@
             if item_infos["type"] == ITEM_PROJECT:
                 name = "Project"
             else:
-                name = UNEDITABLE_NAMES_DICT[name]
+                name = self.UNEDITABLE_NAMES_DICT[name]
 
             if name == "Data Types":
                 menu = wx.Menu(title='')
@@ -2155,7 +2160,7 @@
             self.CurrentEditorToolBar = []
             EditorToolBar = self.Panes["EditorToolBar"]
             if EditorToolBar:
-                for radio, modes, id, method, picture, help in EditorToolBarItems[menu]:
+                for radio, modes, id, method, picture, help in self.EditorToolBarItems[menu]:
                     if modes & self.DrawingMode:
                         if radio or self.DrawingMode == FREEDRAWING_MODE:
                             EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help)
@@ -2420,7 +2425,7 @@
 
         if self.ProjectTree.GetPyData(selected)["type"] != ITEM_PROJECT:
             pou_type = self.ProjectTree.GetItemText(selected)
-            pou_type = UNEDITABLE_NAMES_DICT[pou_type]  # one of 'Functions', 'Function Blocks' or 'Programs'
+            pou_type = self.UNEDITABLE_NAMES_DICT[pou_type]  # one of 'Functions', 'Function Blocks' or 'Programs'
             pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
         else:
             pou_type = None
--- a/controls/DebugVariablePanel/DebugVariablePanel.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/controls/DebugVariablePanel/DebugVariablePanel.py	Wed Aug 29 18:53:02 2018 +0300
@@ -50,14 +50,6 @@
 HOUR = 60 * MINUTE           # Number of nanosecond in a hour
 DAY = 24 * HOUR              # Number of nanosecond in a day
 
-# List of values possible for graph range
-# Format is [(time_in_plain_text, value_in_nanosecond),...]
-RANGE_VALUES = \
-    [(_("%dms") % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
-    [(_("%ds") % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
-    [(_("%dm") % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
-    [(_("%dh") % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
-
 # Scrollbar increment in pixel
 SCROLLBAR_UNIT = 10
 
@@ -189,6 +181,13 @@
         """
         wx.Panel.__init__(self, parent, style=wx.SP_3D | wx.TAB_TRAVERSAL)
 
+        # List of values possible for graph range
+        # Format is [(time_in_plain_text, value_in_nanosecond),...]
+        self.RANGE_VALUES = [(_("%dms") % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
+                            [(_("%ds") % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
+                            [(_("%dm") % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
+                            [(_("%dh") % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
+
         # Save Reference to Beremiz frame
         self.ParentWindow = window
 
@@ -233,7 +232,7 @@
 
         self.CanvasRange.Clear()
         default_range_idx = 0
-        for idx, (text, _value) in enumerate(RANGE_VALUES):
+        for idx, (text, _value) in enumerate(self.RANGE_VALUES):
             self.CanvasRange.Append(text)
             if _value == 1000000000:
                 default_range_idx = idx
@@ -307,7 +306,7 @@
             self.Ticktime = MILLISECOND
 
         # Calculate range to apply to data
-        self.CurrentRange = RANGE_VALUES[
+        self.CurrentRange = self.RANGE_VALUES[
             self.CanvasRange.GetSelection()][1] / self.Ticktime
 
     def SetDataProducer(self, producer):
@@ -614,10 +613,10 @@
     def ChangeRange(self, dir, tick=None):
         current_range = self.CurrentRange
         current_range_idx = self.CanvasRange.GetSelection()
-        new_range_idx = max(0, min(current_range_idx + dir, len(RANGE_VALUES) - 1))
+        new_range_idx = max(0, min(current_range_idx + dir, len(self.RANGE_VALUES) - 1))
         if new_range_idx != current_range_idx:
             self.CanvasRange.SetSelection(new_range_idx)
-            self.CurrentRange = RANGE_VALUES[new_range_idx][1] / self.Ticktime
+            self.CurrentRange = self.RANGE_VALUES[new_range_idx][1] / self.Ticktime
             if len(self.Ticks) > 0:
                 if tick is None:
                     tick = self.StartTick + self.CurrentRange / 2.
@@ -639,7 +638,7 @@
 
     def OnRangeChanged(self, event):
         try:
-            self.CurrentRange = RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime
+            self.CurrentRange = self.RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime
         except ValueError:
             self.CanvasRange.SetValue(str(self.CurrentRange))
         wx.CallAfter(self.RefreshRange)
--- a/controls/VariablePanel.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/controls/VariablePanel.py	Wed Aug 29 18:53:02 2018 +0300
@@ -80,9 +80,6 @@
     return options
 
 
-OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
-
-
 def GetFilterChoiceTransfer():
     _ = NoTranslate
     return {_("All"): _("All"), _("Interface"): _("Interface"),
@@ -91,9 +88,6 @@
             _("   Temp"): _("Temp"), _("Global"): _("Global")}  # , _("Access") : _("Access")}
 
 
-VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()])
-VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
-
 CheckOptionForClass = {
     "Local": lambda x: x,
     "Temp": lambda x: "",
@@ -122,6 +116,10 @@
         # The base class must be initialized *first*
         CustomTable.__init__(self, parent, data, colnames)
         self.old_value = None
+        self.OPTIONS_DICT = dict([(_(option), option)
+                                  for option in GetOptions()])
+        self.VARIABLE_CLASSES_DICT = dict([(_(_class), _class)
+                                           for _class in GetFilterChoiceTransfer().itervalues()])
 
     def GetValueByName(self, row, colname):
         if row < self.GetNumberRows():
@@ -154,12 +152,12 @@
             if colname == "Name":
                 self.old_value = getattr(self.data[row], colname)
             elif colname == "Class":
-                value = VARIABLE_CLASSES_DICT[value]
+                value = self.VARIABLE_CLASSES_DICT[value]
                 self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option")))
                 if value == "External":
                     self.SetValueByName(row, "InitialValue", "")
             elif colname == "Option":
-                value = OPTIONS_DICT[value]
+                value = self.OPTIONS_DICT[value]
             elif colname == "Initial Value":
                 colname = "InitialValue"
             setattr(self.data[row], colname, value)
@@ -444,6 +442,9 @@
     def __init__(self, parent, window, controler, element_type, debug=False):
         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
 
+        self.VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for
+                                           _class in GetFilterChoiceTransfer().iterkeys()])
+
         self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
         self.MainSizer.AddGrowableCol(0)
         self.MainSizer.AddGrowableRow(1)
@@ -763,7 +764,7 @@
         event.Skip()
 
     def OnClassFilter(self, event):
-        self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]]
+        self.Filter = self.FilterChoiceTransfer[self.VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]]
         self.RefreshTypeList()
         self.RefreshValues()
         self.VariablesGrid.RefreshButtons()
--- a/dialogs/BrowseLocationsDialog.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/dialogs/BrowseLocationsDialog.py	Wed Aug 29 18:53:02 2018 +0300
@@ -45,9 +45,6 @@
             (_("Memory"), [LOCATION_VAR_MEMORY])]
 
 
-DIRFILTERCHOICE_OPTIONS = dict([(_(option), filter) for option, filter in GetDirFilterChoiceOptions()])
-
-
 def GetTypeFilterChoiceOptions():
     _ = NoTranslate
     return [_("All"),
@@ -72,6 +69,8 @@
         wx.Dialog.__init__(self, parent, title=_('Browse Locations'),
                            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
 
+        self.DIRFILTERCHOICE_OPTIONS = dict(
+            [(_(option), filter) for option, filter in GetDirFilterChoiceOptions()])
         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
         main_sizer.AddGrowableCol(0)
         main_sizer.AddGrowableRow(1)
@@ -159,7 +158,7 @@
         self.Fit()
 
     def RefreshFilters(self):
-        self.DirFilter = DIRFILTERCHOICE_OPTIONS[self.DirFilterChoice.GetStringSelection()]
+        self.DirFilter = self.DIRFILTERCHOICE_OPTIONS[self.DirFilterChoice.GetStringSelection()]
         self.TypeFilter = self.TypeFilterChoice.GetSelection()
 
     def RefreshLocationsTree(self):
--- a/dialogs/DurationEditorDialog.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/dialogs/DurationEditorDialog.py	Wed Aug 29 18:53:02 2018 +0300
@@ -42,14 +42,6 @@
 
 IEC_TIME_MODEL = re.compile("(?:T|TIME)#(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?$" % {"float": "[0-9]+(?:\.[0-9]+)?"})
 
-CONTROLS = [
-    ("Days", _('Days:')),
-    ("Hours", _('Hours:')),
-    ("Minutes", _('Minutes:')),
-    ("Seconds", _('Seconds:')),
-    ("Milliseconds", _('Milliseconds:')),
-    ("Microseconds", _('Microseconds:')),
-]
 
 # -------------------------------------------------------------------------------
 #                         Edit Duration Value Dialog
@@ -61,6 +53,15 @@
     def __init__(self, parent):
         wx.Dialog.__init__(self, parent, title=_('Edit Duration'))
 
+        CONTROLS = [
+            ("Days", _('Days:')),
+            ("Hours", _('Hours:')),
+            ("Minutes", _('Minutes:')),
+            ("Seconds", _('Seconds:')),
+            ("Milliseconds", _('Milliseconds:')),
+            ("Microseconds", _('Microseconds:')),
+        ]
+
         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
         main_sizer.AddGrowableCol(0)
         main_sizer.AddGrowableRow(0)
--- a/dialogs/FBDVariableDialog.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/dialogs/FBDVariableDialog.py	Wed Aug 29 18:53:02 2018 +0300
@@ -34,16 +34,6 @@
 #                                    Helpers
 # -------------------------------------------------------------------------------
 
-# Dictionaries containing correspondence between variable block class and string
-# to be shown in Class combo box in both sense
-VARIABLE_CLASSES_DICT = {
-    INPUT:  _("Input"),
-    INOUT:  _("InOut"),
-    OUTPUT: _("Output")
-}
-
-VARIABLE_CLASSES_DICT_REVERSE = dict(
-    [(value, key) for key, value in VARIABLE_CLASSES_DICT.iteritems()])
 
 # -------------------------------------------------------------------------------
 #                        Set Variable Parameters Dialog
@@ -67,6 +57,17 @@
         BlockPreviewDialog.__init__(self, parent, controller, tagname,
                                     title=_('Variable Properties'))
 
+        # Dictionaries containing correspondence between variable block class and string
+        # to be shown in Class combo box in both sense
+        self.VARIABLE_CLASSES_DICT = {
+            INPUT:  _("Input"),
+            INOUT:  _("InOut"),
+            OUTPUT: _("Output")
+        }
+
+        self.VARIABLE_CLASSES_DICT_REVERSE = dict(
+            [(value, key) for key, value in self.VARIABLE_CLASSES_DICT.iteritems()])
+
         # Init common sizers
         self._init_sizers(4, 2, 4, None, 3, 2)
 
@@ -119,7 +120,7 @@
             flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
 
         # Set options that can be selected in class combo box
-        for var_class, choice in VARIABLE_CLASSES_DICT.iteritems():
+        for var_class, choice in self.VARIABLE_CLASSES_DICT.iteritems():
             if not exclude_input or var_class != INPUT:
                 self.Class.Append(choice)
         self.Class.SetSelection(0)
@@ -141,7 +142,7 @@
         Called to refresh names in name list box
         """
         # Get variable class to select POU variable applicable
-        var_class = VARIABLE_CLASSES_DICT_REVERSE[
+        var_class = self.VARIABLE_CLASSES_DICT_REVERSE[
             self.Class.GetStringSelection()]
 
         # Refresh names in name list box by selecting variables in POU variables
@@ -172,7 +173,7 @@
         var_class = values.get("class", None)
         if var_class is not None:
             # Set class selected in class combo box
-            self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[var_class])
+            self.Class.SetStringSelection(self.VARIABLE_CLASSES_DICT[var_class])
             # Refresh names in name list box according to var class
             self.RefreshNameList()
 
@@ -204,7 +205,7 @@
         """
         expression = self.Expression.GetValue()
         values = {
-            "class": VARIABLE_CLASSES_DICT_REVERSE[
+            "class": self.VARIABLE_CLASSES_DICT_REVERSE[
                 self.Class.GetStringSelection()],
             "expression": expression,
             "var_type": self.VariableList.get(expression, (None, None))[1],
@@ -288,7 +289,7 @@
         # Set graphic element displayed, creating a FBD variable element
         self.Element = FBD_Variable(
             self.Preview,
-            VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()],
+            self.VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()],
             name,
             self.VariableList.get(name, ("", ""))[1],
             executionOrder=self.ExecutionOrder.GetValue())
--- a/dialogs/PouActionDialog.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/dialogs/PouActionDialog.py	Wed Aug 29 18:53:02 2018 +0300
@@ -36,14 +36,14 @@
     return [_("IL"), _("ST"), _("LD"), _("FBD")]
 
 
-ACTION_LANGUAGES_DICT = dict([(_(language), language) for language in GetActionLanguages()])
-
-
 class PouActionDialog(wx.Dialog):
 
     def __init__(self, parent):
         wx.Dialog.__init__(self, parent, title=_('Create a new action'))
 
+        self.ACTION_LANGUAGES_DICT = dict([(_(language), language)
+                                           for language in GetActionLanguages()])
+
         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
         main_sizer.AddGrowableCol(0)
         main_sizer.AddGrowableRow(0)
@@ -131,5 +131,5 @@
     def GetValues(self):
         values = {}
         values["actionName"] = self.ActionName.GetValue()
-        values["language"] = ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()]
+        values["language"] = self.ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()]
         return values
--- a/dialogs/PouTransitionDialog.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/dialogs/PouTransitionDialog.py	Wed Aug 29 18:53:02 2018 +0300
@@ -40,14 +40,13 @@
     return [_("IL"), _("ST"), _("LD"), _("FBD")]
 
 
-TRANSITION_LANGUAGES_DICT = dict([(_(language), language) for language in GetTransitionLanguages()])
-
-
 class PouTransitionDialog(wx.Dialog):
-
     def __init__(self, parent):
         wx.Dialog.__init__(self, parent, title=_('Create a new transition'))
 
+        self.TRANSITION_LANGUAGES_DICT = dict([(_(language), language)
+                                               for language in GetTransitionLanguages()])
+
         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
         main_sizer.AddGrowableCol(0)
         main_sizer.AddGrowableRow(0)
@@ -133,5 +132,5 @@
     def GetValues(self):
         values = {}
         values["transitionName"] = self.TransitionName.GetValue()
-        values["language"] = TRANSITION_LANGUAGES_DICT[self.Language.GetStringSelection()]
+        values["language"] = self.TRANSITION_LANGUAGES_DICT[self.Language.GetStringSelection()]
         return values
--- a/editors/FileManagementPanel.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/editors/FileManagementPanel.py	Wed Aug 29 18:53:02 2018 +0300
@@ -34,8 +34,6 @@
 from util.BitmapLibrary import GetBitmap
 from controls import FolderTree
 
-FILTER = _("All files (*.*)|*.*|CSV files (*.csv)|*.csv")
-
 
 class FileManagementPanel(EditorPanel):
 
@@ -50,6 +48,7 @@
         managed_dir_label = wx.StaticText(self.Editor, label=_(self.TagName) + ":")
         left_sizer.AddWindow(managed_dir_label, border=5, flag=wx.GROW | wx.BOTTOM)
 
+        FILTER = _("All files (*.*)|*.*|CSV files (*.csv)|*.csv")
         self.ManagedDir = FolderTree(self.Editor, self.Folder, FILTER)
         left_sizer.AddWindow(self.ManagedDir, 1, flag=wx.GROW)
 
--- a/editors/ResourceEditor.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/editors/ResourceEditor.py	Wed Aug 29 18:53:02 2018 +0300
@@ -81,9 +81,6 @@
     return [_("Interrupt"), _("Cyclic")]
 
 
-TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()])
-
-
 def SingleCellEditor(*x):
     return wx.grid.GridCellChoiceEditor()
 
@@ -98,7 +95,6 @@
 
 
 class ResourceTable(CustomTable):
-
     """
     A custom wx.grid.Grid Table using user supplied data
     """
@@ -107,6 +103,8 @@
         CustomTable.__init__(self, parent, data, colnames)
         self.ColAlignements = []
         self.ColSizes = []
+        self.TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option)
+                                                for option in GetTaskTriggeringOptions()])
 
     def GetColAlignements(self):
         return self.ColAlignements
@@ -132,7 +130,7 @@
         if col < len(self.colnames):
             colname = self.GetColLabelValue(col, False)
             if colname == "Triggering":
-                value = TASKTRIGGERINGOPTIONS_DICT[value]
+                value = self.TASKTRIGGERINGOPTIONS_DICT[value]
             self.data[row][colname] = value
 
     def _updateColAttrs(self, grid):
--- a/editors/Viewer.py	Tue Aug 28 18:06:30 2018 +0300
+++ b/editors/Viewer.py	Wed Aug 29 18:53:02 2018 +0300
@@ -470,7 +470,7 @@
 
 
 class DebugInstanceName(DebugDataConsumer):
-    VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")}
+    VALUE_TRANSLATION = None
 
     def __init__(self, parent):
         DebugDataConsumer.__init__(self)
@@ -480,6 +480,9 @@
         self.x_offset = 2
         self.y_offset = 2
 
+        if self.VALUE_TRANSLATION is None:
+            self.__class__.VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")}
+
     def SetValue(self, value):
         self.ActionState = value
         if self.ActionState != self.ActionLastState: