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
):
42 def __init__(self
, parent
, mpclient
, name
):
43 QtCore
.QObject
.__init
__(self
)
45 self
.mpclient
= mpclient
48 self
.settings
= QtCore
.QSettings()
50 self
.logger
= logging
.getLogger(self
.name
)
53 self
.logger
.debug('Initializing default settings.')
54 self
.settings
.beginGroup(name
)
55 for key
in self
.DEFAULTS
:
56 if not self
.settings
.contains(key
):
57 self
.settings
.setValue(key
, QVariant(self
.DEFAULTS
[key
]))
58 self
.settings
.endGroup()
62 def set_status(self
, status
):
63 self
._parent
.setStatus(status
)
66 self
.logger
.info('loading')
68 opts
= QtGui
.QDockWidget
.DockWidgetClosable|QtGui
.QDockWidget
.DockWidgetMovable
69 QtGui
.QApplication
.instance().main_win
.add_dock(self
.get_dock_widget(opts
))
70 QtGui
.QApplication
.instance().main_win
.restore_layout()
71 self
.mpclient
.connect_changed
.connect(self
.set_enabled
)
76 self
.logger
.info("unloading")
78 dock_widget
= self
.get_dock_widget()
80 QtGui
.QApplication
.instance().main_win
.remove_dock(dock_widget
)
81 self
._dock
_widget
= None
82 self
.settingsWidget
= None
83 self
.mpclient
.connect_changed
.disconnect(self
.set_enabled
)
85 def set_enabled(self
, val
):
87 self
.o
.setEnabled(val
)
89 def get_dock_widget(self
, opts
= None):
90 self
._dock
_widget
= self
._get
_dock
_widget
()
91 if self
._dock
_widget
and opts
:
92 self
._dock
_widget
.setFeatures(opts
)
93 self
._dock
_widget
.setAllowedAreas(QtCore
.Qt
.AllDockWidgetAreas
)
94 return self
._dock
_widget
96 class SettingsWidget(QtGui
.QWidget
):
97 """ plugins should subclass this"""
101 def __init__(self
, plugin
):
102 QtGui
.QWidget
.__init
__(self
)
104 self
.settings
= QtCore
.QSettings()
109 def savesettings(self
):
110 """ reimplement this"""
113 def _add_widget(self
, widget
, label
= '', tooltip
= ''):
114 """adds a widget with label"""
115 if not self
.layout():
116 self
.plugin
.logger
.error('Attempted to call add_widget with no layout set.')
117 widget
.setToolTip(tooltip
)
118 layout
= QtGui
.QHBoxLayout()
119 layout
.addWidget(QtGui
.QLabel(label
))
120 layout
.addWidget(widget
)
121 self
.layout().addLayout(layout
)
123 def get_settings_widget(self
):
124 """Should return subclassed SettingsWidget."""
127 def _get_dock_widget(self
):
128 """Override this one."""
130 def _create_dock(self
, widget
):
131 """Creates a QDockWidget with _parent $_parent containing widget $widget."""
132 dock
=QtGui
.QDockWidget(self
.name
, QtGui
.QApplication
.instance().main_win
)
133 dock
.setObjectName(self
.name
)
134 dock
.setWidget(widget
)
138 """Override this one."""
141 """Override this one."""