예제 #1
0
    def __init__(self, parent, window, controler, element_type, debug=False):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)

        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
        self.MainSizer.AddGrowableCol(0)
        self.MainSizer.AddGrowableRow(1)

        controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
        controls_sizer.AddGrowableCol(5)
        controls_sizer.AddGrowableRow(0)
        self.MainSizer.AddSizer(controls_sizer,
                                border=5,
                                flag=wx.GROW | wx.ALL)

        self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
        controls_sizer.AddWindow(self.ReturnTypeLabel,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.ReturnType = wx.ComboBox(self,
                                      size=wx.Size(145, -1),
                                      style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
        controls_sizer.AddWindow(self.ReturnType)

        self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
        controls_sizer.AddWindow(self.DescriptionLabel,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.Description = wx.TextCtrl(self,
                                       size=wx.Size(250, -1),
                                       style=wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged,
                  self.Description)
        self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
        controls_sizer.AddWindow(self.Description)

        class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
        controls_sizer.AddWindow(class_filter_label,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.ClassFilter = wx.ComboBox(self,
                                       size=wx.Size(145, -1),
                                       style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
        controls_sizer.AddWindow(self.ClassFilter)

        for name, bitmap, help in [
            ("AddButton", "add_element", _("Add variable")),
            ("DeleteButton", "remove_element", _("Remove variable")),
            ("UpButton", "up", _("Move variable up")),
            ("DownButton", "down", _("Move variable down"))
        ]:
            button = wx.lib.buttons.GenBitmapButton(self,
                                                    bitmap=GetBitmap(bitmap),
                                                    size=wx.Size(28, 28),
                                                    style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            controls_sizer.AddWindow(button)

        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
                                self.OnVariablesGridCellChange)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
                                self.OnVariablesGridCellLeftClick)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
                                self.OnVariablesGridEditorShown)
        self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)

        self.SetSizer(self.MainSizer)

        self.ParentWindow = window
        self.Controler = controler
        self.ElementType = element_type
        self.Debug = debug

        self.RefreshHighlightsTimer = wx.Timer(self, -1)
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
                  self.RefreshHighlightsTimer)

        self.Filter = "All"
        self.FilterChoices = []
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()

        self.DefaultValue = {
            "Name": "",
            "Class": "",
            "Type": "INT",
            "Location": "",
            "Initial Value": "",
            "Option": "",
            "Documentation": "",
            "Edit": True
        }

        if element_type in ["config", "resource"]:
            self.DefaultTypes = {"All": "Global"}
        else:
            self.DefaultTypes = {
                "All": "Local",
                "Interface": "Input",
                "Variables": "Local"
            }

        if element_type in ["config", "resource"] \
        or element_type in ["program", "transition", "action"]:
            # this is an element that can have located variables
            self.Table = VariableTable(self, [],
                                       GetVariableTableColnames(True))

            if element_type in ["config", "resource"]:
                self.FilterChoices = ["All", "Global"]  #,"Access"]
            else:
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "   External", "Variables", "   Local", "   Temp"
                ]  #,"Access"]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER

            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
            #self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
            self.ColSizes = [30, 120, 70, 80, 80, 80, 70, 160]
            self.ColAlignements = [c, l, l, l, l, l, l, l]

        else:
            # this is an element that cannot have located variables
            self.Table = VariableTable(self, [],
                                       GetVariableTableColnames(False))

            if element_type == "function":
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "Variables", "   Local"
                ]
            else:
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "   External", "Variables", "   Local", "   Temp"
                ]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER

            #                      Num  Name    Class   Type    Init    Option   Doc
            #self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
            self.ColSizes = [30, 120, 70, 80, 80, 70, 160]
            self.ColAlignements = [c, l, l, l, l, l, l]

        for choice in self.FilterChoices:
            self.ClassFilter.Append(_(choice))

        reverse_transfer = {}
        for filter, choice in self.FilterChoiceTransfer.items():
            reverse_transfer[choice] = filter
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
        self.RefreshTypeList()

        self.VariablesGrid.SetTable(self.Table)
        self.VariablesGrid.SetButtons({
            "Add": self.AddButton,
            "Delete": self.DeleteButton,
            "Up": self.UpButton,
            "Down": self.DownButton
        })
        self.VariablesGrid.SetEditable(not self.Debug)

        def _AddVariable(new_row):
            if new_row > 0:
                row_content = self.Values[new_row - 1].copy()

                result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content["Name"])
                if result is not None:
                    name = row_content["Name"][:result.start(1)]
                    suffix = result.group(1)
                    if suffix != "":
                        start_idx = int(suffix)
                    else:
                        start_idx = 0
                else:
                    name = row_content["Name"]
                    start_idx = 0
            else:
                row_content = None
                start_idx = 0
                name = "LocalVar"

            if row_content is not None and row_content["Edit"]:
                row_content = self.Values[new_row - 1].copy()
            else:
                row_content = self.DefaultValue.copy()
                if self.Filter in self.DefaultTypes:
                    row_content["Class"] = self.DefaultTypes[self.Filter]
                else:
                    row_content["Class"] = self.Filter

            row_content["Name"] = self.Controler.GenerateNewName(
                self.TagName, None, name + "%d", start_idx)

            if self.Filter == "All" and len(self.Values) > 0:
                self.Values.insert(new_row, row_content)
            else:
                self.Values.append(row_content)
                new_row = self.Table.GetNumberRows()
            self.SaveValues()
            self.RefreshValues()
            return new_row

        setattr(self.VariablesGrid, "_AddRow", _AddVariable)

        def _DeleteVariable(row):
            if self.Table.GetValueByName(row, "Edit"):
                self.Values.remove(self.Table.GetRow(row))
                self.SaveValues()
                self.RefreshValues()

        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)

        def _MoveVariable(row, move):
            if self.Filter == "All":
                new_row = max(0, min(row + move, len(self.Values) - 1))
                if new_row != row:
                    self.Values.insert(new_row, self.Values.pop(row))
                    self.SaveValues()
                    self.RefreshValues()
                return new_row
            return row

        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)

        def _RefreshButtons():
            if self:
                table_length = len(self.Table.data)
                row_class = None
                row_edit = True
                row = 0
                if table_length > 0:
                    row = self.VariablesGrid.GetGridCursorRow()
                    row_edit = self.Table.GetValueByName(row, "Edit")
                self.AddButton.Enable(not self.Debug)
                self.DeleteButton.Enable(not self.Debug
                                         and (table_length > 0 and row_edit))
                self.UpButton.Enable(
                    not self.Debug and
                    (table_length > 0 and row > 0 and self.Filter == "All"))
                self.DownButton.Enable(
                    not self.Debug
                    and (table_length > 0 and row < table_length - 1
                         and self.Filter == "All"))

        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)

        self.VariablesGrid.SetRowLabelSize(0)
        for col in range(self.Table.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            self.VariablesGrid.SetColAttr(col, attr)
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
            self.VariablesGrid.AutoSizeColumn(col, False)
예제 #2
0
    def __init__(self, parent):
        wx.Dialog.__init__(self,
                           parent,
                           id=wx.ID_ANY,
                           title=_("Object"),
                           pos=wx.DefaultPosition,
                           size=wx.Size(416, 354),
                           style=wx.CAPTION | wx.CLOSE_BOX | wx.RESIZE_BORDER
                           | wx.SYSTEM_MENU)

        self.Repository = None
        self.CurrentLayer = None
        self.TemplateName = ''

        self.SetSizeHintsSz(wx.DefaultSize, maxSize=wx.DefaultSize)

        bSizer = wx.BoxSizer(wx.VERTICAL)

        bSizerTop = wx.BoxSizer(wx.HORIZONTAL)

        self.stName = wx.StaticText(self, wx.ID_ANY, _("Template:"),
                                    wx.DefaultPosition, wx.DefaultSize, 0)
        self.stName.Wrap(-1)
        bSizerTop.Add(self.stName,
                      proportion=0,
                      flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                      border=5)

        self.cbProto = wx.combo.BitmapComboBox(self, wx.ID_ANY)
        bSizerTop.Add(self.cbProto,
                      proportion=1,
                      flag=wx.ALL | wx.EXPAND,
                      border=2)

        self.chReflection = wx.CheckBox(self, wx.ID_ANY, _("reflection"),
                                        wx.DefaultPosition, wx.DefaultSize, 0)
        self.chReflection.Enabled = False
        bSizerTop.Add(self.chReflection, proportion=0, flag=wx.ALL, border=5)

        bSizer.Add(bSizerTop, proportion=0, flag=wx.EXPAND, border=0)

        gbSizer = wx.GridBagSizer(0, 0)
        gbSizer.AddGrowableCol(0)
        gbSizer.AddGrowableRow(2)
        gbSizer.SetFlexibleDirection(wx.BOTH)
        gbSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.attrGrid = CustomGrid(self, wx.ID_ANY, style=0)

        # Grid
        self.attrGrid.CreateGrid(numRows=0, numCols=2)
        self.attrGrid.EnableEditing(True)
        self.attrGrid.EnableGridLines(True)
        self.attrGrid.EnableDragGridSize(False)
        self.attrGrid.SetMargins(extraWidth=0, extraHeight=0)

        # Columns
        self.attrGrid.SetColSize(0, width=130)
        self.attrGrid.SetColSize(1, width=150)
        self.attrGrid.EnableDragColMove(False)
        self.attrGrid.EnableDragColSize(True)
        self.attrGrid.SetColLabelSize(30)
        self.attrGrid.SetColLabelValue(0, _("Attribute"))
        self.attrGrid.SetColLabelValue(1, _("Value"))
        self.attrGrid.SetColLabelAlignment(horiz=wx.ALIGN_CENTRE,
                                           vert=wx.ALIGN_CENTRE)

        # Rows
        self.attrGrid.EnableDragRowSize(True)
        self.attrGrid.SetRowLabelSize(20)
        self.attrGrid.SetRowLabelAlignment(horiz=wx.ALIGN_CENTRE,
                                           vert=wx.ALIGN_CENTRE)

        # Label Appearance

        # Cell Defaults
        self.attrGrid.SetDefaultCellAlignment(horiz=wx.ALIGN_LEFT,
                                              vert=wx.ALIGN_TOP)
        gbSizer.Add(self.attrGrid,
                    pos=wx.GBPosition(0, 0),
                    span=wx.GBSpan(3, 1),
                    flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,
                    border=2)

        self.btnAdd = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_ADD), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnAdd,
                    pos=wx.GBPosition(0, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        self.btnDel = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_REMOVE), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnDel,
                    pos=wx.GBPosition(1, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        self.btnSet = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_FONT), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnSet,
                    pos=wx.GBPosition(2, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        bSizer.Add(gbSizer, proportion=1, flag=wx.EXPAND | wx.BOTTOM, border=5)

        bSizerBottom = wx.BoxSizer(wx.HORIZONTAL)

        self.stTitle = wx.StaticText(self, wx.ID_ANY,
                                     _("Title: %s (%s)") % ('None', 'None'),
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        self.stTitle.Wrap(-1)
        bSizerBottom.Add(self.stTitle,
                         proportion=1,
                         flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                         border=5)

        shapeSelChoices = ["DefaultShape"]
        shapeSelChoices.extend(Deca.world.GetShapes())
        self.shapeSel = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition,
                                  wx.DefaultSize, shapeSelChoices, 0)
        self.shapeSel.SetSelection(0)
        bSizerBottom.Add(self.shapeSel,
                         proportion=1,
                         flag=wx.ALL | wx.EXPAND,
                         border=2)

        bSizer.Add(bSizerBottom, proportion=0, flag=wx.EXPAND, border=0)

        self.sdbSizer = wx.StdDialogButtonSizer()
        self.sdbButtonOK = wx.Button(self, wx.ID_OK)
        self.sdbSizer.AddButton(self.sdbButtonOK)
        self.sdbSizer.AddButton(wx.Button(self, wx.ID_CANCEL))
        self.sdbSizer.Realize()

        bSizer.Add(self.sdbSizer, proportion=0, flag=wx.EXPAND, border=0)

        self.SetSizer(bSizer)
        self.Layout()
        self.Center(wx.BOTH)

        self.TitlePos = -1

        # Connect Events
        self.cbProto.Bind(wx.EVT_COMBOBOX, self.OnPrototype)
        self.btnAdd.Bind(wx.EVT_BUTTON, self.OnAdd)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnDel)
        self.btnSet.Bind(wx.EVT_BUTTON, self.OnSet)
