'Make LeftArrow to work on non-directories.
When LeftArrow is pressed on a file entry or an unexpanded
directory, then move the current index to the parent directory.
This simplifies navigation using the keyboard.
For power-users, we support Vim keybindings ;-P'

def keyPressEvent(self, event):

    widget = self.widget
    index = widget.currentIndex()
    was_expanded = widget.isExpanded(index)
    was_collapsed = (not was_expanded)
    key = event.key()
    if (key == Qt.Key_H):
        event = QtGui.QKeyEvent(event.type(), Qt.Key_Left, event.modifiers())
    elif (key == Qt.Key_J):
        event = QtGui.QKeyEvent(event.type(), Qt.Key_Down, event.modifiers())
    elif (key == Qt.Key_K):
        event = QtGui.QKeyEvent(event.type(), Qt.Key_Up, event.modifiers())
    elif (key == Qt.Key_L):
        event = QtGui.QKeyEvent(event.type(), Qt.Key_Right, event.modifiers())
    key = event.key()
    if (key == Qt.Key_Up):
        idxs = widget.selectedIndexes()
        rows = [idx.row() for idx in idxs]
        if ((len(rows) == 1) and (rows[0] == 0)):
            widget.up.emit()
    elif (key == Qt.Key_Space):
        widget.space.emit()
    result = self.Base.keyPressEvent(widget, event)
    widget.index_about_to_change.emit()
    if ((key == Qt.Key_Right) and was_collapsed and widget.isExpanded(index)):
        index = widget.moveCursor(widget.MoveDown, event.modifiers())
        widget.setCurrentIndex(index)
    elif ((key == Qt.Key_Left) and index.parent().isValid()):
        if (widget.model().itemFromIndex(index).rowCount() == 0):
            widget.setCurrentIndex(index.parent())
        elif was_collapsed:
            widget.setCurrentIndex(index.parent())
    elif (key in (Qt.Key_Left, Qt.Key_Up, Qt.Key_Right, Qt.Key_Down)):
        item = self.selected_item()
        if ((item is None) or (not index.isValid())):
            index = widget.model().index(0, 0, QtCore.QModelIndex())
            if index.isValid():
                widget.setCurrentIndex(index)
    return result
