Classes:MediaManagerItem

From OpenLP

Jump to: navigation, search
  1. # -*- coding: utf-8 -*-
  2. # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
  3. """
  4. OpenLP - Open Source Lyrics Projection
  5. Copyright (c) 2008 Raoul Snyman
  6. Portions copyright (c) 2008 Martin Thompson, Tim Bentley
  7.  
  8. This program is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free Software
  10. Foundation; version 2 of the License.
  11.  
  12. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  14. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License along with
  17. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. Place, Suite 330, Boston, MA 02111-1307 USA
  19. """
  20. import types
  21.  
  22. from PyQt4 import QtCore, QtGui
  23. from openlp.core.resources import *
  24.  
  25. class MediaManagerItem(QtGui.QWidget):
  26.     """
  27.     MediaManagerItem is a helper widget for plugins.
  28.     """
  29.     def __init__(self, icon=None, title=None):
  30.         """
  31.         Constructor to create the media manager item.
  32.         """
  33.         QtGui.QWidget.__init__(self)
  34.         if type(icon) is QtGui.QIcon:
  35.             self.icon = icon
  36.         elif type(icon) is types.StringType:
  37.             self.icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
  38.                 QtGui.QIcon.Normal, QtGui.QIcon.Off)
  39.         else:
  40.             self.icon = None
  41.         if title is not None:
  42.             self.title = title
  43.         self.Toolbar = None
  44.         #self.ToolbarButtons = []
  45.  
  46.     def addToolbar(self):
  47.         """
  48.         A method to help developers easily add a toolbar to the media manager
  49.         item.
  50.         """
  51.         if self.Toolbar is None:
  52.             self.PageLayout = QtGui.QVBoxLayout(self)
  53.             self.PageLayout.setSpacing(0)
  54.             self.PageLayout.setMargin(0)
  55.             self.PageLayout.setObjectName('PageLayout')
  56.             self.Toolbar = QtGui.QToolBar(self)
  57.             self.Toolbar.setObjectName('Toolbar')
  58.             self.PageLayout.addWidget(self.Toolbar)
  59.  
  60.     def addToolbarButton(self, title, tooltip, icon, slot=None, objectname=None):
  61.         """
  62.         A method to help developers easily add a button to the toolbar.
  63.         """
  64.         if type(icon) is QtGui.QIcon:
  65.             ButtonIcon = icon
  66.         elif type(icon) is types.StringType:
  67.             ButtonIcon = QtGui.QIcon()
  68.             if icon.startswith(':/'):
  69.                 ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
  70.                     QtGui.QIcon.Off)
  71.             else:
  72.                 ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
  73.                     QtGui.QIcon.Normal, QtGui.QIcon.Off)
  74.         ToolbarButton = self.Toolbar.addAction(ButtonIcon, title)
  75.         if tooltip is not None:
  76.             ToolbarButton.setToolTip(tooltip)
  77.         if slot is not None:
  78.             QtCore.QObject.connect(ToolbarButton, QtCore.SIGNAL("triggered()"), slot)
  79.  
  80.     def addToolbarSeparator(self):
  81.         """
  82.         A very simple method to add a separator to the toolbar.
  83.         """
  84.         self.Toolbar.addSeparator()
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox