1

Renaming definitions to glossary

Former-commit-id: fc5361ee49f6f74a2032f56d1d13728eecb7b8c8
This commit is contained in:
Alex Yatskov 2013-11-09 17:50:24 -08:00
parent c43d1da885
commit 89f407e9fa
4 changed files with 18 additions and 18 deletions

View File

@ -34,11 +34,11 @@ class Dictionary:
cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if partial else '='), (word, word)) cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if partial else '='), (word, word))
results = list() results = list()
for expression, reading, definitions, tags in cursor.fetchall(): for expression, reading, glossary, tags in cursor.fetchall():
results.append({ results.append({
'expression': expression, 'expression': expression,
'reading': reading, 'reading': reading,
'definitions': definitions, 'glossary': glossary,
'tags': tags.split() 'tags': tags.split()
}) })
@ -51,12 +51,12 @@ class Dictionary:
query = cursor.fetchone() query = cursor.fetchone()
if query is not None: if query is not None:
character, kunyomi, onyomi, meanings = result character, kunyomi, onyomi, glossary = query
return { return {
'character': character, 'character': character,
'kunyomi': kunyomi, 'kunyomi': kunyomi,
'onyomi': onyomi, 'onyomi': onyomi,
'meanings': meanings 'glossary': glossary
} }

View File

@ -54,17 +54,17 @@ class Translator:
root = root or source root = root or source
for entry in self.dictionary.findTerm(root, partial): for entry in self.dictionary.findTerm(root, partial):
key = entry['expression'], entry['reading'], entry['definitions'] key = entry['expression'], entry['reading'], entry['glossary']
if key not in groups: if key not in groups:
groups[key] = entry, source, rules groups[key] = entry, source, rules
def formatResult(self, group): def formatResult(self, group):
(expression, reading, definition), (entry, source, rules) = group (expression, reading, glossary), (entry, source, rules) = group
return { return {
'expression': expression, 'expression': expression,
'reading': reading, 'reading': reading,
'definitions': definition, 'glossary': glossary,
'rules': rules, 'rules': rules,
'source': source 'source': source
} }

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2011 Alex Yatskov # Copyright (C) 2013 Alex Yatskov
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -252,14 +252,14 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
markup = reader_util.buildFactMarkupExpression( markup = reader_util.buildFactMarkupExpression(
definition['expression'], definition['expression'],
definition['reading'], definition['reading'],
definition['definitions'], definition['glossary'],
definition['sentence'] definition['sentence']
) )
self.ankiAddFact(markup) self.ankiAddFact(markup)
if command == 'addReading': if command == 'addReading':
markup = reader_util.buildFactMarkupReading( markup = reader_util.buildFactMarkupReading(
definition['reading'], definition['reading'],
definition['definitions'], definition['glossary'],
definition['sentence'] definition['sentence']
) )
self.ankiAddFact(markup) self.ankiAddFact(markup)

View File

@ -95,20 +95,20 @@ def replaceMarkupInFields(fields, markup):
return result return result
def buildFactMarkupExpression(expression, reading, definitions, sentence=None): def buildFactMarkupExpression(expression, reading, glossary, sentence=None):
return { return {
'%e': expression, '%e': expression,
'%r': reading, '%r': reading,
'%g': definitions, '%g': glossary,
'%s': sentence '%s': sentence
} }
def buildFactMarkupReading(reading, definitions, sentence=None): def buildFactMarkupReading(reading, glossary, sentence=None):
return { return {
'%e': reading, '%e': reading,
'%r': None, '%r': None,
'%g': definitions, '%g': glossary,
'%s': sentence '%s': sentence
} }
@ -130,7 +130,7 @@ def copyDefinitions(definitions):
for definition in definitions: for definition in definitions:
if definition['reading']: if definition['reading']:
text += u'{expression}\t{reading}\t{definitions}\n'.format(**definition) text += u'{expression}\t{reading}\t{glossary}\n'.format(**definition)
else: else:
text += u'{expression}\t{meanings}\n'.format(**definition) text += u'{expression}\t{meanings}\n'.format(**definition)
@ -149,9 +149,9 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex) links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex)
if factQuery: if factQuery:
if factQuery(buildFactMarkupExpression(definition['expression'], definition['reading'], definition['definitions'])): if factQuery(buildFactMarkupExpression(definition['expression'], definition['reading'], definition['glossary'])):
links += '<a href = "addExpression:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(factIndex) links += '<a href = "addExpression:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(factIndex)
if factQuery(buildFactMarkupReading(definition['reading'], definition['definitions'])): if factQuery(buildFactMarkupReading(definition['reading'], definition['glossary'])):
links += '<a href = "addReading:{0}"><img src = "://img/img/icon_add_reading.png" align = "right"/></a>'.format(factIndex) links += '<a href = "addReading:{0}"><img src = "://img/img/icon_add_reading.png" align = "right"/></a>'.format(factIndex)
html = u""" html = u"""
@ -159,7 +159,7 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
<span class = "expression">{1}&nbsp;{2}<br/></span> <span class = "expression">{1}&nbsp;{2}<br/></span>
<span class = "glossary">{3}<br/></span> <span class = "glossary">{3}<br/></span>
<span class = "conjugations">{4}</span> <span class = "conjugations">{4}</span>
<br clear = "all"/>""".format(links, definition['expression'], reading, definition['definitions'], conjugations) <br clear = "all"/>""".format(links, definition['expression'], reading, definition['glossary'], conjugations)
return html return html