Ejemplo n.º 1
0
class HiveClientWriter(qtcore.QThread):
	def __init__(self,parent,socket,master,id):
		qtcore.QThread.__init__(self)
		self.setParent(self)

		self.socket=socket
		self.master=master
		self.id=id

		self.master.registerWriterThread(id,self)

		self.buffer=qtcore.QBuffer()
		self.buffer.open(qtcore.QIODevice.ReadWrite)

		# add to list of writing threads
		lock=qtcore.QReadLocker(self.master.clientslistmutex)
		self.queue=self.master.clientwriterqueues[id]

		# create custom QXmlStreamWriter
		#self.xmlgenerator=SketchLogWriter(self.socket)

		self.xmlgenerator=SketchLogWriter(self.buffer)

		#print "attempting to connect signal"
		#self.connect(self.queue,qtcore.SIGNAL("datainqueue()"),self,qtcore.SIGNAL("datainqueue()"))
		#print "attempted to connect signal"

	def run(self):
		while 1:
			if not self.socket.isConnected():
				self.master.unregisterClient(self.id)
				return

			#print "Hive Client Writer is ready to read from queue:", self.queue
			# block until item is available from thread safe queue
			data=self.queue.get()
			if data[0]==DrawingCommandTypes.quit:
				self.master.unregisterClient(self.id)
				print_debug("exiting client writer thread")
				return
			#print "Hive Client Writer got command from Queue:", data
			# write xml data to socket
			self.xmlgenerator.logCommand(data)

			datastr="%s" % qtcore.QString(self.buffer.data())
			#print_debug("client writer wrote to sending buffer: %s" % datastr)
			self.socket.write(datastr)
			self.buffer.buffer().resize(0)
			self.buffer.seek(0)
Ejemplo n.º 2
0
class NetworkWriterThread (qtcore.QThread):
	def __init__(self,window,socket):
		qtcore.QThread.__init__(self)
		self.socket=socket
		self.gen=SketchLogWriter(self.socket)

		self.window=window
		self.queue=window.remoteoutputqueue

	def run(self):
		while 1:
			print "attempting to get item from queue"
			command=self.queue.get()
			if command[0]==DrawingCommandTypes.quit:
				return
			self.gen.logCommand(command)
Ejemplo n.º 3
0
class HiveClientWriter(qtcore.QThread):
	def __init__(self,parent,socket,master,id):
		#qtcore.QThread.__init__(self,parent)
		qtcore.QThread.__init__(self)
		self.setParent(self)

		self.socket=socket
		self.master=master
		self.id=id

		self.queue=self.master.clientwriterqueues[id]
		self.xmlgenerator=SketchLogWriter(self.socket)

	def run(self):
		self.xmlgenerator.logCreateDocument(self.master.window.docwidth,self.master.window.docheight)
		while 1:
			data=self.queue.get()
			self.xmlgenerator.logCommand(data)
Ejemplo n.º 4
0
class NetworkWriterThread (qtcore.QThread):
	""" class representing a client thread that is sending information to server
  """
	def __init__(self,windowid,socket):
		qtcore.QThread.__init__(self)
		self.socket=socket

		self.buffer=qtcore.QBuffer()
		self.buffer.open(qtcore.QIODevice.ReadWrite)
		self.gen=SketchLogWriter(self.buffer)

		window=BeeApp().master.getWindowById(windowid)

		self.queue=window.remoteoutputqueue

	def run(self):

		while 1:
			# write out initial document start tag
			datastr="%s" % qtcore.QString(self.buffer.data())
			#print "wrote to buffer: %s" % datastr
			self.socket.write(datastr)
			self.buffer.buffer().resize(0)
			self.buffer.seek(0)

			#if self.socket.state()==qtnet.QAbstractSocket.UnconnectedState:
			if not self.socket.isConnected():
				break

			#print_debug("attempting to get item from queue")
			command=self.queue.get()
			print_debug("Network Writer Thread got command from queue: %s" % str(command))
			if command[0]==DrawingCommandTypes.quit:
				return

			self.gen.logCommand(command)