~ubuntu-branches/ubuntu/lucid/exaile/lucid

« back to all changes in this revision

Viewing changes to xlgui/prefs/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2010-02-12 19:51:01 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100212195101-8jt3tculxcl92e6v
Tags: 0.3.1~b1-0ubuntu1
* New upstream release.
* Adjust exaile.install for new plugins.
* debian/control:
 - Drop unneeded python-dev Build-Dep.
 - Bump Standards-Version to 3.8.4 
* debian/rules: No empty po files to delete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2009 Adam Olsen 
 
1
# Copyright (C) 2008-2009 Adam Olsen
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
16
#
17
17
#
18
 
# The developers of the Exaile media player hereby grant permission 
19
 
# for non-GPL compatible GStreamer and Exaile plugins to be used and 
20
 
# distributed together with GStreamer and Exaile. This permission is 
21
 
# above and beyond the permissions granted by the GPL license by which 
22
 
# Exaile is covered. If you modify this code, you may extend this 
23
 
# exception to your version of the code, but you are not obligated to 
24
 
# do so. If you do not wish to do so, delete this exception statement 
25
 
# from your version.
26
 
#
27
 
#
28
 
# The developers of the Exaile media player hereby grant permission 
29
 
# for non-GPL compatible GStreamer and Exaile plugins to be used and 
30
 
# distributed together with GStreamer and Exaile. This permission is 
31
 
# above and beyond the permissions granted by the GPL license by which 
32
 
# Exaile is covered. If you modify this code, you may extend this 
33
 
# exception to your version of the code, but you are not obligated to 
34
 
# do so. If you do not wish to do so, delete this exception statement 
 
18
# The developers of the Exaile media player hereby grant permission
 
19
# for non-GPL compatible GStreamer and Exaile plugins to be used and
 
20
# distributed together with GStreamer and Exaile. This permission is
 
21
# above and beyond the permissions granted by the GPL license by which
 
22
# Exaile is covered. If you modify this code, you may extend this
 
23
# exception to your version of the code, but you are not obligated to
 
24
# do so. If you do not wish to do so, delete this exception statement
35
25
# from your version.
36
26
 
37
 
import thread, os, shlex, string, urllib2
38
 
from xl.nls import gettext as _
 
27
import gobject
39
28
import inspect
 
29
import logging
 
30
import os
 
31
import shlex
 
32
import string
 
33
import thread
 
34
import traceback
 
35
import urllib2
 
36
 
40
37
import pygtk
41
38
pygtk.require('2.0')
42
 
import gtk, gtk.glade
 
39
import gtk
 
40
 
 
41
from xl.nls import gettext as _
43
42
from xl import xdg
44
43
from xl.settings import _SETTINGSMANAGER
45
44
from xlgui.prefs.widgets import *
46
 
from xlgui.prefs import playlists_prefs, osd_prefs
 
45
from xlgui.prefs import playlists_prefs, osd_prefs, collection_prefs
47
46
from xlgui.prefs import cover_prefs, playback_prefs, appearance_prefs
48
47
from xlgui.prefs import plugin_prefs
49
 
import logging, traceback, gobject
50
48
 
51
49
logger = logging.getLogger(__name__)
52
50
 
55
53
        Preferences Dialog
56
54
    """
57
55
 
58
 
    PAGES = (playlists_prefs, appearance_prefs, playback_prefs, 
59
 
        osd_prefs, cover_prefs)
 
56
    PAGES = (playlists_prefs, appearance_prefs, playback_prefs,
 
57
        collection_prefs, osd_prefs, cover_prefs)
60
58
    PREFERENCES_DIALOG = None
61
59
 
62
60
    def __init__(self, parent, main):
67
65
        self.last_child = None
68
66
        self.last_page = None
69
67
        self.parent = parent
70
 
        self.settings = _SETTINGSMANAGER.clone()
 
68
        self.settings = _SETTINGSMANAGER
71
69
        self.plugins = self.main.exaile.plugins.list_installed_plugins()
72
 
        self.fields = {} 
 
70
        self.fields = {}
73
71
        self.panes = {}
74
72
        self.builders = {}
75
73
        self.popup = None
76
74
 
77
 
        self.xml = xml = gtk.glade.XML(
78
 
            xdg.get_data_path('glade/preferences_dialog.glade'), 
79
 
            'PreferencesDialog', 'exaile')
 
75
        self.builder = gtk.Builder()
 
76
        self.builder.set_translation_domain('exaile')
 
77
        self.builder.add_from_file(
 
78
            xdg.get_data_path('ui/preferences_dialog.ui'))
80
79
 
81
 
        self.window = xml.get_widget('PreferencesDialog')
 
80
        self.window = self.builder.get_object('PreferencesDialog')
82
81
        self.window.set_transient_for(parent)
83
82
        self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
84
83
        self.window.connect('delete-event', lambda *e: self.cancel())
85
84
 
86
85
        self._connect_events()
87
86
 
88
 
        self.label = xml.get_widget('prefs_frame_label')
89
 
        self.box = xml.get_widget('prefs_box')
 
87
        self.box = self.builder.get_object('prefs_box')
90
88
 
91
 
        self.tree = xml.get_widget('prefs_tree')
 
89
        self.tree = self.builder.get_object('prefs_tree')
92
90
        text = gtk.CellRendererText()
93
91
        col = gtk.TreeViewColumn(_('Preferences'), text, text=0)
94
92
        self.tree.append_column(col)
119
117
        self._clear_children(self.plug_root)
120
118
        plugin_pages = []
121
119
        plugin_manager = self.main.exaile.plugins
122
 
        
 
120
 
123
121
        for plugin in self.plugins:
124
122
            name = plugin
125
123
            if plugin in plugin_manager.enabled_plugins:
131
129
                        logger.warning('Error loading preferences pane')
132
130
                        traceback.print_exc()
133
131
 
 
132
        import locale
 
133
        plugin_pages.sort(key=lambda x: locale.strxfrm(x.name))
 
134
 
134
135
        for page in plugin_pages:
135
136
            self.model.append(self.plug_root, [page.name, page])
136
137
 
151
152
        """
