From cef3b69a8a9b50dc9678451da75cda5ab5d52474 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 21 Jul 2010 12:59:52 -0600 Subject: [PATCH] Fix #6176 (Custom Columns = Column Orientation Issue) --- src/calibre/gui2/library/views.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 870157c81a..7ccbc027f6 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -478,14 +478,20 @@ class BooksView(QTableView): # {{{ def set_current_row(self, row, select=True): if row > -1: h = self.horizontalHeader() - for i in range(h.count()): - if not h.isSectionHidden(i): - index = self.model().index(row, i) - self.setCurrentIndex(index) - if select: - sm = self.selectionModel() - sm.select(index, sm.ClearAndSelect|sm.Rows) - break + logical_indices = list(range(h.count())) + logical_indices = [x for x in logical_indices if not + h.isSectionHidden(x)] + pairs = [(x, h.visualIndex(x)) for x in logical_indices if + h.visualIndex(x) > -1] + if not pairs: + pairs = [(0, 0)] + pairs.sort(cmp=lambda x,y:cmp(x[1], y[1])) + i = pairs[0][0] + index = self.model().index(row, i) + self.setCurrentIndex(index) + if select: + sm = self.selectionModel() + sm.select(index, sm.ClearAndSelect|sm.Rows) def close(self): self._model.close()