def __init__(self, parent, controler, window, tagname=""): EditorPanel.__init__(self, parent, tagname, window, controler) icon_name = self.Controler.GetIconName() if icon_name is not None: self.SetIcon(GetBitmap(icon_name)) else: self.SetIcon(GetBitmap("Extension"))
def ClearHighlights(self, highlight_type=None): EditorPanel.ClearHighlights(self, highlight_type) self.TasksTable.ClearHighlights(highlight_type) self.InstancesTable.ClearHighlights(highlight_type) self.TasksTable.ResetView(self.TasksGrid) self.InstancesTable.ResetView(self.InstancesGrid)
def __init__(self, parent, controler, name, folder, enable_dragndrop=False): self.Folder = os.path.realpath(folder) self.EnableDragNDrop = enable_dragndrop if wx.Platform == '__WXMSW__': self.HomeDirectory = "/" else: self.HomeDirectory = os.path.expanduser("~") EditorPanel.__init__(self, parent, name, None, None) self.Controler = controler self.EditableFileExtensions = [] self.EditButton.Hide() self.SetIcon(GetBitmap("FOLDER"))
def AddHighlight(self, infos, start, end, highlight_type): EditorPanel.AddHighlight(self, infos, start, end, highlight_type) if infos[0] == "task": self.TasksTable.AddHighlight(infos[1:], highlight_type) elif infos[0] == "instance": self.InstancesTable.AddHighlight(infos[1:], highlight_type) self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
def AddHighlight(self, infos, start, end, highlight_type): EditorPanel.AddHighlight(self, infos, start, end, highlight_type) highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) if infos[0] == "body" and highlight_type is not None: self.Highlights.append((infos[1], start, end, highlight_type)) self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
def RemoveHighlight(self, infos, start, end, highlight_type): EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type) highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) if infos[0] == "body" and highlight_type is not None and \ (infos[1], start, end, highlight_type) in self.Highlights: self.Highlights.remove((infos[1], start, end, highlight_type)) self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
def RefreshView(self, variablepanel=True, reload=False): EditorPanel.RefreshView(self, variablepanel, reload) if self.SHOW_BASE_PARAMS: self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName()) self.RefreshIECChannelControlsState() if self.ParamsEditor is not None: self.RefreshConfNodeParamsSizer() self.RefreshScrollbars()
def ClearHighlights(self, highlight_type=None): EditorPanel.ClearHighlights(self, highlight_type) if highlight_type is None: self.Highlights = [] else: highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) if highlight_type is not None: self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] self.RefreshView()
def RefreshView(self, variablepanel=True): EditorPanel.RefreshView(self, variablepanel) tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) self.TasksTable.SetData(tasks) self.InstancesTable.SetData(instances) self.RefreshTypeList() self.RefreshTaskList() self.RefreshVariableList() self.TasksTable.ResetView(self.TasksGrid) self.InstancesTable.ResetView(self.InstancesGrid) self.TasksGrid.RefreshButtons() self.InstancesGrid.RefreshButtons()
def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): if tagname != "" and controler is not None: self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) EditorPanel.__init__(self, parent, tagname, window, controler, debug) self.Keywords = [] self.Variables = {} self.Functions = {} self.TypeNames = [] self.Jumps = [] self.EnumeratedValues = [] self.DisableEvents = True self.TextSyntax = None self.CurrentAction = None self.InstancePath = instancepath self.ContextStack = [] self.CallStack = [] self.ResetSearchResults() self.RefreshHighlightsTimer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
def RefreshView(self, variablepanel=True): EditorPanel.RefreshView(self, variablepanel) if self.Controler is not None: self.ResetBuffer() self.DisableEvents = True old_cursor_pos = self.GetCurrentPos() line = self.Editor.GetFirstVisibleLine() column = self.Editor.GetXOffset() old_text = self.GetText() new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) if old_text != new_text: self.SetText(new_text) new_cursor_pos = GetCursorPos(old_text, new_text) self.Editor.LineScroll(column, line) if new_cursor_pos is not None: self.Editor.GotoPos(new_cursor_pos) else: self.Editor.GotoPos(old_cursor_pos) self.RefreshJumpList() self.Editor.EmptyUndoBuffer() self.DisableEvents = False self.RefreshVariableTree() self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] self.Functions = {} for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): for blocktype in category["list"]: blockname = blocktype["name"].upper() if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) for param in ["EN", "ENO"]: if param not in interface: interface[param] = {} if blockname in self.Functions: self.Functions[blockname]["interface"].update(interface) self.Functions[blockname]["extensible"] |= blocktype["extensible"] else: self.Functions[blockname] = {"interface": interface, "extensible": blocktype["extensible"]} self.Colourise(0, -1)
def __init__(self, parent, tagname, window, controler): EditorPanel.__init__(self, parent, tagname, window, controler) self.RefreshHighlightsTimer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) self.TasksDefaultValue = {"Name": "task0", "Triggering": "Cyclic", "Single": "", "Interval": "T#20ms", "Priority": 0} self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) self.TasksGrid.SetTable(self.TasksTable) self.TasksGrid.SetButtons({"Add": self.AddTaskButton, "Delete": self.DeleteTaskButton, "Up": self.UpTaskButton, "Down": self.DownTaskButton}) def _AddTask(new_row): if new_row > 0: row_content = self.TasksTable.data[new_row-1].copy() old_name = row_content['Name'] row_content['Name'] =\ self.Controler.GenerateNewName(self.TagName, old_name, old_name+'%d') else: row_content = self.TasksDefaultValue.copy() self.TasksTable.InsertRow(new_row, row_content) self.RefreshModel() self.RefreshView() return new_row setattr(self.TasksGrid, "_AddRow", _AddTask) def _DeleteTask(row): self.TasksTable.RemoveRow(row) self.RefreshModel() self.RefreshView() setattr(self.TasksGrid, "_DeleteRow", _DeleteTask) def _MoveTask(row, move): new_row = self.TasksTable.MoveRow(row, move) if new_row != row: self.RefreshModel() self.RefreshView() return new_row setattr(self.TasksGrid, "_MoveRow", _MoveTask) self.TasksGrid.SetRowLabelSize(0) self.TasksTable.ResetView(self.TasksGrid) self.TasksGrid.RefreshButtons() self.InstancesDefaultValue = {"Name": "instance0", "Type": "", "Task": ""} self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) self.InstancesTable.SetColSizes([200, 150, 150]) self.InstancesGrid.SetTable(self.InstancesTable) self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, "Delete": self.DeleteInstanceButton, "Up": self.UpInstanceButton, "Down": self.DownInstanceButton}) def _AddInstance(new_row): if new_row > 0: row_content = self.InstancesTable.data[new_row - 1].copy() old_name = row_content['Name'] row_content['Name'] =\ self.Controler.GenerateNewName(self.TagName, old_name, old_name+'%d') else: row_content = self.InstancesDefaultValue.copy() self.InstancesTable.InsertRow(new_row, row_content) self.RefreshModel() self.RefreshView() return new_row setattr(self.InstancesGrid, "_AddRow", _AddInstance) def _DeleteInstance(row): self.InstancesTable.RemoveRow(row) self.RefreshModel() self.RefreshView() setattr(self.InstancesGrid, "_DeleteRow", _DeleteInstance) def _MoveInstance(row, move): new_row = max(0, min(row + move, self.InstancesTable.GetNumberRows() - 1)) if new_row != row: if self.InstancesTable.GetValueByName(row, "Task") != self.InstancesTable.GetValueByName(new_row, "Task"): return row self.InstancesTable.MoveRow(row, move) self.RefreshModel() self.RefreshView() return new_row setattr(self.InstancesGrid, "_MoveRow", _MoveInstance) def _RefreshInstanceButtons(): if self: rows = self.InstancesTable.GetNumberRows() row = self.InstancesGrid.GetGridCursorRow() self.DeleteInstanceButton.Enable(rows > 0) self.UpInstanceButton.Enable( row > 0 and self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) self.DownInstanceButton.Enable( 0 <= row < rows - 1 and self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons) self.InstancesGrid.SetRowLabelSize(0) self.InstancesTable.ResetView(self.InstancesGrid) self.InstancesGrid.RefreshButtons() self.TasksGrid.SetFocus()
def __init__(self, parent, tagname, window, controler): EditorPanel.__init__(self, parent, tagname, window, controler) self.StructureElementDefaultValue = { "Name": "", "Type": DefaultType, "Initial Value": "", "documentation": "" } self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames()) self.StructureColSizes = [40, 150, 100, 250, 250] self.StructureColAlignements = [ wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT ] self.StructureElementsGrid.SetTable(self.StructureElementsTable) self.StructureElementsGrid.SetButtons({ "Add": self.StructureAddButton, "Delete": self.StructureDeleteButton, "Up": self.StructureUpButton, "Down": self.StructureDownButton }) self.DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()]) def _AddStructureElement(new_row): self.StructureElementsTable.InsertRow( new_row, self.StructureElementDefaultValue.copy()) self.RefreshTypeInfos() self.StructureElementsTable.ResetView(self.StructureElementsGrid) return new_row setattr(self.StructureElementsGrid, "_AddRow", _AddStructureElement) def _DeleteStructureElement(row): self.StructureElementsTable.RemoveRow(row) self.RefreshTypeInfos() self.StructureElementsTable.ResetView(self.StructureElementsGrid) setattr(self.StructureElementsGrid, "_DeleteRow", _DeleteStructureElement) def _MoveStructureElement(row, move): new_row = self.StructureElementsTable.MoveRow(row, move) if new_row != row: self.RefreshTypeInfos() self.StructureElementsTable.ResetView( self.StructureElementsGrid) return new_row setattr(self.StructureElementsGrid, "_MoveRow", _MoveStructureElement) self.StructureElementsGrid.SetRowLabelSize(0) for col in range(self.StructureElementsTable.GetNumberCols()): attr = wx.grid.GridCellAttr() attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE) self.StructureElementsGrid.SetColAttr(col, attr) self.StructureElementsGrid.SetColMinimalWidth( col, self.StructureColSizes[col]) self.StructureElementsGrid.AutoSizeColumn(col, False) self.StructureElementsGrid.RefreshButtons() for datatype in GetDatatypeTypes(): self.DerivationType.Append(_(datatype)) self.SubrangePanel.Hide() self.EnumeratedPanel.Hide() self.ArrayPanel.Hide() self.StructurePanel.Hide() self.CurrentPanel = "Directly" self.Highlights = [] self.Initializing = False self.HighlightControls = { ("Directly", "base"): self.DirectlyBaseType, ("Directly", "initial"): self.DirectlyInitialValue, ("Subrange", "base"): self.SubrangeBaseType, ("Subrange", "lower"): self.SubrangeMinimum, ("Subrange", "upper"): self.SubrangeMaximum, ("Subrange", "initial"): self.SubrangeInitialValue, ("Enumerated", "value"): self.EnumeratedValues, ("Enumerated", "initial"): self.EnumeratedInitialValue, ("Array", "initial"): self.ArrayInitialValue, ("Array", "base"): self.ArrayBaseType, ("Array", "range"): self.ArrayDimensions, } self.RefreshHighlightsTimer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
def GetTitle(self): if self.Debug or self.TagName == "": if len(self.InstancePath) > 15: return "..." + self.InstancePath[-12:] return self.InstancePath return EditorPanel.GetTitle(self)