openlp/openlp/core/ui/mediadockmanager.py

62 lines
3.1 KiB
Python
Raw Normal View History

2009-10-07 05:10:06 +00:00
# -*- coding: utf-8 -*-
2009-11-03 18:14:25 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
2009-10-07 05:10:06 +00:00
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-03-21 23:58:01 +00:00
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
2009-10-07 05:10:06 +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 #
2010-03-21 23:58:01 +00:00
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
2009-10-07 05:10:06 +00:00
# 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 #
###############################################################################
import logging
2010-03-04 22:09:03 +00:00
log = logging.getLogger(__name__)
2009-10-07 05:10:06 +00:00
class MediaDockManager(object):
2009-10-17 19:13:11 +00:00
def __init__(self, media_dock):
self.media_dock = media_dock
2009-10-07 05:10:06 +00:00
2009-10-17 19:13:11 +00:00
def add_dock(self, media_item, icon, weight):
2009-10-10 04:56:06 +00:00
log.info(u'Adding %s dock' % media_item.title)
2009-10-30 17:44:16 +00:00
self.media_dock.addItem(media_item, icon, media_item.title)
2009-10-07 05:10:06 +00:00
2009-10-17 19:13:11 +00:00
def insert_dock(self, media_item, icon, weight):
2009-10-10 13:13:57 +00:00
"""
This should insert a dock item at a given location
This does not work as it gives a Segmentation error.
For now add at end of stack if not present
"""
2009-10-10 04:56:06 +00:00
log.debug(u'Inserting %s dock' % media_item.title)
2009-10-10 13:13:57 +00:00
match = False
2009-10-17 19:13:11 +00:00
for dock_index in range(0, self.media_dock.count()):
if self.media_dock.widget(dock_index).settingsSection == \
2010-04-28 14:17:42 +00:00
media_item.title.lower():
2009-10-10 13:13:57 +00:00
match = True
break
if not match:
2009-10-17 19:13:11 +00:00
self.media_dock.addItem(media_item, icon, media_item.title)
2009-10-10 13:13:57 +00:00
2009-10-17 19:13:11 +00:00
def remove_dock(self, name):
2009-10-07 05:10:06 +00:00
log.debug(u'remove %s dock' % name)
2009-10-17 19:13:11 +00:00
for dock_index in range(0, self.media_dock.count()):
2009-11-03 18:14:25 +00:00
if self.media_dock.widget(dock_index):
if self.media_dock.widget(dock_index).settingsSection == name:
2009-10-17 19:13:11 +00:00
self.media_dock.widget(dock_index).hide()
2010-03-04 22:09:03 +00:00
self.media_dock.removeItem(dock_index)