annotate bin/ascoltami @ 229:c5a79314afdf

bigger asco window
author drewp@bigasterisk.com
date Sun, 05 Jun 2005 07:03:32 +0000
parents c7797ad42684
children d19c607c41dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
1 #!/usr/bin/env python
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
2
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
3 # this is a fork from semprini/ascotalmi to use mpd
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
4
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
5 """ a separate player program from Semprini.py. name means 'listen to
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
6 me' in italian.
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
7
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
8 features and limitations:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
9
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
10 xmlrpc interface for:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
11 getting the current time in the playing song
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
12 requesting what song is playing
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
13 saying what song should play
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
14
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
15 todo:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
16
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
17 presong and postsong silence
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
18
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
19 """
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
20
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
21 from __future__ import division,nested_scopes
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
22
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
23 from optparse import OptionParser
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
24 import os,math,time
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
25 import Tkinter as tk
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
26
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
27 from twisted.internet import reactor,tksupport
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
28 from twisted.internet.error import CannotListenError
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
29 from twisted.web import xmlrpc, server
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
30
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
31 import run_local
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
32 from light9 import networking, showconfig
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
33
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
34 from pympd import Mpd
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
35
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
36 appstyle={'fg':'white','bg':'black'}
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
37
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
38 class XMLRPCServe(xmlrpc.XMLRPC):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
39 def __init__(self,player):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
40 xmlrpc.XMLRPC.__init__(self)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
41 self.player=player
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
42
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
43 def xmlrpc_echo(self,x):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
44 return x
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
45
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
46 def xmlrpc_playfile(self,musicfilename):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
47 self.player.play(musicfilename)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
48 return 'ok'
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
49 def xmlrpc_stop(self):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
50 self.player.state.set('stop')
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
51 return 'ok'
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
52 def xmlrpc_gettime(self):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
53 """returns seconds from start of song"""
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
54 return float(self.player.smoothCurrentTime())
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
55 def xmlrpc_songlength(self):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
56 """song length, in seconds"""
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
57 return float(self.player.total_time.get())
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
58 def xmlrpc_songname(self):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
59 """song filename, or None"""
223
f6262de03bf2 tk touchups and refactors in asco
drewp@bigasterisk.com
parents: 220
diff changeset
60 return self.player.filename_var.get() or "No song"
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
61
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
62 class Player:
223
f6262de03bf2 tk touchups and refactors in asco
drewp@bigasterisk.com
parents: 220
diff changeset
63 """semprini-style access to mpd. in here is where we add the padding"""
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
64
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
65 def __init__(self, app, playlist, media=None):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
66
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
67 self.mpd = Mpd()
226
09176d5ea00b use networking.mpdServer
drewp@bigasterisk.com
parents: 223
diff changeset
68 reactor.connectTCP(*(networking.mpdServer()+(self.mpd,)))
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
69
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
70 self.state = tk.StringVar()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
71 self.state.set("stop") # 'stop' 'pause' 'play'
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
72
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
73 self.current_time = tk.DoubleVar()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
74 self.total_time = tk.DoubleVar()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
75 self.filename_var = tk.StringVar()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
76
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
77 self.pre_post_names = showconfig.prePostSong()
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
78
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
79 self.last_poll_time = None
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
80
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
81 self.pollStatus()
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
82
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
83
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
84 def smoothCurrentTime(self):
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
85 """like self.current_time.get, but more accurate"""
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
86 if self.last_poll_time and self.state.get() == 'play':
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
87 dt = time.time() - self.last_poll_time
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
88 else:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
89 dt = 0
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
90 return self.current_time.get() + dt
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
91
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
92 def pollStatus(self):
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
93 if self.state.get() == 'stop':
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
94 self.current_time.set(-4)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
95
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
96 self.mpd.status().addCallback(self.pollStatus2)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
97
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
98 def pollStatus2(self, stat):
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
99
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
100 if self.state.get() != stat.state:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
101 self.state.set(stat.state)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
102
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
103
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
104 if hasattr(stat, 'time_elapsed'):
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
105 if stat.song == 1:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
106 t = stat.time_elapsed
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
107 elif stat.song == 0:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
108 t = stat.time_elapsed - stat.time_total
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
109 elif stat.song == 2:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
110 t = self.total_time.get() + stat.time_elapsed
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
111
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
112 self.current_time.set(t)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
113
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
114 self.last_poll_time = time.time()
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
115
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
116 reactor.callLater(.05, self.pollStatus)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
117
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
118 def play(self, song_path):
220
13c089886f61 added the forgotten curve.py; mpd song path fix
drewp@bigasterisk.com
parents: 218
diff changeset
119 self.mpd.clear()
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
120 self.mpd.add(showconfig.songInMpd(self.pre_post_names[0]))
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
121 self.mpd.add(showconfig.songInMpd(song_path))
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
122 self.mpd.add(showconfig.songInMpd(self.pre_post_names[1]))
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
123 self.filename_var.set(song_path)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
124
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
125 # jump to song 1 to get its total_time
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
126 self.mpd.seek(seconds=0, song=1)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
127 self.mpd.pause()
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
128 self.mpd.status().addCallback(self.play2)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
129
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
130 def play2(self, stat):
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
131 self.total_time.set(stat.time_total)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
132 self.mpd.seek(seconds=0, song=0)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
133
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
134 def stop(self):
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
135 self.mpd.seek(seconds=0, song=0)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
136 self.mpd.stop()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
137
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
138 def seek_to(self, time):
227
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
139 if time < 0:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
140 self.mpd.seek(seconds=time - (-4), song=0)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
141 elif time > self.total_time.get():
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
142 self.mpd.seek(seconds=time - self.total_time.get(), song=2)
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
143 else:
c7797ad42684 song pre/post mostly working
drewp@bigasterisk.com
parents: 226
diff changeset
144 self.mpd.seek(seconds=time, song=1)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
145
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
146 def play_pause_toggle(self):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
147 def finish(status):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
148 if status.state == 'play':
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
149 self.mpd.pause()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
150 else:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
151 self.mpd.play()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
152 self.mpd.status().addCallback(finish)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
153
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
154
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
155 def buildsonglist(root,songfiles,player):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
156 songlist=tk.Frame(root,bd=2,relief='raised',bg='black')
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
157
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
158 prefixlen=len(os.path.commonprefix(songfiles))
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
159 # include to the last os.sep- dont crop path elements in the middle
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
160 prefixlen=songfiles[0].rfind(os.sep)+1
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
161 maxsfwidth=max([len(x[prefixlen:]) for x in songfiles])
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
162
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
163 for i,sf in enumerate(songfiles):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
164 b=tk.Button(songlist,text=sf[prefixlen:],width=maxsfwidth,
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
165 anchor='w',pady=0,bd=0,relief='flat',
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
166 font="arial 17 bold")
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
167 b.bind("<Configure>",lambda ev,b=b:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
168 b.config(font="arial %d bold" % min(15,int((ev.height-3)*.8))))
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
169 try:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
170 # rainbow colors
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
171 frac=i/len(songfiles)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
172 b.config(bg='black',
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
173 fg="#%02x%02x%02x" % tuple([int(255*(.7+.3*
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
174 math.sin(frac*4+x))
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
175 ) for x in 1,2,3]))
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
176 except Exception,e:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
177 print "rainbow failed: %s"%e
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
178
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
179 b.config(command=lambda sf=sf: player.play(sf))
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
180 b.pack(side='top',fill='both',exp=1,padx=0,pady=0,ipadx=0,ipady=0)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
181
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
182
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
183 def color_buttons(x, y, z, sf=sf, b=b):
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
184 name = player.filename_var.get()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
185 if name == sf[prefixlen:]:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
186 b['bg'] = 'grey50'
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
187 else:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
188 b['bg'] = 'black'
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
189 player.filename_var.trace("w", color_buttons)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
190 return songlist
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
191
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
192
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
193 class Seeker(tk.Frame):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
194 """scale AND labels below it"""
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
195 def __init__(self,master,player):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
196 tk.Frame.__init__(self,master,bg='black')
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
197
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
198 self.scl = scl = tk.Scale(self, orient="horiz",
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
199 from_=-4,to_=100,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
200 sliderlen=20,width=20,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
201 res=0.001,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
202 showvalue=0,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
203 variable=player.current_time,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
204 troughcolor='black',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
205 bg='lightblue3',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
206 )
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
207 scl.pack(fill='x',side='top')
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
208
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
209 self.buildstatus(player)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
210
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
211
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
212 # dragging the scl changes the player time (which updates the scl)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
213
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
214 # due to mpd having to seemingly play a whole block at every new
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
215 # seek point, we may want a mode that pauses playback while the
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
216 # mouse is down (or is moving too fast; or we've sent a seek too
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
217 # recently)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
218
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
219 scl.mouse_state=0
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
220 def set_mouse_state(evt):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
221 scl.mouse_state = evt.state
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
222 def seeker_cb(time):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
223 if scl.mouse_state:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
224 player.seek_to(float(time))
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
225
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
226 scl.config(command=seeker_cb)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
227 scl.bind("<Motion>", set_mouse_state)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
228 scl.bind("<B1-Motion>",set_mouse_state)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
229
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
230 def b1down(evt):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
231 scl.mouse_state = 1
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
232 def b1up(evt):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
233 scl.mouse_state = 0
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
234 scl.bind("<ButtonPress-1>", b1down)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
235 scl.bind("<ButtonRelease-1>", b1up)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
236
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
237 def buildstatus(self,player):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
238 left_var=tk.DoubleVar()
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
239 for txt,var,fmt in (('Current',player.current_time,"%.2f"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
240 ('Song len',player.total_time,"%.2f",),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
241 ('Left',left_var, "%.2f"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
242 ('Song',player.filename_var, "%s"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
243 ('State', player.state, "%s")):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
244 tk.Label(self,text=txt,
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
245 relief='raised',bd=1,font='arial 9',
223
f6262de03bf2 tk touchups and refactors in asco
drewp@bigasterisk.com
parents: 220
diff changeset
246 **appstyle).pack(side='left',fill='y')
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
247 l = tk.Label(self,width=7, anchor='w', text=var.get(),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
248 relief='sunken',bd=1,font='arial 12 bold',
223
f6262de03bf2 tk touchups and refactors in asco
drewp@bigasterisk.com
parents: 220
diff changeset
249 padx=2,pady=2,
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
250 bg='#800000',fg='white')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
251 if txt == 'Song':
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
252 l.config(anchor='e')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
253 l.pack(side='left',expand=1, fill='x')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
254
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
255 var.trace_variable('w',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
256 lambda a,b,c,l=l,fmt=fmt,var=var:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
257 l.config(text=fmt % var.get()))
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
258
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
259 # update end time as the song changes
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
260 player.total_time.trace("w",lambda *args: (
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
261 self.scl.config(to_=player.total_time.get()+15)))
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
262
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
263 def fixleft(*args):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
264 # update time-left variable
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
265 left_var.set(player.total_time.get()-player.current_time.get())
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
266
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
267 if player.current_time.get() < 0 or left_var.get() < 0:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
268 self.scl['troughcolor'] = 'blue'
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
269 else:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
270 self.scl['troughcolor'] = 'black'
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
271
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
272 player.total_time.trace("w",fixleft)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
273 player.current_time.trace("w",fixleft)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
274
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
275 class ControlButtons(tk.Frame):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
276 def __init__(self,master):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
277 tk.Frame.__init__(self,master,bg='black')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
278
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
279 self.statebuttons = {} # lowercased name : Button
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
280 for txt,cmd,key in (('Stop', player.stop, "<Control-s>"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
281 ('Pause', player.play_pause_toggle, "<Control-p>"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
282 ('Skip Intro',lambda: player.seek_to(-.5), "<Control-i>"),
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
283 ):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
284 b = tk.Button(self, text=txt, command=cmd, font='arial 16 bold',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
285 height=3,**appstyle)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
286 b.pack(side='left', fill='x', expand=1)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
287 # keyboard bindings
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
288 root.bind(key, lambda evt, cmd=cmd: cmd())
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
289 self.statebuttons[txt.lower()] = b
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
290
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
291 def update_state_buttons(self,*args):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
292 state = player.state.get()
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
293 print "State", state
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
294
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
295 if state in ('stop', 'pause'):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
296 self.statebuttons['pause']['text'] = 'Play'
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
297 else:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
298 self.statebuttons['pause']['text'] = 'Pause'
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
299
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
300 colors = {'stop' : 'red',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
301 'play' : 'blue',
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
302 'pause' : 'green'} # very confusing -- play and pause supply colors
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
303 # for each other!
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
304 for name, button in self.statebuttons.items():
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
305 if name == 'pause' and state not in ('stop', 'pause'):
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
306 name = 'play'
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
307
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
308 if state == name: # name gets changed sometimes for 'pause' -- see right above
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
309 button['bg'] = colors.get(name, 'black')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
310 else:
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
311 button['bg'] = 'black'
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
312
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
313 ############################
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
314
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
315 parser=OptionParser()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
316
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
317 (options,songfiles)=parser.parse_args()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
318
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
319 if len(songfiles)<1:
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
320 songfiles = [f for f in os.listdir(showconfig.musicDir())
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
321 if f.endswith('wav')]
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
322
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
323 root=tk.Tk()
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
324 root.wm_title("ascoltami")
229
c5a79314afdf bigger asco window
drewp@bigasterisk.com
parents: 227
diff changeset
325 root.wm_geometry("+1270+440")
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
326 root.config(bg="black")
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
327 player=Player(None,None)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
328
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
329 songlist = buildsonglist(root,songfiles,player)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
330 songlist.pack(fill='both',exp=1)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
331
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
332 f2 = tk.Frame(bg='black')
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
333 buts = ControlButtons(f2)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
334 buts.pack(side='top',fill='x')
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
335
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
336 player.state.trace_variable('w', buts.update_state_buttons)
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
337 buts.update_state_buttons()
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
338
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
339 seeker = Seeker(f2,player)
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
340 seeker.pack(fill='x',exp=1)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
341 f2.pack(side='bottom',fill='x')
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
342
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
343 tksupport.install(root,ms=10)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
344
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
345 try:
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
346 reactor.listenTCP(networking.musicPort(),server.Site(XMLRPCServe(player)))
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
347 print "started server on %s" % networking.musicPort()
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
348 except CannotListenError:
218
65ed570b7ba8 refactored the GUI code
drewp@bigasterisk.com
parents: 217
diff changeset
349 print "no server started- %s is in use" % networking.musicPort()
217
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
350
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
351 root.bind("<Destroy>",lambda ev: reactor.stop)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
352 root.protocol('WM_DELETE_WINDOW', reactor.stop)
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
353
1d4e406d19e6 add new ascoltami that uses mpd
drewp@bigasterisk.com
parents:
diff changeset
354 reactor.run()