예제 #3
0
class VariablePanel(wx.Panel):
    def __init__(self, parent, window, controler, element_type, debug=False):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)

        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
        self.MainSizer.AddGrowableCol(0)
        self.MainSizer.AddGrowableRow(1)

        controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
        controls_sizer.AddGrowableCol(5)
        controls_sizer.AddGrowableRow(0)
        self.MainSizer.AddSizer(controls_sizer,
                                border=5,
                                flag=wx.GROW | wx.ALL)

        self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
        controls_sizer.AddWindow(self.ReturnTypeLabel,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.ReturnType = wx.ComboBox(self,
                                      size=wx.Size(145, -1),
                                      style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
        controls_sizer.AddWindow(self.ReturnType)

        self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
        controls_sizer.AddWindow(self.DescriptionLabel,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.Description = wx.TextCtrl(self,
                                       size=wx.Size(250, -1),
                                       style=wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged,
                  self.Description)
        self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
        controls_sizer.AddWindow(self.Description)

        class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
        controls_sizer.AddWindow(class_filter_label,
                                 flag=wx.ALIGN_CENTER_VERTICAL)

        self.ClassFilter = wx.ComboBox(self,
                                       size=wx.Size(145, -1),
                                       style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
        controls_sizer.AddWindow(self.ClassFilter)

        for name, bitmap, help in [
            ("AddButton", "add_element", _("Add variable")),
            ("DeleteButton", "remove_element", _("Remove variable")),
            ("UpButton", "up", _("Move variable up")),
            ("DownButton", "down", _("Move variable down"))
        ]:
            button = wx.lib.buttons.GenBitmapButton(self,
                                                    bitmap=GetBitmap(bitmap),
                                                    size=wx.Size(28, 28),
                                                    style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            controls_sizer.AddWindow(button)

        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
                                self.OnVariablesGridCellChange)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
                                self.OnVariablesGridCellLeftClick)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
                                self.OnVariablesGridEditorShown)
        self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)

        self.SetSizer(self.MainSizer)

        self.ParentWindow = window
        self.Controler = controler
        self.ElementType = element_type
        self.Debug = debug

        self.RefreshHighlightsTimer = wx.Timer(self, -1)
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
                  self.RefreshHighlightsTimer)

        self.Filter = "All"
        self.FilterChoices = []
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()

        self.DefaultValue = {
            "Name": "",
            "Class": "",
            "Type": "INT",
            "Location": "",
            "Initial Value": "",
            "Option": "",
            "Documentation": "",
            "Edit": True
        }

        if element_type in ["config", "resource"]:
            self.DefaultTypes = {"All": "Global"}
        else:
            self.DefaultTypes = {
                "All": "Local",
                "Interface": "Input",
                "Variables": "Local"
            }

        if element_type in ["config", "resource"] \
        or element_type in ["program", "transition", "action"]:
            # this is an element that can have located variables
            self.Table = VariableTable(self, [],
                                       GetVariableTableColnames(True))

            if element_type in ["config", "resource"]:
                self.FilterChoices = ["All", "Global"]  #,"Access"]
            else:
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "   External", "Variables", "   Local", "   Temp"
                ]  #,"Access"]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER

            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
            #self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
            self.ColSizes = [30, 120, 70, 80, 80, 80, 70, 160]
            self.ColAlignements = [c, l, l, l, l, l, l, l]

        else:
            # this is an element that cannot have located variables
            self.Table = VariableTable(self, [],
                                       GetVariableTableColnames(False))

            if element_type == "function":
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "Variables", "   Local"
                ]
            else:
                self.FilterChoices = [
                    "All", "Interface", "   Input", "   Output", "   InOut",
                    "   External", "Variables", "   Local", "   Temp"
                ]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER

            #                      Num  Name    Class   Type    Init    Option   Doc
            #self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
            self.ColSizes = [30, 120, 70, 80, 80, 70, 160]
            self.ColAlignements = [c, l, l, l, l, l, l]

        for choice in self.FilterChoices:
            self.ClassFilter.Append(_(choice))

        reverse_transfer = {}
        for filter, choice in self.FilterChoiceTransfer.items():
            reverse_transfer[choice] = filter
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
        self.RefreshTypeList()

        self.VariablesGrid.SetTable(self.Table)
        self.VariablesGrid.SetButtons({
            "Add": self.AddButton,
            "Delete": self.DeleteButton,
            "Up": self.UpButton,
            "Down": self.DownButton
        })
        self.VariablesGrid.SetEditable(not self.Debug)

        def _AddVariable(new_row):
            if new_row > 0:
                row_content = self.Values[new_row - 1].copy()

                result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content["Name"])
                if result is not None:
                    name = row_content["Name"][:result.start(1)]
                    suffix = result.group(1)
                    if suffix != "":
                        start_idx = int(suffix)
                    else:
                        start_idx = 0
                else:
                    name = row_content["Name"]
                    start_idx = 0
            else:
                row_content = None
                start_idx = 0
                name = "LocalVar"

            if row_content is not None and row_content["Edit"]:
                row_content = self.Values[new_row - 1].copy()
            else:
                row_content = self.DefaultValue.copy()
                if self.Filter in self.DefaultTypes:
                    row_content["Class"] = self.DefaultTypes[self.Filter]
                else:
                    row_content["Class"] = self.Filter

            row_content["Name"] = self.Controler.GenerateNewName(
                self.TagName, None, name + "%d", start_idx)

            if self.Filter == "All" and len(self.Values) > 0:
                self.Values.insert(new_row, row_content)
            else:
                self.Values.append(row_content)
                new_row = self.Table.GetNumberRows()
            self.SaveValues()
            self.RefreshValues()
            return new_row

        setattr(self.VariablesGrid, "_AddRow", _AddVariable)

        def _DeleteVariable(row):
            if self.Table.GetValueByName(row, "Edit"):
                self.Values.remove(self.Table.GetRow(row))
                self.SaveValues()
                self.RefreshValues()

        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)

        def _MoveVariable(row, move):
            if self.Filter == "All":
                new_row = max(0, min(row + move, len(self.Values) - 1))
                if new_row != row:
                    self.Values.insert(new_row, self.Values.pop(row))
                    self.SaveValues()
                    self.RefreshValues()
                return new_row
            return row

        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)

        def _RefreshButtons():
            if self:
                table_length = len(self.Table.data)
                row_class = None
                row_edit = True
                row = 0
                if table_length > 0:
                    row = self.VariablesGrid.GetGridCursorRow()
                    row_edit = self.Table.GetValueByName(row, "Edit")
                self.AddButton.Enable(not self.Debug)
                self.DeleteButton.Enable(not self.Debug
                                         and (table_length > 0 and row_edit))
                self.UpButton.Enable(
                    not self.Debug and
                    (table_length > 0 and row > 0 and self.Filter == "All"))
                self.DownButton.Enable(
                    not self.Debug
                    and (table_length > 0 and row < table_length - 1
                         and self.Filter == "All"))

        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)

        self.VariablesGrid.SetRowLabelSize(0)
        for col in range(self.Table.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            self.VariablesGrid.SetColAttr(col, attr)
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
            self.VariablesGrid.AutoSizeColumn(col, False)

    def __del__(self):
        self.RefreshHighlightsTimer.Stop()

    def SetTagName(self, tagname):
        self.TagName = tagname

    def GetTagName(self):
        return self.TagName

    def IsFunctionBlockType(self, name):
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
        if poutype != "function" and bodytype in ["ST", "IL"]:
            return False
        else:
            return name in self.Controler.GetFunctionBlockTypes(self.TagName)

    def RefreshView(self):
        self.PouNames = self.Controler.GetProjectPouNames(self.Debug)
        returnType = None
        description = None

        words = self.TagName.split("::")
        if self.ElementType == "config":
            self.Values = self.Controler.GetConfigurationGlobalVars(
                words[1], self.Debug)
        elif self.ElementType == "resource":
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(
                words[1], words[2], self.Debug)
        else:
            if self.ElementType == "function":
                self.ReturnType.Clear()
                for data_type in self.Controler.GetDataTypes(self.TagName,
                                                             debug=self.Debug):
                    self.ReturnType.Append(data_type)
                returnType = self.Controler.GetEditedElementInterfaceReturnType(
                    self.TagName)
            description = self.Controler.GetPouDescription(words[1])
            self.Values = self.Controler.GetEditedElementInterfaceVars(
                self.TagName, self.Debug)

        if returnType is not None:
            self.ReturnType.SetStringSelection(returnType)
            self.ReturnType.Enable(not self.Debug)
            self.ReturnTypeLabel.Show()
            self.ReturnType.Show()
        else:
            self.ReturnType.Enable(False)
            self.ReturnTypeLabel.Hide()
            self.ReturnType.Hide()

        if description is not None:
            self.Description.SetValue(description)
            self.Description.Enable(not self.Debug)
            self.DescriptionLabel.Show()
            self.Description.Show()
        else:
            self.Description.Enable(False)
            self.DescriptionLabel.Hide()
            self.Description.Hide()

        self.RefreshValues()
        self.VariablesGrid.RefreshButtons()
        self.MainSizer.Layout()

    def OnReturnTypeChanged(self, event):
        words = self.TagName.split("::")
        self.Controler.SetPouInterfaceReturnType(
            words[1], self.ReturnType.GetStringSelection())
        self.Controler.BufferProject()
        self.ParentWindow.RefreshView(variablepanel=False)
        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU,
                                   POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
        event.Skip()

    def OnDescriptionChanged(self, event):
        words = self.TagName.split("::")
        old_description = self.Controler.GetPouDescription(words[1])
        new_description = self.Description.GetValue()
        if new_description != old_description:
            self.Controler.SetPouDescription(words[1], new_description)
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES,
                                       POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
        event.Skip()

    def OnClassFilter(self, event):
        self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[
            self.ClassFilter.GetStringSelection()]]
        self.RefreshTypeList()
        self.RefreshValues()
        self.VariablesGrid.RefreshButtons()
        event.Skip()

    def RefreshTypeList(self):
        if self.Filter == "All":
            self.ClassList = [
                self.FilterChoiceTransfer[choice]
                for choice in self.FilterChoices
                if self.FilterChoiceTransfer[choice] not in
                ["All", "Interface", "Variables"]
            ]
        elif self.Filter == "Interface":
            self.ClassList = ["Input", "Output", "InOut", "External"]
        elif self.Filter == "Variables":
            self.ClassList = ["Local", "Temp"]
        else:
            self.ClassList = [self.Filter]

    def OnVariablesGridCellChange(self, event):
        row, col = event.GetRow(), event.GetCol()
        colname = self.Table.GetColLabelValue(col, False)
        value = self.Table.GetValue(row, col)
        message = None

        if colname == "Name" and value != "":
            if not TestIdentifier(value):
                message = _("\"%s\" is not a valid identifier!") % value
            elif value.upper() in IEC_KEYWORDS:
                message = _("\"%s\" is a keyword. It can't be used!") % value
            elif value.upper() in self.PouNames:
                message = _("A POU named \"%s\" already exists!") % value
            elif value.upper() in [
                    var["Name"].upper() for var in self.Values
                    if var != self.Table.data[row]
            ]:
                message = _(
                    "A variable with \"%s\" as name already exists in this pou!"
                ) % value
            else:
                self.SaveValues(False)
                old_value = self.Table.GetOldValue()
                if old_value != "":
                    self.Controler.UpdateEditedElementUsedVariable(
                        self.TagName, old_value, value)
                self.Controler.BufferProject()
                wx.CallAfter(self.ParentWindow.RefreshView, False)
                self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU,
                                           PAGETITLES,
                                           POUINSTANCEVARIABLESPANEL,
                                           LIBRARYTREE)
        else:
            self.SaveValues()
            if colname == "Class":
                wx.CallAfter(self.ParentWindow.RefreshView, False)
            elif colname == "Location":
                wx.CallAfter(self.ParentWindow.RefreshView)

        if message is not None:
            dialog = wx.MessageDialog(self, message, _("Error"),
                                      wx.OK | wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
            event.Veto()
        else:
            event.Skip()

    def OnVariablesGridEditorShown(self, event):
        row, col = event.GetRow(), event.GetCol()

        label_value = self.Table.GetColLabelValue(col, False)
        if label_value == "Type":
            type_menu = wx.Menu(title='')  # the root menu

            # build a submenu containing standard IEC types
            base_menu = wx.Menu(title='')
            for base_type in self.Controler.GetBaseTypes():
                new_id = wx.NewId()
                AppendMenu(base_menu,
                           help='',
                           id=new_id,
                           kind=wx.ITEM_NORMAL,
                           text=base_type)
                self.Bind(wx.EVT_MENU,
                          self.GetVariableTypeFunction(base_type),
                          id=new_id)

            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)

            # build a submenu containing user-defined types
            datatype_menu = wx.Menu(title='')
            datatypes = self.Controler.GetDataTypes(basetypes=False,
                                                    confnodetypes=False)
            for datatype in datatypes:
                new_id = wx.NewId()
                AppendMenu(datatype_menu,
                           help='',
                           id=new_id,
                           kind=wx.ITEM_NORMAL,
                           text=datatype)
                self.Bind(wx.EVT_MENU,
                          self.GetVariableTypeFunction(datatype),
                          id=new_id)

            type_menu.AppendMenu(wx.NewId(), _("User Data Types"),
                                 datatype_menu)

            for category in self.Controler.GetConfNodeDataTypes():

                if len(category["list"]) > 0:
                    # build a submenu containing confnode types
                    confnode_datatype_menu = wx.Menu(title='')
                    for datatype in category["list"]:
                        new_id = wx.NewId()
                        AppendMenu(confnode_datatype_menu,
                                   help='',
                                   id=new_id,
                                   kind=wx.ITEM_NORMAL,
                                   text=datatype)
                        self.Bind(wx.EVT_MENU,
                                  self.GetVariableTypeFunction(datatype),
                                  id=new_id)

                    type_menu.AppendMenu(wx.NewId(), category["name"],
                                         confnode_datatype_menu)

            # build a submenu containing function block types
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
            pouname, poutype = self.Controler.GetEditedElementType(
                self.TagName)
            classtype = self.Table.GetValueByName(row, "Class")

            new_id = wx.NewId()
            AppendMenu(type_menu,
                       help='',
                       id=new_id,
                       kind=wx.ITEM_NORMAL,
                       text=_("Array"))
            self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)

            if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
            poutype != "function" and bodytype in ["ST", "IL"]:
                functionblock_menu = wx.Menu(title='')
                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
                for functionblock_type in fbtypes:
                    new_id = wx.NewId()
                    AppendMenu(functionblock_menu,
                               help='',
                               id=new_id,
                               kind=wx.ITEM_NORMAL,
                               text=functionblock_type)
                    self.Bind(wx.EVT_MENU,
                              self.GetVariableTypeFunction(functionblock_type),
                              id=new_id)

                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"),
                                     functionblock_menu)

            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
            corner_x = rect.x + rect.width
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()

            # pop up this new menu
            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
            type_menu.Destroy()
            event.Veto()
        else:
            event.Skip()

    def GetVariableTypeFunction(self, base_type):
        def VariableTypeFunction(event):
            row = self.VariablesGrid.GetGridCursorRow()
            self.Table.SetValueByName(row, "Type", base_type)
            self.Table.ResetView(self.VariablesGrid)
            self.SaveValues(False)
            self.ParentWindow.RefreshView(variablepanel=False)
            self.Controler.BufferProject()
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES,
                                       POUINSTANCEVARIABLESPANEL, LIBRARYTREE)

        return VariableTypeFunction

    def VariableArrayTypeFunction(self, event):
        row = self.VariablesGrid.GetGridCursorRow()
        dialog = ArrayTypeDialog(self,
                                 self.Controler.GetDataTypes(self.TagName),
                                 self.Table.GetValueByName(row, "Type"))
        if dialog.ShowModal() == wx.ID_OK:
            self.Table.SetValueByName(row, "Type", dialog.GetValue())
            self.Table.ResetView(self.VariablesGrid)
            self.SaveValues(False)
            self.ParentWindow.RefreshView(variablepanel=False)
            self.Controler.BufferProject()
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES,
                                       POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
        dialog.Destroy()

    def OnVariablesGridCellLeftClick(self, event):
        row = event.GetRow()
        if not self.Debug and (event.GetCol() == 0
                               and self.Table.GetValueByName(row, "Edit")):
            var_name = self.Table.GetValueByName(row, "Name")
            var_class = self.Table.GetValueByName(row, "Class")
            var_type = self.Table.GetValueByName(row, "Type")
            data = wx.TextDataObject(
                str((var_name, var_class, var_type, self.TagName)))
            dragSource = wx.DropSource(self.VariablesGrid)
            dragSource.SetData(data)
            dragSource.DoDragDrop()
        event.Skip()

    def RefreshValues(self):
        data = []
        for num, variable in enumerate(self.Values):
            if variable["Class"] in self.ClassList:
                variable["Number"] = num + 1
                data.append(variable)
        self.Table.SetData(data)
        self.Table.ResetView(self.VariablesGrid)

    def SaveValues(self, buffer=True):
        words = self.TagName.split("::")
        if self.ElementType == "config":
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
        elif self.ElementType == "resource":
            self.Controler.SetConfigurationResourceGlobalVars(
                words[1], words[2], self.Values)
        else:
            if self.ReturnType.IsEnabled():
                self.Controler.SetPouInterfaceReturnType(
                    words[1], self.ReturnType.GetStringSelection())
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
        if buffer:
            self.Controler.BufferProject()
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES,
                                       POUINSTANCEVARIABLESPANEL, LIBRARYTREE)

