RFC: Tweaks

This commit is contained in:
Jon Tibble 2010-06-15 16:42:52 +01:00
parent e92b017348
commit 85661fe6e4
6 changed files with 74 additions and 31 deletions

View File

@ -22,7 +22,6 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`lib` module contains most of the components and libraries that make
OpenLP work.
@ -47,6 +46,10 @@ def translate(context, text, comment=None):
``text``
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)
@ -115,6 +118,18 @@ def build_icon(icon):
def context_menu_action(base, icon, text, slot):
"""
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)
if icon:
@ -125,6 +140,15 @@ def context_menu_action(base, icon, text, slot):
def context_menu(base, icon, text):
"""
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.setIcon(build_icon(icon))
@ -133,6 +157,9 @@ def context_menu(base, icon, text):
def context_menu_separator(base):
"""
Add a separator to a context menu
``base``
The menu object to add the separator to
"""
action = QtGui.QAction(u'', base)
action.setSeparator(True)

View File

@ -33,7 +33,7 @@ from sqlalchemy.orm import mapper
from openlp.core.lib import SettingsManager
from openlp.core.lib.db import BaseModel
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):
"""
@ -196,4 +196,3 @@ class MigrateBibles(object):
conn.commit()
conn.execute(u'vacuum;')
conn.commit()

View File

@ -34,10 +34,7 @@ from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation
from openlp.core.lib import SettingsManager
from openlp.core.lib.db import BaseModel
from openlp.core.utils import AppLocation
from openlp.plugins.songs.lib.models import metadata, songs_table, Song, \
Author, Topic, Book
from openlp.plugins.songs.lib.tables import *
from openlp.plugins.songs.lib.classes import *
from openlp.plugins.songs.lib.db import songs_table, Song, Author, Topic, Book
def init_models(url):
engine = create_engine(url)

View File

@ -48,6 +48,9 @@ class alertsPlugin(Plugin):
self.status = PluginStatus.Active
def get_settings_tab(self):
"""
Return the settings tab for the Alerts plugin
"""
self.alertsTab = AlertsTab(self)
return self.alertsTab

View File

@ -197,18 +197,11 @@ class BibleDB(QtCore.QObject, Manager):
The actual Qt wizard form.
"""
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.insert_object(Testament.populate(name=u'Old Testament'))
self.insert_object(Testament.populate(name=u'New Testament'))
self.insert_object(Testament.populate(name=u'Apocrypha'))
return self.name
def create_book(self, name, abbrev, testament=1):
"""
@ -284,26 +277,32 @@ class BibleDB(QtCore.QObject, Manager):
return verse
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)
self.insert_object(BibleMeta.populate(key=key, value=value))
def get_book(self, book):
log.debug(u'BibleDb.get_book("%s")', book)
db_book = self.session.query(Book)\
.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
"""
Return a book object from the database
def get_chapter(self, id, chapter):
log.debug(u'BibleDB.get_chapter("%s", %s)', id, chapter)
return self.session.query(Verse)\
.filter_by(chapter=chapter)\
.filter_by(book_id=id)\
.first()
``book``
The name of the book to return
"""
log.debug(u'BibleDb.get_book("%s")', book)
db_book = self.session.query(Book).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_verses(self, reference_list):
"""
@ -370,6 +369,12 @@ class BibleDB(QtCore.QObject, Manager):
return verses
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)
count = self.session.query(Verse.chapter).join(Book)\
.filter(Book.name==book)\
@ -380,6 +385,15 @@ class BibleDB(QtCore.QObject, Manager):
return count
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)
count = self.session.query(Verse).join(Book)\
.filter(Book.name==book)\
@ -391,6 +405,9 @@ class BibleDB(QtCore.QObject, Manager):
return count
def dump_bible(self):
"""
Utility debugging method to dump the contents of a bible
"""
log.debug(u'.........Dumping Bible Database')
log.debug('...............................Books ')
books = self.session.query(Book).all()

View File

@ -34,7 +34,7 @@ from openlp.core.lib.db import BaseModel, init_db
class CustomSlide(BaseModel):
"""
Custom Slide model
CustomSlide model
"""
pass