Plugins 3 - global var removal

This commit is contained in:
Tim Bentley 2013-03-19 20:05:13 +00:00
parent fb6d292be0
commit f99e22fd4a
18 changed files with 66 additions and 66 deletions

View File

@ -155,7 +155,7 @@ class MediaManagerItem(QtGui.QWidget):
## Import Button ##
if self.hasImportIcon:
toolbar_actions.append([u'Import', StringContent.Import,
u':/general/general_import.png', self.onImportClick])
u':/general/general_import.png', self.on_import_click])
## Load Button ##
if self.hasFileIcon:
toolbar_actions.append([u'Load', StringContent.Load, u':/general/general_open.png', self.onFileClick])
@ -558,7 +558,7 @@ class MediaManagerItem(QtGui.QWidget):
Common method for generating a service item
"""
service_item = ServiceItem(self.plugin)
service_item.add_icon(self.plugin.iconPath)
service_item.add_icon(self.plugin.icon_path)
if self.generateSlideData(service_item, item, xmlVersion, remote, context):
return service_item
else:

View File

@ -79,13 +79,13 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
else:
# PluginStatus.Inactive
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
item.setText(status_text % plugin.nameStrings[u'singular'])
item.setText(status_text % plugin.name_strings[u'singular'])
# If the plugin has an icon, set it!
if plugin.icon:
item.setIcon(plugin.icon)
self.pluginListWidget.addItem(item)
pluginListWidth = max(pluginListWidth, self.fontMetrics().width(
translate('OpenLP.PluginForm', '%s (Inactive)') % plugin.nameStrings[u'singular']))
translate('OpenLP.PluginForm', '%s (Inactive)') % plugin.name_strings[u'singular']))
self.pluginListWidget.setFixedWidth(pluginListWidth + self.pluginListWidget.iconSize().width() + 48)
def _clearDetails(self):
@ -123,7 +123,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
self.activePlugin = None
for plugin in self.plugin_manager.plugins:
if plugin.status != PluginStatus.Disabled:
if plugin.nameStrings[u'singular'] == plugin_name_singular:
if plugin.name_strings[u'singular'] == plugin_name_singular:
self.activePlugin = plugin
break
if self.activePlugin:
@ -152,7 +152,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
elif self.activePlugin.status == PluginStatus.Disabled:
status_text = translate('OpenLP.PluginForm', '%s (Disabled)')
self.pluginListWidget.currentItem().setText(
status_text % self.activePlugin.nameStrings[u'singular'])
status_text % self.activePlugin.name_strings[u'singular'])
def _get_plugin_manager(self):
"""

View File

@ -156,7 +156,7 @@ class BiblePlugin(Plugin):
def on_bible_import_click(self):
if self.media_item:
self.media_item.onImportClick()
self.media_item.on_import_click()
def about(self):
about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>'

View File

