Mercurial > code > home > repos > light9
comparison bin/curvecalc @ 1056:547d65ea9902
port curvecalc to gtk3. mostly worked, but there are severe bugs with redraws
Ignore-this: 2a9ba18d1c180831446257054e5d7e8a
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 01 Jun 2014 20:35:38 +0000 |
parents | 86732ba7d9ae |
children | 7f5a9958095b |
comparison
equal
deleted
inserted
replaced
1055:6ce00faec207 | 1056:547d65ea9902 |
---|---|
11 """ | 11 """ |
12 from __future__ import division | 12 from __future__ import division |
13 | 13 |
14 import sys | 14 import sys |
15 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk | 15 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk |
16 from twisted.internet import gtk2reactor | 16 from twisted.internet import gtk3reactor |
17 gtk2reactor.install() | 17 gtk3reactor.install() |
18 from twisted.internet import reactor | 18 from twisted.internet import reactor |
19 | 19 |
20 import time, textwrap, os, optparse, gtk, linecache, signal, traceback, json | 20 import time, textwrap, os, optparse, linecache, signal, traceback, json |
21 import gi | |
22 from gi.repository import Gtk | |
23 from gi.repository import GObject | |
24 from gi.repository import Gdk | |
25 | |
21 from urlparse import parse_qsl | 26 from urlparse import parse_qsl |
22 import louie as dispatcher | 27 import louie as dispatcher |
23 from rdflib import URIRef, Literal, RDF, RDFS | 28 from rdflib import URIRef, Literal, RDF, RDFS |
24 import logging | 29 import logging |
25 | 30 |
35 from light9.curvecalc.subtermview import add_one_subterm | 40 from light9.curvecalc.subtermview import add_one_subterm |
36 from light9.curvecalc.output import Output | 41 from light9.curvecalc.output import Output |
37 from light9.gtkpyconsole import togglePyConsole | 42 from light9.gtkpyconsole import togglePyConsole |
38 from light9.rdfdb.syncedgraph import SyncedGraph | 43 from light9.rdfdb.syncedgraph import SyncedGraph |
39 from light9.rdfdb.patch import Patch | 44 from light9.rdfdb.patch import Patch |
40 from light9.editchoicegtk import EditChoice | 45 from light9.editchoicegtk import EditChoice, Local |
41 from light9.observable import Observable | 46 from light9.observable import Observable |
42 | 47 |
43 class SubtermExists(ValueError): | 48 class SubtermExists(ValueError): |
44 pass | 49 pass |
45 | 50 |
48 self.graph, self.opts, self.session = graph, opts, session | 53 self.graph, self.opts, self.session = graph, opts, session |
49 self.curveset, self.music = curveset, music | 54 self.curveset, self.music = curveset, music |
50 self.lastSeenInputTime = 0 | 55 self.lastSeenInputTime = 0 |
51 self.currentSubterms = [] # Subterm objects that are synced to the graph | 56 self.currentSubterms = [] # Subterm objects that are synced to the graph |
52 | 57 |
53 wtree = self.wtree = gtk.Builder() | 58 wtree = self.wtree = Gtk.Builder() |
54 wtree.add_from_file("light9/curvecalc/curvecalc.glade") | 59 wtree.add_from_file("light9/curvecalc/curvecalc.glade") |
55 mainwin = wtree.get_object("MainWindow") | 60 mainwin = wtree.get_object("MainWindow") |
56 | 61 |
57 mainwin.connect("destroy", self.onQuit) | 62 mainwin.connect("destroy", self.onQuit) |
58 wtree.connect_signals(self) | 63 wtree.connect_signals(self) |
59 gtk.rc_parse("theme/marble-ice/gtk-2.0/gtkrc") | 64 Gtk.rc_parse("theme/marble-ice/gtk-2.0/gtkrc") |
60 gtk.rc_parse_string("""style "default" {font_name = "sans 9"}""") | 65 Gtk.rc_parse_string("""style "default" {font_name = "sans 9"}""") |
61 if self.opts.reload: | 66 if self.opts.reload: |
62 self.refreshTheme() | 67 self.refreshTheme() |
63 mainwin.show_all() | 68 mainwin.show_all() |
64 | 69 |
65 mainwin.connect("delete-event", lambda *args: reactor.crash()) | 70 mainwin.connect("delete-event", lambda *args: reactor.crash()) |
80 songChoice(graph.value(session, L9['currentSong'])) | 85 songChoice(graph.value(session, L9['currentSong'])) |
81 dispatcher.send("song_has_changed") | 86 dispatcher.send("song_has_changed") |
82 graph.addHandler(setSong) | 87 graph.addHandler(setSong) |
83 # next here, watch songChoice and patch the graph | 88 # next here, watch songChoice and patch the graph |
84 def songToGraph(newSong): | 89 def songToGraph(newSong): |
90 if newSong is Local: | |
91 raise NotImplementedError('what do i patch') | |
85 graph.patchObject(context=session, subject=session, | 92 graph.patchObject(context=session, subject=session, |
86 predicate=L9['currentSong'], newObject=newSong) | 93 predicate=L9['currentSong'], newObject=newSong) |
87 songChoice.subscribe(songToGraph) | 94 songChoice.subscribe(songToGraph) |
88 def current_player_song(song): | 95 def current_player_song(song): |
89 # (this is run on every frame) | 96 # (this is run on every frame) |
98 if wtree.get_object("followPlayerSongChoice").get_active(): | 105 if wtree.get_object("followPlayerSongChoice").get_active(): |
99 songChoice(song) | 106 songChoice(song) |
100 | 107 |
101 self.current_player_song = current_player_song | 108 self.current_player_song = current_player_song |
102 dispatcher.connect(current_player_song, "current_player_song") | 109 dispatcher.connect(current_player_song, "current_player_song") |
103 | 110 |
104 ec = EditChoice(graph, songChoice, label="Editing song:") | 111 ec = EditChoice(graph, songChoice, label="Editing song:") |
105 wtree.get_object("currentSongEditChoice").add(ec) | 112 wtree.get_object("currentSongEditChoice").add(ec) |
106 ec.show() | 113 ec.show() |
107 | 114 |
108 wtree.get_object("subterms").connect("add", self.onSubtermChildAdded) | 115 wtree.get_object("subterms").connect("add", self.onSubtermChildAdded) |
109 | 116 |
110 | |
111 self.refreshCurveView() | 117 self.refreshCurveView() |
112 | 118 |
113 self.makeStatusLines(wtree.get_object("status")) | 119 self.makeStatusLines(wtree.get_object("status")) |
114 self.setupNewSubZone() | 120 self.setupNewSubZone() |
115 self.acceptDragsOnCurveViews() | 121 self.acceptDragsOnCurveViews() |
117 # may not work | 123 # may not work |
118 wtree.get_object("paned1").set_position(600) | 124 wtree.get_object("paned1").set_position(600) |
119 | 125 |
120 def setupNewSubZone(self): | 126 def setupNewSubZone(self): |
121 self.wtree.get_object("newSubZone").drag_dest_set( | 127 self.wtree.get_object("newSubZone").drag_dest_set( |
122 flags=gtk.DEST_DEFAULT_ALL, | 128 flags=Gtk.DestDefaults.ALL, |
123 targets=[('text/uri-list', 0, 0)], | 129 targets=[Gtk.TargetEntry('text/uri-list', 0, 0)], |
124 actions=gtk.gdk.ACTION_COPY) | 130 actions=Gdk.DragAction.COPY) |
125 | 131 |
126 def acceptDragsOnCurveViews(self): | 132 def acceptDragsOnCurveViews(self): |
127 w = self.wtree.get_object("curves") | 133 w = self.wtree.get_object("curves") |
128 w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, | 134 w.drag_dest_set(flags=Gtk.DestDefaults.ALL, |
129 targets=[('text/uri-list', 0, 0)], | 135 targets=[Gtk.TargetEntry('text/uri-list', 0, 0)], |
130 actions=gtk.gdk.ACTION_COPY) | 136 actions=Gdk.DragAction.COPY) |
131 def recv(widget, context, x, y, selection, | 137 def recv(widget, context, x, y, selection, |
132 targetType, time): | 138 targetType, time): |
133 subUri = URIRef(selection.data.strip()) | 139 subUri = URIRef(selection.data.strip()) |
134 print "into curves", subUri | 140 print "into curves", subUri |
135 with self.graph.currentState( | 141 with self.graph.currentState( |
293 add_one_subterm(term, self.curveset, master) | 299 add_one_subterm(term, self.curveset, master) |
294 master.show_all() | 300 master.show_all() |
295 log.debug("%s table children showing" % len(master.get_children())) | 301 log.debug("%s table children showing" % len(master.get_children())) |
296 | 302 |
297 def refreshTheme(self): | 303 def refreshTheme(self): |
298 gtk.rc_reparse_all() | 304 Gtk.rc_reparse_all() |
299 reactor.callLater(1, self.refreshTheme) | 305 reactor.callLater(1, self.refreshTheme) |
300 | 306 |
301 def onSubtermChildAdded(self, subtermsTable, *args): | 307 def onSubtermChildAdded(self, subtermsTable, *args): |
302 # this would probably work, but isn't getting called | 308 # this would probably work, but isn't getting called |
303 log.info("onSubtermChildAdded") | 309 log.info("onSubtermChildAdded") |
358 levels.items()[:2] | 364 levels.items()[:2] |
359 if v>0]),70)), | 365 if v>0]),70)), |
360 ('update period', lambda t: "%.1fms"%(t*1000)), | 366 ('update period', lambda t: "%.1fms"%(t*1000)), |
361 ('update status', lambda x: str(x)), | 367 ('update status', lambda x: str(x)), |
362 ]): | 368 ]): |
363 key = gtk.Label("%s:" % signame) | 369 key = Gtk.Label("%s:" % signame) |
364 value = gtk.Label("") | 370 value = Gtk.Label("") |
365 master.resize(row + 1, 2) | 371 master.resize(row + 1, 2) |
366 master.attach(key, 0, 1, row, row + 1) | 372 master.attach(key, 0, 1, row, row + 1) |
367 master.attach(value, 1, 2, row, row + 1) | 373 master.attach(value, 1, 2, row, row + 1) |
368 key.set_alignment(1, 0) | 374 key.set_alignment(1, 0) |
369 value.set_alignment(0, 0) | 375 value.set_alignment(0, 0) |
454 mt = MaxTime(graph, session) | 460 mt = MaxTime(graph, session) |
455 dispatcher.connect(lambda: mt.get(), "get max time", weak=False) | 461 dispatcher.connect(lambda: mt.get(), "get max time", weak=False) |
456 | 462 |
457 start = Main(graph, opts, session, curveset, music) | 463 start = Main(graph, opts, session, curveset, music) |
458 out = Output(graph, session, music, curveset, start.currentSubterms) | 464 out = Output(graph, session, music, curveset, start.currentSubterms) |
465 | |
459 | 466 |
460 dispatcher.send("show all") | 467 dispatcher.send("show all") |
461 | 468 |
462 if opts.startup_only: | 469 if opts.startup_only: |
463 log.debug("quitting now because of --startup-only") | 470 log.debug("quitting now because of --startup-only") |