Author: bugman Date: Wed Aug 3 10:27:52 2011 New Revision: 14080 URL: http://svn.gna.org/viewcvs/relax?rev=14080&view=rev Log: Implemented limited scroll back on the LogCtrl relax controller log element. This will prevent the computer from running out of memory. The maximum number of lines is now stored in the status singleton. Modified: branches/gui_testing/gui/controller.py branches/gui_testing/status.py Modified: branches/gui_testing/gui/controller.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/controller.py?rev=14080&r1=14079&r2=14080&view=diff ============================================================================== --- branches/gui_testing/gui/controller.py (original) +++ branches/gui_testing/gui/controller.py Wed Aug 3 10:27:52 2011 @@ -512,13 +512,36 @@ self.SetFont(font.modern_8) - def limit_scrollback(self): - """Limit scroll back to the maximum number of lines.""" - - # Limit scroll back by removing lines. - if self.control.GetNumberOfLines() > self.max_entries: - self.control.Remove(0, self.control.GetLineLength(0) + 1) - self.control.Refresh() + def limit_scrollback(self, prune=20): + """Limit scroll back to the maximum number of lines. + + Lines are deleted in blocks of 'prune' number of lines for faster operation. + """ + + # Maximum not reached, so do nothing. + if self.GetLineCount() < status.controller_max_entries: + return + + # Get the current selection, scroll position and caret position. + pos_start, pos_end = self.GetSelection() + curr_pos = self.GetCurrentPos() + + # Prune the first x lines. + del_start = 0 + del_end = self.GetLineEndPosition(prune) + 1 + del_extent = del_end - del_start + self.SetSelection(del_start, del_end) + self.DeleteBack() + + # Determine the new settings. + new_curr_pos = curr_pos - del_extent + new_pos_start = pos_start - del_extent + new_pos_end = pos_end - del_extent + + # Return to the original position and state. + self.SetCurrentPos(new_curr_pos) + self.SetSelection(new_pos_start, new_pos_end) + self.LineScroll(0, prune) def write(self, string): @@ -527,28 +550,33 @@ @param string: The text to add. @type string: str """ + + # First freeze the element. + self.Freeze() # Add the text. sys.__stdout__.write(string) self.AppendText(string) + # Limit the scroll back. + self.limit_scrollback() + + # Finally thaw. + self.Thaw() class Redirect_text(object): """The IO redirection to text control object.""" - def __init__(self, control, max_entries=100000): + def __init__(self, control): """Set up the text redirection object. @param control: The text control object to redirect IO to. @type control: wx.TextCtrl instance - @keyword max_entries: Limit the scroll back to this many lines. - @type max_entries: int """ # Store the args. self.control = control - self.max_entries = max_entries def write(self, string): Modified: branches/gui_testing/status.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/status.py?rev=14080&r1=14079&r2=14080&view=diff ============================================================================== --- branches/gui_testing/status.py (original) +++ branches/gui_testing/status.py Wed Aug 3 10:27:52 2011 @@ -74,8 +74,9 @@ # Testing mode flag. self.test_mode = False - # The GUI flag. - self.show_gui = False + # GUI structures. + self.show_gui = False # The GUI flag. + self.controller_max_entries = 100000 # Scroll back limit in the relax controller. # A structure for skipped system and unit tests. self.skipped_tests = []