Beispiel #1
0
class AbstractBeeMaster:
	""" This is a class that can be inherited from to provide a bee master object that controls tools, windows, layers, and options
	"""
	def __init__(self):
		# setup tool box
		self.toolbox=BeeToolBox()

		self.curwindow=None

		self.config={}
		self.configlock=qtcore.QReadWriteLock()

	def getConfigOption(self,key,default=None):
		""" This function is used to fetch options, I'm well aware that dictionaries have a get function, but I want this function to output a debug message if the key isn't found """
		lock=qtcore.QReadLocker(self.configlock)
		if key in self.config:
			return self.config[key]
		print_debug("couldn't find config option: %s" % key)
		return default

	def refreshLayerThumb(self,window,layer=0):
		""" Indicates that layer thumbnails need to be updated, this may or may not need to be reimplemented in the subclass """
		return

	def getToolClassByName(self,name):
		return self.toolbox.getToolDescByName(name)

	def getCurToolInst(self,window):
		pass

	def getCurWindow(self,lock=None):
		return self.curwindow

	def getCurToolDesc(self):
		"""	return description object for current tool """
		return self.toolbox.getCurToolDesc()

	def registerWindow(self,window):
		pass

	def getLayerById(self,win_id,layer_id):
		""" return layer of current window that has specified ID, return None if no layer with that ID is found """
		return self.curwindow.getLayerByKey(layer_id)

	#def getLayerById(self,win_id):
	#	return self.curwindow

	def startRemoteDrawingThreads(self):
		pass
Beispiel #2
0
class HiveMasterWindow(qtgui.QMainWindow):
	# this constructor should never be called directly, use an alternate
	def __init__(self,app):
		qtgui.QMainWindow.__init__(self)
		self.app=app

		# Initialize values
		self.connections=[]
		self.nextclientid=1
		self.nextclientidmutex=qtcore.QMutex()

		self.password=""

		# setup interface
		self.ui=Ui_HiveMasterSpec()
		self.ui.setupUi(self)
		self.show()

		# setup queues used for all thread communication
		self.routinginput=Queue(0)
		self.routingthread=HiveRoutingThread(self)
		self.routingthread.start()

		# this will be keyed on the client ids and values will be queue objects
		self.clientwriterqueues={}

		# this dictionary will be keyed on id and map to the username
		self.clientnames={}

		self.toolbox=BeeToolBox()

		# drawing window which holds the current state of the network session
		self.window=BeeDrawingWindow(self,600,400,False,WindowTypes.standaloneserver)

	def getToolClassByName(self,name):
		self.toolbox.getToolClassByName(name)

	def getCurToolInst(self,window):
		curtool=self.getCurToolDesc()
		return curtool.setupTool(window)

	def getCurToolDesc(self):
		return self.toolbox.getCurToolDesc()

	# alternate constuctor to create a standalone server
	def standAloneServer(app):
		master=HiveMasterWindow(app)
		master.standalonemode=True
		# this serves as both the window and the master
		master.master=master
		master.layers=[]
		
		master.serverthread=None

	standAloneServer=staticmethod(standAloneServer)

	def registerClient(self,username):
		lock=qtcore.QMutexLocker(self.nextclientidmutex)
		newid=self.nextclientid
		self.nextclientid+=1
		lock.unlock()
		self.clientwriterqueues[newid]=Queue(100)
		self.clientnames[newid]=username
		return newid

	def closeEvent(self,event):
		qtgui.QMainWindow.closeEvent(self,event)
#		self.stopServer()

	def startServer(self):
		# make sure no other instance is running

		self.stopServer()
		self.serverthread=HiveServerThread(self)
		print "starting thread:"
		self.serverthread.start()

	def stopServer(self):
		if self.serverthread:
			self.serverthread.terminate()
			self.serverthread.wait()
			self.serverthread=None

	def on_actionStart_triggered(self):
		self.startServer()