comparison bin/curvecalc @ 701:417e23dc0af0

add marble-ice theme. use --reload to opt in to all autoreloading Ignore-this: d87e96e140fa5c7d43bc3cdc32b86a50
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 10 Jun 2012 06:55:46 +0000
parents d5692ab6bc2a
children 155c7bb9c948
comparison
equal deleted inserted replaced
700:d5692ab6bc2a 701:417e23dc0af0
28 from light9 import showconfig, prof 28 from light9 import showconfig, prof
29 from light9.curvecalc.curve import Curveset 29 from light9.curvecalc.curve import Curveset
30 from light9.curvecalc import curveview 30 from light9.curvecalc import curveview
31 from light9.curvecalc.musicaccess import Music, currentlyPlayingSong 31 from light9.curvecalc.musicaccess import Music, currentlyPlayingSong
32 from light9.wavelength import wavelength 32 from light9.wavelength import wavelength
33 from light9.uihelpers import toplevelat
34 from light9.namespaces import L9 33 from light9.namespaces import L9
35 from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms 34 from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms
36 from light9.curvecalc.subtermview import add_one_subterm 35 from light9.curvecalc.subtermview import add_one_subterm
37 from light9.curvecalc.output import Output 36 from light9.curvecalc.output import Output
38 37
44 read_all_subs(graph) 43 read_all_subs(graph)
45 return graph 44 return graph
46 45
47 class Main(object): 46 class Main(object):
48 def __init__(self, graph, opts, song, curveset, subterms, music): 47 def __init__(self, graph, opts, song, curveset, subterms, music):
49 self.graph = graph 48 self.graph, self.opts, self.song = graph, opts, song
50 self.music = music 49 self.curveset, self.subterms, self.music = curveset, subterms, music
51 wtree = gtk.Builder() 50
51 wtree = self.wtree = gtk.Builder()
52 wtree.add_from_file(sibpath(__file__, "../light9/curvecalc/curvecalc.glade")) 52 wtree.add_from_file(sibpath(__file__, "../light9/curvecalc/curvecalc.glade"))
53 mainwin = wtree.get_object("MainWindow") 53 mainwin = wtree.get_object("MainWindow")
54 54
55 mainwin.connect("destroy", self.onQuit) 55 mainwin.connect("destroy", self.onQuit)
56 wtree.connect_signals(self) 56 wtree.connect_signals(self)
57 gtk.rc_parse("theme/marble-ice/gtk-2.0/gtkrc")
58 gtk.rc_parse_string("""style "default" {font_name = "sans 7"}""")
59 if self.opts.reload:
60 self.refreshTheme()
57 mainwin.show_all() 61 mainwin.show_all()
58 62
59 mainwin.connect("delete-event", lambda *args: reactor.crash()) 63 mainwin.connect("delete-event", lambda *args: reactor.crash())
60 mainwin.set_title("curvecalc - %s" % graph.label(song)) 64 mainwin.set_title("curvecalc - %s" % graph.label(song))
61 65
62 self.add_subterms_for_song(song, curveset, subterms, 66 self.add_subterms_for_song(song, curveset, subterms,
63 wtree.get_object("subterms") 67 wtree.get_object("subterms")
64 ) 68 )
65 69 self.refreshCurveView()
66 def refreshCurveView():
67 mtimes = [os.path.getmtime(f) for f in [
68 'light9/curvecalc/curveview.py',
69 'light9/curvecalc/zoomcontrol.py',
70 ]]
71
72 if (not hasattr(self, 'curvesetView') or
73 self.curvesetView._mtimes != mtimes):
74 print "reload curveview.py"
75 curvesVBox = wtree.get_object("curves")
76 zoomControlBox = wtree.get_object("zoomControlBox")
77 [curvesVBox.remove(c) for c in curvesVBox.get_children()]
78 [zoomControlBox.remove(c) for c in
79 zoomControlBox.get_children()]
80 try:
81 linecache.clearcache()
82 reload(curveview)
83 # mem problem somewhere; need to hold a ref to this
84 self.curvesetView = curveview.Curvesetview(
85 curvesVBox, zoomControlBox, curveset)
86 self.curvesetView._mtimes = mtimes
87
88 # curvesetview must already exist, since this
89 # makes 'add_curve' signals for all the initial
90 # curves
91 curveset.load(basename=os.path.join(
92 showconfig.curvesDir(),
93 showconfig.songFilenameFromURI(song)),
94 skipMusic=opts.skip_music)
95 # this is scheduled after some tk shuffling, to
96 # try to minimize the number of times we redraw
97 # the curve at startup. If tk is very slow, it's
98 # ok. You'll just get some wasted redraws.
99 self.curvesetView.goLive()
100 except Exception, e:
101 print "reload failed:", e
102 reactor.callLater(1, refreshCurveView)
103 refreshCurveView()
104 70
105 self.makeStatusLines(wtree.get_object("status")) 71 self.makeStatusLines(wtree.get_object("status"))
72
73 def refreshTheme(self):
74 gtk.rc_reparse_all()
75 reactor.callLater(1, self.refreshTheme)
106 76
107 def onQuit(self, *args): 77 def onQuit(self, *args):
108 reactor.crash() 78 reactor.crash()
109 # there's a hang after this, maybe in sem_wait in two 79 # there's a hang after this, maybe in sem_wait in two
110 # threads. I don't know whose they are. 80 # threads. I don't know whose they are.
163 dispatcher.connect(lambda val, value=value, tf=textfilter: 133 dispatcher.connect(lambda val, value=value, tf=textfilter:
164 value.set_text(tf(val)), 134 value.set_text(tf(val)),
165 signame, weak=False) 135 signame, weak=False)
166 master.show_all() 136 master.show_all()
167 137
168 138 def refreshCurveView(self):
169 def onReloadSubs(self): # wants to be ctrl-r too 139 wtree = self.wtree
140 mtimes = [os.path.getmtime(f) for f in [
141 'light9/curvecalc/curveview.py',
142 'light9/curvecalc/zoomcontrol.py',
143 ]]
144
145 if (not hasattr(self, 'curvesetView') or
146 self.curvesetView._mtimes != mtimes):
147 print "reload curveview.py"
148 curvesVBox = wtree.get_object("curves")
149 zoomControlBox = wtree.get_object("zoomControlBox")
150 [curvesVBox.remove(c) for c in curvesVBox.get_children()]
151 [zoomControlBox.remove(c) for c in
152 zoomControlBox.get_children()]
153 try:
154 linecache.clearcache()
155 reload(curveview)
156 # mem problem somewhere; need to hold a ref to this
157 self.curvesetView = curveview.Curvesetview(
158 curvesVBox, zoomControlBox, self.curveset)
159 self.curvesetView._mtimes = mtimes
160
161 # curvesetview must already exist, since this
162 # makes 'add_curve' signals for all the initial
163 # curves
164 self.curveset.load(basename=os.path.join(
165 showconfig.curvesDir(),
166 showconfig.songFilenameFromURI(self.song)),
167 skipMusic=self.opts.skip_music)
168 # this is scheduled after some tk shuffling, to
169 # try to minimize the number of times we redraw
170 # the curve at startup. If tk is very slow, it's
171 # ok. You'll just get some wasted redraws.
172 self.curvesetView.goLive()
173 except Exception, e:
174 print "reload failed:", e
175 if self.opts.reload:
176 reactor.callLater(1, self.refreshCurveView)
177
178 def onReloadSubs(self, *args): # wants to be ctrl-r too
170 dispatcher.send('reload all subs') 179 dispatcher.send('reload all subs')
171 180
172 def onAddSubterm(self): 181 def onAddSubterm(self):
173 uri = L9['sub/%s' % newname.get()] 182 uri = L9['sub/%s' % newname.get()]
174 graph.add((uri, RDF.type, L9.Subterm)) 183 graph.add((uri, RDF.type, L9.Subterm))
188 help='use hardware sliders') 197 help='use hardware sliders')
189 parser.add_option("--skip-music", action='store_true', 198 parser.add_option("--skip-music", action='store_true',
190 help="ignore music and smooth_music curve files") 199 help="ignore music and smooth_music curve files")
191 parser.add_option("--debug", action="store_true", 200 parser.add_option("--debug", action="store_true",
192 help="log at DEBUG") 201 help="log at DEBUG")
202 parser.add_option("--reload", action="store_true",
203 help="live reload of themes and code")
193 parser.add_option("--startup-only", action='store_true', 204 parser.add_option("--startup-only", action='store_true',
194 help="quit after loading everything (for timing tests)") 205 help="quit after loading everything (for timing tests)")
195 opts, args = parser.parse_args() 206 opts, args = parser.parse_args()
196 207
197 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") 208 logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
201 try: 212 try:
202 song = URIRef(args[0]) 213 song = URIRef(args[0])
203 except IndexError: 214 except IndexError:
204 song = currentlyPlayingSong() 215 song = currentlyPlayingSong()
205 216
206 music=Music() 217 music = Music()
207 graph = makeGraph() 218 graph = makeGraph()
208 219
209 curveset = Curveset(sliders=opts.sliders) 220 curveset = Curveset(sliders=opts.sliders)
210 subterms = [] 221 subterms = []
211 222
231 242
232 if opts.startup_only: 243 if opts.startup_only:
233 log.debug("quitting now because of --startup-only") 244 log.debug("quitting now because of --startup-only")
234 return 245 return
235 246
236 reactor.run() 247 prof.run(reactor.run, profile=False)
237 248
238 main() 249 main()