#-------------------------------------------------------------------------------
#                        Highlights showing functions
#-------------------------------------------------------------------------------

    def OnRefreshHighlightsTimer(self, event):
        self.Table.ResetView(self.VariablesGrid)
        event.Skip()

    def AddVariableHighlight(self, infos, highlight_type):
        if isinstance(infos[0], TupleType):
            for i in xrange(*infos[0]):
                self.Table.AddHighlight((i, ) + infos[1:], highlight_type)
            cell_visible = infos[0][0]
        else:
            self.Table.AddHighlight(infos, highlight_type)
            cell_visible = infos[0]
        colnames = [colname.lower() for colname in self.Table.colnames]
        self.VariablesGrid.MakeCellVisible(cell_visible,
                                           colnames.index(infos[1]))
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000),
                                          oneShot=True)

    def RemoveVariableHighlight(self, infos, highlight_type):
        if isinstance(infos[0], TupleType):
            for i in xrange(*infos[0]):
                self.Table.RemoveHighlight((i, ) + infos[1:], highlight_type)
        else:
            self.Table.RemoveHighlight(infos, highlight_type)
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000),
                                          oneShot=True)

    def ClearHighlights(self, highlight_type=None):
        self.Table.ClearHighlights(highlight_type)
        self.Table.ResetView(self.VariablesGrid)
