~raoul-snyman/openlp/dont-test-uno-on-macos

« back to all changes in this revision

Viewing changes to openlp/core/widgets/docks.py

  • Committer: Raoul Snyman
  • Date: 2017-10-25 21:18:38 UTC
  • mfrom: (2780.1.2 refactorings-3)
  • Revision ID: raoul@snyman.info-20171025211838-be4wutkihlytvkk3
Merge in refactorings-3

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# with this program; if not, write to the Free Software Foundation, Inc., 59  #
20
20
# Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
21
21
###############################################################################
22
 
 
23
 
"""
24
 
Provide additional functionality required by OpenLP from the inherited QDockWidget.
25
 
"""
26
 
 
 
22
"""
 
23
The :mod:`~openlp.core.widgets.docks` module contains a customised base dock widget and dock widgets
 
24
"""
27
25
import logging
28
26
 
29
27
from PyQt5 import QtWidgets
30
28
 
31
29
from openlp.core.display.screens import ScreenList
32
 
from openlp.core.lib import build_icon
 
30
from openlp.core.lib import StringContent, build_icon
33
31
 
34
32
log = logging.getLogger(__name__)
35
33
 
55
53
            self.setMinimumWidth(300)
56
54
        else:
57
55
            self.setMinimumWidth(main_window_docbars)
 
56
 
 
57
 
 
58
class MediaDockManager(object):
 
59
    """
 
60
    Provide a repository for MediaManagerItems
 
61
    """
 
62
    def __init__(self, media_dock):
 
63
        """
 
64
        Initialise the media dock
 
65
        """
 
66
        self.media_dock = media_dock
 
67
 
 
68
    def add_item_to_dock(self, media_item):
 
69
        """
 
70
        Add a MediaManagerItem to the dock
 
71
        If the item has been added before, it's silently skipped
 
72
 
 
73
        :param media_item: The item to add to the dock
 
74
        """
 
75
        visible_title = media_item.plugin.get_string(StringContent.VisibleName)
 
76
        log.debug('Inserting %s dock' % visible_title['title'])
 
77
        match = False
 
78
        for dock_index in range(self.media_dock.count()):
 
79
            if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
 
80
                match = True
 
81
                break
 
82
        if not match:
 
83
            self.media_dock.addItem(media_item, media_item.plugin.icon, visible_title['title'])
 
84
 
 
85
    def remove_dock(self, media_item):
 
86
        """
 
87
        Removes a MediaManagerItem from the dock
 
88
 
 
89
        :param media_item: The item to add to the dock
 
90
        """
 
91
        visible_title = media_item.plugin.get_string(StringContent.VisibleName)
 
92
        log.debug('remove %s dock' % visible_title['title'])
 
93
        for dock_index in range(self.media_dock.count()):
 
94
            if self.media_dock.widget(dock_index):
 
95
                if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
 
96
                    self.media_dock.widget(dock_index).setVisible(False)
 
97
                    self.media_dock.removeItem(dock_index)