Fix #14. Additional minor GUI bug fixes

This commit is contained in:
Kovid Goyal 2007-01-03 18:44:02 +00:00
parent 0af98226c1
commit 07ad6648de
2 changed files with 39 additions and 27 deletions

View File

@ -200,7 +200,6 @@ class Main(QObject, Ui_MainWindow):
self.write_settings() self.write_settings()
e.accept() e.accept()
@report_error
def add(self, action): def add(self, action):
settings = QSettings() settings = QSettings()
_dir = settings.value("add books dialog dir", \ _dir = settings.value("add books dialog dir", \
@ -215,20 +214,26 @@ class Main(QObject, Ui_MainWindow):
files = unicode(files.join("|||").toUtf8(), 'utf-8').split("|||") files = unicode(files.join("|||").toUtf8(), 'utf-8').split("|||")
self.add_books(files) self.add_books(files)
@report_error
def add_books(self, files): def add_books(self, files):
self.window.setCursor(Qt.WaitCursor) self.window.setCursor(Qt.WaitCursor)
for _file in files: try:
_file = os.path.abspath(_file) for _file in files:
self.library_view.model().add_book(_file) _file = os.path.abspath(_file)
if self.library_view.isVisible(): self.library_view.model().add_book(_file)
self.search.clear() if self.library_view.isVisible():
else: if len(str(self.search.text())):
self.library_model.search("") self.search.clear()
hv = self.library_view.horizontalHeader() else:
col = hv.sortIndicatorSection() self.library_model.search("")
order = hv.sortIndicatorOrder() else:
self.library_view.model().sort(col, order) self.library_model.search("")
self.window.setCursor(Qt.ArrowCursor) hv = self.library_view.horizontalHeader()
col = hv.sortIndicatorSection()
order = hv.sortIndicatorOrder()
self.library_view.model().sort(col, order)
finally:
self.window.setCursor(Qt.ArrowCursor)
@report_error @report_error
def edit(self, action): def edit(self, action):
@ -292,9 +297,12 @@ class Main(QObject, Ui_MainWindow):
order = hv.sortIndicatorOrder() order = hv.sortIndicatorOrder()
model = self.card_model if oncard else self.reader_model model = self.card_model if oncard else self.reader_model
model.sort(col, order) model.sort(col, order)
if self.device_view.isVisible() and self.device_view.model()\ if self.device_view.isVisible() and \
== model: self.device_view.model() == model:
self.search.clear() if len(str(self.search.text())):
self.search.clear()
else:
self.device_view.model().search("")
else: else:
model.search("") model.search("")

View File

@ -165,7 +165,7 @@ class TableView(FileDragAndDrop, QTableView):
@classmethod @classmethod
def wrap(cls, s, width=20): def wrap(cls, s, width=20):
cls.wrapper.width = 20 cls.wrapper.width = width
return cls.wrapper.fill(s) return cls.wrapper.fill(s)
@classmethod @classmethod
@ -566,12 +566,12 @@ class LibraryBooksModel(QAbstractTableModel):
r = 5 r = 5
return QVariant(r) return QVariant(r)
if col == 0: if col == 0:
text = TableView.wrap(row["title"], width=25) text = TableView.wrap(row["title"], width=35)
elif col == 1: elif col == 1:
au = row["authors"] au = row["authors"]
if au: if au:
au = au.split("&") au = au.split("&")
jau = [ TableView.wrap(a, width=25).strip() for a in au ] jau = [ TableView.wrap(a, width=30).strip() for a in au ]
text = "\n".join(jau) text = "\n".join(jau)
elif col == 2: elif col == 2:
text = TableView.human_readable(row["size"]) text = TableView.human_readable(row["size"])
@ -587,7 +587,7 @@ class LibraryBooksModel(QAbstractTableModel):
return QVariant(text) return QVariant(text)
elif role == Qt.TextAlignmentRole and index.column() in [2,3,4]: elif role == Qt.TextAlignmentRole and index.column() in [2,3,4]:
return QVariant(Qt.AlignRight | Qt.AlignVCenter) return QVariant(Qt.AlignRight | Qt.AlignVCenter)
elif role == Qt.ToolTipRole: elif role == Qt.ToolTipRole and index.isValid():
if index.column() in [0, 1, 4, 5]: if index.column() in [0, 1, 4, 5]:
edit = "Double click to <b>edit</b> me<br><br>" edit = "Double click to <b>edit</b> me<br><br>"
else: else:
@ -780,21 +780,25 @@ class DeviceBooksModel(QAbstractTableModel):
class DeviceModel(QAbstractListModel): class DeviceModel(QAbstractListModel):
memory_free = 0 memory_free = 0
card_free = 0 card_free = 0
show_reader = False show_reader = False
show_card = False show_card = False
def update_devices(self, reader=None, card=None): def update_devices(self, reader=None, card=None):
if reader != None: if reader != None:
self.show_reader = reader self.show_reader = reader
if card != None: if card != None:
self.show_card = card self.show_card = card
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \ self.emit(SIGNAL("layoutChanged()"))
self.index(1), self.index(2))
def rowCount(self, parent): def rowCount(self, parent):
return 3 base = 1
if self.show_reader:
base += 1
if self.show_card:
base += 1
return base
def update_free_space(self, reader, card): def update_free_space(self, reader, card):
self.memory_free = reader self.memory_free = reader