editors/DataTypeEditor.py
changeset 1812 8626a4948d5e
parent 1782 5b6ad7a7fd9d
child 1821 44a47d255d36
equal deleted inserted replaced
1811:4e3c78a84c64 1812:8626a4948d5e
     3 
     3 
     4 # This file is part of Beremiz, a Integrated Development Environment for
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 # Copyright (C) 2017: Andrey Skvortsov
     8 #
     9 #
     9 # See COPYING file for copyrights details.
    10 # See COPYING file for copyrights details.
    10 #
    11 #
    11 # This program is free software; you can redistribute it and/or
    12 # This program is free software; you can redistribute it and/or
    12 # modify it under the terms of the GNU General Public License
    13 # modify it under the terms of the GNU General Public License
    26 from types import TupleType
    27 from types import TupleType
    27 
    28 
    28 import wx
    29 import wx
    29 import wx.grid
    30 import wx.grid
    30 import wx.lib.buttons
    31 import wx.lib.buttons
    31 
       
    32 from plcopen.structures import IEC_KEYWORDS, TestIdentifier, DefaultType
    32 from plcopen.structures import IEC_KEYWORDS, TestIdentifier, DefaultType
    33 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
    33 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
    34 from controls import CustomEditableListBox, CustomGrid, CustomTable
    34 from controls import CustomEditableListBox, CustomGrid, CustomTable, CustomIntCtrl
    35 from dialogs import ArrayTypeDialog
    35 from dialogs import ArrayTypeDialog
    36 from EditorPanel import EditorPanel
    36 from EditorPanel import EditorPanel
    37 from util.BitmapLibrary import GetBitmap
    37 from util.BitmapLibrary import GetBitmap
    38 from util.TranslationCatalogs import NoTranslate
    38 from util.TranslationCatalogs import NoTranslate
    39 
    39 
   223         subrange_initialvalue_label = wx.StaticText(self.SubrangePanel,
   223         subrange_initialvalue_label = wx.StaticText(self.SubrangePanel,
   224                                                     label=_('Initial Value:'))
   224                                                     label=_('Initial Value:'))
   225         subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5,
   225         subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5,
   226                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   226                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   227 
   227 
   228         self.SubrangeInitialValue = wx.SpinCtrl(self.SubrangePanel,
   228         self.SubrangeInitialValue = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
   229                                                 style=wx.TAB_TRAVERSAL)
   229         self.SubrangeInitialValue.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnInfosChanged)
   230         self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, self.SubrangeInitialValue)
       
   231         subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5,
   230         subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5,
   232                                        flag=wx.GROW | wx.ALL)
   231                                        flag=wx.GROW | wx.ALL)
   233 
   232 
   234         subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:'))
   233         subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:'))
   235         subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5,
   234         subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5,
   236                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   235                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   237 
   236 
   238         self.SubrangeMinimum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
   237         self.SubrangeMinimum = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
   239         self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, self.SubrangeMinimum)
   238         self.SubrangeMinimum.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnSubrangeMinimumChanged)
   240         subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5,
   239         subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5,
   241                                        flag=wx.GROW | wx.ALL)
   240                                        flag=wx.GROW | wx.ALL)
   242 
   241 
   243         for i in xrange(2):
   242         for i in xrange(2):
   244             subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1)
   243             subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1)
   246         subrange_maximum_label = wx.StaticText(self.SubrangePanel,
   245         subrange_maximum_label = wx.StaticText(self.SubrangePanel,
   247                                                label=_('Maximum:'))
   246                                                label=_('Maximum:'))
   248         subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5,
   247         subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5,
   249                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   248                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
   250 
   249 
   251         self.SubrangeMaximum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
   250         self.SubrangeMaximum = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
   252         self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, self.SubrangeMaximum)
   251         self.SubrangeMaximum.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnSubrangeMaximumChanged)
   253 
   252 
   254         subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5,
   253         subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5,
   255                                        flag=wx.GROW | wx.ALL)
   254                                        flag=wx.GROW | wx.ALL)
   256 
   255 
   257         self.SubrangePanel.SetSizer(subrange_panel_sizer)
   256         self.SubrangePanel.SetSizer(subrange_panel_sizer)
   721 
   720 
   722     def RefreshBoundsRange(self):
   721     def RefreshBoundsRange(self):
   723         range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
   722         range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
   724         if range is not None:
   723         if range is not None:
   725             min_value, max_value = range
   724             min_value, max_value = range
   726             self.SubrangeMinimum.SetRange(min_value, max_value)
   725             self.SubrangeMinimum.SetBounds(min_value, max_value)
   727             self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value))
   726             self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value))
   728             self.SubrangeMaximum.SetRange(min_value, max_value)
   727             self.SubrangeMaximum.SetBounds(min_value, max_value)
   729             self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value))
   728             self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value))
   730 
   729 
   731     def RefreshSubrangeInitialValueRange(self):
   730     def RefreshSubrangeInitialValueRange(self):
   732         self.SubrangeInitialValue.SetRange(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())
   731         self.SubrangeInitialValue.SetBounds(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())
   733 
   732 
   734     def RefreshTypeInfos(self):
   733     def RefreshTypeInfos(self):
   735         selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
   734         selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
   736         infos = {"type": selected}
   735         infos = {"type": selected}
   737         if selected == "Directly":
   736         if selected == "Directly":
   793         for control in self.HighlightControls.itervalues():
   792         for control in self.HighlightControls.itervalues():
   794             if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
   793             if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
   795                 control.SetBackgroundColour(wx.NullColour)
   794                 control.SetBackgroundColour(wx.NullColour)
   796                 control.SetForegroundColour(wx.NullColour)
   795                 control.SetForegroundColour(wx.NullColour)
   797             elif isinstance(control, wx.TextCtrl):
   796             elif isinstance(control, wx.TextCtrl):
   798                 value = control.GetValue()
   797                 value = control.GetValueStr() if isinstance(control, CustomIntCtrl) else \
       
   798                         control.GetValue()
   799                 control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour))
   799                 control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour))
   800             elif isinstance(control, wx.gizmos.EditableListBox):
   800             elif isinstance(control, wx.gizmos.EditableListBox):
   801                 listctrl = control.GetListCtrl()
   801                 listctrl = control.GetListCtrl()
   802                 for i in xrange(listctrl.GetItemCount()):
   802                 for i in xrange(listctrl.GetItemCount()):
   803                     listctrl.SetItemBackgroundColour(i, wx.NullColour)
   803                     listctrl.SetItemBackgroundColour(i, wx.NullColour)