@ -53,7 +53,7 @@ class BibleUpgradeForm(OpenLPWizard):
"""
log.info(u'BibleUpgradeForm loaded')
def __init__(self, parent, manager, bibleplugin):
def __init__(self, parent, manager, bible_plugin):
"""
Instantiate the wizard, and run any extra setup we need to.
@ -67,7 +67,7 @@ class BibleUpgradeForm(OpenLPWizard):
The Bible plugin.
"""
self.manager = manager
self.mediaItem = bibleplugin.mediaItem
self.media_item = bible_plugin.media_item
self.suffix = u'.sqlite'
self.settings_section = u'bibles'
self.path = AppLocation.get_section_data_path(self.settings_section)
@ -75,7 +75,7 @@ class BibleUpgradeForm(OpenLPWizard):
self.files = self.manager.old_bible_databases
self.success = {}
self.newbibles = {}
OpenLPWizard.__init__(self, parent, bibleplugin, u'bibleUpgradeWizard', u':/wizards/wizard_importbible.bmp')
OpenLPWizard.__init__(self, parent, bible_plugin, u'bibleUpgradeWizard', u':/wizards/wizard_importbible.bmp')
def setupUi(self, image):
"""
@ -218,7 +218,7 @@ class BibleUpgradeForm(OpenLPWizard):
"""
self.checkBox = {}
for number, filename in enumerate(self.files):
bible = OldBibleDB(self.mediaItem, path=self.path, file=filename[0])
bible = OldBibleDB(self.media_item, path=self.path, file=filename[0])
self.checkBox[number] = QtGui.QCheckBox(self.scrollAreaContents)
self.checkBox[number].setObjectName(u'checkBox[%d]' % number)
self.checkBox[number].setText(bible.get_name())
@ -367,12 +367,12 @@ class BibleUpgradeForm(OpenLPWizard):
self.success[number] = False
continue
self.progress_bar.reset()
old_bible = OldBibleDB(self.mediaItem, path=self.temp_dir,
old_bible = OldBibleDB(self.media_item, path=self.temp_dir,
file=filename[0])
name = filename[1]
self.progress_label.setText(translate('BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nUpgrading ...') % (number + 1, max_bibles, name))
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path, name=name, file=filename[0])
self.newbibles[number] = BibleDB(self.media_item, path=self.path, name=name, file=filename[0])
self.newbibles[number].register(self.plugin.upgrade_wizard)
metadata = old_bible.get_metadata()
web_bible = False

View File

@ -46,12 +46,12 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
"""
log.info(u'%s EditBibleForm loaded', __name__)
def __init__(self, mediaitem, parent, manager):
def __init__(self, media_item, parent, manager):
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
self.mediaitem = mediaitem
self.media_item = media_item
self.book_names = BibleStrings().BookNames
self.setupUi(self)
self.manager = manager

View File

@ -60,7 +60,7 @@ class BibleMediaItem(MediaManagerItem):
log.info(u'Bible Media Item loaded')
def __init__(self, parent, plugin):
self.IconPath = u'songs/song'
self.icon_path = u'songs/song'
self.lockIcon = build_icon(u':/bibles/bibles_search_lock.png')
self.unlockIcon = build_icon(u':/bibles/bibles_search_unlock.png')
MediaManagerItem.__init__(self, parent, plugin)
@ -461,7 +461,7 @@ class BibleMediaItem(MediaManagerItem):
books.sort(cmp=locale_compare)
set_case_insensitive_completer(books, self.quickSearchEdit)
def onImportClick(self):
def on_import_click(self):
if not hasattr(self, u'import_wizard'):
self.import_wizard = BibleImportForm(self, self.plugin.manager, self.plugin)
# If the import was not cancelled then reload.

View File

