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 random import shuffle
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel, from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel,
QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout, QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout)
QComboBox)
from calibre.gui2 import JSONConfig, info_dialog, error_dialog from calibre.gui2 import JSONConfig, info_dialog, error_dialog
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
@ -72,15 +71,6 @@ class SearchDialog(QDialog, Ui_Dialog):
self.search_author.setText(query['author']) self.search_author.setText(query['author'])
if 'title' in query: if 'title' in query:
self.search_title.setText(query['title']) 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 # Create and add the progress indicator
self.pi = ProgressIndicator(self, 24) self.pi = ProgressIndicator(self, 24)

View File

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