lbessard@145: import keyword lbessard@145: laurent@630: import wx laurent@630: import wx.grid laurent@630: import wx.stc as stc laurent@630: import wx.lib.buttons laurent@630: laurent@651: from controls import CustomGrid, CustomTable, EditorPanel laurent@626: 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, laurent@630: wx.Size(0, 0), 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() Edouard@587: self.ParentWindow.RefreshFileMenu() lbessard@145: self.ParentWindow.RefreshEditMenu() laurent@630: self.ParentWindow.RefreshPageTitles() lbessard@145: lbessard@145: def StartBuffering(self): lbessard@145: self.Controler.StartBuffering() lbessard@145: if self.ParentWindow: lbessard@145: self.ParentWindow.RefreshTitle() Edouard@587: self.ParentWindow.RefreshFileMenu() lbessard@145: self.ParentWindow.RefreshEditMenu() laurent@630: self.ParentWindow.RefreshPageTitles() 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: laurent@630: def DoGetBestSize(self): laurent@630: return self.ParentWindow.GetPanelBestSize() laurent@630: 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: laurent@637: def Cut(self): laurent@637: self.ResetBuffer() laurent@637: self.DisableEvents = True laurent@637: self.CmdKeyExecute(wx.stc.STC_CMD_CUT) laurent@637: self.DisableEvents = False laurent@637: self.RefreshModel() laurent@637: self.RefreshBuffer() laurent@637: laurent@637: def Copy(self): laurent@637: self.CmdKeyExecute(wx.stc.STC_CMD_COPY) laurent@637: laurent@637: def Paste(self): laurent@637: self.ResetBuffer() laurent@637: self.DisableEvents = True laurent@637: self.CmdKeyExecute(wx.stc.STC_CMD_PASTE) laurent@637: self.DisableEvents = False laurent@637: self.RefreshModel() laurent@637: self.RefreshBuffer() laurent@637: lbessard@145: lbessard@145: #------------------------------------------------------------------------------- lbessard@145: # Helper for VariablesGrid values lbessard@145: #------------------------------------------------------------------------------- lbessard@145: laurent@651: class VariablesTable(CustomTable): laurent@651: 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: laurent@651: return str(self.data[row].get(self.GetColLabelValue(col, False), "")) laurent@651: 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() Edouard@603: editor.SetParameters("input,memory,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) laurent@651: self.ResizeRow(grid, row) laurent@651: 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, laurent@630: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@145: laurent@626: self.VariablesGrid = CustomGrid(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: 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) laurent@626: 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) laurent@626: 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) laurent@626: 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) laurent@626: 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) laurent@626: self.VariablesGrid.SetButtons({"Add": self.AddVariableButton, laurent@626: "Delete": self.DeleteVariableButton, laurent@626: "Up": self.UpVariableButton, laurent@626: "Down": self.DownVariableButton}) laurent@626: laurent@626: def _AddVariable(new_row): laurent@626: self.Table.InsertRow(new_row, self.VariablesDefaultValue.copy()) laurent@626: self.RefreshModel() laurent@626: self.RefreshView() laurent@626: return new_row laurent@626: setattr(self.VariablesGrid, "_AddRow", _AddVariable) laurent@626: laurent@626: def _DeleteVariable(row): laurent@626: self.Table.RemoveRow(row) laurent@626: self.RefreshModel() laurent@626: self.RefreshView() laurent@626: setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) laurent@626: laurent@626: def _MoveVariable(row, move): laurent@626: new_row = self.Table.MoveRow(row, move) laurent@626: if new_row != row: laurent@626: self.RefreshModel() laurent@626: self.RefreshView() laurent@626: return new_row laurent@626: setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) laurent@626: 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() Edouard@587: self.ParentWindow.RefreshFileMenu() lbessard@145: self.ParentWindow.RefreshEditMenu() laurent@630: self.ParentWindow.RefreshPageTitles() lbessard@145: lbessard@145: def RefreshView(self): lbessard@145: self.Table.SetData(self.Controler.GetVariables()) lbessard@145: self.Table.ResetView(self.VariablesGrid) laurent@626: self.VariablesGrid.RefreshButtons() laurent@626: laurent@630: def DoGetBestSize(self): laurent@630: return self.ParentWindow.GetPanelBestSize() laurent@630: 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='') laurent@610: for datatype in self.Controler.GetDataTypes(basetypes=False, only_locatables=True): 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 Edouard@603: elif self.Table.GetValueByName(row, "Class") == "memory": Edouard@603: dir = "%M" Edouard@603: for i in xrange(row): Edouard@603: if self.Table.GetValueByName(i, "Class") == "memory": Edouard@603: 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: laurent@630: CFILE_PARTS = [ laurent@630: ("Includes", CppEditor), laurent@630: ("Variables", VariablesEditor), laurent@630: ("Globals", CppEditor), laurent@630: ("Init", CppEditor), laurent@630: ("CleanUp", CppEditor), laurent@630: ("Retrieve", CppEditor), laurent@630: ("Publish", CppEditor), laurent@630: ] laurent@630: laurent@630: #---------------------------------------------------------------------- laurent@630: # different icons for the collapsed/expanded states. laurent@630: # Taken from standard Windows XP collapsed/expanded states. laurent@630: #---------------------------------------------------------------------- laurent@630: laurent@630: def GetCollapsedIconData(): laurent@630: return \ laurent@630: '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ laurent@630: \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ laurent@630: \x00\x01\x8eIDAT8\x8d\xa5\x93-n\xe4@\x10\x85?g\x03\n6lh)\xc4\xd2\x12\xc3\x81\ laurent@630: \xd6\xa2I\x90\x154\xb9\x81\x8f1G\xc8\x11\x16\x86\xcd\xa0\x99F\xb3A\x91\xa1\ laurent@630: \xc9J&\x96L"5lX\xcc\x0bl\xf7v\xb2\x7fZ\xa5\x98\xebU\xbdz\xf5\\\x9deW\x9f\xf8\ laurent@630: H\\\xbfO|{y\x9dT\x15P\x04\x01\x01UPUD\x84\xdb/7YZ\x9f\xa5\n\xce\x97aRU\x8a\ laurent@630: \xdc`\xacA\x00\x04P\xf0!0\xf6\x81\xa0\xf0p\xff9\xfb\x85\xe0|\x19&T)K\x8b\x18\ laurent@630: \xf9\xa3\xe4\xbe\xf3\x8c^#\xc9\xd5\n\xa8*\xc5?\x9a\x01\x8a\xd2b\r\x1cN\xc3\ laurent@630: \x14\t\xce\x97a\xb2F0Ks\xd58\xaa\xc6\xc5\xa6\xf7\xdfya\xe7\xbdR\x13M2\xf9\ laurent@630: \xf9qKQ\x1fi\xf6-\x00~T\xfac\x1dq#\x82,\xe5q\x05\x91D\xba@\xefj\xba1\xf0\xdc\ laurent@630: zzW\xcff&\xb8,\x89\xa8@Q\xd6\xaaf\xdfRm,\xee\xb1BDxr#\xae\xf5|\xddo\xd6\xe2H\ laurent@630: \x18\x15\x84\xa0q@]\xe54\x8d\xa3\xedf\x05M\xe3\xd8Uy\xc4\x15\x8d\xf5\xd7\x8b\ laurent@630: ~\x82\x0fh\x0e"\xb0\xad,\xee\xb8c\xbb\x18\xe7\x8e;6\xa5\x89\x04\xde\xff\x1c\ laurent@630: \x16\xef\xe0p\xfa>\x19\x11\xca\x8d\x8d\xe0\x93\x1b\x01\xd8m\xf3(;x\xa5\xef=\ laurent@630: \xb7w\xf3\x1d$\x7f\xc1\xe0\xbd\xa7\xeb\xa0(,"Kc\x12\xc1+\xfd\xe8\tI\xee\xed)\ laurent@630: \xbf\xbcN\xc1{D\x04k\x05#\x12\xfd\xf2a\xde[\x81\x87\xbb\xdf\x9cr\x1a\x87\xd3\ laurent@630: 0)\xba>\x83\xd5\xb97o\xe0\xaf\x04\xff\x13?\x00\xd2\xfb\xa9`z\xac\x80w\x00\ laurent@630: \x00\x00\x00IEND\xaeB`\x82' laurent@630: laurent@630: def GetCollapsedIconBitmap(): laurent@630: return wx.BitmapFromImage(GetCollapsedIconImage()) laurent@630: laurent@630: def GetCollapsedIconImage(): laurent@630: import cStringIO laurent@630: stream = cStringIO.StringIO(GetCollapsedIconData()) laurent@630: return wx.ImageFromStream(stream) laurent@630: laurent@630: #---------------------------------------------------------------------- laurent@630: def GetExpandedIconData(): laurent@630: return \ laurent@630: '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ laurent@630: \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ laurent@630: \x00\x01\x9fIDAT8\x8d\x95\x93\xa1\x8e\xdc0\x14EO\xb2\xc4\xd0\xd2\x12\xb7(mI\ laurent@630: \xa4%V\xd1lQT4[4-\x9a\xfe\xc1\xc2|\xc6\xc2~BY\x83:A3E\xd3\xa0*\xa4\xd2\x90H!\ laurent@630: \x95\x0c\r\r\x1fK\x81g\xb2\x99\x84\xb4\x0fY\xd6\xbb\xc7\xf7>=\'Iz\xc3\xbcv\ laurent@630: \xfbn\xb8\x9c\x15 \xe7\xf3\xc7\x0fw\xc9\xbc7\x99\x03\x0e\xfbn0\x99F+\x85R\ laurent@630: \x80RH\x10\x82\x08\xde\x05\x1ef\x90+\xc0\xe1\xd8\ryn\xd0Z-\\A\xb4\xd2\xf7\ laurent@630: \x9e\xfbwoF\xc8\x088\x1c\xbbae\xb3\xe8y&\x9a\xdf\xf5\xbd\xe7\xfem\x84\xa4\ laurent@630: \x97\xccYf\x16\x8d\xdb\xb2a]\xfeX\x18\xc9s\xc3\xe1\x18\xe7\x94\x12cb\xcc\xb5\ laurent@630: \xfa\xb1l8\xf5\x01\xe7\x84\xc7\xb2Y@\xb2\xcc0\x02\xb4\x9a\x88%\xbe\xdc\xb4\ laurent@630: \x9e\xb6Zs\xaa74\xadg[6\x88<\xb7]\xc6\x14\x1dL\x86\xe6\x83\xa0\x81\xba\xda\ laurent@630: \x10\x02x/\xd4\xd5\x06\r\x840!\x9c\x1fM\x92\xf4\x86\x9f\xbf\xfe\x0c\xd6\x9ae\ laurent@630: \xd6u\x8d \xf4\xf5\x165\x9b\x8f\x04\xe1\xc5\xcb\xdb$\x05\x90\xa97@\x04lQas\ laurent@630: \xcd*7\x14\xdb\x9aY\xcb\xb8\\\xe9E\x10|\xbc\xf2^\xb0E\x85\xc95_\x9f\n\xaa/\ laurent@630: \x05\x10\x81\xce\xc9\xa8\xf6>\x13\xc0n\xff{PJ\xc5\xfdP\x11""<\xbc\ laurent@630: \xff\x87\xdf\xf8\xbf\xf5\x17FF\xaf\x8f\x8b\xd3\xe6K\x00\x00\x00\x00IEND\xaeB\ laurent@630: `\x82' laurent@630: laurent@630: def GetExpandedIconBitmap(): laurent@630: return wx.BitmapFromImage(GetExpandedIconImage()) laurent@630: laurent@630: def GetExpandedIconImage(): laurent@630: import cStringIO laurent@630: stream = cStringIO.StringIO(GetExpandedIconData()) laurent@630: return wx.ImageFromStream(stream) laurent@630: laurent@630: class FoldPanelCaption(wx.lib.buttons.GenBitmapTextToggleButton): laurent@630: laurent@630: def GetBackgroundBrush(self, dc): laurent@630: colBg = self.GetBackgroundColour() laurent@630: brush = wx.Brush(colBg, wx.SOLID) laurent@630: if self.style & wx.BORDER_NONE: laurent@630: myAttr = self.GetDefaultAttributes() laurent@630: parAttr = self.GetParent().GetDefaultAttributes() laurent@630: myDef = colBg == myAttr.colBg laurent@630: parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg laurent@630: if myDef and parDef: laurent@630: if wx.Platform == "__WXMAC__": laurent@630: brush.MacSetTheme(1) # 1 == kThemeBrushDialogBackgroundActive laurent@630: elif wx.Platform == "__WXMSW__": laurent@630: if self.DoEraseBackground(dc): laurent@630: brush = None laurent@630: elif myDef and not parDef: laurent@630: colBg = self.GetParent().GetBackgroundColour() laurent@630: brush = wx.Brush(colBg, wx.SOLID) laurent@630: return brush laurent@630: laurent@630: def DrawLabel(self, dc, width, height, dx=0, dy=0): laurent@630: bmp = self.bmpLabel laurent@630: if bmp is not None: # if the bitmap is used laurent@630: if self.bmpDisabled and not self.IsEnabled(): laurent@630: bmp = self.bmpDisabled laurent@630: if self.bmpFocus and self.hasFocus: laurent@630: bmp = self.bmpFocus laurent@630: if self.bmpSelected and not self.up: laurent@630: bmp = self.bmpSelected laurent@630: bw,bh = bmp.GetWidth(), bmp.GetHeight() laurent@630: hasMask = bmp.GetMask() is not None laurent@630: else: laurent@630: bw = bh = 0 # no bitmap -> size is zero laurent@630: laurent@630: dc.SetFont(self.GetFont()) laurent@630: if self.IsEnabled(): laurent@630: dc.SetTextForeground(self.GetForegroundColour()) laurent@630: else: laurent@630: dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) laurent@630: laurent@630: label = self.GetLabel() laurent@630: tw, th = dc.GetTextExtent(label) # size of text laurent@630: laurent@630: if bmp is not None: laurent@630: dc.DrawBitmap(bmp, width - bw - 2, (height-bh)/2, hasMask) # draw bitmap if available laurent@630: laurent@630: dc.DrawText(label, 2, (height-th)/2) # draw the text laurent@630: laurent@630: dc.SetPen(wx.Pen(self.GetForegroundColour())) laurent@630: dc.SetBrush(wx.TRANSPARENT_BRUSH) laurent@630: dc.DrawRectangle(0, 0, width, height) 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: laurent@630: class CFileEditor(EditorPanel): laurent@630: laurent@630: def _init_Editor(self, prnt): laurent@630: self.Editor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), laurent@630: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) laurent@630: laurent@630: self.Panels = {} laurent@630: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2 * len(CFILE_PARTS) + 1, vgap=0) laurent@630: self.MainSizer.AddGrowableCol(0) laurent@630: laurent@630: for idx, (name, panel_class) in enumerate(CFILE_PARTS): laurent@630: button_id = wx.NewId() laurent@630: button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name, laurent@630: label=name, bitmap=GetCollapsedIconBitmap(), parent=self.Editor, pos=wx.Point(0, 0), laurent@630: size=wx.Size(0, 20), style=wx.NO_BORDER|wx.ALIGN_LEFT) laurent@630: button.SetBitmapSelected(GetExpandedIconBitmap()) laurent@630: button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id) laurent@630: self.MainSizer.AddWindow(button, 0, border=0, flag=wx.TOP|wx.GROW) laurent@630: laurent@630: if panel_class == VariablesEditor: laurent@630: panel = VariablesEditor(self.Editor, self.ParentWindow, self.Controler) lbessard@145: else: laurent@630: panel = panel_class(self.Editor, name, self.ParentWindow, self.Controler) laurent@630: self.MainSizer.AddWindow(panel, 0, border=0, flag=wx.BOTTOM|wx.GROW) laurent@630: panel.Hide() laurent@630: laurent@630: self.Panels[name] = {"button": button, "panel": panel, "expanded": False, "row": 2 * idx + 1} laurent@630: laurent@630: self.Spacer = wx.Panel(self.Editor, -1) laurent@630: self.SpacerExpanded = True laurent@630: self.MainSizer.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) laurent@630: laurent@630: self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) laurent@630: laurent@630: self.Editor.SetSizer(self.MainSizer) laurent@630: laurent@630: def __init__(self, parent, controler, window): laurent@630: EditorPanel.__init__(self, parent, "", window, controler) laurent@630: laurent@630: img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage() laurent@630: self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16))) laurent@630: laurent@630: def GetTitle(self): laurent@630: filename = self.Controler.GetFilename() laurent@630: if not self.Controler.CFileIsSaved(): laurent@630: return "~%s~" % filename laurent@630: return filename laurent@630: laurent@630: def GetBufferState(self): laurent@630: return self.Controler.GetBufferState() laurent@630: laurent@630: def Undo(self): laurent@630: self.Controler.LoadPrevious() laurent@630: self.RefreshView() laurent@630: laurent@630: def Redo(self): laurent@630: self.Controler.LoadNext() laurent@630: self.RefreshView() laurent@630: laurent@630: def HasNoModel(self): laurent@630: return False laurent@630: laurent@630: def RefreshView(self): laurent@630: for infos in self.Panels.itervalues(): laurent@630: infos["panel"].RefreshView() laurent@630: laurent@630: def GenPanelButtonCallback(self, name): laurent@630: def PanelButtonCallback(event): laurent@630: self.TogglePanel(name) laurent@630: return PanelButtonCallback laurent@630: laurent@630: def ExpandPanel(self, name): laurent@630: infos = self.Panels.get(name, None) laurent@630: if infos is not None and not infos["expanded"]: laurent@630: infos["expanded"] = True laurent@630: infos["button"].SetToggle(True) laurent@630: infos["panel"].Show() laurent@630: self.MainSizer.AddGrowableRow(infos["row"]) laurent@630: laurent@630: self.RefreshSizerLayout() laurent@630: laurent@630: def CollapsePanel(self, name): laurent@630: infos = self.Panels.get(name, None) laurent@630: if infos is not None and infos["expanded"]: laurent@630: infos["expanded"] = False laurent@630: infos["button"].SetToggle(False) laurent@630: infos["panel"].Hide() laurent@630: self.MainSizer.RemoveGrowableRow(infos["row"]) laurent@630: laurent@630: self.RefreshSizerLayout() laurent@630: laurent@630: def TogglePanel(self, name): laurent@630: infos = self.Panels.get(name, None) laurent@630: if infos is not None: laurent@630: infos["expanded"] = not infos["expanded"] laurent@630: infos["button"].SetToggle(infos["expanded"]) laurent@630: if infos["expanded"]: laurent@630: infos["panel"].Show() laurent@630: self.MainSizer.AddGrowableRow(infos["row"]) lbessard@164: else: laurent@630: infos["panel"].Hide() laurent@630: self.MainSizer.RemoveGrowableRow(infos["row"]) lbessard@145: laurent@630: self.RefreshSizerLayout() laurent@630: laurent@630: def RefreshSizerLayout(self): laurent@630: expand_spacer = True laurent@630: for infos in self.Panels.itervalues(): laurent@630: expand_spacer = expand_spacer and not infos["expanded"] laurent@630: laurent@630: if self.SpacerExpanded != expand_spacer: laurent@630: self.SpacerExpanded = expand_spacer laurent@630: if expand_spacer: laurent@630: self.Spacer.Show() laurent@630: self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) laurent@630: else: laurent@630: self.Spacer.Hide() laurent@630: self.MainSizer.RemoveGrowableRow(2 * len(CFILE_PARTS)) laurent@630: laurent@630: self.MainSizer.Layout() lbessard@213: