Files @ dd9474bef2a6
Branch filter:

Location: light9/bin/musictime - annotation

drewp@bigasterisk.com
decimal not double! this caused patch comparisons to fail and led to redundant work
#!bin/python
import run_local  # noqa
import light9.networking

import tkinter as tk
from twisted.internet import reactor, tksupport, task

from light9.ascoltami.musictime_client import MusicTime

mt = MusicTime()


class MusicTimeTk(tk.Frame, MusicTime):

    def __init__(self, master, url):
        tk.Frame.__init__(self)
        MusicTime.__init__(self, url)
        self.timevar = tk.DoubleVar()
        self.timelabel = tk.Label(self,
                                  textvariable=self.timevar,
                                  bd=2,
                                  relief='raised',
                                  width=10,
                                  padx=2,
                                  pady=2,
                                  anchor='w')
        self.timelabel.pack(expand=1, fill='both')

        def print_time(evt, *args):
            self.timevar.set(mt.getLatest().get('t', 0))
            print(self.timevar.get(), evt.keysym)

        self.timelabel.bind('<KeyPress>', print_time)
        self.timelabel.bind('<1>', print_time)
        self.timelabel.focus()
        task.LoopingCall(self.update_time).start(.1)

    def update_time(self):
        t = self.getLatest().get('t', 0)
        self.timevar.set(t)


if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-u", "--url", default=light9.networking.musicPlayer.url)
    options, args = parser.parse_args()

    root = tk.Tk()
    root.title("Time")
    MusicTimeTk(root, options.url).pack(expand=1, fill='both')
    tksupport.install(root, ms=20)
    reactor.run()