commotion_client.commotion_client.CommotionClientApplication Class Reference
Inheritance diagram for commotion_client.commotion_client.CommotionClientApplication:

Public Member Functions

def __init__
 
def init_client
 
def init_logging
 
def start_full
 
def start_daemon
 
def stop_client
 
def restart_client
 
def create_main_window
 
def init_main
 
def hide_main_window
 
def close_main_window
 
def create_controller
 
def init_controller
 
def close_controller
 
def init_sys_tray
 
def create_sys_tray
 
def close_sys_tray
 
def process_message
 
def end
 

Public Attributes

 translate
 
 status
 
 controller
 
 main
 
 sys_tray
 
 logger
 
 log
 

Static Public Attributes

tuple restarted = QtCore.pyqtSignal()
 

Detailed Description

The final layer of the class onion that is the Commotion client. This class includes functions to enable the sub-processes and modules of the Commotion Client (GUI's and controllers). 

Member Function Documentation

def commotion_client.commotion_client.CommotionClientApplication.close_controller (   self,
  force_close = None 
)
Closes the controller process.

@param force_close bool If the application fails to kill the controller, the whole application should be shut down.

Referenced by commotion_client.commotion_client.CommotionClientApplication.stop_client().

404  def close_controller(self, force_close=None):
405  """
406  Closes the controller process.
407 
408  @param force_close bool If the application fails to kill the controller, the whole application should be shut down.
409  """
410  try:
411  pass #TODO Swap with below when controller close function is instantiated
412  #if self.controller.close():
413  # self.controller = None
414  except Exception as _excp:
415  self.log.error(self.translate("logs", "Could not close controller."))
416  if force_close:
417  self.log.info(self.translate("logs", "force_close activated. Closing application."))
418  try:
419  del self.controller
420  except Exception as _excp:
421  _catch_all = self.translate("logs", "Could not close controller using its internal mechanisms. Application will be halted.")
422  self.log.critical(_catch_all)
423  self.log.exception(_excp)
424  self.end(_catch_all)
425  else:
426  self.log.error(self.translate("logs", "Could not cleanly close controller."))
427  self.log.info(self.translate("logs", "It is reccomended that you close the entire application."))
428  self.log.exception(_excp)
429  raise
430 
431 
432 #=================================================
433 # SYSTEM TRAY
434 #=================================================
def close_controller
Definition: commotion_client.py:403
def commotion_client.commotion_client.CommotionClientApplication.close_main_window (   self,
  force_close = None 
)
Closes the main window and task-bar. Only removes the GUI components without closing the application.

@param force_close bool If the application fails to kill the main window, the whole application should be shut down.
@return bool

References commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), commotion_client.commotion_client.CommotionClientApplication.main, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.hide_main_window(), and commotion_client.commotion_client.CommotionClientApplication.stop_client().

356  def close_main_window(self, force_close=None):
357  """
358  Closes the main window and task-bar. Only removes the GUI components without closing the application.
359 
360  @param force_close bool If the application fails to kill the main window, the whole application should be shut down.
361  @return bool
362  """
363  try:
364  self.main.purge
365  self.main = False
366  except Exception as _excp:
367  self.log.error(self.translate("logs", "Could not close main window."))
368  if force_close:
369  self.log.info(self.translate("logs", "force_close activated. Closing application."))
370  try:
371  self.main.deleteLater()
372  self.main = False
373  except Exception as _excp:
374  _catch_all = self.translate("logs", "Could not close main window using its internal mechanisms. Application will be halted.")
375  self.log.critical(_catch_all)
376  self.log.exception(_excp)
377  self.end(_catch_all)
378  else:
379  self.log.error(self.translate("logs", "Could not close main window."))
380  self.log.info(self.translate("logs", "It is reccomended that you close the entire application."))
381  self.log.exception(_excp)
382  raise
383 
384 #=================================================
385 # CONTROLLER
386 #=================================================
def close_main_window
Definition: commotion_client.py:355
def commotion_client.commotion_client.CommotionClientApplication.close_sys_tray (   self,
  force_close = None 
)
Closes the system tray. Only removes the GUI components without closing the application.

@param force_close bool If the application fails to kill the main window, the whole application should be shut down.
@return bool 

References commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), commotion_client.commotion_client.CommotionClientApplication.sys_tray, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.stop_client().

