[PyCrust] bug in OnKeyDown
Brought to you by:
pobrien
From: Raul C. <co...@uc...> - 2002-05-28 03:37:16
|
Hi, One thing I didn't like from pyCrust was that I couldnt do the following in a line of code: shift+home+backspace to delete a whole line The reason is that the backspace doesn't get processed if the cursor is at the beginning of the line. When I went to the code to adapt it to my needs I realized that the following gets processed without problems: >>> t = 6 >>> r = 5 >>> y If I select with the mouse from the "t" to the end of the "y" and then I press whatever key (backspace, delete, etcetera) all the code up to the "t" gets deleted, because after the selection, the cursor is in a valid position (right after the "y"). And of course a nice crash occurs right after. This is how I fixed it for myself: in the OnKey() method of shell.py: # Don't backspace over the latest prompt. elif key == WXK_BACK: if self.GetSelectionStart() != self.GetSelectionEnd(): if self.CanEdit(): event.Skip() elif currpos > self.promptPosEnd: event.Skip() # Only allow these keys after the latest prompt. elif key == WXK_TAB: #There's no point on processing a tab for a selection ?? if self.GetSelectionStart() == self.GetSelectionEnd() and self.CanEdit(): event.Skip() in the CanEdit() method of shell.py: if self.GetSelectionStart() != self.GetSelectionEnd(): if self.GetSelectionStart() >= self.promptPosEnd \ and self.GetSelectionEnd() >= self.promptPosEnd: return 1 else: return 0 else: return self.GetCurrentPos() >= self.promptPosEnd In general, what the code does is to handle the case of a key pressed when there is a selection ( i.e. self.GetSelectionStart() != self.GetSelectionEnd() ) It seems to work fine but perhaps there are few redundant "if" comparisons. I hope what I said made sense Take Care Raúl BTW: I'm not sure what's going on here.... if I run this sys.stdin.readline() I get a dialog box requesting an input line. Where does it come from??? the wxStyledTextCtrl?? The reason is that I have some code that works like this: interface.ProcessCommandStream(stdin, stdout, stdout) how do I call it, by keeping the wxStyledTestCtrl as stdin?? |