comparison bin/curvecalc @ 1859:f066d6e874db

2to3 with these fixers: all idioms set_literal Ignore-this: cbd28518218c2f0ddce8c4f92d3b8b33
author drewp@bigasterisk.com
date Wed, 22 May 2019 00:08:22 +0000
parents 7772cc48e016
children 5bcb950024af
comparison
equal deleted inserted replaced
1858:7772cc48e016 1859:f066d6e874db
6 6
7 7
8 todo: curveview should preserve more objects, for speed maybe 8 todo: curveview should preserve more objects, for speed maybe
9 9
10 """ 10 """
11 from __future__ import division 11
12 12
13 import sys 13 import sys
14 import imp
14 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk 15 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk
15 from twisted.internet import gtk3reactor 16 from twisted.internet import gtk3reactor
16 gtk3reactor.install() 17 gtk3reactor.install()
17 from twisted.internet import reactor 18 from twisted.internet import reactor
18 19
20 import gi 21 import gi
21 from gi.repository import Gtk 22 from gi.repository import Gtk
22 from gi.repository import GObject 23 from gi.repository import GObject
23 from gi.repository import Gdk 24 from gi.repository import Gdk
24 25
25 from urlparse import parse_qsl 26 from urllib.parse import parse_qsl
26 import louie as dispatcher 27 import louie as dispatcher
27 from rdflib import URIRef, Literal, RDF, RDFS 28 from rdflib import URIRef, Literal, RDF, RDFS
28 import logging 29 import logging
29 30
30 from run_local import log 31 from run_local import log
169 targets=[Gtk.TargetEntry('text/uri-list', 0, 0)], 170 targets=[Gtk.TargetEntry('text/uri-list', 0, 0)],
170 actions=Gdk.DragAction.COPY) 171 actions=Gdk.DragAction.COPY)
171 172
172 def recv(widget, context, x, y, selection, targetType, time): 173 def recv(widget, context, x, y, selection, targetType, time):
173 subUri = URIRef(selection.data.strip()) 174 subUri = URIRef(selection.data.strip())
174 print "into curves", subUri 175 print("into curves", subUri)
175 with self.graph.currentState(tripleFilter=(subUri, RDFS.label, 176 with self.graph.currentState(tripleFilter=(subUri, RDFS.label,
176 None)) as current: 177 None)) as current:
177 subName = current.label(subUri) 178 subName = current.label(subUri)
178 179
179 if '?' in subUri: 180 if '?' in subUri:
188 # we're not making sure the expression/etc are 189 # we're not making sure the expression/etc are
189 # correct-- user mihgt need to fix things 190 # correct-- user mihgt need to fix things
190 pass 191 pass
191 curveView = self.curvesetView.row(subName).curveView 192 curveView = self.curvesetView.row(subName).curveView
192 t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source 193 t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source
193 print "time", t 194 print("time", t)
194 curveView.add_points([(t - .5, 0), (t, 1)]) 195 curveView.add_points([(t - .5, 0), (t, 1)])
195 196
196 w.connect("drag-data-received", recv) 197 w.connect("drag-data-received", recv)
197 198
198 def onDragDataInNewSubZone(self, widget, context, x, y, selection, 199 def onDragDataInNewSubZone(self, widget, context, x, y, selection,
410 """various labels that listen for dispatcher signals""" 411 """various labels that listen for dispatcher signals"""
411 for row, (signame, textfilter) in enumerate([ 412 for row, (signame, textfilter) in enumerate([
412 ('input time', lambda t: "%.2fs" % t), 413 ('input time', lambda t: "%.2fs" % t),
413 ('output levels', lambda levels: textwrap.fill( 414 ('output levels', lambda levels: textwrap.fill(
414 "; ".join([ 415 "; ".join([
415 "%s:%.2f" % (n, v) for n, v in levels.items()[:2] if v > 0 416 "%s:%.2f" % (n, v) for n, v in list(levels.items())[:2] if v > 0
416 ]), 70)), 417 ]), 70)),
417 ('update period', lambda t: "%.1fms" % (t * 1000)), 418 ('update period', lambda t: "%.1fms" % (t * 1000)),
418 ('update status', lambda x: str(x)), 419 ('update status', lambda x: str(x)),
419 ]): 420 ]):
420 key = Gtk.Label("%s:" % signame) 421 key = Gtk.Label("%s:" % signame)
443 ] 444 ]
444 ] 445 ]
445 446
446 if (not hasattr(self, 'curvesetView') or 447 if (not hasattr(self, 'curvesetView') or
447 self.curvesetView._mtimes != mtimes): 448 self.curvesetView._mtimes != mtimes):
448 print "reload curveview.py" 449 print("reload curveview.py")
449 curvesVBox = wtree.get_object("curves") 450 curvesVBox = wtree.get_object("curves")
450 zoomControlBox = wtree.get_object("zoomControlBox") 451 zoomControlBox = wtree.get_object("zoomControlBox")
451 [curvesVBox.remove(c) for c in curvesVBox.get_children()] 452 [curvesVBox.remove(c) for c in curvesVBox.get_children()]
452 [zoomControlBox.remove(c) for c in zoomControlBox.get_children()] 453 [zoomControlBox.remove(c) for c in zoomControlBox.get_children()]
453 try: 454 try:
454 linecache.clearcache() 455 linecache.clearcache()
455 reload(curveview) 456 imp.reload(curveview)
456 457
457 # old ones are not getting deleted right 458 # old ones are not getting deleted right
458 if hasattr(self, 'curvesetView'): 459 if hasattr(self, 'curvesetView'):
459 self.curvesetView.live = False 460 self.curvesetView.live = False
460 461
467 # try to minimize the number of times we redraw 468 # try to minimize the number of times we redraw
468 # the curve at startup. If tk is very slow, it's 469 # the curve at startup. If tk is very slow, it's
469 # ok. You'll just get some wasted redraws. 470 # ok. You'll just get some wasted redraws.
470 self.curvesetView.goLive() 471 self.curvesetView.goLive()
471 except Exception: 472 except Exception:
472 print "reload failed:" 473 print("reload failed:")
473 traceback.print_exc() 474 traceback.print_exc()
474 if self.opts.reload: 475 if self.opts.reload:
475 reactor.callLater(1, self.refreshCurveView) 476 reactor.callLater(1, self.refreshCurveView)
476 477
477 478