GUI: Have Authors combo boxes use completion using & just like tags use completion with ,

This commit is contained in:
John Schember 2011-01-16 17:14:26 -05:00
parent 188a96caeb
commit cfa57f63df
9 changed files with 104 additions and 78 deletions

View File

@ -68,6 +68,9 @@ class MetadataWidget(Widget, Ui_Form):
def initialize_metadata_options(self):
self.initialize_combos()
self.author.editTextChanged.connect(self.deduce_author_sort)
self.author.set_separator('&')
self.author.set_space_before_sep(True)
self.author.update_items_cache(self.db.all_author_names())
mi = self.db.get_metadata(self.book_id, index_is_id=True)
self.title.setText(mi.title)

View File

@ -20,38 +20,8 @@
<string>Book Cover</string>
</property>
<layout class="QGridLayout" name="_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="ImageView" name="cover" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="opt_prefer_metadata_cover">
<property name="text">
<string>Use cover from &amp;source file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="_4">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
@ -64,12 +34,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="_5">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="cover_path">
<property name="readOnly">
@ -86,7 +50,7 @@
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/document_open.png</normaloff>:/images/document_open.png</iconset>
</property>
</widget>
@ -95,6 +59,30 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="opt_prefer_metadata_cover">
<property name="text">
<string>Use cover from &amp;source file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="ImageView" name="cover" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder>opt_prefer_metadata_cover</zorder>
<zorder></zorder>
@ -255,7 +243,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="EnComboBox" name="author">
<widget class="CompleteComboBox" name="author">
<property name="editable">
<bool>true</bool>
</property>
@ -320,6 +308,11 @@
<header>calibre/gui2/widgets.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CompleteComboBox</class>
<extends>QComboBox</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>title</tabstop>

View File

@ -727,6 +727,10 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog):
self.authors.addItem(name)
self.authors.setEditText('')
self.authors.set_separator('&')
self.authors.set_space_before_sep(True)
self.authors.update_items_cache(self.db.all_author_names())
def initialize_series(self):
all_series = self.db.all_series()
all_series.sort(key=lambda x : sort_key(x[1]))

View File

@ -14,7 +14,7 @@
<string>Edit Meta information</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/edit_input.png</normaloff>:/images/edit_input.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@ -45,7 +45,7 @@
<x>0</x>
<y>0</y>
<width>842</width>
<height>589</height>
<height>553</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -76,7 +76,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="EnComboBox" name="authors">
<widget class="CompleteComboBox" name="authors">
<property name="editable">
<bool>true</bool>
</property>
@ -210,7 +210,7 @@
<string>Open Tag Editor</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/chapters.png</normaloff>:/images/chapters.png</iconset>
</property>
</widget>
@ -381,7 +381,7 @@ from the value in the box</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
</widget>
@ -874,8 +874,8 @@ not multiple and the destination field is multiple</string>
<rect>
<x>0</x>
<y>0</y>
<width>197</width>
<height>60</height>
<width>231</width>
<height>82</height>
</rect>
</property>
<layout class="QGridLayout" name="testgrid">
@ -964,6 +964,11 @@ not multiple and the destination field is multiple</string>
<extends>QLineEdit</extends>
<header>widgets.h</header>
</customwidget>
<customwidget>
<class>CompleteComboBox</class>
<extends>QComboBox</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>authors</tabstop>

View File

@ -725,6 +725,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
au = ' & '.join([a.strip().replace('|', ',') for a in au.split(',')])
self.authors.setEditText(au)
self.authors.set_separator('&')
self.authors.set_space_before_sep(True)
self.authors.update_items_cache(self.db.all_author_names())
def initialize_series(self):
self.series.setSizeAdjustPolicy(self.series.AdjustToContentsOnFirstShow)
all_series = self.db.all_series()

View File

