[shpy-commit] r2848 - in shpy/trunk/dist/shpy: . net
arigo@codespeak.net
arigo@codespeak.net
Tue, 20 Jan 2004 14:41:13 +0100 (MET)
Author: arigo
Date: Tue Jan 20 14:41:12 2004
New Revision: 2848
Modified:
shpy/trunk/dist/shpy/net/gateway.py
shpy/trunk/dist/shpy/ui_pygame.py
Log:
- Clean shutdown procedure (though holger still get segfaults at exit).
- Beginning of resizable windows -- doesn't really work yet.
Modified: shpy/trunk/dist/shpy/net/gateway.py
==============================================================================
--- shpy/trunk/dist/shpy/net/gateway.py (original)
+++ shpy/trunk/dist/shpy/net/gateway.py Tue Jan 20 14:41:12 2004
@@ -20,15 +20,20 @@
SockQueueSender(self.sock, self.outgoing)
]
for t in self.threads:
- t.running = 1
t.gateway = self
t.start()
self.running = 1
def exit(self):
self.running = 0
+ print "closing socket"
+ self.sock.shutdown(2)
+ print "putting none to queues"
+ self.incoming.put(None)
+ self.outgoing.put(None)
for t in self.threads:
- t.running = 0
+ print "joining thread", t
+ t.join(10.0)
def __nonzero__(self):
return self.running
@@ -38,17 +43,19 @@
class SockQueueReader(threading.Thread):
def __init__(self, sock, queue):
- threading.Thread.__init__(self)
+ threading.Thread.__init__(self, name="queuereader")
self.sock = sock
self.queue = queue
def run(self):
sockfile = self.sock.makefile('rb')
unpickler = pickle.Unpickler(sockfile)
- while self.running:
+ while 1:
try:
string = unpickler.load()
self.queue.put(string)
+ except EOFError:
+ break
except:
import traceback
traceback.print_exc()
@@ -57,12 +64,14 @@
class QueueExecutor(threading.Thread):
def __init__(self, queue):
- threading.Thread.__init__(self)
+ threading.Thread.__init__(self, name="queueexector")
self.queue = queue
def run(self):
- while self.running:
+ while 1:
source = self.queue.get()
+ if source is None:
+ break
try:
print "executing source", source
co = dyncode.makecode(source)
@@ -75,12 +84,14 @@
class SockQueueSender(threading.Thread):
def __init__(self, sock, queue):
- threading.Thread.__init__(self)
+ threading.Thread.__init__(self, name="sockqueuesender")
self.sock = sock
self.queue = queue
def run(self):
- while self.running:
+ while 1:
obj = self.queue.get()
+ if obj is None:
+ break
f = self.sock.makefile('wb')
pickler = pickle.Pickler(f)
pickler.dump(obj)
Modified: shpy/trunk/dist/shpy/ui_pygame.py
==============================================================================
--- shpy/trunk/dist/shpy/ui_pygame.py (original)
+++ shpy/trunk/dist/shpy/ui_pygame.py Tue Jan 20 14:41:12 2004
@@ -6,7 +6,7 @@
import shpy.net.register
from shpy.net.structure import Structure, representstructure, getstructureid
-RESOLUTION = (800, 600)
+RESOLUTION = (768, 512)
#RESOLUTION = (400, 300)
#FONT = 'lucon.ttf'
FONT = None
@@ -119,7 +119,7 @@
self.servergateway = shpy.net.register.ServerGateway(hostport, ns)
pygame.init()
pygame.key.set_repeat(500,30)
- self.screen = pygame.display.set_mode(RESOLUTION)
+ pygame.display.set_mode(RESOLUTION, RESIZABLE)
self.font = pygame.font.Font(FONT, HEIGHT)
self.root = self.servergateway.registerclient()
username = getusername()
@@ -134,21 +134,22 @@
self.vscroll = 0
def repaint(self):
- self.screen.fill((255,255,255))
- self.drawcell(self.cell)
+ screen = pygame.display.get_surface()
+ screen.fill((255,255,255))
+ self.drawcell(screen, self.cell)
pygame.display.flip()
- def drawcell(self, cell):
+ def drawcell(self, screen, cell):
ypos = self.vscroll
yposlist = []
for line in cell.lines:
yposlist.append(ypos)
lineimage = self.font.render(line or ' ', 1, (0,0,0))
- self.screen.blit(lineimage, (0, ypos))
+ screen.blit(lineimage, (0, ypos))
ypos += lineimage.get_size()[1]
- self.drawcursors(yposlist)
+ self.drawcursors(screen, yposlist)
- def drawcursors(self, yposlist):
+ def drawcursors(self, screen, yposlist):
othercursors = self.root.users.__dict__.values()
try:
othercursors.remove(self.cursor)
@@ -165,15 +166,15 @@
ypos = yposlist[y]
char = line[x:x+1] or ' '
charimage = self.font.render(char, 1, (255,255,255), cursor.color)
- self.screen.blit(charimage, (xpos, ypos))
+ screen.blit(charimage, (xpos, ypos))
if ypos < 0:
- self.screen.fill((255, 255, 255))
+ screen.fill((255, 255, 255))
self.vscroll -= ypos
- self.drawcell(self.cell)
- elif ypos + charimage.get_size()[1] > self.screen.get_size()[1]:
- self.screen.fill((255, 255, 255))
- self.vscroll -= ypos + charimage.get_size()[1] - self.screen.get_size()[1]
- self.drawcell(self.cell)
+ self.drawcell(screen, self.cell)
+ elif ypos + charimage.get_size()[1] > screen.get_size()[1]:
+ screen.fill((255, 255, 255))
+ self.vscroll -= ypos + charimage.get_size()[1] - screen.get_size()[1]
+ self.drawcell(screen, self.cell)
def K_UP(self):
if self.cursor.y > 0:
@@ -215,6 +216,10 @@
break
if event.type == REPAINTEVENT:
invalid = True
+ print "trying to quit the gateway ..."
+ self.servergateway.exit()
+ print "calling pygame.quit()"
+ pygame.quit()
def postrepaintevent(self):
pygame.event.post(pygame.event.Event(REPAINTEVENT))