I wrote this function earlier to set the priority if the items in listwidget, however what I think would be more pythonic is to write get and set priority method...
how should i proceed with writing the method in a pythonic way ?
def changePriority(self,direction):
""" Reorder the items in the listWidget """
crntRow = newrow = self.listWidget.currentRow()
total = self.listWidget.count()
self.statusbar.showMessage("Total no. of items %s, and selected item number is %s"%(total,crntRow),2500)
if direction == 'up':
if crntRow > 0 : newrow -= 1
else: self.statusbar.showMessage("This is the first item cannot move up further.",1500)
elif direction == 'down':
if crntRow + 1 < total: newrow += 1
else: self.statusbar.showMessage("This is the last item cannot move down further.",1500)
if crntRow != newrow:
crntItem=self.listWidget.takeItem(crntRow)
self.listWidget.insertItem(newrow,crntItem)
self.listWidget.setCurrentItem(crntItem)