2 # Copyright (C) 2008 jerous <jerous@gmail.com>
3 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
5 # Nephilim is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Nephilim is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4
import QtGui
, QtCore
24 class Plugin(QtCore
.QObject
):
40 def __init__(self
, parent
, mpclient
, name
):
41 QtCore
.QObject
.__init
__(self
)
43 self
.mpclient
= mpclient
46 self
.settings
= QtCore
.QSettings()
48 self
.logger
= logging
.getLogger(self
.name
)
51 self
.logger
.debug('Initializing default settings.')
52 self
.settings
.beginGroup(name
)
53 for key
in self
.DEFAULTS
:
54 if not self
.settings
.contains(key
):
55 self
.settings
.setValue(key
, self
.DEFAULTS
[key
])
56 self
.settings
.endGroup()
62 self
.logger
.info('loading')
64 opts
= QtGui
.QDockWidget
.DockWidgetClosable|QtGui
.QDockWidget
.DockWidgetMovable
65 self
.dock_widget
= self
._get
_dock
_widget
()
67 self
.dock_widget
.setFeatures(opts
)
68 QtGui
.QApplication
.instance().main_win
.add_dock(self
.dock_widget
)
69 QtGui
.QApplication
.instance().main_win
.restore_layout()
70 self
.mpclient
.connect_changed
.connect(self
.set_enabled
)
75 self
.logger
.info("unloading")
78 QtGui
.QApplication
.instance().main_win
.remove_dock(self
.dock_widget
)
79 self
.dock_widget
= None
80 self
.settingsWidget
= None
81 self
.mpclient
.connect_changed
.disconnect(self
.set_enabled
)
83 def set_enabled(self
, val
):
85 self
.o
.setEnabled(val
)
87 class SettingsWidget(QtGui
.QWidget
):
88 """ plugins should subclass this"""
92 def __init__(self
, plugin
):
93 QtGui
.QWidget
.__init
__(self
)
95 self
.settings
= QtCore
.QSettings()
100 def savesettings(self
):
101 """ reimplement this"""
104 def _add_widget(self
, widget
, label
= '', tooltip
= ''):
105 """adds a widget with label"""
106 if not self
.layout():
107 self
.plugin
.logger
.error('Attempted to call add_widget with no layout set.')
108 widget
.setToolTip(tooltip
)
109 layout
= QtGui
.QHBoxLayout()
110 layout
.addWidget(QtGui
.QLabel(label
))
111 layout
.addWidget(widget
)
112 self
.layout().addLayout(layout
)
114 def get_settings_widget(self
):
115 """Should return subclassed SettingsWidget."""
118 def _get_dock_widget(self
):
119 """Override this one."""
121 def _create_dock(self
, widget
):
122 """Creates a QDockWidget with _parent $_parent containing widget $widget."""
123 dock
=QtGui
.QDockWidget(self
.name
, QtGui
.QApplication
.instance().main_win
)
124 dock
.setObjectName(self
.name
)
125 dock
.setWidget(widget
)
126 dock
.setAllowedAreas(QtCore
.Qt
.AllDockWidgetAreas
)
130 """Override this one."""
133 """Override this one."""