Changeset 51
- Timestamp:
- 02/25/06 22:57:18 (3 years ago)
- Files:
-
- trunk/Makefile.in (modified) (1 diff)
- trunk/src/audio_control.py (modified) (3 diffs)
- trunk/src/config.py (added)
- trunk/src/gtk_utils.py (added)
- trunk/src/main_window.py (modified) (7 diffs)
- trunk/src/mesk/__init__.py (modified) (4 diffs)
- trunk/src/mesk/audio_source.py (modified) (1 diff)
- trunk/src/mesk/common/config.py (modified) (1 diff)
- trunk/src/mesk/playlist.py (modified) (1 diff)
- trunk/src/mesk/utils.py (modified) (2 diffs)
- trunk/src/playlist_control.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Makefile.in
r28 r51 78 78 -rm Makefile 79 79 -rm ./src/*.glade.* ./src/*.gladep* 80 -rm ./svn-commit* 80 81 81 82 maintainer-clean: dist-clean docs-clean trunk/src/audio_control.py
r46 r51 53 53 self._rewind_flag = False 54 54 self._rewind_set = False 55 self._gap_delay = mesk.config.getint(mesk. AUDIO, 'gst_delay')55 self._gap_delay = mesk.config.getint(mesk.CONFIG_AUDIO, 'gst_delay') 56 56 57 57 # Get widgets … … 289 289 self._set_track_scale(0, upper = src.audio_info.time_secs) 290 290 291 uri = src.uri 292 # Strip file:// since the file sink does not deal with it. 293 if uri.find("file://") == 0: 294 uri = uri[len("file://"):] 291 uri = mesk.utils.strip_file_uri(src.uri) 295 292 self._src.set_property('location', uri) 296 293 … … 391 388 392 389 def _create_audio_sink(self): 393 config_sink = mesk.config.get(mesk. AUDIO, 'gst_sink')390 config_sink = mesk.config.get(mesk.CONFIG_AUDIO, 'gst_sink') 394 391 if config_sink == mesk.GST_OSS: 395 392 audio_sink = gst.element_factory_make("osssink", "audio_sink") trunk/src/main_window.py
r37 r51 23 23 from playlist_control import PlaylistControl 24 24 25 import config 26 25 27 import mesk 26 28 _ = mesk.common.i18n._ … … 45 47 self.audio_control = AudioControl(self.xml) 46 48 49 self._active_playlist = None 47 50 # Load playlists 48 self._active_playlist = None 49 for pl_config in mesk.config.items(mesk.PLAYLISTS): 50 pl = mesk.playlist.load(pl_config[1]) 51 pl_ctrl = PlaylistControl(pl_config[0], pl, self.audio_control) 51 playlists = config.playlist_names() 52 for pl in playlists: 53 if not config.playlist_auto_open(pl): 54 continue 55 56 try: 57 pl_ctrl = PlaylistControl(pl, self.audio_control) 58 except Exception, ex: 59 msg = _("Error loading playlist '%s'") % (pl) 60 d = gtk.MessageDialog(None, gtk.DIALOG_MODAL, 61 type = gtk.MESSAGE_ERROR, 62 buttons = gtk.BUTTONS_OK, 63 message_format = msg) 64 d.format_secondary_text(str(ex)) 65 d.run() 66 d.destroy() 67 continue 68 52 69 self.add_notebook_control(pl_ctrl) 53 # FIXME: Only one of the playlists may be the active playlist54 70 if not self._active_playlist: 55 71 self._active_playlist = pl_ctrl 56 72 57 self._active_playlist.set_active(True) 58 self.audio_control.set_playlist(self._active_playlist.get_playlist()) 73 if self._active_playlist: 74 self._active_playlist.set_active(True) 75 pl = self._active_playlist.get_playlist() 76 self.audio_control.set_playlist(pl) 59 77 60 78 def add_notebook_control(self, ctrl): … … 65 83 66 84 def show(self): 67 compact = mesk.config.getboolean(mesk. UI, 'compact_state')85 compact = mesk.config.getboolean(mesk.CONFIG_UI, 'compact_state') 68 86 self.xml.get_widget('compact_menuitem').set_active(compact) 69 87 … … 88 106 (x, y) = self.window.get_position() 89 107 if not self._is_compact: 90 mesk.config.set(mesk. UI, 'main_window_width', str(width))91 mesk.config.set(mesk. UI, 'main_window_height', str(height))92 mesk.config.set(mesk. UI, 'main_window_pos_x', str(x))93 mesk.config.set(mesk. UI, 'main_window_pos_y', str(y))108 mesk.config.set(mesk.CONFIG_UI, 'main_window_width', str(width)) 109 mesk.config.set(mesk.CONFIG_UI, 'main_window_height', str(height)) 110 mesk.config.set(mesk.CONFIG_UI, 'main_window_pos_x', str(x)) 111 mesk.config.set(mesk.CONFIG_UI, 'main_window_pos_y', str(y)) 94 112 else: 95 mesk.config.set(mesk. UI, 'compact_main_window_pos_x', str(x))96 mesk.config.set(mesk. UI, 'compact_main_window_pos_y', str(y))113 mesk.config.set(mesk.CONFIG_UI, 'compact_main_window_pos_x', str(x)) 114 mesk.config.set(mesk.CONFIG_UI, 'compact_main_window_pos_y', str(y)) 97 115 98 116 def _restore_window_attrs(self): 99 width = mesk.config.getint(mesk. UI, 'main_window_width')100 height = mesk.config.getint(mesk. UI, 'main_window_height')101 x = mesk.config.getint(mesk. UI, 'main_window_pos_x')102 y = mesk.config.getint(mesk. UI, 'main_window_pos_y')117 width = mesk.config.getint(mesk.CONFIG_UI, 'main_window_width') 118 height = mesk.config.getint(mesk.CONFIG_UI, 'main_window_height') 119 x = mesk.config.getint(mesk.CONFIG_UI, 'main_window_pos_x') 120 y = mesk.config.getint(mesk.CONFIG_UI, 'main_window_pos_y') 103 121 104 122 self.window.resize(width, height) … … 107 125 ### Window event callbacks ### 108 126 def _on_window_delete(self, widget, event): 109 if mesk.config.getboolean(mesk. UI, 'window_hide_on_close'):127 if mesk.config.getboolean(mesk.CONFIG_UI, 'window_hide_on_close'): 110 128 self.window.hide() 111 129 return True … … 137 155 138 156 # Restore compact window position 139 x = mesk.config.getint(mesk. UI, 'compact_main_window_pos_x')140 y = mesk.config.getint(mesk. UI, 'compact_main_window_pos_y')157 x = mesk.config.getint(mesk.CONFIG_UI, 'compact_main_window_pos_x') 158 y = mesk.config.getint(mesk.CONFIG_UI, 'compact_main_window_pos_y') 141 159 self.window.move(x, y) 142 160 else: … … 149 167 150 168 self._is_compact = state 151 mesk.config.set(mesk. UI, 'compact_state', str(state))169 mesk.config.set(mesk.CONFIG_UI, 'compact_state', str(state)) 152 170 153 171 def _on_open_menuitem_activate(self, widget): trunk/src/mesk/__init__.py
r42 r51 30 30 MESK_DIR = os.path.expandvars('${HOME}/.%s' % APP_NAME.lower()) 31 31 PLAYLISTS_DIR = "%s/playlists" 32 32 33 GLADE_XML = 'mesk_gui.glade' 33 34 34 35 # Sections 35 MAIN= 'mesk'36 UI= 'ui'37 AUDIO= 'audio'38 PLAYLISTS = 'playlists'36 CONFIG_MAIN = 'mesk' 37 CONFIG_UI = 'ui' 38 CONFIG_AUDIO = 'audio' 39 CONFIG_PLAYLIST = 'playlist' 39 40 40 41 # GST sinks … … 43 44 GST_ESD = 'esd' 44 45 46 DEFAULT_PLAYLIST_NAME = 'mesk' 47 DEFAULT_PLAYLIST_URI = 'file://%s/%s' % (PLAYLISTS_DIR, DEFAULT_PLAYLIST_NAME) 48 45 49 # Program options 46 50 # section: {opt_name: [type, default, enum_choices, help_string]} 47 51 options = { 48 MAIN: {52 CONFIG_MAIN: { 49 53 'version': [str, APP_VERSION, None, _('Application version')], 54 'playlists': [str, DEFAULT_PLAYLIST_NAME, None, 55 _('A list of playlists (separated by \';\') that refer to ' 56 'a playlist config section below')] 50 57 }, 51 58 52 UI: {59 CONFIG_UI: { 53 60 'compact_state': [bool, True, None, _('Start in compact view mode')], 54 61 'window_hide_on_close': [bool, False, None, … … 66 73 }, 67 74 68 AUDIO: {75 CONFIG_AUDIO: { 69 76 'gst_sink': [str, GST_ALSA, None, 70 77 _("GStreamer output sink. May be '%s', '%s', '%s'") % \ … … 74 81 }, 75 82 76 PLAYLISTS: { 77 '%s' % APP_NAME: [str, '%s/%s.m3u' % (MESK_DIR, APP_NAME), None, 78 _('Default playlist')] 83 CONFIG_PLAYLIST + '.' + DEFAULT_PLAYLIST_NAME: { 84 'uri': [str, DEFAULT_PLAYLIST_URI, None, _('Playlist (file) location')], 85 'auto-open': [bool, True, None, _('Open on startup')], 86 'current': [int, 0, None, _('Starting playlist index')], 87 'repeat': [bool, False, None, _('Is the playlist in repeat mode')], 88 'shuffle': [bool, False, None, _('Is the playlist in shuffle mode')], 79 89 }, 80 90 } trunk/src/mesk/audio_source.py
r28 r51 33 33 class FileAudioSource(AudioSource): 34 34 def __init__(self, file_path): 35 # Hack for gstreamer, which does not like real uris for local files36 if file_path.find('file://') == 0:37 file_path = file_path.split('file://')[1]38 35 AudioSource.__init__(self, file_path) 39 36 trunk/src/mesk/common/config.py
r31 r51 61 61 else: 62 62 # FIXME: Migrage configs 63 if not self.has_section(sect): 64 self.add_section(sect) 63 65 self.set(sect, opt, val) 64 66 trunk/src/mesk/playlist.py
r50 r51 20 20 import sys, os.path 21 21 import random 22 22 23 import audio_source 24 import utils 23 25 24 26 def load(pl_source): 25 27 pl = Playlist() 26 28 if os.path.splitext(pl_source)[1] == '.m3u': 29 pl_source = utils.strip_file_uri(pl_source) 27 30 if not os.path.exists(pl_source): 28 31 fp = file(pl_source, 'w') trunk/src/mesk/utils.py
r50 r51 20 20 # $Id$ 21 21 ################################################################################ 22 23 import gtk, pango24 22 25 23 import common.i18n … … 65 63 return tstr 66 64 67 # This function was ripped from Gajim (http://www.gajim.org) 68 def get_default_font(): 69 '''Get the desktop setting for application font 70 first check for GNOME, then XFCE and last KDE 71 it returns None on failure or else a string 'Font Size' ''' 72 73 # Gnome/gconf 74 try: 75 import gconf 76 # in try because daemon may not be there 77 client = gconf.client_get_default() 78 79 return client.get_string('/desktop/gnome/interface/font_name') 80 except: 81 pass 82 83 # try to get xfce default font 84 # Xfce 4.2 adopts freedesktop.org's Base Directory Specification 85 # see http://www.xfce.org/~benny/xfce/file-locations.html 86 # and http://freedesktop.org/Standards/basedir-spec 87 xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '') 88 if xdg_config_home == '': 89 xdg_config_home = os.path.expanduser('~/.config') # default 90 xfce_config_file = os.path.join(xdg_config_home, 91 'xfce4/mcs_settings/gtk.xml') 92 93 # KDE 94 kde_config_file = os.path.expanduser('~/.kde/share/config/kdeglobals') 95 96 if os.path.exists(xfce_config_file): 97 try: 98 for line in file(xfce_config_file): 99 if line.find('name="Gtk/FontName"') != -1: 100 start = line.find('value="') + 7 101 return line[start:line.find('"', start)] 102 except: 103 #we talk about file 104 print >> sys.stderr, \ 105 _('Error: cannot open %s for reading') % xfce_config_file 106 elif os.path.exists(kde_config_file): 107 try: 108 for line in file(kde_config_file): 109 if line.find('font=') == 0: # font=Verdana,9,other_numbers 110 start = 5 # 5 is len('font=') 111 line = line[start:] 112 values = line.split(',') 113 font_name = values[0] 114 font_size = values[1] 115 font_string = '%s %s' % (font_name, font_size) # Verdana 9 116 return font_string 117 except: 118 #we talk about file 119 print >> sys.stderr, \ 120 _('Error: cannot open %s for reading') % kde_config_file 121 122 return 'Sans 10' 65 def strip_file_uri(uri): 66 file_path = uri 67 if uri.find('file://') == 0: 68 file_path = uri.split('file://')[1] 69 return file_path trunk/src/playlist_control.py
r48 r51 26 26 _ = mesk.common.i18n._ 27 27 28 import gtk_utils, config 29 28 30 # Data model: 29 31 (COL_STATUS_IMG, … … 34 36 class PlaylistControl(gobject.GObject): 35 37 36 def __init__(self, name, playlist,audio_control):38 def __init__(self, name, audio_control): 37 39 self.name = name 40 38 41 self._is_active = False 39 42 self._playlist = None … … 97 100 self._pl_view.append_column(col) 98 101 102 # Load playlist 103 self._pl_config = config.PlaylistConfig(self.name) 104 pl = mesk.playlist.load(self._pl_config.uri) 105 pl.set_shuffle(self._pl_config.shuffle) 106 pl.set_repeat(self._pl_config.repeat) 107 pl.set_curr_index(self._pl_config.current - 1) 108 99 109 # Fill playlist model 100 self.set_playlist(pl aylist)110 self.set_playlist(pl) 101 111 102 112 self._pl_view.set_model(self._pl_model) … … 129 139 130 140 shuffled = self._playlist.is_shuffled() 141 repeating = self._playlist.is_repeating() 131 142 self.widget_xml.get_widget('shuffle_checkbutton').set_active(shuffled) 143 self.widget_xml.get_widget('repeat_checkbutton').set_active(repeating) 132 144 133 145 self._update_playlist_stats() … … 326 338 self._txt_renderer = gtk.CellRendererText() 327 339 # Make text font slightly smaller 328 font = mesk.utils.get_default_font()340 font = gtk_utils.get_default_font() 329 341 font_desc = pango.FontDescription(font) 330 342 # 1024 pango units per device unit, subtract 2 points
