Some debugging for the History stack

This commit is contained in:
Kovid Goyal 2014-09-21 16:26:52 +05:30
parent 1c7a90f21e
commit 0d42146e79

View File

@ -102,7 +102,7 @@ class Metadata(QWebView): # {{{
class History(list): # {{{ class History(list): # {{{
def __init__(self, action_back, action_forward): def __init__(self, action_back=None, action_forward=None):
self.action_back = action_back self.action_back = action_back
self.action_forward = action_forward self.action_forward = action_forward
super(History, self).__init__(self) super(History, self).__init__(self)
@ -112,7 +112,9 @@ class History(list): # {{{
self.set_actions() self.set_actions()
def set_actions(self): def set_actions(self):
if self.action_back is not None:
self.action_back.setDisabled(self.back_pos is None) self.action_back.setDisabled(self.back_pos is None)
if self.action_forward is not None:
self.action_forward.setDisabled(self.forward_pos is None) self.action_forward.setDisabled(self.forward_pos is None)
def back(self, from_pos): def back(self, from_pos):
@ -153,6 +155,21 @@ class History(list): # {{{
# There can be no forward # There can be no forward
self.forward_pos = None self.forward_pos = None
self.set_actions() self.set_actions()
def __str__(self):
return 'History: Items=%s back_pos=%s insert_pos=%s forward_pos=%s' % (tuple(self), self.back_pos, self.insert_pos, self.forward_pos)
def test_history():
h = History()
for i in xrange(4):
h.add(i)
for i in reversed(xrange(4)):
h.back(i)
print (h)
h.forward(0)
print (h)
h.add(1)
print (h)
# }}} # }}}
class Main(MainWindow): class Main(MainWindow):