annotate bin/curvecalc @ 690:847edbfe65c8

refactor subterms Ignore-this: 632a7fcc1917ceed60970e69e85d03f5
author drewp@bigasterisk.com
date Wed, 06 Jun 2012 01:31:51 +0000
parents 03453848ed4c
children 62d83d456f2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
686
a301a0039c66 buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents: 684
diff changeset
1 #!bin/python
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
2
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
3 """
351
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 335
diff changeset
4 now launches like this:
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 335
diff changeset
5 % bin/curvecalc http://light9.bigasterisk.com/show/dance2007/song1
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 335
diff changeset
6
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 335
diff changeset
7
a6662d61ebcd SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents: 335
diff changeset
8
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
9 todo: curveview should preserve more objects, for speed maybe
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
10
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
11 """
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
12 from __future__ import division
690
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
13 import time,textwrap,os,optparse, urllib2
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
14 import Tix as tk
689
03453848ed4c refactor musicaccess
drewp@bigasterisk.com
parents: 688
diff changeset
15 import louie as dispatcher
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 from twisted.internet import reactor,tksupport
689
03453848ed4c refactor musicaccess
drewp@bigasterisk.com
parents: 688
diff changeset
17
690
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
18 from rdflib import URIRef
686
a301a0039c66 buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents: 684
diff changeset
19 from rdflib import Graph
400
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
20 import rdflib
319
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
21 import logging
2193eab0650b add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents: 296
diff changeset
22 log = logging.getLogger()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
23
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 205
diff changeset
24 import run_local
690
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
25 from light9 import showconfig, prof
688
97b028ed0e47 curvecalc package move
drewp@bigasterisk.com
parents: 687
diff changeset
26 from light9.curvecalc.zoomcontrol import Zoomcontrol
97b028ed0e47 curvecalc package move
drewp@bigasterisk.com
parents: 687
diff changeset
27 from light9.curvecalc.curve import Curveset
97b028ed0e47 curvecalc package move
drewp@bigasterisk.com
parents: 687
diff changeset
28 from light9.curvecalc.curveview import Curvesetview
689
03453848ed4c refactor musicaccess
drewp@bigasterisk.com
parents: 688
diff changeset
29 from light9.curvecalc.musicaccess import Music, currentlyPlayingSong
264
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 248
diff changeset
30 from light9.wavelength import wavelength
0f112a7dd6b3 fix window positoins for subcomposer and curvecalc. now saves geometry continuously
drewp@bigasterisk.com
parents: 248
diff changeset
31 from light9.uihelpers import toplevelat
335
8a1ec8aca432 more rdf updates
drewp@bigasterisk.com
parents: 332
diff changeset
32 from light9.namespaces import L9
690
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
33 from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
34 from light9.curvecalc.subtermview import makeSubtermCommandRow, add_one_subterm
847edbfe65c8 refactor subterms
drewp@bigasterisk.com
parents: 689
diff changeset
35 from light9.curvecalc.output import Output
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
36
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
37 def makeStatusLines(master):
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
38 """various labels that listen for dispatcher signals"""
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
39 for signame,textfilter in [
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
40 ('input time',lambda t: "%.2fs"%t),
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
41 ('output levels',
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
42 lambda levels: textwrap.fill("; ".join(["%s:%.2f"%(n,v)
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
43 for n,v in
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
44 levels.items()[:5]
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 202
diff changeset
45 if v>0]),70)),
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
46 ('update period',lambda t: "%.1fms"%(t*1000)),
236
63601fe0c3b0 curvecalc cmdline checking, connection status now in gui
drewp@bigasterisk.com
parents: 230
diff changeset
47 ('update status',lambda t: str(t)),
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
48 ]:
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
49 l = tk.Label(master, anchor='w', justify='left', text='%s:' % signame)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
50 l.pack(side='top',fill='x')
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
51 dispatcher.connect(lambda val,l=l,sn=signame,tf=textfilter:
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
52 l.config(text=sn+": "+tf(val)),
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
53 signame, weak=False)
197
ba2677823b35 zoom control and other cleanups. also reads song length now
drewp
parents: 196
diff changeset
54
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
55 def add_subterms_for_song(graph, song, curveset, subterms, master):
335
8a1ec8aca432 more rdf updates
drewp@bigasterisk.com
parents: 332
diff changeset
56 for st in graph.objects(song, L9['subterm']):
590
0cf00fffd921 logging
drewp@bigasterisk.com
parents: 551
diff changeset
57 log.info("song %s has subterm %s", song, st)
400
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
58 try:
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
59 add_one_subterm(graph, graph.value(st, L9['sub']), curveset,
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
60 subterms, master, graph.value(st, L9['expression']))
400
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
61 except rdflib.exceptions.UniquenessError:
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
62 print "working around curvecalc save corruption"
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
63 # curvecalc put all the expressions on one subterm, which is wrong
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
64 for expr in graph.objects(st, L9['expression']):
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
65 add_one_subterm(graph, graph.value(st, L9['sub']),
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
66 curveset, subterms, master, expr)
400
b2858c2d4a4d aft() has smooth arg; workaround for CC writing poor subterms
Drew Perttula <drewp@bigasterisk.com>
parents: 399
diff changeset
67
287
5322639d61e9 refactoring and little fixes in curvecalc and keyboardcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 284
diff changeset
68
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
69 def makeGraph():
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
70 graphOrig = showconfig.getGraph()
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
71 graph = Graph() # a copy, since we're going to add subs into it
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
72 for s in graphOrig:
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
73 graph.add(s)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
74 read_all_subs(graph)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
75 return graph
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
76
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
77 def setupKeyBindings(root, song, subterms, curveset):
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
78 root.bind("<Control-Key-s>",
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
79 lambda *args: savekey(song, subterms, curveset))
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
80 root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs'))
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
81 root.bind("<Control-Key-n>",
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
82 lambda evt: dispatcher.send('focus new subterm'))
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
83 root.bind("<Control-Key-N>", lambda evt: dispatcher.send('focus new curve'))
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
84 root.bind("<Control-Key-q>",lambda ev: reactor.stop)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
85 root.bind("<Destroy>",lambda ev: reactor.stop)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
86 root.protocol('WM_DELETE_WINDOW', reactor.stop)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
87
641
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
88 def setupMenubar(barFrame, root, song, subterms, curveset):
639
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
89 class newMenu(object):
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
90 def __init__(self, name):
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
91 self.name = name
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
92 def __enter__(self):
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
93 m = tk.Menubutton(barFrame, text=self.name)
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
94 m.pack(side='left')
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
95 mm = tk.Menu(m)
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
96 m.config(menu=mm)
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
97 return mm
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
98 def __exit__(self, type, value, traceback):
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
99 return False
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
100
641
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
101 def notImpl(*args):
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
102 print "sorry, menu command binding isn't done yet. Use the keyboard shortcut"
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
103
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
104 with newMenu("Curvecalc") as m:
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
105 m.add_command(label='Save', underline=0, accelerator="Ctrl+s",
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
106 command=lambda *args: savekey(song, subterms, curveset))
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
107 m.add_command(label='Quit', command=root.destroy)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
108
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
109 with newMenu("View") as m:
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
110 m.add_command(label="See current time", accelerator="Esc", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
111 m.add_command(label="See from current time -> end", accelerator="Shift+Esc", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
112 m.add_command(label="Zoom all", accelerator="Ctrl+Esc", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
113 m.add_command(label="Zoom in", accelerator="Wheel up", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
114 m.add_command(label="Zoom out", accelerator="Wheel down", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
115
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
116 with newMenu("Playback") as m:
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
117 m.add_command(label="Play/pause at mouse", accelerator="Ctrl+P", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
118
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
119 with newMenu("Points") as m:
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
120 m.add_command(label="Delete", accelerator="Del", command=notImpl)
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
121
639
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
122
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
123 def createHelpLines(root):
641
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
124 for helpline in ["Mousewheel zoom; C-p play/pause music at mouse",
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
125 "Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; B1 drag select points",
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
126 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; chan(name); curvename(t) eval curve"]:
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
127 line = tk.Label(root, text=helpline, font="Helvetica -12 italic",
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
128 anchor='w')
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
129 line.pack(side='top',fill='x')
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
130
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
131 def main():
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
132 startTime = time.time()
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
133 parser = optparse.OptionParser()
551
ad5043f70fda bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents: 532
diff changeset
134 parser.set_usage("%prog [opts] [songURI]")
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
135 parser.add_option("--sliders", action='store_true',
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
136 help='use hardware sliders')
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
137 parser.add_option("--skip-music", action='store_true',
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
138 help="ignore music and smooth_music curve files")
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
139 parser.add_option("--debug", action="store_true",
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
140 help="log at DEBUG")
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
141 parser.add_option("--startup-only", action='store_true',
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
142 help="quit after loading everything (for timing tests)")
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
143 opts, args = parser.parse_args()
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
144
590
0cf00fffd921 logging
drewp@bigasterisk.com
parents: 551
diff changeset
145 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
146 log.setLevel(logging.DEBUG if opts.debug else logging.INFO)
590
0cf00fffd921 logging
drewp@bigasterisk.com
parents: 551
diff changeset
147
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
148 log.debug("startup: music %s", time.time() - startTime)
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
149 try:
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
150 song = URIRef(args[0])
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
151 except IndexError:
551
ad5043f70fda bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents: 532
diff changeset
152 song = currentlyPlayingSong()
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
153
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
154 music=Music()
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
155 graph = makeGraph()
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
156 curveset = Curveset(sliders=opts.sliders)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
157 subterms = []
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
158
637
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
159 subtermPath = graphPathForSubterms(song)
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
160 try:
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
161 graph.parse(subtermPath, format='n3')
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
162 except urllib2.URLError, e:
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
163 if e.reason.errno != 2:
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
164 raise
af5539fe35a7 CC startup doesn't need a subterms file. it'll make the first one
Drew Perttula <drewp@bigasterisk.com>
parents: 636
diff changeset
165 log.info("%s not found, starting with empty graph" % subtermPath)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
166
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
167 log.debug("startup: output %s", time.time() - startTime)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
168 out = Output(subterms, music)
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
169
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
170 musicfilename = showconfig.songOnDisk(song)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
171 maxtime = wavelength(musicfilename)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
172 dispatcher.connect(lambda: maxtime, "get max time", weak=False)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
173
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
174
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
175 root=tk.Tk()
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
176 root.tk_setPalette("gray50")
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
177 toplevelat("curvecalc",root)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
178 root.tk_focusFollowsMouse()
639
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
179 root.title("curvecalc - %s" % graph.label(song))
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
180
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
181 menubar = tk.Frame(root)
7ee76a895427 start CC menubar
Drew Perttula <drewp@bigasterisk.com>
parents: 637
diff changeset
182 menubar.pack(side='top', fill='x')
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
183
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
184 if 'fixed top rows':
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
185 zc = Zoomcontrol(root)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
186 zc.pack(side='top', fill='x')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
187
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
188 if 'panes':
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
189 panes = tk.PanedWindow(root, height=1)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
190 panes.add('curvesetView')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
191 panes.add('subterms')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
192 panes.pack(side='top', fill='both', expand=True)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
193
519
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
194 curvesetView = Curvesetview(panes.subwidget('curvesetView'), curveset,
613
54341e5e8d82 curvecalc default height
drewp@bigasterisk.com
parents: 602
diff changeset
195 height=600)
519
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
196 curvesetView.pack(fill='both', expand=True)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
197
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
198 subtermArea = tk.Frame(panes.subwidget('subterms'), height=100)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
199 subtermArea.pack(fill='both', expand=True)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
200
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
201 subtermScroll = tk.ScrolledWindow(subtermArea)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
202 subtermScroll.pack(fill='both')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
203
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
204 if 'fixed bottom rows':
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
205 makeSubtermCommandRow(root, curveset, subterms, root, subtermArea,
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
206 graph).pack(side='top', fill='x')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
207 makeStatusLines(root)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
208
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
209 helpBox = tk.Frame(root)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
210 createHelpLines(helpBox)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
211 helpBox.pack(side='top', fill='x')
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
212
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
213 add_subterms_for_song(graph, song, curveset, subterms,
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
214 subtermScroll.subwidget('window'))
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
215 setupKeyBindings(root, song, subterms, curveset)
641
c113c759559b more menubar. not many working actions yet
Drew Perttula <drewp@bigasterisk.com>
parents: 639
diff changeset
216 setupMenubar(menubar, root, song, subterms, curveset)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
217
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
218 # curvesetview must already exist, since this makes 'add_curve'
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
219 # signals for all the initial curves
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
220 curveset.load(basename=os.path.join(showconfig.curvesDir(),
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
221 showconfig.songFilenameFromURI(song)),
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
222 skipMusic=opts.skip_music)
516
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
223
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
224 dispatcher.send("max time",maxtime=maxtime)
73b181155555 curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents: 505
diff changeset
225 dispatcher.send("show all")
519
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
226
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
227 # this is scheduled after some tk shuffling, to try to minimize
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
228 # the number of times we redraw the curve at startup. If tk is
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
229 # very slow, it's ok. You'll just get some wasted redraws.
f2dbb0b1fb35 optimize the number of curve redraws at curvecalc's startup
drewp@bigasterisk.com
parents: 517
diff changeset
230 reactor.callLater(.1, curvesetView.goLive)
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
231
517
f15ffbfc5cd6 speed up curvecalc tk update to 10ms (since we recently sped up the recalcs)
drewp@bigasterisk.com
parents: 516
diff changeset
232 tksupport.install(root, ms=10)
680
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
233 log.debug("startup: run %s", time.time() - startTime)
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
234 if opts.startup_only:
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
235 log.debug("quitting now because of --startup-only")
ad17b0a09f5c CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents: 641
diff changeset
236 return
505
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
237 prof.run(reactor.run, profile=False)
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
238
cbc98de2ab06 refactor curveCalc toplevel
drewp@bigasterisk.com
parents: 493
diff changeset
239 main()