462  def close_sys_tray(self, force_close=None):
463  """
464  Closes the system tray. Only removes the GUI components without closing the application.
465 
466  @param force_close bool If the application fails to kill the main window, the whole application should be shut down.
467  @return bool
468  """
469  try:
470  self.sys_tray.close()
471  self.sys_tray = False
472  except Exception as _excp:
473  self.log.error(self.translate("logs", "Could not close system tray."))
474  if force_close:
475  self.log.info(self.translate("logs", "force_close activated. Closing application."))
476  try:
477  self.sys_tray.deleteLater()
478  self.sys_tray.close()
479  except:
480  _catch_all = self.translate("logs", "Could not close system tray using its internal mechanisms. Application will be halted.")
481  self.log.critical(_catch_all)
482  self.log.exception(_excp)
483  self.end(_catch_all)
484  else:
485  self.log.error(self.translate("logs", "Could not close system tray."))
486  self.log.info(self.translate("logs", "It is reccomended that you close the entire application."))
487  self.log.exception(_excp)
488  raise
489 
490 #=================================================
491 # APPLICATION UTILS
492 #=================================================
def close_sys_tray
Definition: commotion_client.py:461
def commotion_client.commotion_client.CommotionClientApplication.create_controller (   self)
Creates a controller to act as the middleware between the GUI and the commotion core.

References commotion_client.commotion_client.CommotionClientApplication.translate.

388  def create_controller(self):
389  """
390  Creates a controller to act as the middleware between the GUI and the commotion core.
391  """
392  try:
393  pass #replace when controller is ready
394  #self.controller = CommotionController() #TODO Implement controller
395  #self.controller.init() #??????
396  except Exception as _excp:
397  self.log.critical(self.translate("logs", "Could not create controller. Application must be halted."))
398  self.log.exception(_excp)
399  raise
def create_controller
Definition: commotion_client.py:387
def commotion_client.commotion_client.CommotionClientApplication.create_main_window (   self)
Will create a new main window or return existing main window if one is already created.

References commotion_client.commotion_client.CommotionClientApplication.main, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.hide_main_window(), and commotion_client.commotion_client.CommotionClientApplication.start_full().

273  def create_main_window(self):
274  """
275  Will create a new main window or return existing main window if one is already created.
276  """
277  if self.main:
278  self.log.debug(self.translate("logs", "New window requested when one already exists. Returning existing main window."))
279  self.log.info(self.translate("logs", "If you would like to close the main window and re-open it please call close_main_window() first."))
280  return self.main
281  try:
282  _main = main_window.MainWindow()
283  except Exception as _excp:
284  self.log.critical(self.translate("logs", "Could not create Main Window. Application must be halted."))
285  raise
286  else:
287  return _main
def create_main_window
Definition: commotion_client.py:272
def commotion_client.commotion_client.CommotionClientApplication.create_sys_tray (   self)
Starts the system tray

References commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.start_daemon(), and commotion_client.commotion_client.CommotionClientApplication.start_full().

449  def create_sys_tray(self):
450  """
451  Starts the system tray
452  """
453  try:
454  tray = system_tray.TrayIcon()
455  except Exception as _excp:
456  self.log.error(self.translate("logs", "Could not start system tray."))
457  self.log.exception(_excp)
458  raise
459  else:
460  return tray
def create_sys_tray
Definition: commotion_client.py:448
def commotion_client.commotion_client.CommotionClientApplication.end (   self,
  message = None 
)
Handles properly exiting the application.

@param message string optional exit message to print to standard error on application close. This will FORCE the application to close in an unclean way.

References commotion_client.GUI.system_tray.TrayIcon.exit, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.close_controller(), commotion_client.commotion_client.CommotionClientApplication.close_main_window(), commotion_client.commotion_client.CommotionClientApplication.close_sys_tray(), commotion_client.commotion_client.CommotionClientApplication.init_client(), commotion_client.commotion_client.CommotionClientApplication.restart_client(), commotion_client.commotion_client.CommotionClientApplication.start_full(), and commotion_client.commotion_client.CommotionClientApplication.stop_client().

510  def end(self, message=None):
511  """
512  Handles properly exiting the application.
513 
514  @param message string optional exit message to print to standard error on application close. This will FORCE the application to close in an unclean way.
515  """
516  if message:
517  self.log.error(self.translate("logs", message))
518  self.exit(1)
519  else:
520  self.quit()
def commotion_client.commotion_client.CommotionClientApplication.hide_main_window (   self,
  force = None,
  errors = None 
)
Attempts to hide the main window without closing the task-bar.

