Get something basic working

This commit is contained in:
Marco Pesenti Gritti 2006-05-19 14:18:41 -04:00
parent 795e4bb2db
commit d2cc475095
6 changed files with 49 additions and 30 deletions

View File

@ -1,3 +1,5 @@
from SVGdraw import path
class Sketch:
def __init__(self):
self._points = []
@ -14,3 +16,16 @@ class Sketch:
else:
ctx.line_to(x, y)
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')

View File

@ -5,6 +5,9 @@ import cairo
from Sketch import Sketch
from SVGdraw import drawing
from SVGdraw import svg
class SketchPad(gtk.DrawingArea):
def __init__(self):
gtk.DrawingArea.__init__(self)
@ -42,7 +45,19 @@ class SketchPad(gtk.DrawingArea):
if self._active_sketch:
self._active_sketch.add_point(event.x, event.y)
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__":
window = gtk.Window()
window.set_default_size(400, 300)
@ -54,4 +69,6 @@ if __name__ == "__main__":
window.show()
window.connect("destroy", test_quit, sketchpad)
gtk.main()

View File

@ -537,23 +537,20 @@ class MostlyReliablePipe(object):
return False
def _retransmit_check_worker(self):
try:
now = time.time()
for key in self._incoming.keys()[:]:
message = self._incoming[key]
if message.complete():
continue
next_rt = message.next_rt_time()
if next_rt == 0 or next_rt > now:
continue
if self._retransmit_request(message):
# Kill the message, too many retries
print "(MRP): Dropped message %s, exceeded retries." % _stringify_sha(message.sha())
self._dispatched[key] = message
message.set_dispatch_time()
del self._incoming[key]
except KeyboardInterrupt:
return False
now = time.time()
for key in self._incoming.keys()[:]:
message = self._incoming[key]
if message.complete():
continue
next_rt = message.next_rt_time()
if next_rt == 0 or next_rt > now:
continue
if self._retransmit_request(message):
# Kill the message, too many retries
print "(MRP): Dropped message %s, exceeded retries." % _stringify_sha(message.sha())
self._dispatched[key] = message
message.set_dispatch_time()
del self._incoming[key]
return True
def _process_incoming_data(self, segment):

View File

@ -60,14 +60,7 @@ class PresenceDiscovery(object):
# 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)
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 = 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.connect_to_signal('ItemNew', self.new_service_type)
self._service_type_browsers[(interface, protocol, domain)] = b

View File

@ -38,7 +38,4 @@ def start(console):
args.append('--console')
os.spawnvp(os.P_NOWAIT, 'python', args)
try:
gtk.main()
except KeyboardInterrupt:
pass
gtk.main()