lbessard@145: import wx, wx.grid lbessard@145: import wx.stc as stc lbessard@145: import keyword lbessard@145: lbessard@145: if wx.Platform == '__WXMSW__': lbessard@145: faces = { 'times': 'Times New Roman', lbessard@145: 'mono' : 'Courier New', lbessard@145: 'helv' : 'Arial', lbessard@145: 'other': 'Comic Sans MS', lbessard@145: 'size' : 10, lbessard@145: 'size2': 8, lbessard@145: } lbessard@145: else: lbessard@145: faces = { 'times': 'Times', lbessard@145: 'mono' : 'Courier', lbessard@145: 'helv' : 'Helvetica', lbessard@145: 'other': 'new century schoolbook', lbessard@145: 'size' : 12, lbessard@145: 'size2': 10, lbessard@145: } lbessard@145: lbessard@145: lbessard@145: def AppendMenu(parent, help, id, kind, text): lbessard@145: if wx.VERSION >= (2, 6, 0): lbessard@145: parent.Append(help=help, id=id, kind=kind, text=text) lbessard@145: else: lbessard@145: parent.Append(helpString=help, id=id, kind=kind, item=text) lbessard@145: lbessard@145: lbessard@145: [ID_CPPEDITOR, lbessard@145: ] = [wx.NewId() for _init_ctrls in range(1)] lbessard@145: lbessard@145: CPP_KEYWORDS = ["asm", "auto", "bool", "break", "case", "catch", "char", "class", lbessard@145: "const", "const_cast", "continue", "default", "delete", "do", "double", lbessard@145: "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", lbessard@145: "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", lbessard@145: "namespace", "new", "operator", "private", "protected", "public", "register", lbessard@145: "reinterpret_cast", "return", "short", "signed", "sizeof", "static", lbessard@145: "static_cast", "struct", "switch", "template", "this", "throw", "true", "try", lbessard@145: "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", lbessard@145: "void", "volatile", "wchar_t", "while"] lbessard@145: lbessard@145: def GetCursorPos(old, new): lbessard@145: old_length = len(old) lbessard@145: new_length = len(new) lbessard@145: common_length = min(old_length, new_length) lbessard@145: i = 0 lbessard@145: for i in xrange(common_length): lbessard@145: if old[i] != new[i]: lbessard@145: break lbessard@145: if old_length < new_length: lbessard@145: if common_length > 0 and old[i] != new[i]: lbessard@145: return i + new_length - old_length lbessard@145: else: lbessard@145: return i + new_length - old_length + 1 lbessard@145: elif old_length > new_length or i < min(old_length, new_length) - 1: lbessard@145: if common_length > 0 and old[i] != new[i]: lbessard@145: return i lbessard@145: else: lbessard@145: return i + 1 lbessard@145: else: lbessard@145: return None lbessard@145: lbessard@145: class CppEditor(stc.StyledTextCtrl): lbessard@145: lbessard@145: fold_symbols = 3 lbessard@145: lbessard@145: def __init__(self, parent, name, window, controler): lbessard@145: stc.StyledTextCtrl.__init__(self, parent, ID_CPPEDITOR, wx.DefaultPosition, lbessard@145: wx.DefaultSize, 0) lbessard@145: lbessard@145: self.SetMarginType(1, stc.STC_MARGIN_NUMBER) lbessard@145: self.SetMarginWidth(1, 25) lbessard@145: lbessard@145: self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) lbessard@145: self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) lbessard@145: lbessard@145: self.SetLexer(stc.STC_LEX_CPP) lbessard@145: self.SetKeyWords(0, " ".join(CPP_KEYWORDS)) lbessard@145: lbessard@145: self.SetProperty("fold", "1") lbessard@145: self.SetProperty("tab.timmy.whinge.level", "1") lbessard@145: self.SetMargins(0,0) lbessard@145: lbessard@145: self.SetViewWhiteSpace(False) lbessard@145: #self.SetBufferedDraw(False) lbessard@145: #self.SetViewEOL(True) lbessard@145: #self.SetEOLMode(stc.STC_EOL_CRLF) lbessard@145: #self.SetUseAntiAliasing(True) lbessard@145: lbessard@145: self.SetEdgeMode(stc.STC_EDGE_BACKGROUND) lbessard@145: self.SetEdgeColumn(78) lbessard@145: lbessard@145: # Setup a margin to hold fold markers lbessard@145: #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER? lbessard@145: self.SetMarginType(2, stc.STC_MARGIN_SYMBOL) lbessard@145: self.SetMarginMask(2, stc.STC_MASK_FOLDERS) lbessard@145: self.SetMarginSensitive(2, True) lbessard@145: self.SetMarginWidth(2, 12) lbessard@145: lbessard@145: if self.fold_symbols == 0: lbessard@145: # Arrow pointing right for contracted folders, arrow pointing down for expanded lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: lbessard@145: elif self.fold_symbols == 1: lbessard@145: # Plus for contracted folders, minus for expanded lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") lbessard@145: lbessard@145: elif self.fold_symbols == 2: lbessard@145: # Like a flattened tree control using circular headers and curved joins lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040") lbessard@145: lbessard@145: elif self.fold_symbols == 3: lbessard@145: # Like a flattened tree control using square headers lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") lbessard@145: self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080") lbessard@145: lbessard@145: lbessard@145: self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI) lbessard@145: self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick) lbessard@145: self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed) lbessard@145: lbessard@145: # Make some styles, The lexer defines what each style is used for, we lbessard@145: # just have to define what each style looks like. This set is adapted from lbessard@145: # Scintilla sample property files. lbessard@145: lbessard@145: # Global default styles for all languages lbessard@145: self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) lbessard@145: self.StyleClearAll() # Reset all to be like the default lbessard@145: lbessard@145: # Global default styles for all languages lbessard@145: self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) lbessard@145: self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces) lbessard@145: self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces) lbessard@145: self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold") lbessard@145: self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold") lbessard@145: lbessard@145: self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060') lbessard@145: self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060') lbessard@145: self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060') lbessard@145: self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE') lbessard@145: self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056') lbessard@145: self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff') lbessard@145: self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056') lbessard@145: self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold') lbessard@145: self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF') lbessard@145: lbessard@145: # register some images for use in the AutoComplete box. lbessard@145: #self.RegisterImage(1, images.getSmilesBitmap()) lbessard@145: self.RegisterImage(1, lbessard@145: wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16))) lbessard@145: self.RegisterImage(2, lbessard@145: wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16))) lbessard@145: self.RegisterImage(3, lbessard@145: wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16))) lbessard@145: lbessard@145: # Indentation size lbessard@145: self.SetTabWidth(2) lbessard@145: self.SetUseTabs(0) lbessard@145: lbessard@145: self.Controler = controler lbessard@145: self.ParentWindow = window lbessard@145: lbessard@145: self.DisableEvents = True lbessard@145: self.Name = name lbessard@145: self.CurrentAction = None lbessard@145: lbessard@145: self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) lbessard@145: lbessard@145: self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_CPPEDITOR) lbessard@145: self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) lbessard@145: self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_CPPEDITOR) lbessard@145: lbessard@145: def OnModification(self, event): lbessard@145: if not self.DisableEvents: lbessard@145: mod_type = event.GetModificationType() lbessard@145: if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO): lbessard@145: if mod_type&wx.stc.STC_MOD_BEFOREINSERT: lbessard@145: if self.CurrentAction == None: lbessard@145: self.StartBuffering() lbessard@145: elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: lbessard@145: self.Controler.EndBuffering() lbessard@145: self.StartBuffering() lbessard@145: self.CurrentAction = ("Add", event.GetPosition()) lbessard@145: elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: lbessard@145: if self.CurrentAction == None: lbessard@145: self.StartBuffering() lbessard@145: elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: lbessard@145: self.Controler.EndBuffering() lbessard@145: self.StartBuffering() lbessard@145: self.CurrentAction = ("Delete", event.GetPosition()) lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnDoDrop(self, event): lbessard@145: self.ResetBuffer() lbessard@145: wx.CallAfter(self.RefreshModel) lbessard@145: event.Skip() lbessard@145: lbessard@145: def IsViewing(self, name): lbessard@145: return self.Name == name lbessard@145: lbessard@145: # Buffer the last model state lbessard@145: def RefreshBuffer(self): lbessard@145: self.Controler.BufferCFile() lbessard@145: if self.ParentWindow: lbessard@145: self.ParentWindow.RefreshTitle() lbessard@145: self.ParentWindow.RefreshEditMenu() lbessard@145: lbessard@145: def StartBuffering(self): lbessard@145: self.Controler.StartBuffering() lbessard@145: if self.ParentWindow: lbessard@145: self.ParentWindow.RefreshTitle() lbessard@145: self.ParentWindow.RefreshEditMenu() lbessard@145: lbessard@145: def ResetBuffer(self): lbessard@145: if self.CurrentAction != None: lbessard@145: self.Controler.EndBuffering() lbessard@145: self.CurrentAction = None lbessard@145: lbessard@145: def RefreshView(self): lbessard@145: self.ResetBuffer() lbessard@145: self.DisableEvents = True lbessard@145: old_cursor_pos = self.GetCurrentPos() lbessard@145: old_text = self.GetText() lbessard@145: new_text = self.Controler.GetPartText(self.Name) lbessard@145: self.SetText(new_text) lbessard@145: new_cursor_pos = GetCursorPos(old_text, new_text) lbessard@145: if new_cursor_pos != None: lbessard@145: self.GotoPos(new_cursor_pos) lbessard@145: else: lbessard@145: self.GotoPos(old_cursor_pos) lbessard@145: self.ScrollToColumn(0) lbessard@145: self.EmptyUndoBuffer() lbessard@145: self.DisableEvents = False lbessard@145: lbessard@145: self.Colourise(0, -1) lbessard@145: lbessard@145: def RefreshModel(self): lbessard@145: self.Controler.SetPartText(self.Name, self.GetText()) lbessard@145: lbessard@145: def OnKeyPressed(self, event): lbessard@145: if self.CallTipActive(): lbessard@145: self.CallTipCancel() lbessard@145: key = event.GetKeyCode() lbessard@145: lbessard@145: if key == 32 and event.ControlDown(): lbessard@145: pos = self.GetCurrentPos() lbessard@145: lbessard@145: # Tips lbessard@145: if event.ShiftDown(): lbessard@145: pass lbessard@145: ## self.CallTipSetBackground("yellow") lbessard@145: ## self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n' lbessard@145: ## 'show some suff, maybe parameters..\n\n' lbessard@145: ## 'fubar(param1, param2)') lbessard@145: # Code completion lbessard@145: else: lbessard@145: self.AutoCompSetIgnoreCase(False) # so this needs to match lbessard@145: lbessard@145: # Images are specified with a appended "?type" lbessard@145: self.AutoCompShow(0, " ".join([word + "?1" for word in CPP_KEYWORDS])) lbessard@145: else: lbessard@145: wx.CallAfter(self.RefreshModel) lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnKillFocus(self, event): lbessard@145: self.AutoCompCancel() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnUpdateUI(self, evt): lbessard@145: # check for matching braces lbessard@145: braceAtCaret = -1 lbessard@145: braceOpposite = -1 lbessard@145: charBefore = None lbessard@145: caretPos = self.GetCurrentPos() lbessard@145: lbessard@145: if caretPos > 0: lbessard@145: charBefore = self.GetCharAt(caretPos - 1) lbessard@145: styleBefore = self.GetStyleAt(caretPos - 1) lbessard@145: lbessard@145: # check before lbessard@145: if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR: lbessard@145: braceAtCaret = caretPos - 1 lbessard@145: lbessard@145: # check after lbessard@145: if braceAtCaret < 0: lbessard@145: charAfter = self.GetCharAt(caretPos) lbessard@145: styleAfter = self.GetStyleAt(caretPos) lbessard@145: lbessard@145: if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR: lbessard@145: braceAtCaret = caretPos lbessard@145: lbessard@145: if braceAtCaret >= 0: lbessard@145: braceOpposite = self.BraceMatch(braceAtCaret) lbessard@145: lbessard@145: if braceAtCaret != -1 and braceOpposite == -1: lbessard@145: self.BraceBadLight(braceAtCaret) lbessard@145: else: lbessard@145: self.BraceHighlight(braceAtCaret, braceOpposite) lbessard@145: #pt = self.PointFromPosition(braceOpposite) lbessard@145: #self.Refresh(True, wxRect(pt.x, pt.y, 5,5)) lbessard@145: #print pt lbessard@145: #self.Refresh(False) lbessard@145: lbessard@145: lbessard@145: def OnMarginClick(self, evt): lbessard@145: # fold and unfold as needed lbessard@145: if evt.GetMargin() == 2: lbessard@145: if evt.GetShift() and evt.GetControl(): lbessard@145: self.FoldAll() lbessard@145: else: lbessard@145: lineClicked = self.LineFromPosition(evt.GetPosition()) lbessard@145: lbessard@145: if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG: lbessard@145: if evt.GetShift(): lbessard@145: self.SetFoldExpanded(lineClicked, True) lbessard@145: self.Expand(lineClicked, True, True, 1) lbessard@145: elif evt.GetControl(): lbessard@145: if self.GetFoldExpanded(lineClicked): lbessard@145: self.SetFoldExpanded(lineClicked, False) lbessard@145: self.Expand(lineClicked, False, True, 0) lbessard@145: else: lbessard@145: self.SetFoldExpanded(lineClicked, True) lbessard@145: self.Expand(lineClicked, True, True, 100) lbessard@145: else: lbessard@145: self.ToggleFold(lineClicked) lbessard@145: lbessard@145: lbessard@145: def FoldAll(self): lbessard@145: lineCount = self.GetLineCount() lbessard@145: expanding = True lbessard@145: lbessard@145: # find out if we are folding or unfolding lbessard@145: for lineNum in range(lineCount): lbessard@145: if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG: lbessard@145: expanding = not self.GetFoldExpanded(lineNum) lbessard@145: break lbessard@145: lbessard@145: lineNum = 0 lbessard@145: lbessard@145: while lineNum < lineCount: lbessard@145: level = self.GetFoldLevel(lineNum) lbessard@145: if level & stc.STC_FOLDLEVELHEADERFLAG and \ lbessard@145: (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE: lbessard@145: lbessard@145: if expanding: lbessard@145: self.SetFoldExpanded(lineNum, True) lbessard@145: lineNum = self.Expand(lineNum, True) lbessard@145: lineNum = lineNum - 1 lbessard@145: else: lbessard@145: lastChild = self.GetLastChild(lineNum, -1) lbessard@145: self.SetFoldExpanded(lineNum, False) lbessard@145: lbessard@145: if lastChild > lineNum: lbessard@145: self.HideLines(lineNum+1, lastChild) lbessard@145: lbessard@145: lineNum = lineNum + 1 lbessard@145: lbessard@145: lbessard@145: lbessard@145: def Expand(self, line, doExpand, force=False, visLevels=0, level=-1): lbessard@145: lastChild = self.GetLastChild(line, level) lbessard@145: line = line + 1 lbessard@145: lbessard@145: while line <= lastChild: lbessard@145: if force: lbessard@145: if visLevels > 0: lbessard@145: self.ShowLines(line, line) lbessard@145: else: lbessard@145: self.HideLines(line, line) lbessard@145: else: lbessard@145: if doExpand: lbessard@145: self.ShowLines(line, line) lbessard@145: lbessard@145: if level == -1: lbessard@145: level = self.GetFoldLevel(line) lbessard@145: lbessard@145: if level & stc.STC_FOLDLEVELHEADERFLAG: lbessard@145: if force: lbessard@145: if visLevels > 1: lbessard@145: self.SetFoldExpanded(line, True) lbessard@145: else: lbessard@145: self.SetFoldExpanded(line, False) lbessard@145: lbessard@145: line = self.Expand(line, doExpand, force, visLevels-1) lbessard@145: lbessard@145: else: lbessard@145: if doExpand and self.GetFoldExpanded(line): lbessard@145: line = self.Expand(line, True, force, visLevels-1) lbessard@145: else: lbessard@145: line = self.Expand(line, False, force, visLevels-1) lbessard@145: else: lbessard@145: line = line + 1 lbessard@145: lbessard@145: return line lbessard@145: lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # Helper for VariablesGrid values lbessard@145: #------------------------------------------------------------------------------- lbessard@145: lbessard@145: class VariablesTable(wx.grid.PyGridTableBase): lbessard@145: lbessard@145: """ lbessard@145: A custom wxGrid Table using user supplied data lbessard@145: """ lbessard@145: def __init__(self, parent, data, colnames): lbessard@145: # The base class must be initialized *first* lbessard@145: wx.grid.PyGridTableBase.__init__(self) lbessard@145: self.data = data lbessard@145: self.colnames = colnames lbessard@145: self.Parent = parent lbessard@145: # XXX lbessard@145: # we need to store the row length and collength to lbessard@145: # see if the table has changed size lbessard@145: self._rows = self.GetNumberRows() lbessard@145: self._cols = self.GetNumberCols() lbessard@145: lbessard@145: def GetNumberCols(self): lbessard@145: return len(self.colnames) lbessard@145: lbessard@145: def GetNumberRows(self): lbessard@145: return len(self.data) lbessard@145: lbessard@145: def GetColLabelValue(self, col): lbessard@145: if col < len(self.colnames): lbessard@145: return self.colnames[col] lbessard@145: lbessard@145: def GetRowLabelValues(self, row): lbessard@145: return row lbessard@145: lbessard@145: def GetValue(self, row, col): lbessard@145: if row < self.GetNumberRows(): lbessard@145: if col == 0: lbessard@145: return row + 1 lbessard@145: else: lbessard@145: return str(self.data[row].get(self.GetColLabelValue(col), "")) lbessard@145: lbessard@145: def GetValueByName(self, row, colname): lbessard@145: if row < self.GetNumberRows(): lbessard@145: return self.data[row].get(colname, None) lbessard@145: return None lbessard@145: lbessard@145: def SetValue(self, row, col, value): lbessard@145: if col < len(self.colnames): lbessard@145: self.data[row][self.GetColLabelValue(col)] = value lbessard@145: lbessard@145: def SetValueByName(self, row, colname, value): lbessard@145: if row < self.GetNumberRows(): lbessard@145: self.data[row][colname] = value lbessard@145: lbessard@145: def ResetView(self, grid): lbessard@145: """ lbessard@145: (wxGrid) -> Reset the grid view. Call this to lbessard@145: update the grid if rows and columns have been added or deleted lbessard@145: """ lbessard@145: grid.BeginBatch() lbessard@145: for current, new, delmsg, addmsg in [ lbessard@145: (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@145: (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), lbessard@145: ]: lbessard@145: if new < current: lbessard@145: msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) lbessard@145: grid.ProcessTableMessage(msg) lbessard@145: elif new > current: lbessard@145: msg = wx.grid.GridTableMessage(self,addmsg,new-current) lbessard@145: grid.ProcessTableMessage(msg) lbessard@145: self.UpdateValues(grid) lbessard@145: grid.EndBatch() lbessard@145: lbessard@145: self._rows = self.GetNumberRows() lbessard@145: self._cols = self.GetNumberCols() lbessard@145: # update the column rendering scheme lbessard@145: self._updateColAttrs(grid) lbessard@145: lbessard@145: # update the scrollbars and the displayed part of the grid lbessard@145: grid.AdjustScrollbars() lbessard@145: grid.ForceRefresh() lbessard@145: lbessard@145: def UpdateValues(self, grid): lbessard@145: """Update all displayed values""" lbessard@145: # This sends an event to the grid table to update all of the values lbessard@145: msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) lbessard@145: grid.ProcessTableMessage(msg) lbessard@145: lbessard@145: def _updateColAttrs(self, grid): lbessard@145: """ lbessard@145: wxGrid -> update the column attributes to add the lbessard@145: appropriate renderer given the column name. lbessard@145: lbessard@145: Otherwise default to the default renderer. lbessard@145: """ lbessard@145: lbessard@145: typelist = None lbessard@145: accesslist = None lbessard@145: for row in range(self.GetNumberRows()): lbessard@145: for col in range(self.GetNumberCols()): lbessard@145: editor = None lbessard@145: renderer = None lbessard@145: colname = self.GetColLabelValue(col) lbessard@145: grid.SetReadOnly(row, col, False) lbessard@145: lbessard@145: if colname == "Name": lbessard@145: editor = wx.grid.GridCellTextEditor() lbessard@145: elif colname == "Class": lbessard@145: editor = wx.grid.GridCellChoiceEditor() lbessard@145: editor.SetParameters("input,output") lbessard@145: elif colname == "Type": lbessard@145: pass lbessard@145: else: lbessard@145: grid.SetReadOnly(row, col, True) lbessard@145: lbessard@145: grid.SetCellEditor(row, col, editor) lbessard@145: grid.SetCellRenderer(row, col, renderer) lbessard@145: lbessard@145: grid.SetCellBackgroundColour(row, col, wx.WHITE) lbessard@145: lbessard@145: def SetData(self, data): lbessard@145: self.data = data lbessard@145: lbessard@145: def GetData(self): lbessard@145: return self.data lbessard@145: lbessard@145: def GetCurrentIndex(self): lbessard@145: return self.CurrentIndex lbessard@145: lbessard@145: def SetCurrentIndex(self, index): lbessard@145: self.CurrentIndex = index lbessard@145: lbessard@145: def AppendRow(self, row_content): lbessard@145: self.data.append(row_content) lbessard@145: lbessard@145: def RemoveRow(self, row_index): lbessard@145: self.data.pop(row_index) lbessard@145: lbessard@145: def MoveRow(self, row_index, move, grid): lbessard@145: new_index = max(0, min(row_index + move, len(self.data) - 1)) lbessard@145: if new_index != row_index: lbessard@145: self.data.insert(new_index, self.data.pop(row_index)) lbessard@145: grid.SetGridCursor(new_index, grid.GetGridCursorCol()) lbessard@145: lbessard@145: def GetRow(self, row_index): lbessard@145: return self.data[row_index] lbessard@145: lbessard@145: def Empty(self): lbessard@145: self.data = [] lbessard@145: self.editors = [] lbessard@145: lbessard@145: lbessard@145: [ID_VARIABLESEDITOR, ID_VARIABLESEDITORVARIABLESGRID, lbessard@145: ID_VARIABLESEDITORADDVARIABLEBUTTON, ID_VARIABLESEDITORDELETEVARIABLEBUTTON, lbessard@145: ID_VARIABLESEDITORUPVARIABLEBUTTON, ID_VARIABLESEDITORDOWNVARIABLEBUTTON lbessard@145: ] = [wx.NewId() for _init_ctrls in range(6)] lbessard@145: lbessard@145: class VariablesEditor(wx.Panel): lbessard@145: lbessard@145: if wx.VERSION < (2, 6, 0): lbessard@145: def Bind(self, event, function, id = None): lbessard@145: if id is not None: lbessard@145: event(self, id, function) lbessard@145: else: lbessard@145: event(self, function) lbessard@145: lbessard@145: def _init_coll_MainSizer_Growables(self, parent): lbessard@145: parent.AddGrowableCol(0) lbessard@145: parent.AddGrowableRow(0) lbessard@145: lbessard@145: def _init_coll_MainSizer_Items(self, parent): lbessard@145: parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) lbessard@145: parent.AddSizer(self.ButtonsSizer, 0, border=0, flag=wx.GROW) lbessard@145: lbessard@145: def _init_coll_ButtonsSizer_Growables(self, parent): lbessard@145: parent.AddGrowableCol(0) lbessard@145: parent.AddGrowableRow(0) lbessard@145: lbessard@145: def _init_coll_ButtonsSizer_Items(self, parent): lbessard@145: parent.AddWindow(self.AddVariableButton, 0, border=0, flag=wx.ALIGN_RIGHT) lbessard@145: parent.AddWindow(self.DeleteVariableButton, 0, border=0, flag=0) lbessard@145: parent.AddWindow(self.UpVariableButton, 0, border=0, flag=0) lbessard@145: parent.AddWindow(self.DownVariableButton, 0, border=0, flag=0) lbessard@145: lbessard@145: def _init_sizers(self): lbessard@145: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) lbessard@145: self.ButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) lbessard@145: lbessard@145: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@145: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@145: self._init_coll_ButtonsSizer_Growables(self.ButtonsSizer) lbessard@145: self._init_coll_ButtonsSizer_Items(self.ButtonsSizer) lbessard@145: lbessard@145: self.SetSizer(self.MainSizer) lbessard@145: lbessard@145: def _init_ctrls(self, prnt): lbessard@145: wx.Panel.__init__(self, id=ID_VARIABLESEDITOR, name='', parent=prnt, lbessard@145: size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) lbessard@145: lbessard@145: self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLESEDITORVARIABLESGRID, lbessard@145: name='VariablesGrid', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(-1, -1), style=wx.VSCROLL) lbessard@145: self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, lbessard@145: 'Sans')) lbessard@145: self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, lbessard@145: False, 'Sans')) lbessard@145: if wx.VERSION >= (2, 5, 0): lbessard@145: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) lbessard@145: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) lbessard@145: self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) lbessard@145: else: lbessard@145: wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange) lbessard@145: wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) lbessard@145: wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown) lbessard@145: lbessard@145: self.AddVariableButton = wx.Button(id=ID_VARIABLESEDITORADDVARIABLEBUTTON, label='Add Variable', lbessard@145: name='AddVariableButton', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(122, 32), style=0) lbessard@145: self.Bind(wx.EVT_BUTTON, self.OnAddVariableButton, id=ID_VARIABLESEDITORADDVARIABLEBUTTON) lbessard@145: lbessard@145: self.DeleteVariableButton = wx.Button(id=ID_VARIABLESEDITORDELETEVARIABLEBUTTON, label='Delete Variable', lbessard@145: name='DeleteVariableButton', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(122, 32), style=0) lbessard@145: self.Bind(wx.EVT_BUTTON, self.OnDeleteVariableButton, id=ID_VARIABLESEDITORDELETEVARIABLEBUTTON) lbessard@145: lbessard@145: self.UpVariableButton = wx.Button(id=ID_VARIABLESEDITORUPVARIABLEBUTTON, label='^', lbessard@145: name='UpVariableButton', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(32, 32), style=0) lbessard@145: self.Bind(wx.EVT_BUTTON, self.OnUpVariableButton, id=ID_VARIABLESEDITORUPVARIABLEBUTTON) lbessard@145: lbessard@145: self.DownVariableButton = wx.Button(id=ID_VARIABLESEDITORDOWNVARIABLEBUTTON, label='v', lbessard@145: name='DownVariableButton', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(32, 32), style=0) lbessard@145: self.Bind(wx.EVT_BUTTON, self.OnDownVariableButton, id=ID_VARIABLESEDITORDOWNVARIABLEBUTTON) lbessard@145: lbessard@145: self._init_sizers() lbessard@145: lbessard@145: def __init__(self, parent, window, controler): lbessard@145: self._init_ctrls(parent) lbessard@145: lbessard@145: self.ParentWindow = window lbessard@145: self.Controler = controler lbessard@145: lbessard@145: self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""} lbessard@145: self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"]) lbessard@145: self.ColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] lbessard@145: self.ColSizes = [40, 200, 150, 150] lbessard@145: self.VariablesGrid.SetTable(self.Table) lbessard@145: self.VariablesGrid.SetRowLabelSize(0) lbessard@145: for col in range(self.Table.GetNumberCols()): lbessard@145: attr = wx.grid.GridCellAttr() lbessard@145: attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) lbessard@145: self.VariablesGrid.SetColAttr(col, attr) lbessard@145: self.VariablesGrid.SetColSize(col, self.ColSizes[col]) lbessard@145: self.Table.ResetView(self.VariablesGrid) lbessard@145: lbessard@145: def IsViewing(self, name): lbessard@145: return name == "Variables" lbessard@145: lbessard@145: def RefreshModel(self): lbessard@145: self.Controler.SetVariables(self.Table.GetData()) lbessard@145: self.RefreshBuffer() lbessard@145: lbessard@145: def ResetBuffer(self): lbessard@145: pass lbessard@145: lbessard@145: # Buffer the last model state lbessard@145: def RefreshBuffer(self): lbessard@145: self.Controler.BufferCFile() lbessard@145: self.ParentWindow.RefreshTitle() lbessard@145: self.ParentWindow.RefreshEditMenu() lbessard@145: lbessard@145: def RefreshView(self): lbessard@145: self.Table.SetData(self.Controler.GetVariables()) lbessard@145: self.Table.ResetView(self.VariablesGrid) lbessard@145: lbessard@145: def OnAddVariableButton(self, event): lbessard@145: self.Table.AppendRow(self.VariablesDefaultValue.copy()) lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnDeleteVariableButton(self, event): lbessard@145: row = self.VariablesGrid.GetGridCursorRow() lbessard@145: self.Table.RemoveRow(row) lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnUpVariableButton(self, event): lbessard@145: row = self.VariablesGrid.GetGridCursorRow() lbessard@145: self.Table.MoveRow(row, -1, self.VariablesGrid) lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnDownVariableButton(self, event): lbessard@145: row = self.VariablesGrid.GetGridCursorRow() lbessard@145: self.Table.MoveRow(row, 1, self.VariablesGrid) lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnVariablesGridCellChange(self, event): lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnVariablesGridEditorShown(self, event): lbessard@145: row, col = event.GetRow(), event.GetCol() lbessard@145: if self.Table.GetColLabelValue(col) == "Type": lbessard@145: type_menu = wx.Menu(title='') lbessard@145: base_menu = wx.Menu(title='') lbessard@145: for base_type in self.Controler.GetBaseTypes(): lbessard@145: new_id = wx.NewId() lbessard@145: AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) lbessard@145: self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) lbessard@145: type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu) lbessard@145: datatype_menu = wx.Menu(title='') lbessard@145: for datatype in self.Controler.GetDataTypes(basetypes = False): lbessard@145: new_id = wx.NewId() lbessard@145: AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) lbessard@145: self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) lbessard@145: type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu) lbessard@145: rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) lbessard@145: self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) lbessard@145: event.Veto() lbessard@145: else: lbessard@145: event.Skip() lbessard@145: lbessard@145: def GetVariableTypeFunction(self, base_type): lbessard@145: def VariableTypeFunction(event): lbessard@145: row = self.VariablesGrid.GetGridCursorRow() lbessard@145: self.Table.SetValueByName(row, "Type", base_type) lbessard@145: self.Table.ResetView(self.VariablesGrid) lbessard@145: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@145: event.Skip() lbessard@145: return VariableTypeFunction lbessard@145: lbessard@145: def OnVariablesGridCellLeftClick(self, event): lbessard@145: if event.GetCol() == 0: lbessard@145: row = event.GetRow() lbessard@145: num = 0 lbessard@145: if self.Table.GetValueByName(row, "Class") == "input": lbessard@145: dir = "%I" lbessard@145: for i in xrange(row): lbessard@145: if self.Table.GetValueByName(i, "Class") == "input": lbessard@145: num += 1 lbessard@145: else: lbessard@145: dir = "%Q" lbessard@145: for i in xrange(row): lbessard@161: if self.Table.GetValueByName(i, "Class") == "output": lbessard@145: num += 1 lbessard@145: data_type = self.Table.GetValueByName(row, "Type") laurent@401: var_name = self.Table.GetValueByName(row, "Name") lbessard@145: base_location = ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation())) lbessard@145: location = "%s%s%s.%d"%(dir, self.Controler.GetSizeOfType(data_type), base_location, num) laurent@401: data = wx.TextDataObject(str((location, "location", data_type, var_name, ""))) lbessard@145: dragSource = wx.DropSource(self.VariablesGrid) lbessard@145: dragSource.SetData(data) lbessard@145: dragSource.DoDragDrop() lbessard@145: event.Skip() lbessard@145: lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # SVGUIEditor Main Frame Class lbessard@145: #------------------------------------------------------------------------------- lbessard@145: lbessard@145: lbessard@145: CFILE_PARTS = ["Includes", "Variables", "Globals", "Init", "CleanUp", "Retrieve", lbessard@145: "Publish"] lbessard@145: lbessard@145: [ID_CFILEEDITOR, ID_CFILEEDITORMAINSPLITTER, lbessard@164: ID_CFILEEDITORCFILETREE, ID_CFILEEDITORPARTSOPENED, lbessard@145: ] = [wx.NewId() for _init_ctrls in range(4)] lbessard@145: lbessard@213: class CFileEditor(wx.Frame): lbessard@145: lbessard@145: if wx.VERSION < (2, 6, 0): lbessard@145: def Bind(self, event, function, id = None): lbessard@145: if id is not None: lbessard@145: event(self, id, function) lbessard@145: else: lbessard@145: event(self, function) lbessard@145: lbessard@145: def _init_coll_EditMenu_Items(self, parent): lbessard@145: AppendMenu(parent, help='', id=wx.ID_REFRESH, lbessard@145: kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') lbessard@145: AppendMenu(parent, help='', id=wx.ID_UNDO, lbessard@145: kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') lbessard@145: AppendMenu(parent, help='', id=wx.ID_REDO, lbessard@145: kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') lbessard@145: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) lbessard@145: self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) lbessard@145: self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) lbessard@145: lbessard@145: def _init_coll_MenuBar_Menus(self, parent): lbessard@145: parent.Append(menu=self.EditMenu, title=u'&Edit') lbessard@145: lbessard@145: def _init_utils(self): lbessard@145: self.MenuBar = wx.MenuBar() lbessard@145: lbessard@145: self.EditMenu = wx.Menu(title='') lbessard@145: lbessard@145: self._init_coll_MenuBar_Menus(self.MenuBar) lbessard@145: self._init_coll_EditMenu_Items(self.EditMenu) lbessard@145: lbessard@145: def _init_ctrls(self, prnt): lbessard@213: wx.Frame.__init__(self, id=ID_CFILEEDITOR, name=u'CFileEditor', lbessard@213: parent=prnt, pos=wx.DefaultPosition, size=wx.Size(800, 650), lbessard@213: style=wx.DEFAULT_FRAME_STYLE, title=u'CFileEditor') lbessard@145: self._init_utils() lbessard@145: self.SetClientSize(wx.Size(1000, 600)) lbessard@145: self.SetMenuBar(self.MenuBar) lbessard@145: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) lbessard@145: lbessard@145: self.Bind(wx.EVT_MENU, self.OnSaveMenu, id=wx.ID_SAVE) lbessard@145: accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)]) lbessard@145: self.SetAcceleratorTable(accel) lbessard@145: lbessard@145: if wx.VERSION >= (2, 8, 0): lbessard@145: self.AUIManager = wx.aui.AuiManager(self) lbessard@145: self.AUIManager.SetDockSizeConstraint(0.5, 0.5) lbessard@145: lbessard@145: if wx.VERSION < (2, 8, 0): lbessard@145: self.MainSplitter = wx.SplitterWindow(id=ID_CFILEEDITORMAINSPLITTER, lbessard@145: name='MainSplitter', parent=self, point=wx.Point(0, 0), lbessard@145: size=wx.Size(-1, -1), style=wx.SP_3D) lbessard@145: self.MainSplitter.SetNeedUpdating(True) lbessard@145: self.MainSplitter.SetMinimumPaneSize(1) lbessard@145: lbessard@145: self.CFileTree = wx.TreeCtrl(id=ID_CFILEEDITORCFILETREE, lbessard@145: name='CFileTree', parent=self.MainSplitter, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(-1, -1), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) lbessard@145: else: lbessard@145: self.CFileTree = wx.TreeCtrl(id=ID_CFILEEDITORCFILETREE, lbessard@145: name='CFileTree', parent=self, pos=wx.Point(0, 0), lbessard@145: size=wx.Size(-1, -1), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) lbessard@145: self.AUIManager.AddPane(self.CFileTree, wx.aui.AuiPaneInfo().Caption("CFile Tree").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False)) lbessard@145: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnCFileTreeItemSelected, lbessard@145: id=ID_CFILEEDITORCFILETREE) lbessard@145: self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnCFileTreeItemActivated, lbessard@145: id=ID_CFILEEDITORCFILETREE) lbessard@145: lbessard@145: if wx.VERSION < (2, 8, 0): lbessard@145: self.PartsOpened = wx.Notebook(id=ID_CFILEEDITORPARTSOPENED, lbessard@145: name='PartsOpened', parent=self.MainSplitter, pos=wx.Point(0, lbessard@145: 0), size=wx.Size(0, 0), style=0) lbessard@145: if wx.VERSION >= (2, 6, 0): lbessard@145: self.PartsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, lbessard@164: self.OnPartSelectedChanged, id=ID_CFILEEDITORPARTSOPENED) lbessard@164: else: lbessard@164: wx.EVT_NOTEBOOK_PAGE_CHANGED(self.PartsOpened, ID_CFILEEDITORPARTSOPENED, lbessard@145: self.OnPartSelectedChanged) lbessard@145: lbessard@145: self.MainSplitter.SplitVertically(self.ProjectTree, self.PartsOpened, 200) lbessard@213: else: lbessard@213: self.PartsOpened = wx.aui.AuiNotebook(self) lbessard@213: self.PartsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, lbessard@213: self.OnPartSelectedChanged) lbessard@213: self.AUIManager.AddPane(self.PartsOpened, wx.aui.AuiPaneInfo().CentrePane()) lbessard@213: lbessard@145: self.StatusBar = wx.StatusBar( name='HelpBar', lbessard@145: parent=self, style=wx.ST_SIZEGRIP) lbessard@145: self.SetStatusBar(self.StatusBar) lbessard@145: lbessard@145: if wx.VERSION >= (2, 8, 0): lbessard@145: self.AUIManager.Update() lbessard@145: lbessard@145: def __init__(self, parent, controler): lbessard@145: self._init_ctrls(parent) lbessard@145: lbessard@145: self.Controler = controler lbessard@145: lbessard@145: self.InitCFileTree() lbessard@145: self.RefreshTitle() lbessard@145: self.RefreshEditMenu() lbessard@145: lbessard@145: def OnCloseFrame(self, event): lbessard@145: if wx.VERSION >= (2, 8, 0): lbessard@145: self.AUIManager.UnInit() lbessard@145: if getattr(self, "_onclose", None) is not None: lbessard@145: self._onclose() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnCloseTabMenu(self, event): lbessard@213: selected = self.PartsOpened.GetSelection() lbessard@145: if selected >= 0: lbessard@213: self.PartsOpened.DeletePage(selected) lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnSaveMenu(self, event): lbessard@145: if getattr(self, "_onsave", None) != None: lbessard@145: self._onsave() lbessard@145: self.RefreshTitle() lbessard@145: self.RefreshEditMenu() lbessard@145: event.Skip() lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # Notebook Unified Functions lbessard@145: #------------------------------------------------------------------------------- lbessard@213: lbessard@145: def DeleteAllPages(self): lbessard@145: if wx.VERSION >= (2, 8, 0): lbessard@213: for idx in xrange(self.PartsOpened.GetPageCount()): lbessard@213: self.PartsOpened.DeletePage(0) lbessard@145: else: lbessard@145: self.PartsOpened.DeleteAllPages() lbessard@145: lbessard@145: def SetPageBitmap(self, idx, bitmap): lbessard@145: if wx.VERSION >= (2, 8, 0): lbessard@213: return self.PartsOpened.SetPageBitmap(idx, bitmap) lbessard@145: else: lbessard@145: return self.PartsOpened.SetPageImage(idx, bitmap) lbessard@145: lbessard@145: def IsOpened(self, name): lbessard@213: for idx in xrange(self.PartsOpened.GetPageCount()): lbessard@213: if self.PartsOpened.GetPage(idx).IsViewing(name): lbessard@145: return idx lbessard@145: return None lbessard@145: lbessard@145: def RefreshTitle(self): lbessard@145: self.SetTitle("CFileEditor - %s"%self.Controler.GetFilename()) lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # Edit Project Menu Functions lbessard@145: #------------------------------------------------------------------------------- lbessard@145: lbessard@145: def RefreshEditMenu(self): lbessard@185: undo, redo = self.Controler.GetBufferState() lbessard@185: self.EditMenu.Enable(wx.ID_UNDO, undo) lbessard@185: self.EditMenu.Enable(wx.ID_REDO, redo) lbessard@145: lbessard@145: def OnRefreshMenu(self, event): lbessard@213: selected = self.PartsOpened.GetSelection() lbessard@145: if selected != -1: lbessard@213: window = self.PartsOpened.GetPage(selected) lbessard@145: window.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnUndoMenu(self, event): lbessard@145: self.Controler.LoadPrevious() lbessard@213: selected = self.PartsOpened.GetSelection() lbessard@145: if selected != -1: lbessard@213: window = self.PartsOpened.GetPage(selected) lbessard@145: window.RefreshView() lbessard@145: self.RefreshTitle() lbessard@145: self.RefreshEditMenu() lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnRedoMenu(self, event): lbessard@145: self.Controler.LoadNext() lbessard@213: selected = self.PartsOpened.GetSelection() lbessard@145: if selected != -1: lbessard@213: window = self.PartsOpened.GetPage(selected) lbessard@145: window.RefreshView() lbessard@145: self.RefreshTitle() lbessard@145: self.RefreshEditMenu() lbessard@145: event.Skip() lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # CFile Editor Panels Management Functions lbessard@145: #------------------------------------------------------------------------------- lbessard@145: lbessard@145: def OnPartSelectedChanged(self, event): lbessard@213: old_selected = self.PartsOpened.GetSelection() lbessard@213: if old_selected >= 0: lbessard@213: self.PartsOpened.GetPage(old_selected).ResetBuffer() lbessard@213: selected = event.GetSelection() lbessard@213: if selected >= 0: lbessard@213: window = self.PartsOpened.GetPage(selected) lbessard@213: window.RefreshView() lbessard@145: event.Skip() lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # CFile Tree Management Functions lbessard@145: #------------------------------------------------------------------------------- lbessard@145: lbessard@145: def InitCFileTree(self): lbessard@145: root = self.CFileTree.AddRoot("C File") lbessard@145: for name in CFILE_PARTS: lbessard@145: self.CFileTree.AppendItem(root, name) lbessard@145: self.CFileTree.Expand(root) lbessard@145: lbessard@145: def OnCFileTreeItemActivated(self, event): lbessard@145: self.EditCFilePart(self.CFileTree.GetItemText(event.GetItem())) lbessard@145: event.Skip() lbessard@145: lbessard@145: def OnCFileTreeItemSelected(self, event): lbessard@145: select_item = event.GetItem() lbessard@145: self.EditCFilePart(self.CFileTree.GetItemText(event.GetItem()), True) lbessard@145: event.Skip() lbessard@145: lbessard@145: def EditCFilePart(self, name, onlyopened = False): lbessard@145: openedidx = self.IsOpened(name) lbessard@145: if openedidx is not None: lbessard@213: old_selected = self.PartsOpened.GetSelection() lbessard@145: if old_selected != openedidx: lbessard@145: if old_selected >= 0: lbessard@213: self.PartsOpened.GetPage(old_selected).ResetBuffer() lbessard@213: self.PartsOpened.SetSelection(openedidx) lbessard@213: self.PartsOpened.GetPage(openedidx).RefreshView() lbessard@145: elif not onlyopened: lbessard@213: if name == "Variables": lbessard@213: new_window = VariablesEditor(self.PartsOpened, self, self.Controler) lbessard@213: self.PartsOpened.AddPage(new_window, name) lbessard@145: else: lbessard@213: new_window = CppEditor(self.PartsOpened, name, self, self.Controler) lbessard@213: self.PartsOpened.AddPage(new_window, name) lbessard@145: openedidx = self.IsOpened(name) lbessard@213: old_selected = self.PartsOpened.GetSelection() lbessard@145: if old_selected != openedidx: lbessard@145: if old_selected >= 0: lbessard@213: self.PartsOpened.GetPage(old_selected).ResetBuffer() lbessard@213: for i in xrange(self.PartsOpened.GetPageCount()): lbessard@213: window = self.PartsOpened.GetPage(i) lbessard@145: if window.IsViewing(name): lbessard@213: self.PartsOpened.SetSelection(i) lbessard@145: window.RefreshView() lbessard@145: window.SetFocus()