1

Handle glossary in list format

This commit is contained in:
Alex Yatskov 2016-05-17 22:28:56 -07:00
parent a8f784f0a4
commit 60c37d73fd
2 changed files with 18 additions and 10 deletions

View File

@ -56,7 +56,7 @@ class Dictionary:
'id': vocabId, 'id': vocabId,
'expression': expression, 'expression': expression,
'reading': reading, 'reading': reading,
'glossary': '; '.join(glossary), 'glossary': glossary,
'tags': tags + addons, 'tags': tags + addons,
'addons': addons 'addons': addons
}) })
@ -86,7 +86,7 @@ class Dictionary:
'character': character, 'character': character,
'kunyomi': kunyomi, 'kunyomi': kunyomi,
'onyomi': onyomi, 'onyomi': onyomi,
'glossary': '; '.join(glossary), 'glossary': glossary
} }

View File

@ -151,11 +151,11 @@ def buildDefHeader():
toolTipBg = palette.color(QtGui.QPalette.Window).name() toolTipBg = palette.color(QtGui.QPalette.Window).name()
toolTipFg = palette.color(QtGui.QPalette.WindowText).name() toolTipFg = palette.color(QtGui.QPalette.WindowText).name()
return u""" return u'''
<html><head><style> <html><head><style>
body {{ background-color: {0}; color: {1}; font-size: 11pt; }} body {{ background-color: {0}; color: {1}; font-size: 11pt; }}
span.expression {{ font-size: 15pt; }} span.expression {{ font-size: 15pt; }}
</style></head><body>""".format(toolTipBg, toolTipFg) </style></head><body>'''.format(toolTipBg, toolTipFg)
def buildDefFooter(): def buildDefFooter():
@ -163,10 +163,10 @@ def buildDefFooter():
def buildEmpty(): def buildEmpty():
return u""" return u'''
<p>No definitions to display.</p> <p>No definitions to display.</p>
<p>Mouse over text with the <em>middle mouse button</em> or <em>shift key</em> pressed to search.</p> <p>Mouse over text with the <em>middle mouse button</em> or <em>shift key</em> pressed to search.</p>
<p>You can also also input terms in the search box below.""" <p>You can also also input terms in the search box below.'''
def buildVocabDef(definition, index, query): def buildVocabDef(definition, index, query):
@ -186,13 +186,13 @@ def buildVocabDef(definition, index, query):
if query('vocab', markupVocabReading(definition)): if query('vocab', markupVocabReading(definition)):
links += '<a href="addVocabReading:{0}"><img src="://img/img/icon_add_reading.png" align="right"></a>'.format(index) links += '<a href="addVocabReading:{0}"><img src="://img/img/icon_add_reading.png" align="right"></a>'.format(index)
html = u""" html = u'''
<span class="links">{0}</span> <span class="links">{0}</span>
<span class="expression">{1}<br></span> <span class="expression">{1}<br></span>
{2} {2}
<span class="glossary">{3}<br></span> <span class="glossary">{3}<br></span>
{4} {4}
<br clear="all">""".format(links, definition['expression'], reading, definition['glossary'], rules) <br clear="all">'''.format(links, definition['expression'], reading, enumListItems(definition['glossary']), rules)
return html return html
@ -214,16 +214,24 @@ def buildKanjiDef(definition, index, query):
links += '<a href="addKanji:{0}"><img src="://img/img/icon_add_expression.png" align="right"></a>'.format(index) links += '<a href="addKanji:{0}"><img src="://img/img/icon_add_expression.png" align="right"></a>'.format(index)
readings = ', '.join([definition['kunyomi'], definition['onyomi']]) readings = ', '.join([definition['kunyomi'], definition['onyomi']])
html = u""" html = u'''
<span class="links">{0}</span> <span class="links">{0}</span>
<span class="expression">{1}<br></span> <span class="expression">{1}<br></span>
<span class="reading">[{2}]<br></span> <span class="reading">[{2}]<br></span>
<span class="glossary">{3}<br></span> <span class="glossary">{3}<br></span>
<br clear="all">""".format(links, definition['character'], readings, definition['glossary']) <br clear="all">'''.format(links, definition['character'], readings, enumListItems(definition['glossary']))
return html return html
def enumListItems(items):
result = u'<ol>'
for item in items:
result += u'<li>{0}</li>'.format(item)
result += u'</ol>'
return result
def buildKanjiDefs(definitions, query): def buildKanjiDefs(definitions, query):
html = buildDefHeader() html = buildDefHeader()