--- a/CodeFileTreeNode.py Wed May 08 18:33:49 2013 +0200
+++ b/CodeFileTreeNode.py Wed May 08 21:37:31 2013 +0200
@@ -4,246 +4,142 @@
-from CFileEditor import CFileEditor
-from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT
-CFileClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "cext_xsd.xsd"))
-TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
- "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
- "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
+from PLCControler import UndoBuffer +from editors.CodeFileEditor import SECTIONS_NAMES
- XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <xsd:element name="CExtension">
- <xsd:attribute name="CFLAGS" type="xsd:string" use="required"/>
- <xsd:attribute name="LDFLAGS" type="xsd:string" use="required"/>
- EditorType = CFileEditor
+CodeFileClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "code_file.xsd")) - filepath = self.CFileName()
+ filepath = self.CodeFileName() - self.CFile = CFileClasses["CFile"]()
+ self.CodeFile = CodeFileClasses["CodeFile"]() if os.path.isfile(filepath):
xmlfile = open(filepath, 'r')
tree = minidom.parse(xmlfile)
for child in tree.childNodes:
- if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile":
- self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"])
- self.CreateCFileBuffer(True)
+ if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CodeFile": + self.CodeFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) + self.CreateCodeFileBuffer(True) - self.CreateCFileBuffer(False)
+ self.CreateCodeFileBuffer(False)
- return os.path.join(self.CTNPath(), "cfile.xml")
return self.GetCTRoot().GetBaseTypes()
- def GetDataTypes(self, basetypes = False, only_locatables = False):
- return self.GetCTRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables)
- def GetSizeOfType(self, type):
- return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
+ def GetDataTypes(self, basetypes = False): + return self.GetCTRoot().GetDataTypes(basetypes=basetypes) def SetVariables(self, variables):
- self.CFile.variables.setvariable([])
+ self.CodeFile.variables.setvariable([]) - variable = CFileClasses["variables_variable"]()
+ variable = CodeFileClasses["variables_variable"]() variable.setname(var["Name"])
variable.settype(var["Type"])
- variable.setclass(var["Class"])
- self.CFile.variables.appendvariable(variable)
+ variable.setinitial(var["Initial"]) + self.CodeFile.variables.appendvariable(variable) - for var in self.CFile.variables.getvariable():
- datas.append({"Name" : var.getname(), "Type" : var.gettype(), "Class" : var.getclass()})
+ for var in self.CodeFile.variables.getvariable(): + datas.append({"Name" : var.getname(), "Type" : var.gettype(), "Initial" : var.getinitial()}) - def SetPartText(self, name, text):
- self.CFile.includes.settext(text)
- elif name == "Globals":
- self.CFile.globals.settext(text)
- self.CFile.initFunction.settext(text)
- elif name == "CleanUp":
- self.CFile.cleanUpFunction.settext(text)
- elif name == "Retrieve":
- self.CFile.retrieveFunction.settext(text)
- elif name == "Publish":
- self.CFile.publishFunction.settext(text)
+ def SetTextParts(self, parts): + for section, code_object in zip( + [self.CodeFile.includes, + self.CodeFile.initFunction, + self.CodeFile.cleanUpFunction, + self.CodeFile.retrieveFunction, + self.CodeFile.publishFunction]): + code_object.settext(parts[section]) - def GetPartText(self, name):
- return self.CFile.includes.gettext()
- elif name == "Globals":
- return self.CFile.globals.gettext()
- return self.CFile.initFunction.gettext()
- elif name == "CleanUp":
- return self.CFile.cleanUpFunction.gettext()
- elif name == "Retrieve":
- return self.CFile.retrieveFunction.gettext()
- elif name == "Publish":
- return self.CFile.publishFunction.gettext()
+ def GetTextParts(self): + for section, code_object in zip( + [self.CodeFile.includes, + self.CodeFile.initFunction, + self.CodeFile.cleanUpFunction, + self.CodeFile.retrieveFunction, + self.CodeFile.publishFunction]): + parts[section] = code_object.gettext() def CTNTestModified(self):
- return self.ChangesToSave or not self.CFileIsSaved()
+ return self.ChangesToSave or not self.CodeFileIsSaved() def OnCTNSave(self, from_project_path=None):
- filepath = self.CFileName()
+ filepath = self.CodeFileName() text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
extras = {"xmlns":"http://www.w3.org/2001/XMLSchema",
"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
- "xsi:schemaLocation" : "cext_xsd.xsd"}
- text += self.CFile.generateXMLText("CFile", 0, extras)
+ "xsi:schemaLocation" : "codefile.xsd"} + text += self.CodeFile.generateXMLText("CodeFile", 0, extras) xmlfile = open(filepath,"w")
xmlfile.write(text.encode("utf-8"))
- self.MarkCFileAsSaved()
+ self.MarkCodeFileAsSaved() def CTNGlobalInstances(self):
current_location = self.GetCurrentLocation()
- variable.getname(),"_".join(map(str, current_location))),
- for variable in self.CFile.variables.variable]
- def CTNGenerate_C(self, buildpath, locations):
- @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
- @param locations: List of complete variables locations \
- [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
- "NAME" : name of the variable (generally "__IW0_1_2" style)
- "DIR" : direction "Q","I" or "M"
- "SIZE" : size "X", "B", "W", "D", "L"
- "LOC" : tuple of interger for IEC location (0,1,2,...)
- @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
- current_location = self.GetCurrentLocation()
- # define a unique name for the generated C file
- location_str = "_".join(map(str, current_location))
- text = "/* Code generated by Beremiz c_ext confnode */\n\n"
- text += "#include <stdio.h>"
- text += "/* User includes */\n"
- text += self.CFile.includes.gettext()
- text += '#include "iec_types_all.h"'
- base_types = self.GetCTRoot().GetBaseTypes()
- config = self.GetCTRoot().GetProjectConfigNames()[0]
- text += "/* User variables reference */\n"
- for variable in self.CFile.variables.variable:
- "name": variable.getname(),
- "global": "%s__%s_%s" % (config.upper(),
- variable.getname().upper(),
- "type": "__IEC_%s_t" % variable.gettype()}
- text += "extern %(type)s %(global)s;\n" % var_infos
- text += "#define %(name)s %(global)s.value\n" % var_infos
- # Adding user global variables and routines
- text += "/* User internal user variables and routines */\n"
- text += self.CFile.globals.gettext()
- # Adding Beremiz confnode functions
- text += "/* Beremiz confnode functions */\n"
- text += "int __init_%s(int argc,char **argv)\n{\n"%location_str
- text += self.CFile.initFunction.gettext()
- text += "void __cleanup_%s(void)\n{\n"%location_str
- text += self.CFile.cleanUpFunction.gettext()
- text += "void __retrieve_%s(void)\n{\n"%location_str
- text += self.CFile.retrieveFunction.gettext()
- text += "void __publish_%s(void)\n{\n"%location_str
- text += self.CFile.publishFunction.gettext()
- Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c"%location_str)
- cfile = open(Gen_Cfile_path,'w')
- matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath())
- return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True
+ return [(variable.getname(), + for variable in self.CodeFile.variables.variable] #-------------------------------------------------------------------------------
# Current Buffering Management Functions
#-------------------------------------------------------------------------------
- Return a copy of the cfile model
+ Return a copy of the codefile model return cPickle.loads(cPickle.dumps(model))
- def CreateCFileBuffer(self, saved):
+ def CreateCodeFileBuffer(self, saved): - self.CFileBuffer = UndoBuffer(cPickle.dumps(self.CFile), saved)
+ self.CodeFileBuffer = UndoBuffer(cPickle.dumps(self.CodeFile), saved)
- self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
+ def BufferCodeFile(self): + self.CodeFileBuffer.Buffering(cPickle.dumps(self.CodeFile)) def StartBuffering(self):
- self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
+ self.CodeFileBuffer.Buffering(cPickle.dumps(self.CodeFile)) - def MarkCFileAsSaved(self):
+ def MarkCodeFileAsSaved(self): - self.CFileBuffer.CurrentSaved()
+ self.CodeFileBuffer.CurrentSaved() - def CFileIsSaved(self):
- return self.CFileBuffer.IsCurrentSaved() and not self.Buffering
+ def CodeFileIsSaved(self): + return self.CodeFileBuffer.IsCurrentSaved() and not self.Buffering - self.CFile = cPickle.loads(self.CFileBuffer.Previous())
+ self.CodeFile = cPickle.loads(self.CodeFileBuffer.Previous()) - self.CFile = cPickle.loads(self.CFileBuffer.Next())
+ self.CodeFile = cPickle.loads(self.CodeFileBuffer.Next()) def GetBufferState(self):
- first = self.CFileBuffer.IsFirst() and not self.Buffering
- last = self.CFileBuffer.IsLast()
+ first = self.CodeFileBuffer.IsFirst() and not self.Buffering + last = self.CodeFileBuffer.IsLast() return not first, not last
--- a/c_ext/CFileEditor.py Wed May 08 18:33:49 2013 +0200
+++ b/c_ext/CFileEditor.py Wed May 08 21:37:31 2013 +0200
@@ -1,132 +1,25 @@
-from controls import CustomGrid, CustomTable
-from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
-from util.BitmapLibrary import GetBitmap
-from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos
-def AppendMenu(parent, help, id, kind, text):
- if wx.VERSION >= (2, 6, 0):
- parent.Append(help=help, id=id, kind=kind, text=text)
- parent.Append(helpString=help, id=id, kind=kind, item=text)
-] = [wx.NewId() for _init_ctrls in range(1)]
-CPP_KEYWORDS = ["asm", "auto", "bool", "break", "case", "catch", "char", "class",
- "const", "const_cast", "continue", "default", "delete", "do", "double",
- "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false",
- "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable",
- "namespace", "new", "operator", "private", "protected", "public", "register",
- "reinterpret_cast", "return", "short", "signed", "sizeof", "static",
- "static_cast", "struct", "switch", "template", "this", "throw", "true", "try",
- "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual",
- "void", "volatile", "wchar_t", "while"]
-class CppEditor(CustomStyledTextCtrl):
- def __init__(self, parent, name, window, controler):
- CustomStyledTextCtrl.__init__(self, parent, ID_CPPEDITOR, wx.DefaultPosition,
+from controls.CustomStyledTextCtrl import faces +from editors.CodeFileEditor import CodeFileEditor, CodeEditor - self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
- self.SetMarginWidth(1, 25)
- self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
- self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
- self.SetLexer(stc.STC_LEX_CPP)
- self.SetKeyWords(0, " ".join(CPP_KEYWORDS))
- self.SetProperty("fold", "1")
- self.SetProperty("tab.timmy.whinge.level", "1")
- self.SetViewWhiteSpace(False)
- #self.SetBufferedDraw(False)
- #self.SetEOLMode(stc.STC_EOL_CRLF)
- #self.SetUseAntiAliasing(True)
- self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
+class CppEditor(CodeEditor): - # Setup a margin to hold fold markers
- #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
- self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
- self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
- self.SetMarginSensitive(2, True)
- self.SetMarginWidth(2, 12)
- if self.fold_symbols == 0:
- # Arrow pointing right for contracted folders, arrow pointing down for expanded
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
- elif self.fold_symbols == 1:
- # Plus for contracted folders, minus for expanded
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
- elif self.fold_symbols == 2:
- # Like a flattened tree control using circular headers and curved joins
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040")
- elif self.fold_symbols == 3:
- # Like a flattened tree control using square headers
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080")
- self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
- self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
- self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
- # Make some styles, The lexer defines what each style is used for, we
- # just have to define what each style looks like. This set is adapted from
- # Scintilla sample property files.
- # Global default styles for all languages
- self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
- self.StyleClearAll() # Reset all to be like the default
- # Global default styles for all languages
- self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
- self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size)d" % faces)
- self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
- self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
- self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
+ KEYWORDS = ["asm", "auto", "bool", "break", "case", "catch", "char", "class", + "const", "const_cast", "continue", "default", "delete", "do", "double", + "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", + "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", + "namespace", "new", "operator", "private", "protected", "public", "register", + "reinterpret_cast", "return", "short", "signed", "sizeof", "static", + "static_cast", "struct", "switch", "template", "this", "throw", "true", "try", + "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", + "void", "volatile", "wchar_t", "while"] + def SetCodeLexer(self): + self.SetLexer(stc.STC_LEX_CPP) self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060,size:%(size)d' % faces)
self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060,size:%(size)d' % faces)
self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060,size:%(size)d' % faces)
@@ -136,669 +29,22 @@
self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056,size:%(size)d' % faces)
self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold,size:%(size)d' % faces)
self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF,size:%(size)d' % faces)
- # register some images for use in the AutoComplete box.
- #self.RegisterImage(1, images.getSmilesBitmap())
- wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16)))
- wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
- wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
- self.Controler = controler
- self.ParentWindow = window
- self.DisableEvents = True
- self.CurrentAction = None
- self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
- self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_CPPEDITOR)
- self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
- self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_CPPEDITOR)
- def OnModification(self, event):
- if not self.DisableEvents:
- mod_type = event.GetModificationType()
- if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO):
- if mod_type&wx.stc.STC_MOD_BEFOREINSERT:
- if self.CurrentAction == None:
- elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
- self.Controler.EndBuffering()
- self.CurrentAction = ("Add", event.GetPosition())
- wx.CallAfter(self.RefreshModel)
- elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
- if self.CurrentAction == None:
- elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
- self.Controler.EndBuffering()
- self.CurrentAction = ("Delete", event.GetPosition())
- wx.CallAfter(self.RefreshModel)
- def OnDoDrop(self, event):
- wx.CallAfter(self.RefreshModel)
- # Buffer the last model state
- def RefreshBuffer(self):
- self.Controler.BufferCFile()
- if self.ParentWindow is not None:
- self.ParentWindow.RefreshTitle()
- self.ParentWindow.RefreshFileMenu()
- self.ParentWindow.RefreshEditMenu()
- self.ParentWindow.RefreshPageTitles()
- def StartBuffering(self):
- self.Controler.StartBuffering()
- if self.ParentWindow is not None:
- self.ParentWindow.RefreshTitle()
- self.ParentWindow.RefreshFileMenu()
- self.ParentWindow.RefreshEditMenu()
- self.ParentWindow.RefreshPageTitles()
- if self.CurrentAction != None:
- self.Controler.EndBuffering()
- self.CurrentAction = None
- self.DisableEvents = True
- old_cursor_pos = self.GetCurrentPos()
- line = self.GetFirstVisibleLine()
- column = self.GetXOffset()
- old_text = self.GetText()
- new_text = self.Controler.GetPartText(self.Name)
- if old_text != new_text:
- new_cursor_pos = GetCursorPos(old_text, new_text)
- self.LineScroll(column, line)
- if new_cursor_pos != None:
- self.GotoPos(new_cursor_pos)
- self.GotoPos(old_cursor_pos)
- self.DisableEvents = False
- def DoGetBestSize(self):
- return self.ParentWindow.GetPanelBestSize()
- def RefreshModel(self):
- self.Controler.SetPartText(self.Name, self.GetText())
- def OnKeyPressed(self, event):
- if self.CallTipActive():
- key = event.GetKeyCode()
- if key == 32 and event.ControlDown():
- pos = self.GetCurrentPos()
-## self.CallTipSetBackground("yellow")
-## self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
-## 'show some suff, maybe parameters..\n\n'
-## 'fubar(param1, param2)')
- self.AutoCompSetIgnoreCase(False) # so this needs to match
- # Images are specified with a appended "?type"
- self.AutoCompShow(0, " ".join([word + "?1" for word in CPP_KEYWORDS]))
- def OnKillFocus(self, event):
- def OnUpdateUI(self, evt):
- # check for matching braces
- caretPos = self.GetCurrentPos()
- charBefore = self.GetCharAt(caretPos - 1)
- styleBefore = self.GetStyleAt(caretPos - 1)
- if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
- braceAtCaret = caretPos - 1
- charAfter = self.GetCharAt(caretPos)
- styleAfter = self.GetStyleAt(caretPos)
- if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
- braceAtCaret = caretPos
- braceOpposite = self.BraceMatch(braceAtCaret)
- if braceAtCaret != -1 and braceOpposite == -1:
- self.BraceBadLight(braceAtCaret)
- self.BraceHighlight(braceAtCaret, braceOpposite)
- #pt = self.PointFromPosition(braceOpposite)
- #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
- def OnMarginClick(self, evt):
- # fold and unfold as needed
- if evt.GetMargin() == 2:
- if evt.GetShift() and evt.GetControl():
- lineClicked = self.LineFromPosition(evt.GetPosition())
- if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
- self.SetFoldExpanded(lineClicked, True)
- self.Expand(lineClicked, True, True, 1)
- if self.GetFoldExpanded(lineClicked):
- self.SetFoldExpanded(lineClicked, False)
- self.Expand(lineClicked, False, True, 0)
- self.SetFoldExpanded(lineClicked, True)
- self.Expand(lineClicked, True, True, 100)
- self.ToggleFold(lineClicked)
- lineCount = self.GetLineCount()
- # find out if we are folding or unfolding
- for lineNum in range(lineCount):
- if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
- expanding = not self.GetFoldExpanded(lineNum)
- while lineNum < lineCount:
- level = self.GetFoldLevel(lineNum)
- if level & stc.STC_FOLDLEVELHEADERFLAG and \
- (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
- self.SetFoldExpanded(lineNum, True)
- lineNum = self.Expand(lineNum, True)
- lastChild = self.GetLastChild(lineNum, -1)
- self.SetFoldExpanded(lineNum, False)
- if lastChild > lineNum:
- self.HideLines(lineNum+1, lastChild)
- def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
- lastChild = self.GetLastChild(line, level)
- while line <= lastChild:
- self.ShowLines(line, line)
- self.HideLines(line, line)
- self.ShowLines(line, line)
- level = self.GetFoldLevel(line)
- if level & stc.STC_FOLDLEVELHEADERFLAG:
- self.SetFoldExpanded(line, True)
- self.SetFoldExpanded(line, False)
- line = self.Expand(line, doExpand, force, visLevels-1)
- if doExpand and self.GetFoldExpanded(line):
- line = self.Expand(line, True, force, visLevels-1)
- line = self.Expand(line, False, force, visLevels-1)
- self.DisableEvents = True
- self.CmdKeyExecute(wx.stc.STC_CMD_CUT)
- self.DisableEvents = False
- self.CmdKeyExecute(wx.stc.STC_CMD_COPY)
- self.DisableEvents = True
- self.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
- self.DisableEvents = False
#-------------------------------------------------------------------------------
-# Helper for VariablesGrid values
+# CFileEditor Main Frame Class #-------------------------------------------------------------------------------
-class VariablesTable(CustomTable):
- def GetValue(self, row, col):
- if row < self.GetNumberRows():
- return str(self.data[row].get(self.GetColLabelValue(col, False), ""))
- def _updateColAttrs(self, grid):
- wxGrid -> update the column attributes to add the
- appropriate renderer given the column name.
- Otherwise default to the default renderer.
- for row in range(self.GetNumberRows()):
- for col in range(self.GetNumberCols()):
- colname = self.GetColLabelValue(col, False)
- editor = wx.grid.GridCellTextEditor()
- elif colname == "Class":
- editor = wx.grid.GridCellChoiceEditor()
- editor.SetParameters("input,memory,output")
- elif colname == "Type":
- grid.SetReadOnly(row, col, True)
- grid.SetCellEditor(row, col, editor)
- grid.SetCellRenderer(row, col, renderer)
- grid.SetCellBackgroundColour(row, col, wx.WHITE)
- self.ResizeRow(grid, row)
-class VariablesEditor(wx.Panel):
- def __init__(self, parent, window, controler):
- wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
- main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4)
- main_sizer.AddGrowableCol(0)
- main_sizer.AddGrowableRow(0)
- self.VariablesGrid = CustomGrid(self, size=wx.Size(-1, 300), style=wx.VSCROLL)
- 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)
- main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
- controls_sizer = wx.BoxSizer(wx.HORIZONTAL)
- main_sizer.AddSizer(controls_sizer, border=5, flag=wx.TOP|wx.ALIGN_RIGHT)
- for name, bitmap, help in [
- ("AddVariableButton", "add_element", _("Add variable")),
- ("DeleteVariableButton", "remove_element", _("Remove variable")),
- ("UpVariableButton", "up", _("Move variable up")),
- ("DownVariableButton", "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, border=5, flag=wx.LEFT)
- self.SetSizer(main_sizer)
- self.ParentWindow = window
- self.Controler = controler
- self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""}
- self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"])
- self.ColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
- self.ColSizes = [40, 200, 150, 150]
- self.VariablesGrid.SetTable(self.Table)
- self.VariablesGrid.SetButtons({"Add": self.AddVariableButton,
- "Delete": self.DeleteVariableButton,
- "Up": self.UpVariableButton,
- "Down": self.DownVariableButton})
- def _AddVariable(new_row):
- self.Table.InsertRow(new_row, self.VariablesDefaultValue.copy())
- setattr(self.VariablesGrid, "_AddRow", _AddVariable)
- def _DeleteVariable(row):
- self.Table.RemoveRow(row)
- setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
- def _MoveVariable(row, move):
- new_row = self.Table.MoveRow(row, move)
- setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
- 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.SetColSize(col, self.ColSizes[col])
- self.Table.ResetView(self.VariablesGrid)
- def RefreshModel(self):
- self.Controler.SetVariables(self.Table.GetData())
- # Buffer the last model state
- def RefreshBuffer(self):
- self.Controler.BufferCFile()
- self.ParentWindow.RefreshTitle()
- self.ParentWindow.RefreshFileMenu()
- self.ParentWindow.RefreshEditMenu()
- self.ParentWindow.RefreshPageTitles()
- self.Table.SetData(self.Controler.GetVariables())
- self.Table.ResetView(self.VariablesGrid)
- self.VariablesGrid.RefreshButtons()
- def DoGetBestSize(self):
- return self.ParentWindow.GetPanelBestSize()
+class CFileEditor(CodeFileEditor): - def OnVariablesGridCellChange(self, event):
- wx.CallAfter(self.RefreshView)
- def OnVariablesGridEditorShown(self, event):
- row, col = event.GetRow(), event.GetCol()
- if self.Table.GetColLabelValue(col, False) == "Type":
- type_menu = wx.Menu(title='')
- base_menu = wx.Menu(title='')
- for base_type in self.Controler.GetBaseTypes():
- 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)
- datatype_menu = wx.Menu(title='')
- for datatype in self.Controler.GetDataTypes(basetypes=False, only_locatables=True):
- 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)
- rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
- self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
- def GetVariableTypeFunction(self, base_type):
- def VariableTypeFunction(event):
- row = self.VariablesGrid.GetGridCursorRow()
- self.Table.SetValueByName(row, "Type", base_type)
- self.Table.ResetView(self.VariablesGrid)
- return VariableTypeFunction
- def OnVariablesGridCellLeftClick(self, event):
- if event.GetCol() == 0:
- if self.Table.GetValueByName(row, "Class") == "input":
- if self.Table.GetValueByName(i, "Class") == "input":
- elif self.Table.GetValueByName(row, "Class") == "memory":
- if self.Table.GetValueByName(i, "Class") == "memory":
- if self.Table.GetValueByName(i, "Class") == "output":
- data_type = self.Table.GetValueByName(row, "Type")
- var_name = self.Table.GetValueByName(row, "Name")
- base_location = ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation()))
- location = "%s%s%s.%d"%(dir, self.Controler.GetSizeOfType(data_type), base_location, num)
- data = wx.TextDataObject(str((location, "location", data_type, var_name, "")))
- dragSource = wx.DropSource(self.VariablesGrid)
- dragSource.SetData(data)
- dragSource.DoDragDrop()
-#-------------------------------------------------------------------------------
-# SVGUIEditor Main Frame Class
-#-------------------------------------------------------------------------------
- ("Includes", CppEditor),
- ("Variables", VariablesEditor),
- ("Globals", CppEditor),
- ("CleanUp", CppEditor),
- ("Retrieve", CppEditor),
- ("Publish", CppEditor),
-class FoldPanelCaption(wx.lib.buttons.GenBitmapTextToggleButton):
- def GetBackgroundBrush(self, dc):
- colBg = self.GetBackgroundColour()
- brush = wx.Brush(colBg, wx.SOLID)
- if self.style & wx.BORDER_NONE:
- myAttr = self.GetDefaultAttributes()
- parAttr = self.GetParent().GetDefaultAttributes()
- myDef = colBg == myAttr.colBg
- parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg
- if wx.Platform == "__WXMAC__":
- brush.MacSetTheme(1) # 1 == kThemeBrushDialogBackgroundActive
- elif wx.Platform == "__WXMSW__":
- if self.DoEraseBackground(dc):
- elif myDef and not parDef:
- colBg = self.GetParent().GetBackgroundColour()
- brush = wx.Brush(colBg, wx.SOLID)
- def DrawLabel(self, dc, width, height, dx=0, dy=0):
- if bmp is not None: # if the bitmap is used
- if self.bmpDisabled and not self.IsEnabled():
- if self.bmpFocus and self.hasFocus:
- if self.bmpSelected and not self.up:
- bw,bh = bmp.GetWidth(), bmp.GetHeight()
- hasMask = bmp.GetMask() is not None
- bw = bh = 0 # no bitmap -> size is zero
- dc.SetFont(self.GetFont())
- dc.SetTextForeground(self.GetForegroundColour())
- dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
- label = self.GetLabel()
- tw, th = dc.GetTextExtent(label) # size of text
- dc.DrawBitmap(bmp, width - bw - 2, (height-bh)/2, hasMask) # draw bitmap if available
- dc.DrawText(label, 2, (height-th)/2) # draw the text
- dc.SetPen(wx.Pen(self.GetForegroundColour()))
- dc.SetBrush(wx.TRANSPARENT_BRUSH)
- dc.DrawRectangle(0, 0, width, height)
-class CFileEditor(ConfTreeNodeEditor):
- CONFNODEEDITOR_TABS = [
+ CONFNODEEDITOR_TABS = CodeFileEditor.CONFNODEEDITOR_TABS + [ (_("C code"), "_create_CCodeEditor")]
def _create_CCodeEditor(self, prnt):
- self.CCodeEditor = wx.ScrolledWindow(prnt,
- style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
- self.CCodeEditor.Bind(wx.EVT_SIZE, self.OnCCodeEditorResize)
- self.MainSizer = wx.BoxSizer(wx.VERTICAL)
- for idx, (name, panel_class) in enumerate(CFILE_PARTS):
- button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name,
- label=name, bitmap=GetBitmap("CollapsedIconData"),
- parent=self.CCodeEditor, pos=wx.Point(0, 0),
- size=wx.Size(0, 20), style=wx.NO_BORDER|wx.ALIGN_LEFT)
- button.SetBitmapSelected(GetBitmap("ExpandedIconData"))
- button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id)
- self.MainSizer.AddWindow(button, 0, border=0, flag=wx.TOP|wx.GROW)
- if panel_class == VariablesEditor:
- panel = VariablesEditor(self.CCodeEditor, self.ParentWindow, self.Controler)
- panel = panel_class(self.CCodeEditor, name, self.ParentWindow, self.Controler)
- self.MainSizer.AddWindow(panel, 0, border=0, flag=wx.BOTTOM|wx.GROW)
- self.Panels[name] = {"button": button, "panel": panel, "expanded": False, "row": 2 * idx + 1}
- self.CCodeEditor.SetSizer(self.MainSizer)
+ self.CCodeEditor = CppEditor(prnt, self.ParentWindow, self.Controler)
- def __init__(self, parent, controler, window):
- ConfTreeNodeEditor.__init__(self, parent, controler, window)
- def GetBufferState(self):
- return self.Controler.GetBufferState()
- self.Controler.LoadPrevious()
- self.Controler.LoadNext()
- ConfTreeNodeEditor.RefreshView(self)
- for infos in self.Panels.itervalues():
- infos["panel"].RefreshView()
+ CodeFileEditor.RefreshView(self) - self.RefreshCCodeEditorScrollbars()
- def GenPanelButtonCallback(self, name):
- def PanelButtonCallback(event):
- return PanelButtonCallback
- def ExpandPanel(self, name):
- infos = self.Panels.get(name, None)
- if infos is not None and not infos["expanded"]:
- infos["expanded"] = True
- infos["button"].SetToggle(True)
- self.RefreshSizerLayout()
- def CollapsePanel(self, name):
- infos = self.Panels.get(name, None)
- if infos is not None and infos["expanded"]:
- infos["expanded"] = False
- infos["button"].SetToggle(False)
- self.RefreshSizerLayout()
- def TogglePanel(self, name):
- infos = self.Panels.get(name, None)
- infos["expanded"] = not infos["expanded"]
- infos["button"].SetToggle(infos["expanded"])
- self.RefreshSizerLayout()
- def RefreshSizerLayout(self):
- self.MainSizer.Layout()
- self.RefreshCCodeEditorScrollbars()
- def RefreshCCodeEditorScrollbars(self):
- self.CCodeEditor.GetBestSize()
- xstart, ystart = self.CCodeEditor.GetViewStart()
- window_size = self.CCodeEditor.GetClientSize()
- maxx, maxy = self.MainSizer.GetMinSize()
- posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
- self.CCodeEditor.Scroll(posx, posy)
- self.CCodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
- maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
- def OnCCodeEditorResize(self, event):
- self.RefreshCCodeEditorScrollbars()
+ self.CCodeEditor.RefreshView() --- a/c_ext/c_ext.py Wed May 08 18:33:49 2013 +0200
+++ b/c_ext/c_ext.py Wed May 08 21:37:31 2013 +0200
@@ -1,19 +1,9 @@
-from xml.dom import minidom
from CFileEditor import CFileEditor
-from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT
-CFileClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "cext_xsd.xsd"))
+from CodeFileTreeNode import CodeFile -TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
- "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
- "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CExtension">
@@ -26,140 +16,12 @@
- filepath = self.CFileName()
- self.CFile = CFileClasses["CFile"]()
- if os.path.isfile(filepath):
- xmlfile = open(filepath, 'r')
- tree = minidom.parse(xmlfile)
- for child in tree.childNodes:
- if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile":
- self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"])
- self.CreateCFileBuffer(True)
- self.CreateCFileBuffer(False)
+ def CodeFileName(self): return os.path.join(self.CTNPath(), "cfile.xml")
- def GetBaseTypes(self):
- return self.GetCTRoot().GetBaseTypes()
- def GetDataTypes(self, basetypes = False, only_locatables = False):
- return self.GetCTRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables)
- def GetSizeOfType(self, type):
- return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
- def SetVariables(self, variables):
- self.CFile.variables.setvariable([])
- variable = CFileClasses["variables_variable"]()
- variable.setname(var["Name"])
- variable.settype(var["Type"])
- variable.setclass(var["Class"])
- self.CFile.variables.appendvariable(variable)
- def GetVariables(self):
- for var in self.CFile.variables.getvariable():
- datas.append({"Name" : var.getname(), "Type" : var.gettype(), "Class" : var.getclass()})
- def GetVariableLocationTree(self):
- '''See ConfigTreeNode.GetVariableLocationTree() for a description.'''
- current_location = ".".join(map(str, self.GetCurrentLocation()))
- input = memory = output = 0
- for var in self.CFile.variables.getvariable():
- var_size = self.GetSizeOfType(var.gettype())
- if var.getclass() == "input":
- var_class = LOCATION_VAR_INPUT
- if var_size is not None:
- var_location = "%%I%s%s.%d"%(var_size, current_location, input)
- elif var.getclass() == "memory":
- var_class = LOCATION_VAR_INPUT
- if var_size is not None:
- var_location = "%%M%s%s.%d"%(var_size, current_location, memory)
- var_class = LOCATION_VAR_OUTPUT
- if var_size is not None:
- var_location = "%%Q%s%s.%d"%(var_size, current_location, output)
- vars.append({"name": var.getname(),
- "IEC_type": var.gettype(),
- "var_name": var.getname(),
- "location": var_location,
- return {"name": self.BaseParams.getName(),
- "type": LOCATION_CONFNODE,
- "location": self.GetFullIEC_Channel(),
- def SetPartText(self, name, text):
- self.CFile.includes.settext(text)
- elif name == "Globals":
- self.CFile.globals.settext(text)
- self.CFile.initFunction.settext(text)
- elif name == "CleanUp":
- self.CFile.cleanUpFunction.settext(text)
- elif name == "Retrieve":
- self.CFile.retrieveFunction.settext(text)
- elif name == "Publish":
- self.CFile.publishFunction.settext(text)
- def GetPartText(self, name):
- return self.CFile.includes.gettext()
- elif name == "Globals":
- return self.CFile.globals.gettext()
- return self.CFile.initFunction.gettext()
- elif name == "CleanUp":
- return self.CFile.cleanUpFunction.gettext()
- elif name == "Retrieve":
- return self.CFile.retrieveFunction.gettext()
- elif name == "Publish":
- return self.CFile.publishFunction.gettext()
- def CTNTestModified(self):
- return self.ChangesToSave or not self.CFileIsSaved()
- def OnCTNSave(self, from_project_path=None):
- filepath = self.CFileName()
- text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
- extras = {"xmlns":"http://www.w3.org/2001/XMLSchema",
- "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
- "xsi:schemaLocation" : "cext_xsd.xsd"}
- text += self.CFile.generateXMLText("CFile", 0, extras)
- xmlfile = open(filepath,"w")
- xmlfile.write(text.encode("utf-8"))
- self.MarkCFileAsSaved()
def CTNGenerate_C(self, buildpath, locations):
@@ -178,64 +40,50 @@
location_str = "_".join(map(str, current_location))
text = "/* Code generated by Beremiz c_ext confnode */\n\n"
+ text += "#include <stdio.h>" text += "/* User includes */\n"
- text += self.CFile.includes.gettext()
+ text += self.CodeFile.includes.gettext() - text += '#include "iec_types.h"'
+ text += '#include "iec_types_all.h"'
- inputs = memories = outputs = 0
- for variable in self.CFile.variables.variable:
- var = {"Name" : variable.getname(), "Type" : variable.gettype()}
- if variable.getclass() == "input":
- var["location"] = "__I%s%s_%d"%(self.GetSizeOfType(var["Type"]), location_str, inputs)
- elif variable.getclass() == "memory":
- var["location"] = "__M%s%s_%d"%(self.GetSizeOfType(var["Type"]), location_str, memories)
- var["location"] = "__Q%s%s_%d"%(self.GetSizeOfType(var["Type"]), location_str, outputs)
- text += "/* Beremiz c_ext confnode user variables definition */\n"
base_types = self.GetCTRoot().GetBaseTypes()
- if var["Type"] in base_types:
- text += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
- text += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"])
+ config = self.GetCTRoot().GetProjectConfigNames()[0] text += "/* User variables reference */\n"
- text += "#define %s beremiz%s\n"%(var["Name"], var["location"])
+ for variable in self.CodeFile.variables.variable: + "name": variable.getname(), + "global": "%s__%s" % (config.upper(), + variable.getname().upper()), + "type": "__IEC_%s_t" % variable.gettype()} + text += "extern %(type)s %(global)s;\n" % var_infos + text += "#define %(name)s %(global)s.value\n" % var_infos # Adding user global variables and routines
text += "/* User internal user variables and routines */\n"
- text += self.CFile.globals.gettext()
+ text += self.CodeFile.globals.gettext() # Adding Beremiz confnode functions
text += "/* Beremiz confnode functions */\n"
text += "int __init_%s(int argc,char **argv)\n{\n"%location_str
- text += self.CFile.initFunction.gettext()
+ text += self.CodeFile.initFunction.gettext() text += "void __cleanup_%s(void)\n{\n"%location_str
- text += self.CFile.cleanUpFunction.gettext()
+ text += self.CodeFile.cleanUpFunction.gettext() text += "void __retrieve_%s(void)\n{\n"%location_str
- text += self.CFile.retrieveFunction.gettext()
+ text += self.CodeFile.retrieveFunction.gettext() text += "void __publish_%s(void)\n{\n"%location_str
- text += self.CFile.publishFunction.gettext()
+ text += self.CodeFile.publishFunction.gettext() Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c"%location_str)
@@ -247,48 +95,3 @@
return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True
-#-------------------------------------------------------------------------------
-# Current Buffering Management Functions
-#-------------------------------------------------------------------------------
- Return a copy of the cfile model
- return cPickle.loads(cPickle.dumps(model))
- def CreateCFileBuffer(self, saved):
- self.CFileBuffer = UndoBuffer(cPickle.dumps(self.CFile), saved)
- self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
- def StartBuffering(self):
- def EndBuffering(self):
- self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
- def MarkCFileAsSaved(self):
- self.CFileBuffer.CurrentSaved()
- def CFileIsSaved(self):
- return self.CFileBuffer.IsCurrentSaved() and not self.Buffering
- def LoadPrevious(self):
- self.CFile = cPickle.loads(self.CFileBuffer.Previous())
- self.CFile = cPickle.loads(self.CFileBuffer.Next())
- def GetBufferState(self):
- first = self.CFileBuffer.IsFirst() and not self.Buffering
- last = self.CFileBuffer.IsLast()
- return not first, not last
--- a/editors/CodeFileEditor.py Wed May 08 18:33:49 2013 +0200
+++ b/editors/CodeFileEditor.py Wed May 08 21:37:31 2013 +0200
@@ -1,4 +1,4 @@
@@ -6,36 +6,20 @@
from controls import CustomGrid, CustomTable
-from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
+from editors.ConfTreeNodeEditor import ConfTreeNodeEditor from util.BitmapLibrary import GetBitmap
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos
-def AppendMenu(parent, help, id, kind, text):
- if wx.VERSION >= (2, 6, 0):
- parent.Append(help=help, id=id, kind=kind, text=text)
- parent.Append(helpString=help, id=id, kind=kind, item=text)
-] = [wx.NewId() for _init_ctrls in range(1)]
+SECTIONS_NAMES = ["Includes", "Globals", "Init", + "CleanUp", "Retrieve", "Publish"] -CPP_KEYWORDS = ["asm", "auto", "bool", "break", "case", "catch", "char", "class",
- "const", "const_cast", "continue", "default", "delete", "do", "double",
- "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false",
- "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable",
- "namespace", "new", "operator", "private", "protected", "public", "register",
- "reinterpret_cast", "return", "short", "signed", "sizeof", "static",
- "static_cast", "struct", "switch", "template", "this", "throw", "true", "try",
- "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual",
- "void", "volatile", "wchar_t", "while"]
+class CodeEditor(CustomStyledTextCtrl): -class CppEditor(CustomStyledTextCtrl):
- def __init__(self, parent, name, window, controler):
- CustomStyledTextCtrl.__init__(self, parent, ID_CPPEDITOR, wx.DefaultPosition,
+ def __init__(self, parent, window, controler): + CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition, self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
@@ -44,70 +28,30 @@
self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
- self.SetLexer(stc.STC_LEX_CPP)
- self.SetKeyWords(0, " ".join(CPP_KEYWORDS))
self.SetProperty("fold", "1")
self.SetProperty("tab.timmy.whinge.level", "1")
self.SetViewWhiteSpace(False)
- #self.SetBufferedDraw(False)
- #self.SetEOLMode(stc.STC_EOL_CRLF)
- #self.SetUseAntiAliasing(True)
self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
# Setup a margin to hold fold markers
- #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
self.SetMarginSensitive(2, True)
self.SetMarginWidth(2, 12)
- if self.fold_symbols == 0:
- # Arrow pointing right for contracted folders, arrow pointing down for expanded
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
- elif self.fold_symbols == 1:
- # Plus for contracted folders, minus for expanded
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
- elif self.fold_symbols == 2:
- # Like a flattened tree control using circular headers and curved joins
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040")
- elif self.fold_symbols == 3:
- # Like a flattened tree control using square headers
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
- self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080")
+ # Like a flattened tree control using square headers + self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") + self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080") self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
@@ -126,16 +70,6 @@
self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
- self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold,size:%(size)d' % faces)
- self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF,size:%(size)d' % faces)
# register some images for use in the AutoComplete box.
#self.RegisterImage(1, images.getSmilesBitmap())
@@ -149,19 +83,37 @@
+ self.SetKeyWords(0, " ".join(self.KEYWORDS)) self.Controler = controler
self.ParentWindow = window
self.DisableEvents = True
self.CurrentAction = None
+ self.SectionsComments = {} + for section in SECTIONS_NAMES: + section_start_comment = "%s %s section\n" % (self.COMMENT_HEADER, section) + section_end_comment = "\n%s End %s section\n\n" % (self.COMMENT_HEADER, section) + self.SectionsComments[section] = { + "start": section_start_comment, + "end": section_end_comment, + "pattern": re.compile(section_start_comment + self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
- self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_CPPEDITOR)
+ self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
- self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_CPPEDITOR)
+ self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification) + def SetCodeLexer(self): def OnModification(self, event):
if not self.DisableEvents:
@@ -192,7 +144,7 @@
# Buffer the last model state
- self.Controler.BufferCFile()
+ self.Controler.BufferCodeFile() if self.ParentWindow is not None:
self.ParentWindow.RefreshTitle()
self.ParentWindow.RefreshFileMenu()
@@ -212,6 +164,16 @@
self.Controler.EndBuffering()
self.CurrentAction = None
+ parts = self.Controler.GetTextParts() + for section in SECTIONS_NAMES: + section_comments = self.SectionsComments[section] + text += section_comments["start"] + text += section_comments["end"] self.DisableEvents = True
@@ -219,7 +181,7 @@
line = self.GetFirstVisibleLine()
column = self.GetXOffset()
old_text = self.GetText()
- new_text = self.Controler.GetPartText(self.Name)
+ new_text = self.GetCodeText() new_cursor_pos = GetCursorPos(old_text, new_text)
@@ -237,7 +199,16 @@
return self.ParentWindow.GetPanelBestSize()
- self.Controler.SetPartText(self.Name, self.GetText())
+ for section in SECTIONS_NAMES: + section_comments = self.SectionsComments[section] + result = section_comments["pattern"].search(text) + parts[section] = result.group(1) + self.Controler.SetTextParts(parts) def OnKeyPressed(self, event):
@@ -250,16 +221,12 @@
-## self.CallTipSetBackground("yellow")
-## self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
-## 'show some suff, maybe parameters..\n\n'
-## 'fubar(param1, param2)')
self.AutoCompSetIgnoreCase(False) # so this needs to match
# Images are specified with a appended "?type"
- self.AutoCompShow(0, " ".join([word + "?1" for word in CPP_KEYWORDS]))
+ self.AutoCompShow(0, " ".join([word + "?1" for word in self.KEYWORDS])) @@ -297,11 +264,6 @@
self.BraceBadLight(braceAtCaret)
self.BraceHighlight(braceAtCaret, braceOpposite)
- #pt = self.PointFromPosition(braceOpposite)
- #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
def OnMarginClick(self, evt):
# fold and unfold as needed
@@ -443,7 +405,7 @@
colname = self.GetColLabelValue(col, False)
+ if colname in ["Name", "Initial"]: editor = wx.grid.GridCellTextEditor()
editor = wx.grid.GridCellChoiceEditor()
@@ -494,8 +456,8 @@
self.ParentWindow = window
self.Controler = controler
- self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""}
- self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"])
+ self.VariablesDefaultValue = {"Name" : "", "Type" : "", "Initial": ""} + self.Table = VariablesTable(self, [], ["#", "Name", "Type", "Initial"]) self.ColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
self.ColSizes = [40, 200, 150, 150]
self.VariablesGrid.SetTable(self.Table)
@@ -539,7 +501,7 @@
# Buffer the last model state
- self.Controler.BufferCFile()
+ self.Controler.BufferCodeFile() self.ParentWindow.RefreshTitle()
self.ParentWindow.RefreshFileMenu()
self.ParentWindow.RefreshEditMenu()
@@ -565,13 +527,13 @@
base_menu = wx.Menu(title='')
for base_type in self.Controler.GetBaseTypes():
- AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
+ base_menu.Append(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)
datatype_menu = wx.Menu(title='')
for datatype in self.Controler.GetDataTypes(basetypes=False, only_locatables=True):
- AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
+ datatype_menu.Append(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)
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
@@ -608,107 +570,18 @@
#-------------------------------------------------------------------------------
-# SVGUIEditor Main Frame Class
+# CodeFileEditor Main Frame Class #-------------------------------------------------------------------------------
- ("Includes", CppEditor),
- ("Variables", VariablesEditor),
- ("Globals", CppEditor),
- ("CleanUp", CppEditor),
- ("Retrieve", CppEditor),
- ("Publish", CppEditor),
-class FoldPanelCaption(wx.lib.buttons.GenBitmapTextToggleButton):
- def GetBackgroundBrush(self, dc):
- colBg = self.GetBackgroundColour()
- brush = wx.Brush(colBg, wx.SOLID)
- if self.style & wx.BORDER_NONE:
- myAttr = self.GetDefaultAttributes()
- parAttr = self.GetParent().GetDefaultAttributes()
- myDef = colBg == myAttr.colBg
- parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg
- if wx.Platform == "__WXMAC__":
- brush.MacSetTheme(1) # 1 == kThemeBrushDialogBackgroundActive
- elif wx.Platform == "__WXMSW__":
- if self.DoEraseBackground(dc):
- elif myDef and not parDef:
- colBg = self.GetParent().GetBackgroundColour()
- brush = wx.Brush(colBg, wx.SOLID)
- def DrawLabel(self, dc, width, height, dx=0, dy=0):
- if bmp is not None: # if the bitmap is used
- if self.bmpDisabled and not self.IsEnabled():
- if self.bmpFocus and self.hasFocus:
- if self.bmpSelected and not self.up:
- bw,bh = bmp.GetWidth(), bmp.GetHeight()
- hasMask = bmp.GetMask() is not None
- bw = bh = 0 # no bitmap -> size is zero
- dc.SetFont(self.GetFont())
- dc.SetTextForeground(self.GetForegroundColour())
- dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
- label = self.GetLabel()
- tw, th = dc.GetTextExtent(label) # size of text
- dc.DrawBitmap(bmp, width - bw - 2, (height-bh)/2, hasMask) # draw bitmap if available
- dc.DrawText(label, 2, (height-th)/2) # draw the text
- dc.SetPen(wx.Pen(self.GetForegroundColour()))
- dc.SetBrush(wx.TRANSPARENT_BRUSH)
- dc.DrawRectangle(0, 0, width, height)
-class CFileEditor(ConfTreeNodeEditor):
+class CodeFileEditor(ConfTreeNodeEditor): - (_("C code"), "_create_CCodeEditor")]
+ (_("Variables"), "_create_VariablesPanel")] - def _create_CCodeEditor(self, prnt):
- self.CCodeEditor = wx.ScrolledWindow(prnt,
- style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
- self.CCodeEditor.Bind(wx.EVT_SIZE, self.OnCCodeEditorResize)
- self.MainSizer = wx.BoxSizer(wx.VERTICAL)
+ def _create_VariablesPanel(self, prnt): + self.VariablesPanel = VariablesEditor(prnt, self.ParentWindow, self.Controler) - for idx, (name, panel_class) in enumerate(CFILE_PARTS):
- button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name,
- label=name, bitmap=GetBitmap("CollapsedIconData"),
- parent=self.CCodeEditor, pos=wx.Point(0, 0),
- size=wx.Size(0, 20), style=wx.NO_BORDER|wx.ALIGN_LEFT)
- button.SetBitmapSelected(GetBitmap("ExpandedIconData"))
- button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id)
- self.MainSizer.AddWindow(button, 0, border=0, flag=wx.TOP|wx.GROW)
- if panel_class == VariablesEditor:
- panel = VariablesEditor(self.CCodeEditor, self.ParentWindow, self.Controler)
- panel = panel_class(self.CCodeEditor, name, self.ParentWindow, self.Controler)
- self.MainSizer.AddWindow(panel, 0, border=0, flag=wx.BOTTOM|wx.GROW)
- self.Panels[name] = {"button": button, "panel": panel, "expanded": False, "row": 2 * idx + 1}
- self.CCodeEditor.SetSizer(self.MainSizer)
- return self.CCodeEditor
+ return self.VariablesPanel def __init__(self, parent, controler, window):
ConfTreeNodeEditor.__init__(self, parent, controler, window)
@@ -727,62 +600,5 @@
ConfTreeNodeEditor.RefreshView(self)
- for infos in self.Panels.itervalues():
- infos["panel"].RefreshView()
- self.RefreshCCodeEditorScrollbars()
- def GenPanelButtonCallback(self, name):
- def PanelButtonCallback(event):
- return PanelButtonCallback
- def ExpandPanel(self, name):
- infos = self.Panels.get(name, None)
- if infos is not None and not infos["expanded"]:
- infos["expanded"] = True
- infos["button"].SetToggle(True)
- self.RefreshSizerLayout()
- def CollapsePanel(self, name):
- infos = self.Panels.get(name, None)
- if infos is not None and infos["expanded"]:
- infos["expanded"] = False
- infos["button"].SetToggle(False)
- self.RefreshSizerLayout()
- def TogglePanel(self, name):
- infos = self.Panels.get(name, None)
- infos["expanded"] = not infos["expanded"]
- infos["button"].SetToggle(infos["expanded"])
- self.RefreshSizerLayout()
- def RefreshSizerLayout(self):
- self.MainSizer.Layout()
- self.RefreshCCodeEditorScrollbars()
- def RefreshCCodeEditorScrollbars(self):
- self.CCodeEditor.GetBestSize()
- xstart, ystart = self.CCodeEditor.GetViewStart()
- window_size = self.CCodeEditor.GetClientSize()
- maxx, maxy = self.MainSizer.GetMinSize()
- posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
- self.CCodeEditor.Scroll(posx, posy)
- self.CCodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
- maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
- def OnCCodeEditorResize(self, event):
- self.RefreshCCodeEditorScrollbars()
+ self.VariablesPanel.RefreshView() \ No newline at end of file