@param force bool Force window reset if hiding is unsuccessful.
@param errors If set to "strict" errors found will be raised before returning the boolean result.
@return bool Return True if successful and false is unsuccessful.

References commotion_client.commotion_client.CommotionClientApplication.close_main_window(), commotion_client.commotion_client.CommotionClientApplication.create_main_window(), commotion_client.commotion_client.CommotionClientApplication.main, commotion_client.commotion_client.CommotionClientApplication.process_message(), and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.start_daemon().

309  def hide_main_window(self, force=None, errors=None):
310  """
311  Attempts to hide the main window without closing the task-bar.
312 
313  @param force bool Force window reset if hiding is unsuccessful.
314  @param errors If set to "strict" errors found will be raised before returning the boolean result.
315  @return bool Return True if successful and false is unsuccessful.
316  """
317  try:
318  self.main.exit()
319  except Exception as _excp:
320  self.log.error(self.translate("logs", "Could not hide main window. Attempting to close all and only open taskbar."))
321  self.log.exception(_excp)
322  if force:
323  try:
324  self.main.purge()
325  self.main = None
326  self.main = self.create_main_window()
327  except Exception as _excp:
328  self.log.error(self.translate("logs", "Could not force main window restart."))
329  self.log.exception(_excp)
330  raise
331  elif errors == "strict":
332  raise
333  else:
334  return False
335  else:
336  return True
337  #force hide settings
338  try:
339  #if already open, then close first
340  if self.main:
341  self.close_main_window()
342  #re-open
343  self.main = main_window.MainWindow()
344  self.main.app_message.connect(self.process_message)
345  except:
346  self.log.error(self.translate("logs", "Could close and re-open the main window."))
347  self.log.exception(_excp)
348  if errors == "strict":
349  raise
350  else:
351  return False
352  else:
353  return True
354  return False
def create_main_window
Definition: commotion_client.py:272
def close_main_window
Definition: commotion_client.py:355
def process_message
Definition: commotion_client.py:493
def hide_main_window
Definition: commotion_client.py:308
def commotion_client.commotion_client.CommotionClientApplication.init_client (   self)
Start up client using current status to determine run_level.

References commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), commotion_client.commotion_client.HoldStateDuringRestart.log, commotion_client.commotion_client.CommotionClientApplication.log, commotion_client.commotion_client.CommotionClientApplication.logger, commotion_client.commotion_client.CommotionClientApplication.start_daemon(), commotion_client.commotion_client.CommotionClientApplication.start_full(), commotion_client.commotion_client.CommotionClientApplication.status, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.restart_client().

153  def init_client(self):
154  """
155  Start up client using current status to determine run_level.
156  """
157  try:
158  if not self.status:
159  self.start_full()
160  elif self.status == "daemon":
161  self.start_daemon()
162  except Exception as _excp: #log failure here and exit
163  _catch_all = self.translate("logs", "Could not fully initialize applicaiton. Application must be halted.")
164  self.log.critical(_catch_all)
165  self.log.exception(_excp)
166  self.end(_catch_all)
def start_full
Definition: commotion_client.py:171
def init_client
Definition: commotion_client.py:152
def start_daemon
Definition: commotion_client.py:198
def commotion_client.commotion_client.CommotionClientApplication.init_main (   self)
Main window initializer that shows and connects the main window's messaging function to the app message processor.

References commotion_client.commotion_client.CommotionClientApplication.process_message(), commotion_client.commotion_client.CommotionClientApplication.sys_tray, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.start_full().

289  def init_main(self):
290  """
291  Main window initializer that shows and connects the main window's messaging function to the app message processor.
292  """
293  try:
294  self.main.app_message.connect(self.process_message)
295  if self.sys_tray:
296  self.sys_tray.exit.triggered.connect(self.main.exitEvent)
297  self.sys_tray.show_main.connect(self.main.bring_front)
298  except Exception as _excp:
299  self.log.error(self.translate("logs", "Could not initialize connections between the main window and other application components."))
300  self.log.exception(_excp)
301  raise
302  try:
303  self.main.show()
304  except Exception as _excp:
305  self.log.error(self.translate("logs", "Could not show the main window."))
306  self.log.exception(_excp)
307  raise
def process_message
Definition: commotion_client.py:493
def init_main
Definition: commotion_client.py:288
def commotion_client.commotion_client.CommotionClientApplication.init_sys_tray (   self)
System Tray initializer that runs all processes required to connect the system tray to other application commponents

