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): def initialize_metadata_options(self):
self.initialize_combos() self.initialize_combos()
self.author.editTextChanged.connect(self.deduce_author_sort) 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) mi = self.db.get_metadata(self.book_id, index_is_id=True)
self.title.setText(mi.title) self.title.setText(mi.title)

View File

@ -20,38 +20,8 @@
<string>Book Cover</string> <string>Book Cover</string>
</property> </property>
<layout class="QGridLayout" name="_2"> <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"> <item row="1" column="0">
<layout class="QVBoxLayout" name="_4"> <layout class="QVBoxLayout" name="_4">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
@ -64,12 +34,6 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="_5"> <layout class="QHBoxLayout" name="_5">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLineEdit" name="cover_path"> <widget class="QLineEdit" name="cover_path">
<property name="readOnly"> <property name="readOnly">
@ -86,7 +50,7 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../../resources/images.qrc"> <iconset>
<normaloff>:/images/document_open.png</normaloff>:/images/document_open.png</iconset> <normaloff>:/images/document_open.png</normaloff>:/images/document_open.png</iconset>
</property> </property>
</widget> </widget>
@ -95,6 +59,30 @@
</item> </item>
</layout> </layout>
</item> </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> </layout>
<zorder>opt_prefer_metadata_cover</zorder> <zorder>opt_prefer_metadata_cover</zorder>
<zorder></zorder> <zorder></zorder>
@ -255,7 +243,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="EnComboBox" name="author"> <widget class="CompleteComboBox" name="author">
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -320,6 +308,11 @@
<header>calibre/gui2/widgets.h</header> <header>calibre/gui2/widgets.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>CompleteComboBox</class>
<extends>QComboBox</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>title</tabstop> <tabstop>title</tabstop>

View File

@ -726,6 +726,10 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog):
name = name.strip().replace('|', ',') name = name.strip().replace('|', ',')
self.authors.addItem(name) self.authors.addItem(name)
self.authors.setEditText('') 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): def initialize_series(self):
all_series = self.db.all_series() all_series = self.db.all_series()

View File

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

View File

@ -724,6 +724,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
au = _('Unknown') au = _('Unknown')
au = ' & '.join([a.strip().replace('|', ',') for a in au.split(',')]) au = ' & '.join([a.strip().replace('|', ',') for a in au.split(',')])
self.authors.setEditText(au) 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): def initialize_series(self):
self.series.setSizeAdjustPolicy(self.series.AdjustToContentsOnFirstShow) self.series.setSizeAdjustPolicy(self.series.AdjustToContentsOnFirstShow)

View File

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

View File

@ -31,6 +31,9 @@ class SearchDialog(QDialog, Ui_Dialog):
self.authors_box.setEditText('') self.authors_box.setEditText('')
self.authors_box.completer().setCompletionMode(QCompleter.PopupCompletion) self.authors_box.completer().setCompletionMode(QCompleter.PopupCompletion)
self.authors_box.setAutoCompletionCaseSensitivity(Qt.CaseInsensitive) 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 = db.all_series()
all_series.sort(key=lambda x : sort_key(x[1])) all_series.sort(key=lambda x : sort_key(x[1]))

View File

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

View File

@ -540,6 +540,22 @@ class EnComboBox(QComboBox):
idx = 0 idx = 0
self.setCurrentIndex(idx) 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): class HistoryLineEdit(QComboBox):
lost_focus = pyqtSignal() lost_focus = pyqtSignal()