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()