References commotion_client.commotion_client.CommotionClientApplication.main, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.start_daemon(), and commotion_client.commotion_client.CommotionClientApplication.start_full().

436  def init_sys_tray(self):
437  """
438  System Tray initializer that runs all processes required to connect the system tray to other application commponents
439  """
440  try:
441  if self.main:
442  self.sys_tray.exit.triggered.connect(self.main.exitEvent)
443  self.sys_tray.show_main.connect(self.main.bring_front)
444  except Exception as _excp:
445  self.log.error(self.translate("logs", "Could not initialize connections between the system tray and other application components."))
446  self.log.exception(_excp)
447  raise
def init_sys_tray
Definition: commotion_client.py:435
def commotion_client.commotion_client.CommotionClientApplication.process_message (   self,
  message 
)
Process which processes messages an app receives and takes actions on valid requests.

References commotion_client.commotion_client.CommotionClientApplication.main, commotion_client.commotion_client.CommotionClientApplication.restart_client(), and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.hide_main_window(), and commotion_client.commotion_client.CommotionClientApplication.init_main().

494  def process_message(self, message):
495  """
496  Process which processes messages an app receives and takes actions on valid requests.
497  """
498  if message == "showMain":
499  if self.main != False:
500  self.main.show()
501  self.main.raise_()
502  elif message == "restart":
503  self.log.info(self.translate("logs", "Received a message to restart. Restarting Now."))
504  self.restart_client(force_close=True) #TODO, might not want strict here post-development
505  elif message == "debug":
506  self.logger.set_verbosity("DEBUG")
507  else:
508  self.log.info(self.translate("logs", "message \"{0}\" not a supported type.".format(message)))
def process_message
Definition: commotion_client.py:493
def restart_client
Definition: commotion_client.py:243
def commotion_client.commotion_client.CommotionClientApplication.restart_client (   self,
  force_close = None 
)
Restarts the entire client stack according to current application status.

@param force_close bool Whole application exit if clean close fails. See: close_controller() & close_main_window()

References commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), commotion_client.commotion_client.CommotionClientApplication.init_client(), commotion_client.commotion_client.CommotionClientApplication.stop_client(), and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.process_message().

244  def restart_client(self, force_close=None):
245  """
246  Restarts the entire client stack according to current application status.
247 
248  @param force_close bool Whole application exit if clean close fails. See: close_controller() & close_main_window()
249  """
250  #hold applicaiton state while restarting all other components.
251  _restart = HoldStateDuringRestart()
252  _restart.start()
253  try:
254  self.stop_client(force_close)
255  self.init_client()
256  except Exception as _excp:
257  if force_close:
258  _catch_all = self.translate("logs", "Client could not be restarted. Applicaiton will now be halted")
259  self.log.error(_catch_all)
260  self.log.exception(_excp)
261  self.end(_catch_all)
262  else:
263  self.log.error(self.translate("logs", "Client could not be restarted."))
264  self.log.info(self.translate("logs", "It is reccomended that you restart the application."))
265  self.log.exception(_excp)
266  raise
267  _restart.end()
268 
269 #=================================================
270 # MAIN WINDOW
271 #=================================================
def init_client
Definition: commotion_client.py:152
def stop_client
Definition: commotion_client.py:222
def restart_client
Definition: commotion_client.py:243
def commotion_client.commotion_client.CommotionClientApplication.start_daemon (   self)
Start or switch client over to daemon mode. Daemon mode runs the taskbar without showing the main window.

References commotion_client.commotion_client.CommotionClientApplication.create_sys_tray(), commotion_client.commotion_client.CommotionClientApplication.hide_main_window(), commotion_client.commotion_client.CommotionClientApplication.init_sys_tray(), commotion_client.commotion_client.CommotionClientApplication.main, commotion_client.commotion_client.CommotionClientApplication.sys_tray, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.init_client().

