concentrate action creation in slide controller

This commit is contained in:
M2j 2012-02-28 10:24:42 +01:00
parent 95c8f8fe5a
commit d13ec2184a
4 changed files with 50 additions and 136 deletions

View File

@ -364,10 +364,11 @@ def create_action(parent, name, **kwargs):
return action
def context_menu_action(base, icon, text, slot, shortcuts=None, category=None,
context=QtCore.Qt.WidgetShortcut, **kwargs):
return create_action(parent=base, name=u'', icon=icon, text=text,
triggers=slot, shortcuts=shortcuts, category=category, context=context,
**kwargs)
context=QtCore.Qt.WidgetShortcut):
action = create_action(parent=base, name=u'', text=text, icon=icon,
shortcuts=shortcuts, context=context, category=category, triggers=slot)
base.addAction(action)
return action
def context_menu(base, icon, text):
"""
@ -393,7 +394,7 @@ def context_menu_separator(base):
``base``
The menu object to add the separator to
"""
action = QtGui.QAction(u'', base)
action = QtGui.QAction(base)
action.setSeparator(True)
base.addAction(action)
return action

View File

@ -27,6 +27,7 @@
from PyQt4 import QtGui
from openlp.core.lib.ui import create_action
from openlp.core.utils import LanguageManager
from firsttimelanguagedialog import Ui_FirstTimeLanguageDialog
@ -55,8 +56,7 @@ class FirstTimeLanguageForm(QtGui.QDialog, Ui_FirstTimeLanguageDialog):
LanguageManager.set_language(False, False)
else:
LanguageManager.auto_language = False
action = QtGui.QAction(None)
action.setObjectName(unicode(self.languageComboBox.currentText()))
action = create_action(None, self.languageComboBox.currentText())
LanguageManager.set_language(action, False)
return QtGui.QDialog.accept(self)

View File

