Пример #1
0
	def __init__(self):
		self._mode = self._get_AdvPressed()

		cfg = "ABCClient.cfg"
		self._cfg = UT.load_cfg(cfg)
		#self.__cfgCheckDefaults()
		self.connectionManager = ConnectionManager( self._cfg )
		newLogger = Logger(self.connectionManager.logger)
		# Remove to start the logging
		sys.stdout = newLogger

		self._handler = ClABCHandler( self.connectionManager )
		self._handler._frames['main'] = ActivityManager(None,-1,"Activity Manager", self )

		self.__initGUI()
Пример #2
0
class ABCClient(object):
	def __init__(self):
		self._mode = self._get_AdvPressed()

		cfg = "ABCClient.cfg"
		self._cfg = UT.load_cfg(cfg)
		#self.__cfgCheckDefaults()
		self.connectionManager = ConnectionManager( self._cfg )
		newLogger = Logger(self.connectionManager.logger)
		# Remove to start the logging
		sys.stdout = newLogger

		self._handler = ClABCHandler( self.connectionManager )
		self._handler._frames['main'] = ActivityManager(None,-1,"Activity Manager", self )

		self.__initGUI()

	def _get_AdvPressed(self):
		"""Hack for key hook"""
		ms = wx.GetMouseState()
		if ms.shiftDown: 
			sel = 0
		elif ms.controlDown: 
			# text for query
			sel = 1
		else: 
			# normal usage
			sel = -1        
		return sel

	def __cfgCheckDefaults(self): # TODO> update new stuff
		if 'General' not in self._cfg.sections():
			self._cfg.add_section('General')
			self._cfg.set('General', 'ServerIp', 'localhost')
			self._cfg.set('General', 'ServerPort', '5000')
			self._cfg.set('General', 'ClientIp', 'localhost')
			self._cfg.set('General', 'ClientPort', '5001')
			self._cfg.set('General', 'cfgFile', cfgFile)
			self._cfg.set('General', 'UserName', 'Paolo')
			self._cfg.set('General', 'frameFolder', '../library/basic_frames')
		if 'ActivityManager' not in self._cfg.sections():
			self._cfg.add_section('ActivityManager')
			self._cfg.set('', 'Position_x', '0')
			self._cfg.set('ActivityManager', 'Position_y', '0')
			self._cfg.set('ActivityManager', 'Dimension_x', '100')
			self._cfg.set('ActivityManager', 'Dimension_y', '50')
		if 'Frames' not in self._cfg.sections():
			self._cfg.add_section('Frames')
			self._cfg.set('Frames', 'application', 'ApplicationList.py')
			self._cfg.set('Frames', 'notifications', 'NotificationManager.py')
			self._cfg.set('Frames', 'activities', 'ActivityList.py')
			self._cfg.set('Frames', 'contacts', 'ContactList.py')

	def _getHandler(self):
		return self._handler
	def _getCfg(self):
		return self._cfg

	def _log(self, msg, raw=False):
		if isinstance(msg, str):
			msg = (msg, )
		for x in msg:
			self._handler._frames['main']._log(x, raw)

	def __initGUI(self):
		if self._mode == -1:
			# normal usage
			self._log('Normal usage')
			for model in self._cfg.get('General', 'model').split(','):
				if len(model):            
					self._log( self._handler.connect( self._cfg.get('General', 'UserName'), model ))
					if self._handler._me == None:
						return
			self._executeGUI()

		elif self._mode == 1:
			# ctrl - only text for query 
			self._log('Ctrl usage')

		elif self._mode == 0:
			# shift - ?
			self._log('Shift usage')

	def _executeGUI(self):
		folder = self._cfg.get('General', 'frameFolder')
		toLoad = self._cfg.items('Frames')
		for name, file in toLoad:
			if name in ['activities']:
				self._handler._execute(name,'python', [os.path.join(folder, file)])                

	def CloseGUI(self):
		self._handler.suspend(True)
		time.sleep(1)
		for x in self._handler._model:
			self.disconnect(x)
		return


    # ----------------------------------------------
    # ActivityManager functionalities
    # ----------------------------------------------
	def connect(self, name, model):
		self._handler._clearGUI()
		self._log( self._handler.connect( name, model ))

		self._cfg.set('General', 'UserName', name)
		self._cfg.set('General', 'model', ', '.join(self._handler._model))

		self._handler._frames['main'].SetStatusText(self._cfg.get('General', 'ServerIp') + ':' + str(self._cfg.get('General', 'ServerPort')), 1)
		self._handler._frames['main'].SetStatusText(self._cfg.get('General', 'UserName'), 2)
		self._handler._frames['main'].SetStatusText(repr(self._handler._model), 3)

	def disconnect(self, model):
		self._log( self._handler.disconnect(model) )
		self._handler._frames['main'].SetStatusText(repr(self._handler._model), 3)

	def setServer(self, addr, port):
		self._log(self._handler.setServer( addr, port ) )
	def store(self, wip):
		self._log(self._handler.store( wip ))
	def restore(self, wip='srv.state'):
		self._log(self._handler.restore( wip ))
	def run(self, wip):
		self._log( self._handler.run( wip ), True )
	def getDataCopy(self):
		return self._handler._getDataCopy()