openlp/openlp/core/lib/toolbar.py

89 lines
3.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
2014-01-14 19:25:18 +00:00
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
2012-11-07 21:37:01 +00:00
# Frode Woldsund, Martin Zibricky #
# --------------------------------------------------------------------------- #
# 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 the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2010-06-19 17:31:42 +00:00
"""
Provide common toolbar handling for OpenLP
"""
import logging
2011-01-21 19:09:56 +00:00
from PyQt4 import QtCore, QtGui
from openlp.core.lib.ui import create_widget_action
2010-03-04 22:09:03 +00:00
log = logging.getLogger(__name__)
2009-09-29 12:51:38 +00:00
class OpenLPToolbar(QtGui.QToolBar):
"""
Lots of toolbars around the place, so it makes sense to have a common way
to manage them. This is the base toolbar class.
"""
def __init__(self, parent):
"""
Initialise the toolbar.
"""
2010-07-06 21:59:52 +00:00
QtGui.QToolBar.__init__(self, parent)
# useful to be able to reuse button icons...
2009-09-29 12:51:38 +00:00
self.setIconSize(QtCore.QSize(20, 20))
self.actions = {}
log.debug(u'Init done for %s' % parent.__class__.__name__)
def addToolbarAction(self, name, **kwargs):
"""
A method to help developers easily add a button to the toolbar.
A new QAction is created by calling ``create_action()``. The action is
added to the toolbar and the toolbar is set as parent.
For more details please look at openlp.core.lib.ui.create_action()
"""
action = create_widget_action(self, name, **kwargs)
self.actions[name] = action
return action
def addToolbarWidget(self, widget):
2009-08-28 17:40:07 +00:00
"""
Add a widget and store it's handle under the widgets object name.
2009-08-28 17:40:07 +00:00
"""
action = self.addWidget(widget)
self.actions[unicode(widget.objectName())] = action
2009-09-04 22:50:19 +00:00
def setWidgetVisible(self, widgets, visible=True):
2009-09-04 22:50:19 +00:00
"""
Set the visibitity for a widget or a list of widgets.
2009-08-28 17:40:07 +00:00
``widget``
A list of string with widget object names.
2009-09-04 22:50:19 +00:00
``visible``
The new state as bool.
2009-09-04 22:50:19 +00:00
"""
for handle in widgets:
if handle in self.actions:
self.actions[handle].setVisible(visible)
else:
log.warn(u'No handle "%s" in actions list.', unicode(handle))
2009-10-01 23:43:16 +00:00