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
20 from PyQt4
.QtCore
import QVariant
25 class Plugin(QtCore
.QObject
):
41 def __init__(self
, parent
, mpclient
, name
):
42 QtCore
.QObject
.__init
__(self
)
44 self
.mpclient
= mpclient
47 self
.settings
= QtCore
.QSettings()
49 self
.logger
= logging
.getLogger(self
.name
)
52 self
.logger
.debug('Initializing default settings.')
53 self
.settings
.beginGroup(name
)
54 for key
in self
.DEFAULTS
:
55 if not self
.settings
.contains(key
):
56 self
.settings
.setValue(key
, QVariant(self
.DEFAULTS
[key
]))
57 self
.settings
.endGroup()
63 self
.logger
.info('loading')
65 opts
= QtGui
.QDockWidget
.DockWidgetClosable|QtGui
.QDockWidget
.DockWidgetMovable
66 self
.dock_widget
= self
._get
_dock
_widget
()
68 self
.dock_widget
.setFeatures(opts
)
69 QtGui
.QApplication
.instance().main_win
.add_dock(self
.dock_widget
)
70 QtGui
.QApplication
.instance().main_win
.restore_layout()
71 self
.mpclient
.connect_changed
.connect(self
.set_enabled
)
76 self
.logger
.info("unloading")
79 QtGui
.QApplication
.instance().main_win
.remove_dock(self
.dock_widget
)
80 self
.dock_widget
= None
81 self
.settingsWidget
= None
82 self
.mpclient
.connect_changed
.disconnect(self
.set_enabled
)
84 def set_enabled(self
, val
):
86 self
.o
.setEnabled(val
)
88 class SettingsWidget(QtGui
.QWidget
):
89 """ plugins should subclass this"""
93 def __init__(self
, plugin
):
94 QtGui
.QWidget
.__init
__(self
)
96 self
.settings
= QtCore
.QSettings()
101 def savesettings(self
):
102 """ reimplement this"""
105 def _add_widget(self
, widget
, label
= '', tooltip
= ''):
106 """adds a widget with label"""
107 if not self
.layout():
108 self
.plugin
.logger
.error('Attempted to call add_widget with no layout set.')
109 widget
.setToolTip(tooltip
)
110 layout
= QtGui
.QHBoxLayout()
111 layout
.addWidget(QtGui
.QLabel(label
))
112 layout
.addWidget(widget
)
113 self
.layout().addLayout(layout
)
115 def get_settings_widget(self
):
116 """Should return subclassed SettingsWidget."""
119 def _get_dock_widget(self
):
120 """Override this one."""
122 def _create_dock(self
, widget
):
123 """Creates a QDockWidget with _parent $_parent containing widget $widget."""
124 dock
=QtGui
.QDockWidget(self
.name
, QtGui
.QApplication
.instance().main_win
)
125 dock
.setObjectName(self
.name
)
126 dock
.setWidget(widget
)
127 dock
.setAllowedAreas(QtCore
.Qt
.AllDockWidgetAreas
)
131 """Override this one."""
134 """Override this one."""