예제 #4
0
class ObjDialog(wx.Dialog):

    ID_SelectShape = wx.NewId()

    def __init__(self, parent):
        wx.Dialog.__init__(self,
                           parent,
                           id=wx.ID_ANY,
                           title=_("Object"),
                           pos=wx.DefaultPosition,
                           size=wx.Size(416, 354),
                           style=wx.CAPTION | wx.CLOSE_BOX | wx.RESIZE_BORDER
                           | wx.SYSTEM_MENU)

        self.Repository = None
        self.CurrentLayer = None
        self.TemplateName = ''

        self.SetSizeHintsSz(wx.DefaultSize, maxSize=wx.DefaultSize)

        bSizer = wx.BoxSizer(wx.VERTICAL)

        bSizerTop = wx.BoxSizer(wx.HORIZONTAL)

        self.stName = wx.StaticText(self, wx.ID_ANY, _("Template:"),
                                    wx.DefaultPosition, wx.DefaultSize, 0)
        self.stName.Wrap(-1)
        bSizerTop.Add(self.stName,
                      proportion=0,
                      flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                      border=5)

        self.cbProto = wx.combo.BitmapComboBox(self, wx.ID_ANY)
        bSizerTop.Add(self.cbProto,
                      proportion=1,
                      flag=wx.ALL | wx.EXPAND,
                      border=2)

        self.chReflection = wx.CheckBox(self, wx.ID_ANY, _("reflection"),
                                        wx.DefaultPosition, wx.DefaultSize, 0)
        self.chReflection.Enabled = False
        bSizerTop.Add(self.chReflection, proportion=0, flag=wx.ALL, border=5)

        bSizer.Add(bSizerTop, proportion=0, flag=wx.EXPAND, border=0)

        gbSizer = wx.GridBagSizer(0, 0)
        gbSizer.AddGrowableCol(0)
        gbSizer.AddGrowableRow(2)
        gbSizer.SetFlexibleDirection(wx.BOTH)
        gbSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.attrGrid = CustomGrid(self, wx.ID_ANY, style=0)

        # Grid
        self.attrGrid.CreateGrid(numRows=0, numCols=2)
        self.attrGrid.EnableEditing(True)
        self.attrGrid.EnableGridLines(True)
        self.attrGrid.EnableDragGridSize(False)
        self.attrGrid.SetMargins(extraWidth=0, extraHeight=0)

        # Columns
        self.attrGrid.SetColSize(0, width=130)
        self.attrGrid.SetColSize(1, width=150)
        self.attrGrid.EnableDragColMove(False)
        self.attrGrid.EnableDragColSize(True)
        self.attrGrid.SetColLabelSize(30)
        self.attrGrid.SetColLabelValue(0, _("Attribute"))
        self.attrGrid.SetColLabelValue(1, _("Value"))
        self.attrGrid.SetColLabelAlignment(horiz=wx.ALIGN_CENTRE,
                                           vert=wx.ALIGN_CENTRE)

        # Rows
        self.attrGrid.EnableDragRowSize(True)
        self.attrGrid.SetRowLabelSize(20)
        self.attrGrid.SetRowLabelAlignment(horiz=wx.ALIGN_CENTRE,
                                           vert=wx.ALIGN_CENTRE)

        # Label Appearance

        # Cell Defaults
        self.attrGrid.SetDefaultCellAlignment(horiz=wx.ALIGN_LEFT,
                                              vert=wx.ALIGN_TOP)
        gbSizer.Add(self.attrGrid,
                    pos=wx.GBPosition(0, 0),
                    span=wx.GBSpan(3, 1),
                    flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,
                    border=2)

        self.btnAdd = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_ADD), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnAdd,
                    pos=wx.GBPosition(0, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        self.btnDel = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_REMOVE), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnDel,
                    pos=wx.GBPosition(1, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        self.btnSet = wx.BitmapButton(
            self, wx.ID_ANY,
            wx.ArtProvider_GetBitmap(str(ed_glob.ID_FONT), wx.ART_MENU,
                                     wx.Size(16, 16)), wx.DefaultPosition,
            wx.DefaultSize, wx.BU_AUTODRAW)
        gbSizer.Add(self.btnSet,
                    pos=wx.GBPosition(2, 1),
                    span=wx.GBSpan(1, 1),
                    flag=wx.ALL,
                    border=5)

        bSizer.Add(gbSizer, proportion=1, flag=wx.EXPAND | wx.BOTTOM, border=5)

        bSizerBottom = wx.BoxSizer(wx.HORIZONTAL)

        self.stTitle = wx.StaticText(self, wx.ID_ANY,
                                     _("Title: %s (%s)") % ('None', 'None'),
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        self.stTitle.Wrap(-1)
        bSizerBottom.Add(self.stTitle,
                         proportion=1,
                         flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                         border=5)

        shapeSelChoices = ["DefaultShape"]
        shapeSelChoices.extend(Deca.world.GetShapes())
        self.shapeSel = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition,
                                  wx.DefaultSize, shapeSelChoices, 0)
        self.shapeSel.SetSelection(0)
        bSizerBottom.Add(self.shapeSel,
                         proportion=1,
                         flag=wx.ALL | wx.EXPAND,
                         border=2)

        bSizer.Add(bSizerBottom, proportion=0, flag=wx.EXPAND, border=0)

        self.sdbSizer = wx.StdDialogButtonSizer()
        self.sdbButtonOK = wx.Button(self, wx.ID_OK)
        self.sdbSizer.AddButton(self.sdbButtonOK)
        self.sdbSizer.AddButton(wx.Button(self, wx.ID_CANCEL))
        self.sdbSizer.Realize()

        bSizer.Add(self.sdbSizer, proportion=0, flag=wx.EXPAND, border=0)

        self.SetSizer(bSizer)
        self.Layout()
        self.Center(wx.BOTH)

        self.TitlePos = -1

        # Connect Events
        self.cbProto.Bind(wx.EVT_COMBOBOX, self.OnPrototype)
        self.btnAdd.Bind(wx.EVT_BUTTON, self.OnAdd)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnDel)
        self.btnSet.Bind(wx.EVT_BUTTON, self.OnSet)
        #self.sdbButtonOK.Bind( wx.EVT_BUTTON, self.OnOK )

    def SetEditMode(self, mode=True):
        self.stName.Enable(not mode)
        self.cbProto.Enable(not mode)
        self.chReflection.Enable(not mode)

    def AddChoice(self, img, name, code):
        self.cbProto.Append(name, bitmap=img, clientData=code)

    def EnableReflection(self, enable=True):
        self.chReflection.Enabled = enable
        if not enable:
            self.chReflection.SetValue(False)

    def AppendRows(self, num=1):
        last = self.attrGrid.GetNumberRows()
        self.attrGrid.AppendRows(num)
        pos = self.attrGrid.GetNumberRows()
        for r in range(last, pos):
            self.attrGrid.SetRowLabelValue(r, '')
            self.attrGrid.SetCellRenderer(row=r,
                                          col=1,
                                          renderer=ToStringRenderer())
            self.attrGrid.SetCellEditor(row=r, col=1, editor=ToStringEditor())

    def FixGrid(self):
        pos = self.attrGrid.GetNumberRows()
        self.attrGrid.DisableCellEditControl()
        #self.attrGrid.DeleteRows(pos=0, numRows=1)
        #for r in range(pos):
        #	self.attrGrid.SetCellEditor(row=r, col=1, editor=self.attrGrid.GetDefaultEditor())

    # Virtual event handlers, overide them in your derived class
    def OnPrototype(self, event):
        event.GetId()
        x = self.attrGrid.GetNumberRows()
        if x > 0:
            self.attrGrid.DeleteRows(0, numRows=x)
        self.TitlePos = -1

        ttl = self.cbProto.GetSelection()
        if ttl != wx.NOT_FOUND:
            ttn = self.cbProto.GetString(ttl)
            ttl = self.cbProto.GetClientData(ttl)
            if ttl != '':
                # try to get template
                sample = self.Repository.GetTemplate(ttl)
                # try to get repo object
                if not sample: sample = self.Repository.GetObject(ttl)
                # try to get local object
                if not sample: sample = self.CurrentLayer.GetObject(ttl)
                # check reflection ability
                self.chReflection.Enabled = True
                if isinstance(sample, DecaTemplate):
                    # can't reflect template
                    self.chReflection.Value = False
                    self.chReflection.Enabled = False
                    self.TemplateName = ttn
                if isinstance(sample, DecaObject) and sample.IsReflection:
                    # can't reflect reflection
                    self.chReflection.Value = False
                    self.chReflection.Enabled = False
                    # reset TemplateName
                    self.TemplateName = sample.TemplateName
                if sample is not None:
                    self.AppendRows(len(sample.Attributes))
                    x = 0
                    for k, v in sample.Attributes.items():
                        self.attrGrid.SetRowLabelValue(x, '')
                        if k == sample.TitleAttr:
                            self.attrGrid.SetRowLabelValue(x, '*')
                            self.TitlePos = x
                            self.stTitle.Label = _("Title attribute: %s") % k
                        self.attrGrid.SetCellValue(row=x, col=0, s=k)
                        self.attrGrid.SetCellValue(row=x, col=1, s=v)
                        x += 1
                    # end for each attribute
                    if self.shapeSel.SetStringSelection(str(sample.Graphics)):
                        self.shapeSel.SetSelection(0)
            # end if selected source
        # end if found

    def OnAdd(self, event):
        event.GetId()
        self.AppendRows()

    def OnDel(self, event):
        event.GetId()
        pos = self.attrGrid.GetSelectedRows()
        if len(pos) >= 0:
            for x in pos:
                self.attrGrid.DeleteRows(x)
                if x == self.TitlePos:
                    self.TitlePos = -1
                    self.stTitle.Label = _("Title attribute: %s") % 'None'
                # end if Title
            # end for selected
        # end deletion

    def OnSet(self, event):
        event.GetId()
        pos = self.attrGrid.GetSelectedRows()
        if not len(pos):
            cll = self.attrGrid.GetSelectedCells()
            if not len(cll):
                pos.append(self.attrGrid.GetGridCursorRow())
            for c in cll:
                pos.append(c.row)
        if len(pos) > 0:
            if self.TitlePos > -1:
                self.attrGrid.SetRowLabelValue(self.TitlePos, '')
            self.TitlePos = pos[0]
            self.attrGrid.SetRowLabelValue(pos[0], '*')
            self.stTitle.Label = _(
                "Title attribute: %s") % self.attrGrid.GetCellValue(pos[0], 0)
        # end set Title

    def GetShapeName(self):
        return self.shapeSel.GetStringSelection()