152
153
            Connects the various events to their handlers
153
154
        """
154
 
        self.xml.signal_autoconnect({
 
155
        self.builder.connect_signals({
155
156
            'on_cancel_button_clicked': lambda *e: self.cancel(),
156
157
            'on_apply_button_clicked': self.apply,
157
158
            'on_ok_button_clicked': self.ok,
161
162
        """
162
163
            Called when the user clicks 'ok'
163
164
        """
164
 
        if self.apply(None): 
 
165
        if self.apply(None):
165
166
            self.cancel()
166
167
            self.window.hide()
167
168
            self.window.destroy()
204
205
        if not iter: return
205
206
        page = self.model.get_value(iter, 1)
206
207
        if not page: return
207
 
        self.label.set_markup("<b>%s</b>" %
208
 
            page.name)
209
208
 
210
209
        if self.last_child:
211
210
            self.box.remove(self.last_child)
212
211
 
213
212
        if self.last_page:
214
 
            if hasattr(self.last_page, 'page_leave'): 
 
213
            if hasattr(self.last_page, 'page_leave'):
215
214
                self.last_page.page_leave(self)
216
215
 
217
216
        self.last_page = page
219
218
        child = self.panes.get(page)
220
219
        if not child:
221
220
            if hasattr(page, 'ui'):
 
221
                import gtk
222
222
                builder = gtk.Builder()
223
223
                builder.add_from_file(page.ui)
224
224
            else:
225
 
                builder = gtk.glade.XML(page.glade, 'prefs_pane')
226
 
                builder.get_object = builder.get_widget
 
225
                try:
 
226
                    logger.warning('Please switch to gtk.Builder for preferences panes')
 
227
                    import gtk.glade
 
228
                    builder = gtk.glade.XML(page.glade, 'prefs_pane')
 
229
                    builder.get_object = builder.get_widget
 
230
                    builder.connect_signals = builder.signal_autoconnect
 
231
                except ImportError:
 
232
                    logger.error('Importing Glade as fallback failed')
 
233
                    return
 
234
 
227
235
            child = builder.get_object('prefs_pane')
228
236
            init = getattr(page, 'init', None)
229
237
            if init: init(self, builder)
235
243
 
236
244
        if hasattr(page, 'page_enter'):
237
245
            page.page_enter(self)
238
 
                
 
246
 
 
247
        child.unparent()
239
248
        self.box.pack_start(child, True, True)
240
249
        self.last_child = child
241
250
        self.box.show_all()
251
260
            try:
252
261
                klass = getattr(page, attr)
253
262
                if inspect.isclass(klass) and \
254
 
                    issubclass(klass, widgets.PrefsItem): 
 
263
                    issubclass(klass, widgets.PrefsItem):
255
264
                    widget = builder.get_object(klass.name)
256
265
                    if not widget:
257
 
                        logger.warning('Invalid prefs widget: %s' % klass.name) 
 
266
                        logger.warning('Invalid prefs widget: %s' % klass.name)
258
267
                        continue
259
268
                    field = klass(self, widget)
260
269
                    self.fields[page].append(field)
261
270
            except:
262
271
                logger.warning('Broken prefs class: %s' % attr)
263
272
                traceback.print_exc()
264
 
 
 
273
 
265
274
    def run(self):
266
275
        """
267
276
            Runs the dialog