@ -47,13 +47,13 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
"""
log.info(u'Custom Editor loaded')
def __init__(self, mediaitem, parent, manager):
def __init__(self, media_item, parent, manager):
"""
Constructor
"""
super(EditCustomForm, self).__init__(parent)
self.manager = manager
self.mediaitem = mediaitem
self.media_item = media_item
self.setupUi(self)
# Create other objects and forms.
self.edit_slide_form = EditCustomSlideForm(self)
@ -130,7 +130,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.custom_slide.credits = self.credit_edit.text()
self.custom_slide.theme_name = self.theme_combo_box.currentText()
success = self.manager.save_object(self.custom_slide)
self.mediaitem.autoSelectId = self.custom_slide.id
self.media_item.autoSelectId = self.custom_slide.id
return success
def on_up_button_clicked(self):

View File

@ -55,7 +55,7 @@ class CustomMediaItem(MediaManagerItem):
log.info(u'Custom Media Item loaded')
def __init__(self, parent, plugin):
self.IconPath = u'custom/custom'
self.icon_path = u'custom/custom'
MediaManagerItem.__init__(self, parent, plugin)
self.edit_custom_form = EditCustomForm(self, self.main_window, self.plugin.manager)
self.singleServiceItem = False

View File

@ -50,7 +50,7 @@ class ImageMediaItem(MediaManagerItem):
log.info(u'Image Media Item loaded')
def __init__(self, parent, plugin):
self.IconPath = u'images/image'
self.icon_path = u'images/image'
MediaManagerItem.__init__(self, parent, plugin)
self.quickPreviewAllowed = True
self.hasSearch = True
@ -537,7 +537,7 @@ class ImageMediaItem(MediaManagerItem):
if isinstance(items[0].data(0, QtCore.Qt.UserRole), ImageGroups):
service_item.title = items[0].text(0)
else:
service_item.title = unicode(self.plugin.nameStrings[u'plural'])
service_item.title = unicode(self.plugin.name_strings[u'plural'])
service_item.add_capability(ItemCapabilities.CanMaintain)
service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop)

View File

@ -54,7 +54,7 @@ class MediaMediaItem(MediaManagerItem):
log.info(u'%s MediaMediaItem loaded', __name__)
def __init__(self, parent, plugin):
self.iconPath = u'images/image'
self.icon_path = u'images/image'
self.background = False
self.automatic = u''
MediaManagerItem.__init__(self, parent, plugin)

View File

@ -49,8 +49,8 @@ class MediaPlugin(Plugin):
def __init__(self):
Plugin.__init__(self, u'media', __default_settings__, MediaMediaItem)
self.weight = -6
self.iconPath = u':/plugins/plugin_media.png'
self.icon = build_icon(self.iconPath)
self.icon_path = u':/plugins/plugin_media.png'
self.icon = build_icon(self.icon_path)
# passed with drag and drop messages
self.dnd_id = u'Media'
@ -59,7 +59,7 @@ class MediaPlugin(Plugin):
Create the settings Tab
"""
visible_name = self.get_string(StringContent.VisibleName)
self.settings_tab = MediaTab(parent, self.name, visible_name[u'title'], self.iconPath)
self.settings_tab = MediaTab(parent, self.name, visible_name[u'title'], self.icon_path)
def about(self):
about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>'

View File

@ -54,7 +54,7 @@ class PresentationMediaItem(MediaManagerItem):
Constructor. Setup defaults
"""
self.controllers = controllers
self.IconPath = u'presentations/presentation'
self.icon_path = u'presentations/presentation'
self.Automatic = u''
MediaManagerItem.__init__(self, parent, plugin)
self.message_listener = MessageListener(self)

View File

@ -288,9 +288,9 @@ class MessageListener(object):
"""
log.info(u'Message Listener loaded')
def __init__(self, mediaitem):
self.controllers = mediaitem.controllers
self.mediaitem = mediaitem
def __init__(self, media_item):
self.controllers = media_item.controllers
self.media_item = media_item
self.preview_handler = Controller(False)
self.live_handler = Controller(True)
# messages are sent from core.ui.slidecontroller
@ -319,8 +319,8 @@ class MessageListener(object):
hide_mode = message[2]
file = item.get_frame_path()
self.handler = item.title
if self.handler == self.mediaitem.Automatic:
self.handler = self.mediaitem.findControllerByType(file)
if self.handler == self.media_item.Automatic:
self.handler = self.media_item.findControllerByType(file)
if not self.handler:
return
if is_live:

View File

