Get Books: Use a better HistoryLineEdit

Get Books: Fix unable to change case of words in the
title/author/keywords boxes because of completion.
This commit is contained in:
Kovid Goyal 2013-06-13 15:25:41 +05:30
parent 9975b586bf
commit c41df1537c
3 changed files with 44 additions and 20 deletions

View File

@ -10,8 +10,7 @@ import re
from random import shuffle
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel,
QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout,
QComboBox)
QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout)
from calibre.gui2 import JSONConfig, info_dialog, error_dialog
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
@ -72,15 +71,6 @@ class SearchDialog(QDialog, Ui_Dialog):
self.search_author.setText(query['author'])
if 'title' in query:
self.search_title.setText(query['title'])
# Title
self.search_title.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLengthWithIcon)
self.search_title.setMinimumContentsLength(25)
# Author
self.search_author.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLengthWithIcon)
self.search_author.setMinimumContentsLength(25)
# Keyword
self.search_edit.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLengthWithIcon)
self.search_edit.setMinimumContentsLength(25)
# Create and add the progress indicator
self.pi = ProgressIndicator(self, 24)

View File

@ -14,7 +14,7 @@
<string>Get Books</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../../resources/images.qrc">
<iconset resource="../../../../work/calibre/resources/images.qrc">
<normaloff>:/images/store.png</normaloff>:/images/store.png</iconset>
</property>
<property name="sizeGripEnabled">
@ -22,7 +22,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="HistoryLineEdit" name="search_title">
<widget class="HistoryLineEdit2" name="search_title">
<property name="placeholderText">
<string>Search by title</string>
</property>
@ -42,7 +42,7 @@
</widget>
</item>
<item row="1" column="2">
<widget class="HistoryLineEdit" name="search_author">
<widget class="HistoryLineEdit2" name="search_author">
<property name="placeholderText">
<string>Search by author</string>
</property>
@ -69,7 +69,7 @@
</widget>
</item>
<item row="2" column="2">
<widget class="HistoryLineEdit" name="search_edit">
<widget class="HistoryLineEdit2" name="search_edit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -107,8 +107,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>204</width>
<height>141</height>
<width>207</width>
<height>163</height>
</rect>
</property>
</widget>
@ -314,9 +314,9 @@
<header>results_view.h</header>
</customwidget>
<customwidget>
<class>HistoryLineEdit</class>
<class>HistoryLineEdit2</class>
<extends>QLineEdit</extends>
<header>widgets.h</header>
<header>calibre/gui2/widgets2.h</header>
</customwidget>
</customwidgets>
<tabstops>
@ -335,7 +335,7 @@
<tabstop>close</tabstop>
</tabstops>
<resources>
<include location="../../../../../resources/images.qrc"/>
<include location="../../../../work/calibre/resources/images.qrc"/>
</resources>
<connections>
<connection>

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from calibre.gui2.complete2 import LineEdit
from calibre.gui2.widgets import history
class HistoryLineEdit2(LineEdit):
@property
def store_name(self):
return 'lineedit_history_'+self._name
def initialize(self, name):
self._name = name
self.history = history.get(self.store_name, [])
self.set_separator(None)
self.update_items_cache(self.history)
self.setText('')
self.editingFinished.connect(self.save_history)
def save_history(self):
ct = unicode(self.text())
try:
self.history.remove(ct)
except ValueError:
pass
self.history.insert(0, ct)
history.set(self.store_name, self.history)