199  def start_daemon(self):
200  """
201  Start or switch client over to daemon mode. Daemon mode runs the taskbar without showing the main window.
202  """
203  try:
204  #Close main window without closing taskbar and system tray
205  if self.main:
206  self.hide_main_window(force=True, errors="strict")
207  except Exception as _excp:
208  self.log.critical(self.translate("logs", "Could not close down existing GUI componenets to switch to daemon mode."))
209  self.log.exception(_excp)
210  raise
211  try:
212  #create controller and sys tray
213  self.sys_tray = self.create_sys_tray()
214  #if not self.controller: #TODO Actually create a stub controller file
215  # self.controller = create_controller()
216  except Exception as _excp:
217  self.log.critical(self.translate("logs", "Could not start daemon. Application must be halted."))
218  self.log.exception(_excp)
219  raise
220  else:
221  self.init_sys_tray()
def init_sys_tray
Definition: commotion_client.py:435
def start_daemon
Definition: commotion_client.py:198
def hide_main_window
Definition: commotion_client.py:308
def create_sys_tray
Definition: commotion_client.py:448
def commotion_client.commotion_client.CommotionClientApplication.start_full (   self)
Start or switch client over to full client.

References commotion_client.commotion_client.CommotionClientApplication.create_main_window(), commotion_client.commotion_client.CommotionClientApplication.create_sys_tray(), commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), commotion_client.commotion_client.CommotionClientApplication.init_main(), commotion_client.commotion_client.CommotionClientApplication.init_sys_tray(), commotion_client.commotion_client.CommotionClientApplication.main, commotion_client.commotion_client.CommotionClientApplication.sys_tray, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.init_client().

172  def start_full(self):
173  """
174  Start or switch client over to full client.
175  """
176  extensions = extension_manager.ExtensionManager()
177  if not extensions.check_installed():
178  extensions.init_extension_libraries()
179  if not self.main:
180  try:
181  self.main = self.create_main_window()
182  except Exception as _excp:
183  _catch_all = self.translate("logs", "Could not create Main Window. Application must be halted.")
184  self.log.critical(_catch_all)
185  self.log.exception(_excp)
186  self.end(_catch_all)
187  else:
188  self.init_main()
189  try:
190  self.sys_tray = self.create_sys_tray()
191  except Exception as _excp:
192  _catch_all = self.translate("logs", "Could not create system tray. Application must be halted.")
193  self.log.critical(_catch_all)
194  self.log.exception(_excp)
195  self.end(_catch_all)
196  else:
197  self.init_sys_tray()
def create_main_window
Definition: commotion_client.py:272
def start_full
Definition: commotion_client.py:171
def init_sys_tray
Definition: commotion_client.py:435
def init_main
Definition: commotion_client.py:288
def create_sys_tray
Definition: commotion_client.py:448
def commotion_client.commotion_client.CommotionClientApplication.stop_client (   self,
  force_close = None 
)
Stops all running client processes.

@param force_close bool Whole application exit if clean close fails. See: close_controller() & close_main_window()

References commotion_client.commotion_client.CommotionClientApplication.close_controller(), commotion_client.commotion_client.CommotionClientApplication.close_main_window(), commotion_client.commotion_client.CommotionClientApplication.close_sys_tray(), commotion_client.commotion_client.HoldStateDuringRestart.end(), commotion_client.commotion_client.CommotionClientApplication.end(), and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.commotion_client.CommotionClientApplication.restart_client().

223  def stop_client(self, force_close=None):
224  """
225  Stops all running client processes.
226 
227  @param force_close bool Whole application exit if clean close fails. See: close_controller() & close_main_window()
228  """
229  try:
230  self.close_main_window(force_close)
231  self.close_sys_tray(force_close)
232  self.close_controller(force_close)
233  except Exception as _excp:
234  if force_close:
235  _catch_all = self.translate("logs", "Could not cleanly close client. Application must be halted.")
236  self.log.critical(_catch_all)
237  self.log.exception(_excp)
238  self.end(_catch_all)
239  else:
240  self.log.error(self.translate("logs", "Client could not be closed."))
241  self.log.info(self.translate("logs", "It is reccomended that you restart the application."))
242  self.log.exception(_excp)
def close_sys_tray
Definition: commotion_client.py:461
def close_main_window
Definition: commotion_client.py:355
def close_controller
Definition: commotion_client.py:403
def stop_client
Definition: commotion_client.py:222

The documentation for this class was generated from the following file: