Implement #4238 (Recent xPath list)

This commit is contained in:
Kovid Goyal 2009-12-17 18:02:09 -07:00
parent fd3838b84c
commit d6c36c0bbb
3 changed files with 94 additions and 11 deletions

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>422</width>
<height>64</height>
</rect>
</property>
@ -30,7 +30,20 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit"/>
<widget class="HistoryLineEdit" name="edit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
@ -54,8 +67,28 @@
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HistoryLineEdit</class>
<extends>QComboBox</extends>
<header>calibre/gui2/widgets.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>

View File

@ -70,13 +70,18 @@ class XPathEdit(QWidget, Ui_Edit):
if wiz.exec_() == wiz.Accepted:
self.edit.setText(wiz.xpath)
def setObjectName(self, *args):
QWidget.setObjectName(self, *args)
if hasattr(self, 'edit'):
self.edit.initialize('xpath_edit_'+unicode(self.objectName()))
def set_msg(self, msg):
self.msg.setText(msg)
@property
def text(self):
return unicode(self.edit.text())
return unicode(self.edit.currentText())
@property
def xpath(self):
@ -95,4 +100,10 @@ class XPathEdit(QWidget, Ui_Edit):
return True
if __name__ == '__main__':
from PyQt4.Qt import QApplication
app = QApplication([])
w = XPathEdit()
w.setObjectName('test')
w.show()
app.exec_()

View File

@ -11,7 +11,7 @@ from PyQt4.Qt import QListView, QIcon, QFont, QLabel, QListWidget, \
QAbstractListModel, QVariant, Qt, SIGNAL, \
QRegExp, QSettings, QSize, QModelIndex, \
QAbstractButton, QPainter, QLineEdit, QComboBox, \
QMenu, QStringListModel, QCompleter
QMenu, QStringListModel, QCompleter, QStringList
from calibre.gui2 import human_readable, NONE, TableView, \
qstring_to_unicode, error_dialog
@ -21,9 +21,11 @@ from calibre import fit_image
from calibre.utils.fonts import fontconfig
from calibre.ebooks import BOOK_EXTENSIONS
from calibre.ebooks.metadata.meta import metadata_from_filename
from calibre.utils.config import prefs
from calibre.utils.config import prefs, XMLConfig
from calibre.gui2.progress_indicator import ProgressIndicator as _ProgressIndicator
history = XMLConfig('history')
class ProgressIndicator(QWidget):
def __init__(self, *args):
@ -506,16 +508,16 @@ class LineEditECM(object):
menu.exec_(event.globalPos())
def upper_case(self):
self.setText(qstring_to_unicode(self.text()).upper())
self.setText(unicode(self.text()).upper())
def lower_case(self):
self.setText(qstring_to_unicode(self.text()).lower())
self.setText(unicode(self.text()).lower())
def swap_case(self):
self.setText(qstring_to_unicode(self.text()).swapcase())
self.setText(unicode(self.text()).swapcase())
def title_case(self):
self.setText(qstring_to_unicode(self.text()).title())
self.setText(unicode(self.text()).title())
class EnLineEdit(LineEditECM, QLineEdit):
@ -620,7 +622,7 @@ class EnComboBox(QComboBox):
self.setLineEdit(EnLineEdit(self))
def text(self):
return qstring_to_unicode(self.currentText())
return unicode(self.currentText())
def setText(self, text):
idx = self.findText(text, Qt.MatchFixedString)
@ -629,6 +631,43 @@ class EnComboBox(QComboBox):
idx = 0
self.setCurrentIndex(idx)
class HistoryLineEdit(QComboBox):
def __init__(self, *args):
QComboBox.__init__(self, *args)
self.setEditable(True)
self.setInsertPolicy(self.NoInsert)
self.setMaxCount(10)
@property
def store_name(self):
return 'lineedit_history_'+self._name
def initialize(self, name):
self._name = name
self.addItems(QStringList(history.get(self.store_name, [])))
self.setEditText('')
self.lineEdit().editingFinished.connect(self.save_history)
def save_history(self):
items = []
ct = unicode(self.currentText())
if ct:
items.append(ct)
for i in range(self.count()):
item = unicode(self.itemText(i))
if item not in items:
items.append(item)
history.set(self.store_name, items)
def setText(self, t):
self.setEditText(t)
self.lineEdit().setCursorPosition(0)
def text(self):
return self.currentText()
class PythonHighlighter(QSyntaxHighlighter):
Rules = []