@ -492,7 +492,7 @@ class HttpConnection(object):
if action == u'search':
searches = []
for plugin in self.plugin_manager.plugins:
if plugin.status == PluginStatus.Active and plugin.mediaItem and plugin.mediaItem.hasSearch:
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.mediaItem.hasSearch:
searches.append([plugin.name, unicode(plugin.textStrings[StringContent.Name][u'plural'])])
return HttpResponse(json.dumps({u'results': {u'items': searches}}), {u'Content-Type': u'application/json'})
@ -509,8 +509,8 @@ class HttpConnection(object):
return HttpResponse(code=u'400 Bad Request')
text = urllib.unquote(text)
plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.mediaItem and plugin.mediaItem.hasSearch:
results = plugin.mediaItem.search(text, False)
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.mediaItem.hasSearch:
results = plugin.media_item.search(text, False)
else:
results = []
return HttpResponse(json.dumps({u'results': {u'items': results}}), {u'Content-Type': u'application/json'})
@ -524,8 +524,8 @@ class HttpConnection(object):
except KeyError, ValueError:
return HttpResponse(code=u'400 Bad Request')
plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.mediaItem:
plugin.mediaItem.goLive(id, remote=True)
if plugin.status == PluginStatus.Active and plugin.media_item:
plugin.media_item.goLive(id, remote=True)
return HttpResponse(code=u'200 OK')
def add_to_service(self, plugin_name):
@ -537,9 +537,9 @@ class HttpConnection(object):
except KeyError, ValueError:
return HttpResponse(code=u'400 Bad Request')
plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.mediaItem:
item_id = plugin.mediaItem.createItemFromId(id)
plugin.mediaItem.addToService(item_id, remote=True)
if plugin.status == PluginStatus.Active and plugin.media_item:
item_id = plugin.media_item.createItemFromId(id)
plugin.media_item.addToService(item_id, remote=True)
return HttpResponse(code=u'200 OK')
def send_response(self, response):

View File

@ -59,12 +59,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
"""
log.info(u'%s EditSongForm loaded', __name__)
def __init__(self, mediaitem, parent, manager):
def __init__(self, media_item, parent, manager):
"""
Constructor
"""
super(EditSongForm, self).__init__(parent)
self.mediaitem = mediaitem
self.media_item = media_item
self.song = None
# can this be automated?
self.width = 400
@ -320,7 +320,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
for plugin in self.plugin_manager.plugins:
if plugin.name == u'media' and plugin.status == PluginStatus.Active:
self.from_media_button.setVisible(True)
self.media_form.populateFiles(plugin.mediaItem.getList(MediaType.Audio))
self.media_form.populateFiles(plugin.media_item.getList(MediaType.Audio))
break
def new_song(self):
@ -714,7 +714,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
text = self.song_book_combo_box.currentText()
if item == 0 and text:
temp_song_book = text
self.mediaitem.songMaintenanceForm.exec_(True)
self.media_item.songMaintenanceForm.exec_(True)
self.load_authors()
self.load_books()
self.load_topics()
@ -884,7 +884,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.manager.save_object(self.song)
audio_files = map(lambda a: a.file_name, self.song.media_files)
log.debug(audio_files)
save_path = os.path.join(AppLocation.get_section_data_path(self.mediaitem.plugin.name), 'audio',
save_path = os.path.join(AppLocation.get_section_data_path(self.media_item.plugin.name), 'audio',
str(self.song.id))
check_directory_exists(save_path)
self.song.media_files = []
@ -914,7 +914,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
log.exception(u'Could not remove directory: %s', save_path)
clean_song(self.manager, self.song)
self.manager.save_object(self.song)
self.mediaitem.autoSelectId = self.song.id
self.media_item.autoSelectId = self.song.id
def _get_plugin_manager(self):
"""

View File

@ -70,7 +70,7 @@ class SongMediaItem(MediaManagerItem):
log.info(u'Song Media Item loaded')
def __init__(self, parent, plugin):
self.IconPath = u'songs/song'
self.icon_path = u'songs/song'
MediaManagerItem.__init__(self, parent, plugin)
self.editSongForm = EditSongForm(self, self.main_window, self.plugin.manager)
self.openLyrics = OpenLyrics(self.plugin.manager)
@ -295,14 +295,14 @@ class SongMediaItem(MediaManagerItem):
elif not text:
self.onClearTextButtonClick()
def onImportClick(self):
def on_import_click(self):
if not hasattr(self, u'import_wizard'):
self.import_wizard = SongImportForm(self, self.plugin)
self.import_wizard.exec_()
# Run song load as list may have been cancelled but some songs loaded
Registry().execute(u'songs_load_list')
def onExportClick(self):
def on_export_click(self):
if not hasattr(self, u'exportWizard'):
self.exportWizard = SongExportForm(self, self.plugin)
self.exportWizard.exec_()

View File

