Skip to content
Snippets Groups Projects
Commit 92e8f4bc authored by Max Kahnt's avatar Max Kahnt Committed by maxka
Browse files

bin: fix control options for hierarchicviewer_qt4.py

 - maxlevel spinbox working
 - follow checkbox working
 - autoappend disabled (is default)

[[Imported from SVN: r8599]]
parent 61256683
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,8 @@ class HListView(Qt.QTreeWidget): ...@@ -14,7 +14,8 @@ class HListView(Qt.QTreeWidget):
def __init__(self, follow, *args): def __init__(self, follow, *args):
apply(Qt.QTreeWidget.__init__, (self,) + args) apply(Qt.QTreeWidget.__init__, (self,) + args)
self.header().hide() self.header().hide()
self.setRootIsDecorated(1) self.setRootIsDecorated(True)
self.setSortingEnabled(False)
self.setFont(Qt.QFont('monospace',8)) self.setFont(Qt.QFont('monospace',8))
parentItem = Qt.QTreeWidgetItem() parentItem = Qt.QTreeWidgetItem()
...@@ -29,16 +30,12 @@ class HListView(Qt.QTreeWidget): ...@@ -29,16 +30,12 @@ class HListView(Qt.QTreeWidget):
self.follow=follow self.follow=follow
def queueItem(self,item): def queueItem(self,item):
#print 'Queueing item', item
self.buffer.append(item) self.buffer.append(item)
def setMaxLevel(self, maxLevel): def setMaxLevel(self, maxLevel):
self.maxLevel = maxLevel self.maxLevel = maxLevel
for item in self.items: self.expandToDepth(maxLevel)
if (item[1]<self.maxLevel):
item[2].setExpanded(True)
else:
item[2].setExpanded(False)
def toggleFollow(self, *args): def toggleFollow(self, *args):
if (len(args)>0): if (len(args)>0):
...@@ -71,17 +68,18 @@ class HListView(Qt.QTreeWidget): ...@@ -71,17 +68,18 @@ class HListView(Qt.QTreeWidget):
self.items.append(item) self.items.append(item)
if (self.follow): if (self.follow):
# self.setCurrentItem(newviewitem) # self.setCurrentItem(newviewitem)
self.ensureItemVisible(newviewitem) self.scrollToItem(newviewitem)
self.buffer=[] self.buffer=[]
class MainWindow(Qt.QMainWindow): class MainWindow(Qt.QMainWindow):
def __init__(self, app, hit, timeout, autoAppend, follow, *args): #def __init__(self, app, hit, timeout, autoAppend, follow, *args):
def __init__(self, app, hit, timeout, follow, *args):
apply(Qt.QMainWindow.__init__, (self,) + args) apply(Qt.QMainWindow.__init__, (self,) + args)
self.app = app self.app = app
self.hit = hit self.hit = hit
self.timeout = timeout self.timeout = timeout
self.autoAppend = autoAppend #self.autoAppend = autoAppend
self.content = Qt.QFrame(self) self.content = Qt.QFrame(self)
self.setCentralWidget(self.content) self.setCentralWidget(self.content)
...@@ -99,7 +97,8 @@ class MainWindow(Qt.QMainWindow): ...@@ -99,7 +97,8 @@ class MainWindow(Qt.QMainWindow):
self.hview = HListView(follow, self.content) self.hview = HListView(follow, self.content)
self.followControl.setOn(self.hview.follow) self.followControl.setOn(self.hview.follow)
self.autoAppendControl.setOn(self.autoAppend) self.autoAppendControl.setOn(True)
self.autoAppendControl.setDisabled(True) #autoAppend functionality is disabled because it is default
self.controlBoxLayout.addWidget(self.maxLevelControl) self.controlBoxLayout.addWidget(self.maxLevelControl)
self.controlBoxLayout.addWidget(self.followControl) self.controlBoxLayout.addWidget(self.followControl)
...@@ -109,25 +108,25 @@ class MainWindow(Qt.QMainWindow): ...@@ -109,25 +108,25 @@ class MainWindow(Qt.QMainWindow):
self.connect(self.maxLevelControl, Qt.SIGNAL('valueChanged(int)'), self.hview.setMaxLevel) self.connect(self.maxLevelControl, Qt.SIGNAL('valueChanged(int)'), self.hview.setMaxLevel)
self.connect(self.followControl, Qt.SIGNAL('toggled(bool)'), self.hview.toggleFollow) self.connect(self.followControl, Qt.SIGNAL('toggled(bool)'), self.hview.toggleFollow)
self.connect(self.autoAppendControl, Qt.SIGNAL('toggled(bool)'), self.toggleAutoAppend) #self.connect(self.autoAppendControl, Qt.SIGNAL('toggled(bool)'), self.toggleAutoAppend)
self.readerThread = ItemReaderThread(self.hit,self.hview.queueItem) self.readerThread = ItemReaderThread(self.hit,self.hview.queueItem)
self.readerThread.setDaemon(True) self.readerThread.setDaemon(True)
self.readerThread.start() self.readerThread.start()
self.postProcessBufferThread = PeriodicActionThread(self.timeout,self.processQueue) #self.postProcessBufferThread = PeriodicActionThread(self.timeout,self.processQueue)
self.postProcessBufferThread.setDaemon(True) #self.postProcessBufferThread.setDaemon(True)
self.postProcessBufferThread.start() #self.postProcessBufferThread.start()
def toggleAutoAppend(self, *args): #def toggleAutoAppend(self, *args):
if (len(args)>0): #if (len(args)>0):
self.autoAppend = args[0] # self.autoAppend = args[0]
else: #else:
self.autoAppend = not(self.autoAppend) # self.autoAppend = not(self.autoAppend)
def processQueue(self): #def processQueue(self):
if (self.autoAppend): #if (self.autoAppend):
self.app.postEvent(self.hview, Qt.QEvent(12345)) # self.app.postEvent(self.hview, Qt.QEvent(1))
class ItemReaderThread (threading.Thread): class ItemReaderThread (threading.Thread):
...@@ -145,21 +144,21 @@ class ItemReaderThread (threading.Thread): ...@@ -145,21 +144,21 @@ class ItemReaderThread (threading.Thread):
pass pass
class PeriodicActionThread (threading.Thread): #class PeriodicActionThread (threading.Thread):
def __init__(self, timeout, action): # def __init__(self, timeout, action):
self.timeout = timeout # self.timeout = timeout
self.action = action # self.action = action
print 'Thread running' # print 'Thread running'
threading.Thread.__init__ (self) # threading.Thread.__init__ (self)
def run(self): # def run(self):
try: # try:
while True: # while True:
self.action() # self.action()
time.sleep(self.timeout) # time.sleep(self.timeout)
except: # except:
print "Unexpected error:", sys.exc_info() # print "Unexpected error:", sys.exc_info()
pass # pass
...@@ -225,7 +224,7 @@ def main(args): ...@@ -225,7 +224,7 @@ def main(args):
hideupdown = False hideupdown = False
# switch to determine if new lines are auto appended (default: True) # switch to determine if new lines are auto appended (default: True)
autoAppend = True #autoAppend = True
# switch to determine if view follows appended lines (default: True) # switch to determine if view follows appended lines (default: True)
follow = True follow = True
...@@ -258,14 +257,15 @@ def main(args): ...@@ -258,14 +257,15 @@ def main(args):
hideupdown = True hideupdown = True
elif o in ("-n", "--nofollow"): elif o in ("-n", "--nofollow"):
follow = False follow = False
elif o in ("--noappend"): #elif o in ("--noappend"):
autoAppend = False #autoAppend = False
it = FileIterator(infile) it = FileIterator(infile)
hit = HierarchyIterator(it, up, down, hideupdown) hit = HierarchyIterator(it, up, down, hideupdown)
app=Qt.QApplication(args) app=Qt.QApplication(args)
win=MainWindow(app, hit, timeout, autoAppend, follow) #win=MainWindow(app, hit, timeout, autoAppend, follow)
win=MainWindow(app, hit, timeout, follow)
win.resize(1000,600) win.resize(1000,600)
win.show() win.show()
app.connect(app, Qt.SIGNAL("lastWindowClosed()"), app.connect(app, Qt.SIGNAL("lastWindowClosed()"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment