mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Limit amount of text inserted into regex results, changed default exclude_genre regex
This commit is contained in:
parent
1dc4dd91dc
commit
8f2ae4e46a
@ -75,7 +75,7 @@ class PluginWidget(QWidget,Ui_Form):
|
||||
['radio_button' for i in RadioButtonControls])
|
||||
|
||||
# LineEditControls
|
||||
option_fields += zip(['exclude_genre'],['\[.+\]|\+'],['line_edit'])
|
||||
option_fields += zip(['exclude_genre'],['\[.+\]|^\+$'],['line_edit'])
|
||||
|
||||
# TextEditControls
|
||||
#option_fields += zip(['exclude_genre_results'],['excluded genres will appear here'],['text_edit'])
|
||||
@ -156,6 +156,32 @@ class PluginWidget(QWidget,Ui_Form):
|
||||
Output:
|
||||
self.exclude_genre_results (QLabel): updated to show tags to be excluded as genres
|
||||
"""
|
||||
def _truncated_results(excluded_tags, limit=180):
|
||||
'''
|
||||
Limit number of genres displayed to avoid dialog explosion
|
||||
'''
|
||||
start = []
|
||||
end = []
|
||||
lower = 0
|
||||
upper = len(excluded_tags) -1
|
||||
excluded_tags.sort()
|
||||
while True:
|
||||
if lower > upper:
|
||||
break
|
||||
elif lower == upper:
|
||||
start.append(excluded_tags[lower])
|
||||
break
|
||||
start.append(excluded_tags[lower])
|
||||
end.insert(0,excluded_tags[upper])
|
||||
if len(', '.join(start)) + len(', '.join(end)) > limit:
|
||||
break
|
||||
lower += 1
|
||||
upper -= 1
|
||||
if excluded_tags == start + end:
|
||||
return ', '.join(excluded_tags)
|
||||
else:
|
||||
return "%s ... %s" % (', '.join(start), ', '.join(end))
|
||||
|
||||
results = _('No genres will be excluded')
|
||||
if not regex:
|
||||
self.exclude_genre_results.clear()
|
||||
@ -176,7 +202,7 @@ class PluginWidget(QWidget,Ui_Form):
|
||||
if set(excluded_tags) == set(self.all_tags):
|
||||
results = _("All genres will be excluded")
|
||||
else:
|
||||
results = ', '.join(sorted(excluded_tags))
|
||||
results = _truncated_results(excluded_tags)
|
||||
finally:
|
||||
if self.DEBUG:
|
||||
print(results)
|
||||
|
@ -208,7 +208,7 @@ The default pattern \[.+\]|\+ excludes tags of the form [tag], e.g., [Test book]
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string extracomment="Default: \[[\w]*\]"/>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -223,7 +223,7 @@ The default pattern \[.+\]|\+ excludes tags of the form [tag], e.g., [Test book]
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="regex_results_label">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>175</width>
|
||||
|
@ -51,7 +51,7 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
"Default: '%default'\n"
|
||||
"Applies to: AZW3, ePub, MOBI output formats")),
|
||||
Option('--exclude-genre',
|
||||
default='\[.+\]|\+',
|
||||
default='\[.+\]|^\+$',
|
||||
dest='exclude_genre',
|
||||
action = None,
|
||||
help=_("Regex describing tags to exclude as genres.\n"
|
||||
@ -313,18 +313,16 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
keys.sort()
|
||||
build_log.append(" opts:")
|
||||
for key in keys:
|
||||
if key in ['catalog_title','author_clip','connected_kindle','description_clip',
|
||||
'exclude_book_marker','exclude_genre','exclude_tags',
|
||||
'exclusion_rules', 'fmt',
|
||||
if key in ['catalog_title','author_clip','connected_kindle','creator',
|
||||
'description_clip','exclude_book_marker','exclude_genre',
|
||||
'exclude_tags','exclusion_rules', 'fmt',
|
||||
'header_note_source_field','merge_comments_rule',
|
||||
'output_profile','prefix_rules','read_book_marker',
|
||||
'search_text','sort_by','sort_descriptions_by_author','sync',
|
||||
'thumb_width','use_existing_cover','wishlist_tag']:
|
||||
build_log.append(" %s: %s" % (key, repr(opts_dict[key])))
|
||||
|
||||
if opts.verbose:
|
||||
log('\n'.join(line for line in build_log))
|
||||
|
||||
self.opts = opts
|
||||
|
||||
# Launch the Catalog builder
|
||||
|
Loading…
x
Reference in New Issue
Block a user