Mercurial > code > home > repos > light9
annotate bin/curvecalc @ 705:ed50631cf333
new curve dialog
Ignore-this: cf65cf980b86995377971a0982efc67c
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 10 Jun 2012 08:06:54 +0000 |
parents | d5a9933a2222 |
children | 16042667ab51 |
rev | line source |
---|---|
686
a301a0039c66
buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents:
684
diff
changeset
|
1 #!bin/python |
0 | 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 | 12 from __future__ import division |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
13 |
691 | 14 from twisted.internet import gtk2reactor |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
15 gtk2reactor.install() |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
16 from twisted.internet import reactor |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
17 |
700
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
18 import time, textwrap, os, optparse, urllib2, gtk, gobject, linecache, signal |
689 | 19 import louie as dispatcher |
691 | 20 from twisted.python.util import sibpath |
690 | 21 from rdflib import URIRef |
686
a301a0039c66
buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents:
684
diff
changeset
|
22 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
|
23 import rdflib |
319
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
24 import logging |
2193eab0650b
add startup logging to curvecalc
Drew Perttula <drewp@bigasterisk.com>
parents:
296
diff
changeset
|
25 log = logging.getLogger() |
0 | 26 |
210
f41004d5a507
factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents:
205
diff
changeset
|
27 import run_local |
690 | 28 from light9 import showconfig, prof |
688 | 29 from light9.curvecalc.curve import Curveset |
696
929ccd4ec800
live reloading of curveview.py, very nice
Drew Perttula <drewp@bigasterisk.com>
parents:
695
diff
changeset
|
30 from light9.curvecalc import curveview |
689 | 31 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
|
32 from light9.wavelength import wavelength |
335 | 33 from light9.namespaces import L9 |
690 | 34 from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
35 from light9.curvecalc.subtermview import add_one_subterm |
690 | 36 from light9.curvecalc.output import Output |
0 | 37 |
505 | 38 def makeGraph(): |
39 graphOrig = showconfig.getGraph() | |
40 graph = Graph() # a copy, since we're going to add subs into it | |
41 for s in graphOrig: | |
42 graph.add(s) | |
43 read_all_subs(graph) | |
44 return graph | |
0 | 45 |
691 | 46 class Main(object): |
698
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
47 def __init__(self, graph, opts, song, curveset, subterms, music): |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
48 self.graph, self.opts, self.song = graph, opts, song |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
49 self.curveset, self.subterms, self.music = curveset, subterms, music |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
50 |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
51 wtree = self.wtree = gtk.Builder() |
702 | 52 wtree.add_from_file("light9/curvecalc/curvecalc.glade") |
691 | 53 mainwin = wtree.get_object("MainWindow") |
700
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
54 |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
55 mainwin.connect("destroy", self.onQuit) |
691 | 56 wtree.connect_signals(self) |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
57 gtk.rc_parse("theme/marble-ice/gtk-2.0/gtkrc") |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
58 gtk.rc_parse_string("""style "default" {font_name = "sans 7"}""") |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
59 if self.opts.reload: |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
60 self.refreshTheme() |
691 | 61 mainwin.show_all() |
62 | |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
63 mainwin.connect("delete-event", lambda *args: reactor.crash()) |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
64 mainwin.set_title("curvecalc - %s" % graph.label(song)) |
702 | 65 mainwin.parse_geometry("715x930+1080+26") |
66 | |
67 # this is the only one i found that would set the size right, | |
68 # but it's a minimum size, which i don't really want | |
69 mainwin.set_size_request(1000, 1000) | |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
70 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
71 self.add_subterms_for_song(song, curveset, subterms, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
72 wtree.get_object("subterms") |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
73 ) |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
74 self.refreshCurveView() |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
75 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
76 self.makeStatusLines(wtree.get_object("status")) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
77 |
705 | 78 def onNewCurve(self, *args): |
79 nc = self.wtree.get_object("newCurve") | |
80 entry = self.wtree.get_object("newCurveName") | |
81 # if you don't have songx, that should be the suggested name | |
82 entry.set_text("") | |
83 response = nc.run() | |
84 if response == 1: | |
85 self.curveset.new_curve(entry.get_text()) | |
86 nc.hide() | |
87 | |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
88 def refreshTheme(self): |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
89 gtk.rc_reparse_all() |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
90 reactor.callLater(1, self.refreshTheme) |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
91 |
700
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
92 def onQuit(self, *args): |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
93 reactor.crash() |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
94 # there's a hang after this, maybe in sem_wait in two |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
95 # threads. I don't know whose they are. |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
96 os.kill(os.getpid(), signal.SIGKILL) |
d5692ab6bc2a
fix quit and ctrl-q by using kill -9
Drew Perttula <drewp@bigasterisk.com>
parents:
699
diff
changeset
|
97 |
699
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
98 def onSeeCurrentTime(self, item): |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
99 dispatcher.send("see time") |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
100 |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
101 def onSeeTimeUntilEnd(self, item): |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
102 dispatcher.send("see time until end") |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
103 |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
104 def onZoomAll(self, item): |
d12bc8919d6e
ported the zoom control
Drew Perttula <drewp@bigasterisk.com>
parents:
698
diff
changeset
|
105 dispatcher.send("show all") |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
106 |
698
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
107 def onPlayPause(self, item): |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
108 # since the X coord in a curveview affects the handling, one |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
109 # of them may be able to pick this up |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
110 results = dispatcher.send("onPlayPause") |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
111 times = [t for listener, t in results if t is not None] |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
112 self.music.playOrPause(t=times[0] if times else None) |
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
113 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
114 def onSave(self, *args): |
703 | 115 savekey(self.song, self.subterms, self.curveset) |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
116 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
117 def add_subterms_for_song(self, song, curveset, subterms, master): |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
118 for st in self.graph.objects(song, L9['subterm']): |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
119 log.info("song %s has subterm %s", song, st) |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
120 add_one_subterm(self.graph, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
121 self.graph.value(st, L9['sub']), |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
122 curveset, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
123 subterms, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
124 master, |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
125 self.graph.value(st, L9['expression'])) |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
126 master.show_all() |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
127 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
128 def makeStatusLines(self, master): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
129 """various labels that listen for dispatcher signals""" |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
130 for row, (signame, textfilter) in enumerate([ |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
131 ('input time', lambda t: "%.2fs"%t), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
132 ('output levels', |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
133 lambda levels: textwrap.fill("; ".join(["%s:%.2f"%(n,v) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
134 for n,v in |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
135 levels.items()[:5] |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
136 if v>0]),70)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
137 ('update period', lambda t: "%.1fms"%(t*1000)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
138 ('update status', lambda x: str(x)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
139 ]): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
140 key = gtk.Label("%s:" % signame) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
141 value = gtk.Label("") |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
142 master.resize(row + 1, 2) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
143 master.attach(key, 0, 1, row, row + 1) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
144 master.attach(value, 1, 2, row, row + 1) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
145 key.set_alignment(1, 0) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
146 value.set_alignment(0, 0) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
147 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
148 dispatcher.connect(lambda val, value=value, tf=textfilter: |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
149 value.set_text(tf(val)), |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
150 signame, weak=False) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
151 master.show_all() |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
152 |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
153 def refreshCurveView(self): |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
154 wtree = self.wtree |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
155 mtimes = [os.path.getmtime(f) for f in [ |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
156 'light9/curvecalc/curveview.py', |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
157 'light9/curvecalc/zoomcontrol.py', |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
158 ]] |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
159 |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
160 if (not hasattr(self, 'curvesetView') or |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
161 self.curvesetView._mtimes != mtimes): |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
162 print "reload curveview.py" |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
163 curvesVBox = wtree.get_object("curves") |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
164 zoomControlBox = wtree.get_object("zoomControlBox") |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
165 [curvesVBox.remove(c) for c in curvesVBox.get_children()] |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
166 [zoomControlBox.remove(c) for c in |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
167 zoomControlBox.get_children()] |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
168 try: |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
169 linecache.clearcache() |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
170 reload(curveview) |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
171 # mem problem somewhere; need to hold a ref to this |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
172 self.curvesetView = curveview.Curvesetview( |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
173 curvesVBox, zoomControlBox, self.curveset) |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
174 self.curvesetView._mtimes = mtimes |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
175 |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
176 # this is scheduled after some tk shuffling, to |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
177 # try to minimize the number of times we redraw |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
178 # the curve at startup. If tk is very slow, it's |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
179 # ok. You'll just get some wasted redraws. |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
180 self.curvesetView.goLive() |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
181 except Exception, e: |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
182 print "reload failed:", e |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
183 if self.opts.reload: |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
184 reactor.callLater(1, self.refreshCurveView) |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
185 |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
186 def onReloadSubs(self, *args): # wants to be ctrl-r too |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
187 dispatcher.send('reload all subs') |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
188 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
189 def onAddSubterm(self): |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
190 uri = L9['sub/%s' % newname.get()] |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
191 graph.add((uri, RDF.type, L9.Subterm)) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
192 graph.add((uri, RDFS.label, Literal(newname.get()))) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
193 add_one_subterm(graph, uri, |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
194 curveset, subterms, ssv, None) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
195 if evt.state & 4: # control key modifier |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
196 curveset.new_curve(newname.get()) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
197 newname.set('') |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
198 |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
199 |
505 | 200 def main(): |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
201 startTime = time.time() |
505 | 202 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
|
203 parser.set_usage("%prog [opts] [songURI]") |
505 | 204 parser.add_option("--sliders", action='store_true', |
205 help='use hardware sliders') | |
206 parser.add_option("--skip-music", action='store_true', | |
207 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
|
208 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
|
209 help="log at DEBUG") |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
210 parser.add_option("--reload", action="store_true", |
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
211 help="live reload of themes and code") |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
212 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
|
213 help="quit after loading everything (for timing tests)") |
505 | 214 opts, args = parser.parse_args() |
215 | |
590 | 216 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
|
217 log.setLevel(logging.DEBUG if opts.debug else logging.INFO) |
590 | 218 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
219 log.debug("startup: music %s", time.time() - startTime) |
505 | 220 try: |
221 song = URIRef(args[0]) | |
222 except IndexError: | |
551
ad5043f70fda
bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on
drewp@bigasterisk.com
parents:
532
diff
changeset
|
223 song = currentlyPlayingSong() |
505 | 224 |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
225 music = Music() |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
226 graph = makeGraph() |
691 | 227 |
505 | 228 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
|
229 subterms = [] |
505 | 230 |
704
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
231 # curvesetview must already exist, since this |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
232 # makes 'add_curve' signals for all the initial |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
233 # curves. |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
234 curveset.load(basename=os.path.join( |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
235 showconfig.curvesDir(), |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
236 showconfig.songFilenameFromURI(song)), |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
237 skipMusic=opts.skip_music) |
d5a9933a2222
don't reload curve files upon curve code reload
Drew Perttula <drewp@bigasterisk.com>
parents:
703
diff
changeset
|
238 |
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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 |
680
ad17b0a09f5c
CC more startup logging, timing option to quit after init
drewp@bigasterisk.com
parents:
641
diff
changeset
|
247 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
|
248 out = Output(subterms, music) |
505 | 249 |
250 musicfilename = showconfig.songOnDisk(song) | |
251 maxtime = wavelength(musicfilename) | |
516
73b181155555
curvecalc ui touchups, adjustable pane, curve draw speedup, restructured main layout code
drewp@bigasterisk.com
parents:
505
diff
changeset
|
252 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
|
253 |
698
2aac2ef23495
time cursor, control-p over curveviews
Drew Perttula <drewp@bigasterisk.com>
parents:
697
diff
changeset
|
254 start = Main(graph, opts, song, curveset, subterms, music) |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
255 |
694
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
256 dispatcher.send("max time", maxtime=maxtime) |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
257 dispatcher.send("show all") |
34dacd800505
eval loop is running, music drives lights. started to add goocanvas curve view
Drew Perttula <drewp@bigasterisk.com>
parents:
692
diff
changeset
|
258 |
692
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
259 if opts.startup_only: |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
260 log.debug("quitting now because of --startup-only") |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
261 return |
ccdd04f4ca7d
subterm display is working
Drew Perttula <drewp@bigasterisk.com>
parents:
691
diff
changeset
|
262 |
701
417e23dc0af0
add marble-ice theme. use --reload to opt in to all autoreloading
Drew Perttula <drewp@bigasterisk.com>
parents:
700
diff
changeset
|
263 prof.run(reactor.run, profile=False) |
505 | 264 |
265 main() |