@ -20,7 +20,7 @@
<string>Edit Meta Information</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/edit_input.png</normaloff>:/images/edit_input.png</iconset>
</property>
<property name="sizeGripEnabled">
@ -43,8 +43,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>986</width>
<height>677</height>
<width>955</width>
<height>665</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -125,7 +125,7 @@ Using this button to create title sort will change title sort from red to green.
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/auto_author_sort.png</normaloff>:/images/auto_author_sort.png</iconset>
</property>
</widget>
@ -152,7 +152,7 @@ Using this button to create title sort will change title sort from red to green.
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/swap.png</normaloff>:/images/swap.png</iconset>
</property>
<property name="iconSize">
@ -186,7 +186,7 @@ Using this button to create author sort will change author sort from red to gree
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/auto_author_sort.png</normaloff>:/images/auto_author_sort.png</iconset>
</property>
</widget>
@ -240,7 +240,7 @@ Using this button to create author sort will change author sort from red to gree
</widget>
</item>
<item row="2" column="1">
<widget class="EnComboBox" name="authors">
<widget class="CompleteComboBox" name="authors">
<property name="editable">
<bool>true</bool>
</property>
@ -352,7 +352,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>Open Tag Editor</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/chapters.png</normaloff>:/images/chapters.png</iconset>
</property>
</widget>
@ -405,7 +405,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
</widget>
@ -491,7 +491,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>Clear published date</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
</widget>
@ -550,15 +550,9 @@ If the box is colored green, then text matches the individual author's sort stri
</item>
<item>
<layout class="QVBoxLayout" name="_4">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
@ -571,19 +565,13 @@ If the box is colored green, then text matches the individual author's sort stri
</item>
<item>
<layout class="QHBoxLayout" name="_5">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="cover_button">
<property name="text">
<string>&amp;Browse</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/document_open.png</normaloff>:/images/document_open.png</iconset>
</property>
</widget>
@ -597,7 +585,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>T&amp;rim</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trim.png</normaloff>:/images/trim.png</iconset>
</property>
</widget>
@ -611,7 +599,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>&amp;Remove</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
</widget>
@ -702,7 +690,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/add_book.png</normaloff>:/images/add_book.png</iconset>
</property>
<property name="iconSize">
@ -722,7 +710,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/trash.png</normaloff>:/images/trash.png</iconset>
</property>
<property name="iconSize">
@ -742,7 +730,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/book.png</normaloff>:/images/book.png</iconset>
</property>
<property name="iconSize">
@ -762,7 +750,7 @@ If the box is colored green, then text matches the individual author's sort stri
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/edit_input.png</normaloff>:/images/edit_input.png</iconset>
</property>
<property name="iconSize">
@ -863,6 +851,11 @@ If the box is colored green, then text matches the individual author's sort stri
<header location="global">calibre/gui2/comments_editor.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CompleteComboBox</class>
<extends>QComboBox</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>title</tabstop>

View File

@ -31,6 +31,9 @@ class SearchDialog(QDialog, Ui_Dialog):
self.authors_box.setEditText('')
self.authors_box.completer().setCompletionMode(QCompleter.PopupCompletion)
self.authors_box.setAutoCompletionCaseSensitivity(Qt.CaseInsensitive)
self.authors_box.set_separator('&')
self.authors_box.set_space_before_sep(True)
self.authors_box.update_items_cache(self.db.all_author_names())
all_series = db.all_series()
all_series.sort(key=lambda x : sort_key(x[1]))

View File

@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>731</width>
<height>411</height>
<width>752</width>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
<string>Advanced Search</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/search.png</normaloff>:/images/search.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@ -265,7 +265,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="EnComboBox" name="authors_box">
<widget class="CompleteComboBox" name="authors_box">
<property name="toolTip">
<string>Enter an author's name. Only one author can be used.</string>
</property>
@ -364,6 +364,11 @@
<extends>QLineEdit</extends>
<header>widgets.h</header>
</customwidget>
<customwidget>
<class>CompleteComboBox</class>
<extends>QComboBox</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>all</tabstop>

View File

@ -540,6 +540,22 @@ class EnComboBox(QComboBox):
idx = 0
self.setCurrentIndex(idx)
class CompleteComboBox(EnComboBox):
def __init__(self, *args):
EnComboBox.__init__(self, *args)
self.setLineEdit(CompleteLineEdit(self))
def update_items_cache(self, complete_items):
self.lineEdit().update_items_cache(complete_items)
def set_separator(self, sep):
self.lineEdit().set_separator(sep)
def set_space_before_sep(self, space_before):
self.lineEdit().set_space_before_sep(space_before)
class HistoryLineEdit(QComboBox):
lost_focus = pyqtSignal()