mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GUI add regex: Store history in gprefs instead of in filename_pattern.
This commit is contained in:
parent
94fb463ab2
commit
156dc57e99
@ -142,13 +142,7 @@ def metadata_from_filename(name, pat=None):
|
|||||||
name = name.rpartition('.')[0]
|
name = name.rpartition('.')[0]
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
if pat is None:
|
if pat is None:
|
||||||
pat_re = prefs.get('filename_pattern')
|
pat = re.compile(prefs.get('filename_pattern'))
|
||||||
if isinstance(pat_re, list):
|
|
||||||
if pat_re:
|
|
||||||
pat_re = pat_re[0]
|
|
||||||
else:
|
|
||||||
pat_re = ''
|
|
||||||
pat = re.compile(pat_re)
|
|
||||||
name = name.replace('_', ' ')
|
name = name.replace('_', ' ')
|
||||||
match = pat.search(name)
|
match = pat.search(name)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
|
@ -71,17 +71,27 @@ class FilenamePattern(QWidget, Ui_Form):
|
|||||||
self.re.lineEdit().textChanged.connect(lambda x: self.changed_signal.emit())
|
self.re.lineEdit().textChanged.connect(lambda x: self.changed_signal.emit())
|
||||||
|
|
||||||
def initialize(self, defaults=False):
|
def initialize(self, defaults=False):
|
||||||
|
# Get all itmes in the combobox. If we are resting
|
||||||
|
# to defaults we don't want to lose what the user
|
||||||
|
# has added.
|
||||||
|
val_hist = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
||||||
|
self.re.clear()
|
||||||
|
|
||||||
if defaults:
|
if defaults:
|
||||||
val = prefs.defaults['filename_pattern']
|
val = prefs.defaults['filename_pattern']
|
||||||
else:
|
else:
|
||||||
val = prefs['filename_pattern']
|
val = prefs['filename_pattern']
|
||||||
if isinstance(val, list):
|
self.re.lineEdit().setText(val)
|
||||||
if len(val) > 0:
|
|
||||||
for v in val:
|
val_hist += gprefs.get('filename_pattern_history', ['(?P<title>.+)', '(?P<author>[^_-]+) -?\s*(?P<series>[^_0-9-]*)(?P<series_index>[0-9]*)\s*-\s*(?P<title>[^_].+) ?'])
|
||||||
self.re.addItem(v)
|
if val in val_hist:
|
||||||
self.re.setCurrentIndex(0)
|
del val_hist[val_hist.index(val)]
|
||||||
else:
|
val_hist.insert(0, val)
|
||||||
self.re.lineEdit().setText(val if val else '')
|
for v in val_hist:
|
||||||
|
# Ensure we don't have duplicate items.
|
||||||
|
if v and self.re.findText(v) == -1:
|
||||||
|
self.re.addItem(v)
|
||||||
|
self.re.setCurrentIndex(0)
|
||||||
|
|
||||||
def do_test(self):
|
def do_test(self):
|
||||||
try:
|
try:
|
||||||
@ -118,12 +128,17 @@ class FilenamePattern(QWidget, Ui_Form):
|
|||||||
return re.compile(pat)
|
return re.compile(pat)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
pat = []
|
pat = self.pattern().pattern
|
||||||
patterns = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
|
||||||
for p in patterns[:14]:
|
|
||||||
if p not in pat:
|
|
||||||
pat.append(p)
|
|
||||||
prefs['filename_pattern'] = pat
|
prefs['filename_pattern'] = pat
|
||||||
|
|
||||||
|
history = []
|
||||||
|
history_pats = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
||||||
|
for p in history_pats[:14]:
|
||||||
|
# Ensure we don't have duplicate items.
|
||||||
|
if p and p not in history:
|
||||||
|
history.append(p)
|
||||||
|
gprefs['filename_pattern_history'] = history
|
||||||
|
|
||||||
return pat
|
return pat
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user