Index: pygmy
===================================================================
--- pygmy (revision 47)
+++ pygmy (working copy)
@@ -27,5 +27,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
+import sys
import pygmy
-pygmy.main()
+
+try:
+ pygmy.main()
+except KeyboardInterrupt:
+ sys.exit()
Index: pygmy.py
===================================================================
--- pygmy.py (revision 47)
+++ pygmy.py (working copy)
@@ -76,12 +76,16 @@
messages[(host, port, password)] = 'printed'
return c
-class Empty:
- # Just an empty class for a very specific purpose
- def get(self, one, two):
- pass
+class WindowProps:
+ def __init__(self, x, y, w, h, we=0, he=0, visible=True):
+ self.x = x
+ self.y = y
+ self.w = w
+ self.h = h
+ self.we = we
+ self.he = he
+ self.visible = visible
-
class Client:
def conn(self):
return getConnection(self.host, self.port, self.password)
@@ -152,25 +156,13 @@
self.password = ''
# prev* are used to test on subsequent self.update calls;
# initialize as None.
- self.prevc = 0
- self.prevstatus = Empty()
- self.prevstatus.state = None
- self.prevstatus.song = None
- self.prevstatus.playlist = 0
- self.prevstatus.repeat = 0
- self.prevstatus.random = 0
- self.prevstatus.volume = None
- self.prevsonginfo = Empty()
+ self.prevc = None
+ self.prevstatus = None
+ self.prevsonginfo = None
self.stopaftercurrent = False
self.volume_sliding = False
- self.windowprops = Empty()
- self.windowprops.x, self.windowprops.y = 0, 0
- self.windowprops.w, self.windowprops.h = 250, 72
- self.windowprops.we, self.windowprops.he = 250, 200
- self.playlistwindowprops = Empty()
- self.playlistwindowprops.x, self.playlistwindowprops.y = 0, 0
- self.playlistwindowprops.w, self.playlistwindowprops.h = 375, 250
- self.playlistwindowprops.visible = False
+ self.windowprops = WindowProps(0, 0, 250, 72, 250, 200)
+ self.playlistwindowprops = WindowProps(0, 0, 375, 250, visible=False)
self.format = 'artist:\ntitle'
self.titleformat = 'artist: title - Pygmy'
self.playlistformat = 'artist: title'
@@ -232,8 +224,7 @@
self.w.playlist.set_model(self.playlistdata)
self.playlistdata.connect('row-changed', self.playlist_changed)
self.playlistcell = gtk.CellRendererText()
- self.playlistcolumn = gtk.TreeViewColumn('Pango Markup',
-self.playlistcell, markup=1)
+ self.playlistcolumn = gtk.TreeViewColumn('Pango Markup', self.playlistcell, markup=1)
self.w.playlist.append_column(self.playlistcolumn)
self.selection = self.w.playlist.get_selection()
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
@@ -308,167 +299,166 @@
def update(self):
global count
count += 1
- try:
- if self.conn() is not self.prevc:
- self.prevc = self.conn()
- if self.conn() is None:
- self.w.ppbutton.set_property('sensitive', False)
- self.w.stopbutton.set_property('sensitive', False)
- self.w.prevbutton.set_property('sensitive', False)
- self.w.nextbutton.set_property('sensitive', False)
- self.w.volumebutton.set_property('sensitive', False)
- self.w.playlistbutton.set_property('sensitive', False)
- self.w.rmbutton.set_property('sensitive', False)
- self.w.clbutton.set_property('sensitive', False)
- self.w.repeatbutton.set_property('sensitive', False)
- self.w.shufflebutton.set_property('sensitive', False)
- self.w.statusimage.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR)
- self.w.updateimage.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
-
- try:
- self.trayimage.set_from_stock('pygmy', gtk.ICON_SIZE_BUTTON)
- except:
- pass
-
- self.update_progressbar(False)
- self.w.songlabel.set_text('Playlist')
- self.playlistdata.clear()
- self.tooltips.set_tip(self.w.statusbox, "Not connected")
- self.w.prefsbutton.grab_focus()
-
- return True
-
- elif self.conn() is not None:
- self.w.ppbutton.set_property('sensitive', True)
- self.w.stopbutton.set_property('sensitive', True)
- self.w.prevbutton.set_property('sensitive', True)
- self.w.nextbutton.set_property('sensitive', True)
- self.w.volumebutton.set_property('sensitive', True)
- self.w.playlistbutton.set_property('sensitive', True)
- self.w.rmbutton.set_property('sensitive', True)
- self.w.clbutton.set_property('sensitive', True)
- self.w.repeatbutton.set_property('sensitive', True)
- self.w.shufflebutton.set_property('sensitive', True)
- self.w.statusimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_SMALL_TOOLBAR)
- #self.w.updateimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU)
- self.tooltips.set_tip(self.w.statusbox, "Connected")
- self.w.ppbutton.grab_focus()
-
+
+# try:
+ self.update_conn()
+
+ if self.conn():
self.status = self.conn().do.status()
self.songinfo = self.conn().do.currentsong()
- if not hasattr(self.songinfo, 'artist'):
- self.songinfo.artist = None
- if not hasattr(self.songinfo, 'title'):
- self.songinfo.title = None
- if not hasattr(self.status, 'song'):
- self.status.song = None
-
- # Display current playlist
- if self.prevstatus.playlist != self.status.playlist:
- self.update_playlist()
+ self.update_state()
- # Update progress frequently if we're playing
- if self.status.state in ['play', 'pause']:
- self.update_progressbar(True)
+ self.prevc = self.conn()
+ self.prevstatus = self.status
+ self.prevsonginfo = self.songinfo
- # If state changes
- if self.prevstatus.state != self.status.state:
- # Update progressbar if the state changes too
- self.update_progressbar(True)
- self.update_songtitle()
- if self.status.state == 'stop':
- self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
- try:
- self.trayimage.set_from_stock('pygmy', gtk.ICON_SIZE_BUTTON)
- except:
- pass
+# except (mpdclient.socket.error, EOFError, AttributeError, IndexError):
+# global connections
+# connections = {}
+# self.prevstatus = None
+# except KeyboardInterrupt, e:
+# raise e
- self.tooltips.set_tip(self.w.ppbutton, "Play")
- # Unbold playing song (if we were playing)
- if self.prevstatus.state == 'play':
- oldrow = int(self.prevsonginfo.pos)
- snip = self.playlistdata[oldrow][1]
- if snip[0:3] == '' and snip[-4:] == '':
- self.playlistdata[oldrow][1] = snip[3:-4]
- elif self.status.state == 'pause':
- self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
- try:
- self.trayimage.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON)
- except:
- pass
- self.tooltips.set_tip(self.w.ppbutton, "Play")
- elif self.status.state == 'play':
- self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON)
- try:
- self.trayimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
- except:
- pass
- self.tooltips.set_tip(self.w.ppbutton, "Pause")
- if self.status.state in ['play', 'pause']:
- row = int(self.songinfo.pos)
- self.playlistdata[row][1] = make_bold( self.playlistdata[row][1])
+ return True
- # Only update song info if song has changed
- if self.prevstatus.song != self.status.song:
- if self.stopaftercurrent == True:
- self.conn().do.stop()
- self.stopaftercurrent = False
- self.prevstatus = self.status
- self.prevsonginfo = self.songinfo
- return True
- self.update_windowtitle()
+ def update_conn(self):
+ if self.conn() != self.prevc:
+ if self.conn() is None:
+ self.w.ppbutton.set_property('sensitive', False)
+ self.w.stopbutton.set_property('sensitive', False)
+ self.w.prevbutton.set_property('sensitive', False)
+ self.w.nextbutton.set_property('sensitive', False)
+ self.w.volumebutton.set_property('sensitive', False)
+ self.w.playlistbutton.set_property('sensitive', False)
+ self.w.rmbutton.set_property('sensitive', False)
+ self.w.clbutton.set_property('sensitive', False)
+ self.w.repeatbutton.set_property('sensitive', False)
+ self.w.shufflebutton.set_property('sensitive', False)
+ self.w.statusimage.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ self.w.updateimage.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
+
+ try:
+ self.trayimage.set_from_stock('pygmy', gtk.ICON_SIZE_BUTTON)
+ except:
+ pass
+
+ self.update_progressbar(False)
self.update_songtitle()
-
- # Unbold all songs. If you have a better idea, let me know.
- for song in self.playlistdata:
- if song[1][0:3] == '' and song[1][-4:] == '':
- self.playlistdata[song.path[0]][1] = song[1][3:-4]
+ self.update_windowtitle()
+ self.playlistdata.clear()
+ self.tooltips.set_tip(self.w.statusbox, "Not connected")
+ self.w.prefsbutton.grab_focus()
- if self.status.state in ['play', 'pause']:
- row = int(self.songinfo.pos)
- self.playlistdata[row][1] = make_bold(self.playlistdata[row][1])
+ else:
+ self.w.ppbutton.set_property('sensitive', True)
+ self.w.stopbutton.set_property('sensitive', True)
+ self.w.prevbutton.set_property('sensitive', True)
+ self.w.nextbutton.set_property('sensitive', True)
+ self.w.volumebutton.set_property('sensitive', True)
+ self.w.playlistbutton.set_property('sensitive', True)
+ self.w.rmbutton.set_property('sensitive', True)
+ self.w.clbutton.set_property('sensitive', True)
+ self.w.repeatbutton.set_property('sensitive', True)
+ self.w.shufflebutton.set_property('sensitive', True)
+ self.w.statusimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ #self.w.updateimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU)
+ self.tooltips.set_tip(self.w.statusbox, "Connected")
+ self.w.ppbutton.grab_focus()
+ self.prevc = self.conn()
- self.tooltips.set_tip(self.trayeventbox, self.songinfo.artist + ':' + '\n' + self.songinfo.title)
- self.after_expander_activate(self.w.expander)
+ def update_state(self):
+ if not hasattr(self.status, 'song'):
+ self.status.song = None
+
+ # Display current playlist
+ if self.prevstatus is None or self.prevstatus.playlist != self.status.playlist:
+ self.update_playlist()
- # If shuffle/repeat have changed, update the button state
- if self.status.repeat != self.prevstatus.repeat:
- self.w.repeatbutton.handler_block(self.repeatid)
- self.w.repeatbutton.set_active('1' == self.status.repeat)
- self.w.repeatbutton.handler_unblock(self.repeatid)
- if self.status.random != self.prevstatus.random:
- self.w.shufflebutton.handler_block(self.shuffleid)
- self.w.shufflebutton.set_active('1' == self.status.random)
- self.w.shufflebutton.handler_unblock(self.shuffleid)
+ # Update progress frequently if we're playing
+ if self.status.state in ['play', 'pause']:
+ self.update_progressbar(True)
- # Check if MPD is updating the library
- if self.prevstatus.get('updating_db', 0) != self.status.get('updating_db', 0):
- if self.status.get('updating_db', 0):
- self.w.statusimage.set_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_SMALL_TOOLBAR)
- self.tooltips.set_tip(self.w.statusbox, "Updating...")
- else:
- self.w.statusimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_SMALL_TOOLBAR)
- self.tooltips.set_tip(self.w.statusbox, "Connected")
-
- if self.status.volume != self.prevstatus.volume:
- self.w.volumescale.get_adjustment().set_value(int(self.status.volume))
+ # If state changes
+ if self.prevstatus is None or self.prevstatus.state != self.status.state:
+ # Update progressbar if the state changes too
+ self.update_progressbar(True)
+ self.update_windowtitle()
+ self.update_songtitle()
+ if self.status.state == 'stop':
+ self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
+ try:
+ self.trayimage.set_from_stock('pygmy', gtk.ICON_SIZE_BUTTON)
+ except:
+ pass
- self.prevstatus = self.status
- self.prevsonginfo = self.songinfo
-
- except (mpdclient.socket.error, EOFError, AttributeError, IndexError):
- global connections
- connections = {}
- self.prevstatus.state = None
- self.prevstatus.song = None
- self.prevstatus.playlist = 0
- self.prevstatus.repeat = 0
- self.prevstatus.random = 0
- self.prevstatus.volume = None
- except KeyboardInterrupt:
- sys.exit()
- return True
+ self.tooltips.set_tip(self.w.ppbutton, "Play")
+ # Unbold playing song (if we were playing)
+ if self.prevstatus and self.prevstatus.state == 'play':
+ oldrow = int(self.prevsonginfo.pos)
+ snip = self.playlistdata[oldrow][1]
+ if snip[0:3] == '' and snip[-4:] == '':
+ self.playlistdata[oldrow][1] = snip[3:-4]
+ elif self.status.state == 'pause':
+ self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
+ try:
+ self.trayimage.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON)
+ except:
+ pass
+ self.tooltips.set_tip(self.w.ppbutton, "Play")
+ elif self.status.state == 'play':
+ self.w.ppimage.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON)
+ try:
+ self.trayimage.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
+ except:
+ pass
+ self.tooltips.set_tip(self.w.ppbutton, "Pause")
+ if self.status.state in ['play', 'pause']:
+ row = int(self.songinfo.pos)
+ self.playlistdata[row][1] = make_bold( self.playlistdata[row][1])
+ # Only update song info if song has changed
+ if self.prevstatus is None or self.prevstatus.song != self.status.song:
+ if self.stopaftercurrent == True:
+ self.conn().do.stop()
+ self.stopaftercurrent = False
+ return
+ self.update_windowtitle()
+ self.update_songtitle()
+
+ # Unbold all songs. If you have a better idea, let me know.
+ for song in self.playlistdata:
+ if song[1][0:3] == '' and song[1][-4:] == '':
+ self.playlistdata[song.path[0]][1] = song[1][3:-4]
+
+ if self.status.state in ['play', 'pause']:
+ row = int(self.songinfo.pos)
+ self.playlistdata[row][1] = make_bold(self.playlistdata[row][1])
+
+ self.tooltips.set_tip(self.trayeventbox, parse_format(self.playlistformat, self.songinfo))
+ self.after_expander_activate(self.w.expander)
+
+ # If shuffle/repeat have changed, update the button state
+ if self.prevstatus is None or self.status.repeat != self.prevstatus.repeat:
+ self.w.repeatbutton.handler_block(self.repeatid)
+ self.w.repeatbutton.set_active('1' == self.status.repeat)
+ self.w.repeatbutton.handler_unblock(self.repeatid)
+ if self.prevstatus is None or self.status.random != self.prevstatus.random:
+ self.w.shufflebutton.handler_block(self.shuffleid)
+ self.w.shufflebutton.set_active('1' == self.status.random)
+ self.w.shufflebutton.handler_unblock(self.shuffleid)
+
+ # Check if MPD is updating the library
+ if self.prevstatus and self.prevstatus.get('updating_db', 0) != self.status.get('updating_db', 0):
+ if self.status.get('updating_db', 0):
+ self.w.statusimage.set_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ self.tooltips.set_tip(self.w.statusbox, "Updating...")
+ else:
+ self.w.statusimage.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ self.tooltips.set_tip(self.w.statusbox, "Connected")
+
+ if self.prevstatus and self.status.volume != self.prevstatus.volume:
+ self.w.volumescale.get_adjustment().set_value(int(self.status.volume))
+
# Don't touch the text every time if timecheckbutton is False
def update_progressbar(self, connected):
if connected:
@@ -512,6 +502,8 @@
if self.status.state in ['play', 'pause']:
row = int(self.songinfo.pos)
self.playlistdata[row][1] = make_bold( self.playlistdata[row][1])
+
+ self.tooltips.set_tip(self.trayeventbox, parse_format(self.playlistformat, self.songinfo))
def update_browser(self):
self.pm.update_browser(self.playlistformat)
@@ -1136,12 +1128,8 @@
pass
def main():
- try:
- Pygmy()
- gtk.main()
- except KeyboardInterrupt:
- sys.exit()
- return 0
+ Pygmy()
+ gtk.main()
if __name__ == "__main__":
main()