You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

  1. '''
  2. Created on Dec 22, 2013
  3. @author: Chris
  4. '''
  5. import wx
  6. import sys
  7. import traceback
  8. from gooey import i18n
  9. from multiprocessing.dummy import Pool, Process
  10. YES = 5103
  11. NO = 5104
  12. class Controller(object):
  13. '''
  14. Main controller for the gui.
  15. All controlls are delegated to this central control point.
  16. Args:
  17. base_frame = Reference to the Basewindow
  18. head_panel = reference to the BaseWindow's Head Panel
  19. body_panel = reference to the BaseWindow's Body Panel
  20. footer_panel = reference to the BaseWindow's Footer Panel
  21. model = configuration model
  22. translator = instance of the I18N class
  23. '''
  24. def __init__(self, base_frame, client_app):
  25. self._base = base_frame
  26. self._client_app = client_app
  27. self._payload_runner = Process(target=self.RunClientCode)
  28. def OnCancelButton(self, widget, event):
  29. msg = i18n.translate('sure_you_want_to_exit')
  30. dlg = wx.MessageDialog(None, msg, i18n.translate('close_program'), wx.YES_NO)
  31. result = dlg.ShowModal()
  32. print result
  33. if result == YES:
  34. dlg.Destroy()
  35. self._base.Destroy()
  36. sys.exit()
  37. dlg.Destroy()
  38. def OnStartButton(self, widget, event):
  39. cmd_line_args = self._base.GetOptions()
  40. if not self._client_app.IsValidArgString(cmd_line_args):
  41. error_msg = self._client_app.GetErrorMsg(cmd_line_args)
  42. self.ShowDialog(i18n.translate('error_title'), error_msg, wx.ICON_ERROR)
  43. return
  44. self._client_app.AddToArgv(cmd_line_args)
  45. self._base.NextPage()
  46. self._payload_runner.start()
  47. def ManualStart(self):
  48. self._base.NextPage()
  49. wx.CallAfter(wx.ActivateEvent)
  50. self._payload_runner.start()
  51. def OnCloseButton(self, widget, event):
  52. self._base.Destroy()
  53. sys.exit()
  54. def RunClientCode(self):
  55. pool = Pool(1)
  56. try:
  57. pool.apply(self._client_app.payload)
  58. self._base.NextPage()
  59. self.ShowGoodFinishedDialog()
  60. except:
  61. self.ShowBadFinishedDialog(traceback.format_exc())
  62. def ShowGoodFinishedDialog(self):
  63. self.ShowDialog(i18n.translate("execution_finished"),
  64. i18n.translate('success_message'),
  65. wx.ICON_INFORMATION)
  66. def ShowBadFinishedDialog(self, error_msg):
  67. msg = i18n.translate('uh_oh').format(error_msg)
  68. self.ShowDialog(i18n.translate('error_title'), msg, wx.ICON_ERROR)
  69. def ShowDialog(self, title, content, style):
  70. a = wx.MessageDialog(None, content, title, style)
  71. a.ShowModal()
  72. a.Destroy()