2009-02-21 19:23:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-28 22:06:43 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2009-07-14 13:51:27 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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
|
|
|
|
"""
|
2009-07-08 06:55:08 +00:00
|
|
|
import logging
|
2009-02-21 19:23:54 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2011-01-21 19:09:56 +00:00
|
|
|
|
2012-03-02 10:22:52 +00:00
|
|
|
from openlp.core.lib.ui import create_widget_action
|
2009-09-29 02:54:32 +00:00
|
|
|
|
2010-03-04 22:09:03 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-02-01 19:58:18 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
class OpenLPToolbar(QtWidgets.QToolBar):
|
2009-02-21 19:23:54 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
Lots of toolbars around the place, so it makes sense to have a common way to manage them. This is the base toolbar
|
|
|
|
class.
|
2009-02-21 19:23:54 +00:00
|
|
|
"""
|
|
|
|
def __init__(self, parent):
|
2009-07-08 06:55:08 +00:00
|
|
|
"""
|
|
|
|
Initialise the toolbar.
|
|
|
|
"""
|
2013-07-18 11:23:59 +00:00
|
|
|
super(OpenLPToolbar, self).__init__(parent)
|
2009-05-01 22:26:43 +00:00
|
|
|
# useful to be able to reuse button icons...
|
2009-09-29 12:51:38 +00:00
|
|
|
self.setIconSize(QtCore.QSize(20, 20))
|
2009-08-27 05:17:20 +00:00
|
|
|
self.actions = {}
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Init done for %s' % parent.__class__.__name__)
|
2009-05-01 22:26:43 +00:00
|
|
|
|
2013-03-07 06:48:09 +00:00
|
|
|
def add_toolbar_action(self, name, **kwargs):
|
2009-02-21 19:23:54 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
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()
|
2009-02-21 19:23:54 +00:00
|
|
|
"""
|
2012-03-02 10:22:52 +00:00
|
|
|
action = create_widget_action(self, name, **kwargs)
|
2012-03-02 12:11:13 +00:00
|
|
|
self.actions[name] = action
|
2012-03-02 10:22:52 +00:00
|
|
|
return action
|
2009-05-01 22:26:43 +00:00
|
|
|
|
2013-03-07 06:48:09 +00:00
|
|
|
def add_toolbar_widget(self, widget):
|
2009-08-28 17:40:07 +00:00
|
|
|
"""
|
2012-03-02 12:11:13 +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)
|
2012-05-17 18:57:01 +00:00
|
|
|
self.actions[widget.objectName()] = action
|
2009-09-04 22:50:19 +00:00
|
|
|
|
2013-03-07 06:48:09 +00:00
|
|
|
def set_widget_visible(self, widgets, visible=True):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2013-12-24 08:56:50 +00:00
|
|
|
Set the visibility for a widget or a list of widgets.
|
2009-08-28 17:40:07 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param widgets: A list of string with widget object names.
|
|
|
|
:param visible: The new state as bool.
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2012-03-02 12:11:13 +00:00
|
|
|
for handle in widgets:
|
|
|
|
if handle in self.actions:
|
2012-03-03 13:52:57 +00:00
|
|
|
self.actions[handle].setVisible(visible)
|
2012-03-02 12:11:13 +00:00
|
|
|
else:
|
2014-06-30 20:59:22 +00:00
|
|
|
log.warning('No handle "%s" in actions list.', str(handle))
|
2014-10-10 02:49:18 +00:00
|
|
|
|
|
|
|
def set_widget_enabled(self, widgets, enabled=True):
|
|
|
|
"""
|
|
|
|
Set the enabled state for a widget or a list of widgets.
|
|
|
|
|
|
|
|
:param widgets: A list of string with widget object names.
|
|
|
|
:param enabled: The new state as bool.
|
|
|
|
"""
|
|
|
|
for handle in widgets:
|
|
|
|
if handle in self.actions:
|
|
|
|
self.actions[handle].setEnabled(enabled)
|
|
|
|
else:
|
|
|
|
log.warning('No handle "%s" in actions list.', str(handle))
|