forked from openlp/openlp
RFC: Tweaks
This commit is contained in:
parent
e92b017348
commit
85661fe6e4
@ -22,7 +22,6 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The :mod:`lib` module contains most of the components and libraries that make
|
The :mod:`lib` module contains most of the components and libraries that make
|
||||||
OpenLP work.
|
OpenLP work.
|
||||||
@ -47,6 +46,10 @@ def translate(context, text, comment=None):
|
|||||||
|
|
||||||
``text``
|
``text``
|
||||||
The text to put into the translation tables for translation.
|
The text to put into the translation tables for translation.
|
||||||
|
|
||||||
|
``comment``
|
||||||
|
An identifying string for when the same text is used in different roles
|
||||||
|
within the same context.
|
||||||
"""
|
"""
|
||||||
return QtCore.QCoreApplication.translate(context, text, comment)
|
return QtCore.QCoreApplication.translate(context, text, comment)
|
||||||
|
|
||||||
@ -115,6 +118,18 @@ def build_icon(icon):
|
|||||||
def context_menu_action(base, icon, text, slot):
|
def context_menu_action(base, icon, text, slot):
|
||||||
"""
|
"""
|
||||||
Utility method to help build context menus for plugins
|
Utility method to help build context menus for plugins
|
||||||
|
|
||||||
|
``base``
|
||||||
|
The parent menu to add this menu item to
|
||||||
|
|
||||||
|
``icon``
|
||||||
|
An icon for this action
|
||||||
|
|
||||||
|
``text``
|
||||||
|
The text to display for this action
|
||||||
|
|
||||||
|
``slot``
|
||||||
|
The code to run when this action is triggered
|
||||||
"""
|
"""
|
||||||
action = QtGui.QAction(text, base)
|
action = QtGui.QAction(text, base)
|
||||||
if icon:
|
if icon:
|
||||||
@ -125,6 +140,15 @@ def context_menu_action(base, icon, text, slot):
|
|||||||
def context_menu(base, icon, text):
|
def context_menu(base, icon, text):
|
||||||
"""
|
"""
|
||||||
Utility method to help build context menus for plugins
|
Utility method to help build context menus for plugins
|
||||||
|
|
||||||
|
``base``
|
||||||
|
The parent object to add this menu to
|
||||||
|
|
||||||
|
``icon``
|
||||||
|
An icon for this menu
|
||||||
|
|
||||||
|
``text``
|
||||||
|
The text to display for this menu
|
||||||
"""
|
"""
|
||||||
action = QtGui.QMenu(text, base)
|
action = QtGui.QMenu(text, base)
|
||||||
action.setIcon(build_icon(icon))
|
action.setIcon(build_icon(icon))
|
||||||
@ -133,6 +157,9 @@ def context_menu(base, icon, text):
|
|||||||
def context_menu_separator(base):
|
def context_menu_separator(base):
|
||||||
"""
|
"""
|
||||||
Add a separator to a context menu
|
Add a separator to a context menu
|
||||||
|
|
||||||
|
``base``
|
||||||
|
The menu object to add the separator to
|
||||||
"""
|
"""
|
||||||
action = QtGui.QAction(u'', base)
|
action = QtGui.QAction(u'', base)
|
||||||
action.setSeparator(True)
|
action.setSeparator(True)
|
||||||
|
@ -33,7 +33,7 @@ from sqlalchemy.orm import mapper
|
|||||||
from openlp.core.lib import SettingsManager
|
from openlp.core.lib import SettingsManager
|
||||||
from openlp.core.lib.db import BaseModel
|
from openlp.core.lib.db import BaseModel
|
||||||
from openlp.core.utils import AppLocation
|
from openlp.core.utils import AppLocation
|
||||||
from openlp.plugins.bibles.lib.models import *
|
from openlp.plugins.bibles.lib.db import BibleMeta, Book, Testament, Verse
|
||||||
|
|
||||||
class TBibleMeta(BaseModel):
|
class TBibleMeta(BaseModel):
|
||||||
"""
|
"""
|
||||||
@ -196,4 +196,3 @@ class MigrateBibles(object):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.execute(u'vacuum;')
|
conn.execute(u'vacuum;')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
@ -34,10 +34,7 @@ from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation
|
|||||||
from openlp.core.lib import SettingsManager
|
from openlp.core.lib import SettingsManager
|
||||||
from openlp.core.lib.db import BaseModel
|
from openlp.core.lib.db import BaseModel
|
||||||
from openlp.core.utils import AppLocation
|
from openlp.core.utils import AppLocation
|
||||||
from openlp.plugins.songs.lib.models import metadata, songs_table, Song, \
|
from openlp.plugins.songs.lib.db import songs_table, Song, Author, Topic, Book
|
||||||
Author, Topic, Book
|
|
||||||
from openlp.plugins.songs.lib.tables import *
|
|
||||||
from openlp.plugins.songs.lib.classes import *
|
|
||||||
|
|
||||||
def init_models(url):
|
def init_models(url):
|
||||||
engine = create_engine(url)
|
engine = create_engine(url)
|
||||||
|
@ -48,6 +48,9 @@ class alertsPlugin(Plugin):
|
|||||||
self.status = PluginStatus.Active
|
self.status = PluginStatus.Active
|
||||||
|
|
||||||
def get_settings_tab(self):
|
def get_settings_tab(self):
|
||||||
|
"""
|
||||||
|
Return the settings tab for the Alerts plugin
|
||||||
|
"""
|
||||||
self.alertsTab = AlertsTab(self)
|
self.alertsTab = AlertsTab(self)
|
||||||
return self.alertsTab
|
return self.alertsTab
|
||||||
|
|
||||||
|
@ -197,18 +197,11 @@ class BibleDB(QtCore.QObject, Manager):
|
|||||||
The actual Qt wizard form.
|
The actual Qt wizard form.
|
||||||
"""
|
"""
|
||||||
self.wizard = wizard
|
self.wizard = wizard
|
||||||
self.create_tables()
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def create_tables(self):
|
|
||||||
"""
|
|
||||||
Create some initial metadata.
|
|
||||||
"""
|
|
||||||
log.debug(u'createTables')
|
|
||||||
self.create_meta(u'dbversion', u'2')
|
self.create_meta(u'dbversion', u'2')
|
||||||
self.insert_object(Testament.populate(name=u'Old Testament'))
|
self.insert_object(Testament.populate(name=u'Old Testament'))
|
||||||
self.insert_object(Testament.populate(name=u'New Testament'))
|
self.insert_object(Testament.populate(name=u'New Testament'))
|
||||||
self.insert_object(Testament.populate(name=u'Apocrypha'))
|
self.insert_object(Testament.populate(name=u'Apocrypha'))
|
||||||
|
return self.name
|
||||||
|
|
||||||
def create_book(self, name, abbrev, testament=1):
|
def create_book(self, name, abbrev, testament=1):
|
||||||
"""
|
"""
|
||||||
@ -284,26 +277,32 @@ class BibleDB(QtCore.QObject, Manager):
|
|||||||
return verse
|
return verse
|
||||||
|
|
||||||
def create_meta(self, key, value):
|
def create_meta(self, key, value):
|
||||||
|
"""
|
||||||
|
Utility method to save BibleMeta objects in a Bible database
|
||||||
|
|
||||||
|
``key``
|
||||||
|
The key for this instance
|
||||||
|
|
||||||
|
``value``
|
||||||
|
The value for this instance
|
||||||
|
"""
|
||||||
log.debug(u'save_meta %s/%s', key, value)
|
log.debug(u'save_meta %s/%s', key, value)
|
||||||
self.insert_object(BibleMeta.populate(key=key, value=value))
|
self.insert_object(BibleMeta.populate(key=key, value=value))
|
||||||
|
|
||||||
def get_book(self, book):
|
def get_book(self, book):
|
||||||
log.debug(u'BibleDb.get_book("%s")', book)
|
"""
|
||||||
db_book = self.session.query(Book)\
|
Return a book object from the database
|
||||||
.filter(Book.name.like(book + u'%'))\
|
|
||||||
.first()
|
|
||||||
if db_book is None:
|
|
||||||
db_book = self.session.query(Book)\
|
|
||||||
.filter(Book.abbreviation.like(book + u'%'))\
|
|
||||||
.first()
|
|
||||||
return db_book
|
|
||||||
|
|
||||||
def get_chapter(self, id, chapter):
|
``book``
|
||||||
log.debug(u'BibleDB.get_chapter("%s", %s)', id, chapter)
|
The name of the book to return
|
||||||
return self.session.query(Verse)\
|
"""
|
||||||
.filter_by(chapter=chapter)\
|
log.debug(u'BibleDb.get_book("%s")', book)
|
||||||
.filter_by(book_id=id)\
|
db_book = self.session.query(Book).filter(
|
||||||
.first()
|
Book.name.like(book + u'%')).first()
|
||||||
|
if db_book is None:
|
||||||
|
db_book = self.session.query(Book).filter(
|
||||||
|
Book.abbreviation.like(book + u'%')).first()
|
||||||
|
return db_book
|
||||||
|
|
||||||
def get_verses(self, reference_list):
|
def get_verses(self, reference_list):
|
||||||
"""
|
"""
|
||||||
@ -370,6 +369,12 @@ class BibleDB(QtCore.QObject, Manager):
|
|||||||
return verses
|
return verses
|
||||||
|
|
||||||
def get_chapter_count(self, book):
|
def get_chapter_count(self, book):
|
||||||
|
"""
|
||||||
|
Return the number of chapters in a book
|
||||||
|
|
||||||
|
``book``
|
||||||
|
The book to get the chapter count for
|
||||||
|
"""
|
||||||
log.debug(u'BibleDB.get_chapter_count("%s")', book)
|
log.debug(u'BibleDB.get_chapter_count("%s")', book)
|
||||||
count = self.session.query(Verse.chapter).join(Book)\
|
count = self.session.query(Verse.chapter).join(Book)\
|
||||||
.filter(Book.name==book)\
|
.filter(Book.name==book)\
|
||||||
@ -380,6 +385,15 @@ class BibleDB(QtCore.QObject, Manager):
|
|||||||
return count
|
return count
|
||||||
|
|
||||||
def get_verse_count(self, book, chapter):
|
def get_verse_count(self, book, chapter):
|
||||||
|
"""
|
||||||
|
Return the number of verses in a chapter
|
||||||
|
|
||||||
|
``book``
|
||||||
|
The book containing the chapter
|
||||||
|
|
||||||
|
``chapter``
|
||||||
|
The chapter to get the verse count for
|
||||||
|
"""
|
||||||
log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter)
|
log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter)
|
||||||
count = self.session.query(Verse).join(Book)\
|
count = self.session.query(Verse).join(Book)\
|
||||||
.filter(Book.name==book)\
|
.filter(Book.name==book)\
|
||||||
@ -391,6 +405,9 @@ class BibleDB(QtCore.QObject, Manager):
|
|||||||
return count
|
return count
|
||||||
|
|
||||||
def dump_bible(self):
|
def dump_bible(self):
|
||||||
|
"""
|
||||||
|
Utility debugging method to dump the contents of a bible
|
||||||
|
"""
|
||||||
log.debug(u'.........Dumping Bible Database')
|
log.debug(u'.........Dumping Bible Database')
|
||||||
log.debug('...............................Books ')
|
log.debug('...............................Books ')
|
||||||
books = self.session.query(Book).all()
|
books = self.session.query(Book).all()
|
||||||
|
Loading…
Reference in New Issue
Block a user