Mercurial > code > home > repos > light9
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 |
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 | 8 |
1858 | 9 |
0 | 10 class MusicTime: |
1858 | 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 | 14 |
0 | 15 def get_music_time(self): |
16 playtime = None | |
17 while not playtime: | |
18 try: | |
660 | 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 | 23 time.sleep(2) |
24 return playtime | |
25 | |
1858 | 26 |
0 | 27 class MusicTimeTk(tk.Frame, MusicTime): |
1858 | 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 | 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 | 32 self.timevar = tk.DoubleVar() |
1858 | 33 self.timelabel = tk.Label(self, |
34 textvariable=self.timevar, | |
35 bd=2, | |
36 relief='raised', | |
37 width=10, | |
38 padx=2, | |
39 pady=2, | |
40 anchor='w') | |
0 | 41 self.timelabel.pack(expand=1, fill='both') |
1858 | 42 |
0 | 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 | 46 |
0 | 47 self.timelabel.bind('<KeyPress>', print_time) |
48 self.timelabel.bind('<1>', print_time) | |
49 self.timelabel.focus() | |
50 self.update_time() | |
1858 | 51 |
0 | 52 def update_time(self): |
53 self.timevar.set(self.get_music_time()) | |
54 self.after(100, self.update_time) | |
55 | |
1858 | 56 |
0 | 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 | 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 | 61 options, args = parser.parse_args() |
1858 | 62 |
0 | 63 root = tk.Tk() |
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 | 66 try: |
67 tk.mainloop() | |
68 except KeyboardInterrupt: | |
69 root.destroy() |