Get something basic working
This commit is contained in:
parent
795e4bb2db
commit
d2cc475095
@ -1,3 +1,5 @@
|
|||||||
|
from SVGdraw import path
|
||||||
|
|
||||||
class Sketch:
|
class Sketch:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._points = []
|
self._points = []
|
||||||
@ -14,3 +16,16 @@ class Sketch:
|
|||||||
else:
|
else:
|
||||||
ctx.line_to(x, y)
|
ctx.line_to(x, y)
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
|
|
||||||
|
def draw_to_svg(self):
|
||||||
|
i = 0
|
||||||
|
for [x, y] in self._points:
|
||||||
|
coords = str(x) + ' ' + str(y) + ' '
|
||||||
|
if i == 0:
|
||||||
|
path_data = 'M ' + coords
|
||||||
|
elif i == 1:
|
||||||
|
path_data += 'L ' + coords
|
||||||
|
else:
|
||||||
|
path_data += coords
|
||||||
|
i += 1
|
||||||
|
return path(path_data, fill = 'none', stroke = '#000000')
|
||||||
|
@ -5,6 +5,9 @@ import cairo
|
|||||||
|
|
||||||
from Sketch import Sketch
|
from Sketch import Sketch
|
||||||
|
|
||||||
|
from SVGdraw import drawing
|
||||||
|
from SVGdraw import svg
|
||||||
|
|
||||||
class SketchPad(gtk.DrawingArea):
|
class SketchPad(gtk.DrawingArea):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.DrawingArea.__init__(self)
|
gtk.DrawingArea.__init__(self)
|
||||||
@ -43,6 +46,18 @@ class SketchPad(gtk.DrawingArea):
|
|||||||
self._active_sketch.add_point(event.x, event.y)
|
self._active_sketch.add_point(event.x, event.y)
|
||||||
self.window.invalidate_rect(None, False)
|
self.window.invalidate_rect(None, False)
|
||||||
|
|
||||||
|
def to_svg(self):
|
||||||
|
d = drawing()
|
||||||
|
s = svg()
|
||||||
|
for sketch in self._sketches:
|
||||||
|
s.addElement(sketch.draw_to_svg())
|
||||||
|
d.setSVG(s)
|
||||||
|
return d.toXml()
|
||||||
|
|
||||||
|
def test_quit(w, sketchpad):
|
||||||
|
print sketchpad.to_svg()
|
||||||
|
gtk.main_quit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
window = gtk.Window()
|
window = gtk.Window()
|
||||||
window.set_default_size(400, 300)
|
window.set_default_size(400, 300)
|
||||||
@ -54,4 +69,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
window.connect("destroy", test_quit, sketchpad)
|
||||||
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
@ -537,7 +537,6 @@ class MostlyReliablePipe(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _retransmit_check_worker(self):
|
def _retransmit_check_worker(self):
|
||||||
try:
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for key in self._incoming.keys()[:]:
|
for key in self._incoming.keys()[:]:
|
||||||
message = self._incoming[key]
|
message = self._incoming[key]
|
||||||
@ -552,8 +551,6 @@ class MostlyReliablePipe(object):
|
|||||||
self._dispatched[key] = message
|
self._dispatched[key] = message
|
||||||
message.set_dispatch_time()
|
message.set_dispatch_time()
|
||||||
del self._incoming[key]
|
del self._incoming[key]
|
||||||
except KeyboardInterrupt:
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _process_incoming_data(self, segment):
|
def _process_incoming_data(self, segment):
|
||||||
|
@ -60,14 +60,7 @@ class PresenceDiscovery(object):
|
|||||||
|
|
||||||
# print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
|
# print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
|
||||||
|
|
||||||
try:
|
|
||||||
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
|
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
|
||||||
except dbus.DBusException, exc:
|
|
||||||
str_exc = str(exc)
|
|
||||||
if str_exc.find("The name org.freedesktop.Avahi was not provided by any .service files") >= 0:
|
|
||||||
raise Exception("Avahi does not appear to be running. '%s'" % str_exc)
|
|
||||||
else:
|
|
||||||
raise exc
|
|
||||||
b.connect_to_signal('ItemNew', self.new_service_type)
|
b.connect_to_signal('ItemNew', self.new_service_type)
|
||||||
|
|
||||||
self._service_type_browsers[(interface, protocol, domain)] = b
|
self._service_type_browsers[(interface, protocol, domain)] = b
|
||||||
|
@ -38,7 +38,4 @@ def start(console):
|
|||||||
args.append('--console')
|
args.append('--console')
|
||||||
os.spawnvp(os.P_NOWAIT, 'python', args)
|
os.spawnvp(os.P_NOWAIT, 'python', args)
|
||||||
|
|
||||||
try:
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
Loading…
Reference in New Issue
Block a user