@ -328,96 +328,29 @@ class SlideController(Controller):
self.shortcutTimer = QtCore.QTimer()
self.shortcutTimer.setObjectName(u'shortcutTimer')
self.shortcutTimer.setSingleShot(True)
self.verseShortcut = create_action(self, u'verseShortcut',
text=translate('OpenLP.SlideController', 'Go to "Verse"'),
shortcuts=[QtGui.QKeySequence(u'V')],
shortcuts = [{u'key': u'V', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Verse"')},
{u'key': u'C', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Chorus"')},
{u'key': u'B', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Bridge"')},
{u'key': u'P', u'configurable': True,
u'text': translate('OpenLP.SlideController',
'Go to "Pre-Chorus"')},
{u'key': u'I', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Intro"')},
{u'key': u'E', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Ending"')},
{u'key': u'O', u'configurable': True,
u'text': translate('OpenLP.SlideController', 'Go to "Other"')}]
shortcuts += [{u'key': unicode(number)} for number in range(0, 10)]
self.previewListWidget.addActions([create_action(self,
u'shortcutAction_%s' % s[u'key'], text=s.get(u'text'),
shortcuts=[QtGui.QKeySequence(s[u'key'])],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.shortcut0 = create_action(self, u'0',
shortcuts=[QtGui.QKeySequence(u'0')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut1 = create_action(self, u'1',
shortcuts=[QtGui.QKeySequence(u'1')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut2 = create_action(self, u'2',
shortcuts=[QtGui.QKeySequence(u'2')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut3 = create_action(self, u'3',
shortcuts=[QtGui.QKeySequence(u'3')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut4 = create_action(self, u'4',
shortcuts=[QtGui.QKeySequence(u'4')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut5 = create_action(self, u'5',
shortcuts=[QtGui.QKeySequence(u'5')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut6 = create_action(self, u'6',
shortcuts=[QtGui.QKeySequence(u'6')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut7 = create_action(self, u'7',
shortcuts=[QtGui.QKeySequence(u'7')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut8 = create_action(self, u'8',
shortcuts=[QtGui.QKeySequence(u'8')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.shortcut9 = create_action(self, u'9',
shortcuts=[QtGui.QKeySequence(u'9')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
triggers=self.slideShortcutActivated)
self.chorusShortcut = create_action(self, u'chorusShortcut',
text=translate('OpenLP.SlideController', 'Go to "Chorus"'),
shortcuts=[QtGui.QKeySequence(u'C')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.bridgeShortcut = create_action(self, u'bridgeShortcut',
text=translate('OpenLP.SlideController', 'Go to "Bridge"'),
shortcuts=[QtGui.QKeySequence(u'B')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.preChorusShortcut = create_action(self, u'preChorusShortcut',
text=translate('OpenLP.SlideController', 'Go to "Pre-Chorus"'),
shortcuts=[QtGui.QKeySequence(u'P')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.introShortcut = create_action(self, u'introShortcut',
text=translate('OpenLP.SlideController', 'Go to "Intro"'),
shortcuts=[QtGui.QKeySequence(u'I')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.endingShortcut = create_action(self, u'endingShortcut',
text=translate('OpenLP.SlideController', 'Go to "Ending"'),
shortcuts=[QtGui.QKeySequence(u'E')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.otherShortcut = create_action(self, u'otherShortcut',
text=translate('OpenLP.SlideController', 'Go to "Other"'),
shortcuts=[QtGui.QKeySequence(u'O')],
context=QtCore.Qt.WidgetWithChildrenShortcut,
category=unicode(UiStrings().LiveToolbar),
triggers=self.slideShortcutActivated)
self.previewListWidget.addActions([
self.shortcut0, self.shortcut1, self.shortcut2, self.shortcut3,
self.shortcut4, self.shortcut5, self.shortcut6, self.shortcut7,
self.shortcut8, self.shortcut9, self.verseShortcut,
self.chorusShortcut, self.bridgeShortcut,
self.preChorusShortcut, self.introShortcut, self.endingShortcut,
self.otherShortcut
])
category=unicode(UiStrings().LiveToolbar) \
if s.get(u'configurable') else None,
triggers=self.slideShortcutActivated) for s in shortcuts])
QtCore.QObject.connect(
self.shortcutTimer, QtCore.SIGNAL(u'timeout()'),
self.slideShortcutActivated)
@ -486,52 +419,37 @@ class SlideController(Controller):
SONGS_PLUGIN_AVAILABLE = True
except ImportError:
SONGS_PLUGIN_AVAILABLE = False
verse_type = unicode(self.sender().objectName())
if verse_type.startswith(u'verseShortcut'):
if SONGS_PLUGIN_AVAILABLE:
verse_type = \
unicode(self.sender().objectName())[len(u'shortcutAction_'):]
if SONGS_PLUGIN_AVAILABLE:
if verse_type == u'V':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Verse]
else:
self.current_shortcut = u'V'
elif verse_type.startswith(u'chorusShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'C':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Chorus]
else:
self.current_shortcut = u'C'
elif verse_type.startswith(u'bridgeShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'B':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Bridge]
else:
self.current_shortcut = u'B'
elif verse_type.startswith(u'preChorusShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'P':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.PreChorus]
else:
self.current_shortcut = u'P'
elif verse_type.startswith(u'introShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'I':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Intro]
else:
self.current_shortcut = u'I'
elif verse_type.startswith(u'endingShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'E':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Ending]
else:
self.current_shortcut = u'E'
elif verse_type.startswith(u'otherShortcut'):
if SONGS_PLUGIN_AVAILABLE:
elif verse_type == u'O':
self.current_shortcut = \
VerseType.TranslatedTags[VerseType.Other]
else:
self.current_shortcut = u'O'
elif verse_type.isnumeric():
self.current_shortcut += verse_type
self.current_shortcut = self.current_shortcut.upper()
elif verse_type.isnumeric():
self.current_shortcut += verse_type
self.current_shortcut = self.current_shortcut.upper()
else:
self.current_shortcut = verse_type
keys = self.slideList.keys()
matches = [match for match in keys
if match.startswith(self.current_shortcut)]

View File

@ -114,17 +114,12 @@ class BiblePlugin(Plugin):
use it as their parent.
"""
log.debug(u'add tools menu')
self.toolsUpgradeItem = QtGui.QAction(tools_menu)
self.toolsUpgradeItem.setObjectName(u'toolsUpgradeItem')
self.toolsUpgradeItem.setText(
translate('BiblesPlugin', '&Upgrade older Bibles'))
self.toolsUpgradeItem.setStatusTip(
translate('BiblesPlugin', 'Upgrade the Bible databases to the '
'latest format.'))
self.toolsUpgradeItem = create_action(tools_menu, u'toolsUpgradeItem',
text=translate('BiblesPlugin', '&Upgrade older Bibles'),
statustip=translate('BiblesPlugin',
'Upgrade the Bible databases to the latest format.'),
visible=False, triggers=self.onToolsUpgradeItemTriggered)
tools_menu.addAction(self.toolsUpgradeItem)
QtCore.QObject.connect(self.toolsUpgradeItem,
QtCore.SIGNAL(u'triggered()'), self.onToolsUpgradeItemTriggered)
self.toolsUpgradeItem.setVisible(False)
def onToolsUpgradeItemTriggered(self):
"""