annotate bin/musictime @ 1898:d3091e6dd1a0

more initial data for 2019 show Ignore-this: 1bf5c652531d8653ae74528414b772ef
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 30 May 2019 17:14:11 +0000
parents 3c523c71da29
children cce016abe31e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
1 #!/usr/bin/env python
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1859
diff changeset
2 import run_local # noqa
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
3 import light9.networking
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
4
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
5 import tkinter as tk
532
8d6f6d8a4719 clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents: 305
diff changeset
6 import time
8d6f6d8a4719 clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents: 305
diff changeset
7 import restkit, jsonlib
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
8
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
9
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 class MusicTime:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
11
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
12 def __init__(self, url):
532
8d6f6d8a4719 clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents: 305
diff changeset
13 self.player = restkit.Resource(url)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
14
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 def get_music_time(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 playtime = None
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 while not playtime:
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 try:
660
3322285457ac fix musictime restkit api
drewp@bigasterisk.com
parents: 623
diff changeset
19 playtime = jsonlib.read(self.player.get("time").body_string(),
532
8d6f6d8a4719 clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents: 305
diff changeset
20 use_float=True)['t']
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
21 except restkit.RequestError as e:
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
22 print("Server error %s, waiting" % e)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 time.sleep(2)
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 return playtime
45b12307c695 Initial revision
drewp
parents:
diff changeset
25
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
26
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 class MusicTimeTk(tk.Frame, MusicTime):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
28
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
29 def __init__(self, master, url):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 tk.Frame.__init__(self)
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
31 MusicTime.__init__(self, url)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 self.timevar = tk.DoubleVar()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
33 self.timelabel = tk.Label(self,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
34 textvariable=self.timevar,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
35 bd=2,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
36 relief='raised',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
37 width=10,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
38 padx=2,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
39 pady=2,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
40 anchor='w')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
41 self.timelabel.pack(expand=1, fill='both')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
42
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
43 def print_time(evt, *args):
305
4072d93f02c5 musictime was piling on more and more timers every time you pressed a key
Drew Perttula <drewp@bigasterisk.com>
parents: 266
diff changeset
44 self.timevar.set(self.get_music_time())
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
45 print(self.timevar.get(), evt.keysym)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
46
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 self.timelabel.bind('<KeyPress>', print_time)
45b12307c695 Initial revision
drewp
parents:
diff changeset
48 self.timelabel.bind('<1>', print_time)
45b12307c695 Initial revision
drewp
parents:
diff changeset
49 self.timelabel.focus()
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 self.update_time()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
51
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
52 def update_time(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
53 self.timevar.set(self.get_music_time())
45b12307c695 Initial revision
drewp
parents:
diff changeset
54 self.after(100, self.update_time)
45b12307c695 Initial revision
drewp
parents:
diff changeset
55
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
56
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
57 if __name__ == "__main__":
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 0
diff changeset
58 from optparse import OptionParser
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
59 parser = OptionParser()
623
46d319974176 move networking settings to config.n3
drewp@bigasterisk.com
parents: 532
diff changeset
60 parser.add_option("-u", "--url", default=light9.networking.musicPlayer.url)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
61 options, args = parser.parse_args()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 660
diff changeset
62
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
63 root = tk.Tk()
45b12307c695 Initial revision
drewp
parents:
diff changeset
64 root.title("Time")
266
58bbf9f42457 Revive MusicTime as bin/musictime, use light9.networking for music server location
David McClosky <dmcc@bigasterisk.com>
parents: 205
diff changeset
65 MusicTimeTk(root, options.url).pack(expand=1, fill='both')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
66 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
67 tk.mainloop()
45b12307c695 Initial revision
drewp
parents:
diff changeset
68 except KeyboardInterrupt:
45b12307c695 Initial revision
drewp
parents:
diff changeset
69 root.destroy()