commotion_client.utils.single_application.SingleApplicationWithMessaging Class Reference
Inheritance diagram for commotion_client.utils.single_application.SingleApplicationWithMessaging:
commotion_client.utils.single_application.SingleApplication

Public Member Functions

def __init__
 
def handle_message
 
def send_message
 
def process_message
 
- Public Member Functions inherited from commotion_client.utils.single_application.SingleApplication
def __init__
 
def is_running
 

Additional Inherited Members

- Public Attributes inherited from commotion_client.utils.single_application.SingleApplication
 log
 
 main
 
 status_bar
 
 control_panel
 
 shared_memory
 

Detailed Description

The interprocess messaging class for the Commotion Client. This class extends the single application to allow for instantiations of the Commotion Client to pass messages to the existing client if it is already running. When a second instance of a Commotion Client is run without a message specified it will reaise the earler clients main window to the front and then close itself.

e.g:
python3.3 CommotionClient.py --message "COMMAND"

Member Function Documentation

def commotion_client.utils.single_application.SingleApplicationWithMessaging.handle_message (   self)
Server side implementation of the messaging functions. This function waits for signals it receives and then emits a SIGNAL "messageAvailable" with the decoded message.

(Emits a signal instead of just calling a function in case we decide we would like to allow other components or extensions to listen for messages from new instances.)

References commotion_client.utils.single_application.SingleApplicationWithMessaging._timeout, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.validate.ClientConfig.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, commotion_client.utils.validate.Networking.translate, and commotion_client.utils.extension_manager.ConfigManager.translate.

76 
77  def handle_message(self):
78  """
79  Server side implementation of the messaging functions. This function waits for signals it receives and then emits a SIGNAL "messageAvailable" with the decoded message.
80 
81  (Emits a signal instead of just calling a function in case we decide we would like to allow other components or extensions to listen for messages from new instances.)
82  """
83  socket = self._server.nextPendingConnection()
84  if socket.waitForReadyRead(self._timeout):
85  self.emit(QtCore.SIGNAL("messageAvailable"), bytes(socket.readAll().data()).decode('utf-8'))
86  socket.disconnectFromServer()
87  self.log.debug(self.translate("logs", "message received and emitted in a messageAvailable signal"))
88  else:
89  self.log.error(socket.errorString())
def commotion_client.utils.single_application.SingleApplicationWithMessaging.process_message (   self,
  message 
)
Process which processes messages an app receives and takes actions on valid requests.

References commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.utils.validate.ClientConfig.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, commotion_client.utils.validate.Networking.translate, and commotion_client.utils.extension_manager.ConfigManager.translate.

110  def process_message(self, message):
111  """
112  Process which processes messages an app receives and takes actions on valid requests.
113  """
114  self.log.debug(self.translate("logs", "Applicaiton received a message {0}, but does not have a message parser to handle it.").format(message))
def commotion_client.utils.single_application.SingleApplicationWithMessaging.send_message (   self,
  message 
)
Message sending function. Connected to local socket specified by shared key and if successful writes the message to it and returns.

References commotion_client.utils.single_application.SingleApplication._key, commotion_client.utils.single_application.SingleApplicationWithMessaging._timeout, commotion_client.utils.single_application.SingleApplication.is_running(), commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.validate.ClientConfig.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, commotion_client.utils.validate.Networking.translate, and commotion_client.utils.extension_manager.ConfigManager.translate.

90 
91  def send_message(self, message):
92  """
93  Message sending function. Connected to local socket specified by shared key and if successful writes the message to it and returns.
94  """
95  if self.is_running():
96  socket = QtNetwork.QLocalSocket(self)
97  socket.connectToServer(self._key, QtCore.QIODevice.WriteOnly)
98  if not socket.waitForConnected(self._timeout):
99  self.log.error(socket.errorString())
100  return False
101  socket.write(str(message).encode("utf-8"))
102  if not socket.waitForBytesWritten(self._timeout):
103  self.log.error(socket.errorString())
104  return False
105  socket.disconnectFromServer()
106  return True
107  self.log.debug(self.translate("logs", "Attempted to send message when commotion client application was not currently running."))
108  return False
def is_running
Definition: single_application.py:49

The documentation for this class was generated from the following file:
  • commotion_client/utils/single_application.py