@ -210,7 +210,7 @@ class SongsPlugin(Plugin):
def importSongs(self, format, **kwargs):
class_ = SongFormat.get(format, u'class')
importer = class_(self.manager, **kwargs)
importer.register(self.mediaItem.import_wizard)
importer.register(self.media_item.import_wizard)
return importer
def set_plugin_text_strings(self):
@ -275,7 +275,7 @@ class SongsPlugin(Plugin):
importer.doImport(progress)
self.application.process_events()
progress.setValue(song_count)
self.mediaItem.onSearchTextButtonClicked()
self.media_item.onSearchTextButtonClicked()
def finalise(self):
"""

View File

@ -27,7 +27,7 @@ class TestImageMediaItem(TestCase):
mocked_plugin = MagicMock()
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.__init__') as mocked_init:
mocked_init.return_value = None
self.mediaitem = ImageMediaItem(mocked_parent, mocked_plugin)
self.media_item = ImageMediaItem(mocked_parent, mocked_plugin)
def save_new_images_list_empty_list_test(self):
"""
@ -36,13 +36,13 @@ class TestImageMediaItem(TestCase):
# GIVEN: An empty image_list
image_list = []
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.loadFullList') as mocked_loadFullList:
self.mediaitem.manager = MagicMock()
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with the empty list
self.mediaitem.save_new_images_list(image_list)
self.media_item.save_new_images_list(image_list)
# THEN: The save_object() method should not have been called
assert self.mediaitem.manager.save_object.call_count == 0, \
assert self.media_item.manager.save_object.call_count == 0, \
u'The save_object() method should not have been called'
def save_new_images_list_single_image_with_reload_test(self):
@ -53,10 +53,10 @@ class TestImageMediaItem(TestCase):
image_list = [ u'test_image.jpg' ]
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.loadFullList') as mocked_loadFullList:
ImageFilenames.filename = ''
self.mediaitem.manager = MagicMock()
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with reload_list=True
self.mediaitem.save_new_images_list(image_list, reload_list=True)
self.media_item.save_new_images_list(image_list, reload_list=True)
# THEN: loadFullList() should have been called
assert mocked_loadFullList.call_count == 1, u'loadFullList() should have been called'
@ -71,10 +71,10 @@ class TestImageMediaItem(TestCase):
# GIVEN: A list with 1 image
image_list = [ u'test_image.jpg' ]
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.loadFullList') as mocked_loadFullList:
self.mediaitem.manager = MagicMock()
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with reload_list=False
self.mediaitem.save_new_images_list(image_list, reload_list=False)
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: loadFullList() should not have been called
assert mocked_loadFullList.call_count == 0, u'loadFullList() should not have been called'
@ -86,13 +86,13 @@ class TestImageMediaItem(TestCase):
# GIVEN: A list with 3 images
image_list = [ u'test_image_1.jpg', u'test_image_2.jpg', u'test_image_3.jpg' ]
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.loadFullList') as mocked_loadFullList:
self.mediaitem.manager = MagicMock()
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with the list of 3 images
self.mediaitem.save_new_images_list(image_list, reload_list=False)
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: loadFullList() should not have been called
assert self.mediaitem.manager.save_object.call_count == 3, \
assert self.media_item.manager.save_object.call_count == 3, \
u'loadFullList() should have been called three times'
def save_new_images_list_other_objects_in_list_test(self):
@ -102,11 +102,11 @@ class TestImageMediaItem(TestCase):
# GIVEN: A list with images and objects
image_list = [ u'test_image_1.jpg', None, True, ImageFilenames(), 'test_image_2.jpg' ]
with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.loadFullList') as mocked_loadFullList:
self.mediaitem.manager = MagicMock()
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with the list of images and objects
self.mediaitem.save_new_images_list(image_list, reload_list=False)
self.media_item.save_new_images_list(image_list, reload_list=False)
# THEN: loadFullList() should not have been called
assert self.mediaitem.manager.save_object.call_count == 2, \
assert self.media_item.manager.save_object.call_count == 2, \
u'loadFullList() should have been called only once'