Hey all, it’s me again.
I need some help debugging some of my code. Here’s how it’s set up-
···
class MainWin(wx.Frame):
def init(self, parent, id, title):
self.undoList = [""]
self.redoList = [""]
edit = wx.Menu()
e_undo = wx.MenuItem(edit, wx.ID_UNDO, '&Undo\tCtrl+Z', 'Undo your changes')
e_undo.SetBitmap(self.undoImage)
edit.AppendItem(e_undo)
e_redo = wx.MenuItem(edit, wx.ID_REDO, '&Redo\tCtrl+Y', 'Redo your changes')
e_redo.SetBitmap(
self.redoImage)
edit.AppendItem(e_redo)
menubar.Append(edit, ‘&Edit’)
self.code = wx.TextCtrl(self, ID_TEXTBOX, size=(200, 130), style=wx.TE_MULTILINE)
self.code.SetFont
(wx.Font(11, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL))
self.Bind(wx.EVT_UPDATE_UI, self.LookAtCode, id=ID_TEXTBOX)
self.s = self.code.GetValue()
def LookAtCode(self, event):
if self.s != self.code.GetValue():
codeArray = [self.code.GetValue()]
self.undoList = self.undoList + codeArray
self.s = self.code.GetValue()
def OnUndo(self, event):
if len(self.undoList) > 1:
undoLen = len(self.undoList)
undoLen = undoLen-1
undoItem = self.undoList[undoLen]
codeVal = self.code.GetValue()
codeValArray = [codeVal]
self.redoList = self.redoList + codeValArray
print self.undoList[1]
self.code.SetValue(undoItem)
else:
cantundo = wx.MessageDialog(None, 'Can\'t undo', 'Can\'t undo', wx.OK | wx.ICON_INFORMATION)
cantundo.ShowModal()
def OnRedo(self, event):
if len(self.redoList) > 1:
redoLen = len(self.redoList)
redoLen = redoLen-1
redoItem = self.redoList[undolen]
codeVal = self.code.GetValue()
codeValArray = [codeVal]
self.undoList = self.undoList + codeValArray
self.code.SetValue
(redoItem)
else:
cantundo = wx.MessageDialog(None, ‘Can’t redo’, ‘Can’t redo’, wx.OK | wx.ICON_INFORMATION)
cantundo.ShowModal()
class MyApp(wx.App
):
def OnInit(self):
MySplash = MySplashScreen()
MySplash.Show()
return True
app = MyApp(redirect=True, filename = “error.log”)
app.MainLoop()
Sorry for the hefty code snippet, but I can’t quite figure out what’s wrong (and I wanted to show the framework of how this works).
I know that the problem is in OnUndo
and OnRedo, but I can’t figure out where it is.
When I click undo, It does nothing except move the cursor to the start of the file (on linux, at least).
Sorry for the huge example, again!
Thanks so much for any help.