Ejemplo n.º 1
0
  def _on_parse(self, e):
    old_snarks = self._snarks_wrapper.clone_snarks()
    if (len(old_snarks) > 0):
      user_cancelled = False
      d = wx.MessageDialog(self, "If you parse again, existing snarks will be lost.\nContinue?", "Are you sure?",
                           wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
      d.Center()  # Doesn't work.
      if (d.ShowModal() != wx.ID_YES):
        user_cancelled = True
      d.Destroy()
      if (user_cancelled is True): return

    if (self.show_log_nags is True):
      wx.GetApp().show_log_frame(self)

    config = self._snarks_wrapper.clone_config()

    def threaded_code(snarks_wrapper=self._snarks_wrapper, config=config, keep_alive_func=None, sleep_func=None):
      # Don't touch snarks_wrapper until back in the main thread.
      try:
        logging.info("Calling %s parser..." % config.parser_name)
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Calling %s parser..." % config.parser_name})
        snarks = snarkutils.parse_snarks(config, keep_alive_func=keep_alive_func, sleep_func=sleep_func)

        if (len(snarks) == 0):
          raise common.CompileSubsException("No messages were parsed.")

        snarkutils.gui_preprocess_snarks(config, snarks)
        snarkutils.gui_fudge_users(config, snarks)

        if (len(snarks) == 0):
          raise common.CompileSubsException("After preprocessing, no messages were left.")

        logging.info("Parsing succeeded.")
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Parsing succeeded."})

        def main_code(snarks_wrapper=snarks_wrapper, snarks=snarks):
          snarks_wrapper.checkout(self.__class__.__name__)
          snarks_wrapper.set_snarks(snarks)
          snarks_wrapper.commit()

          event = common.SnarksEvent([common.SnarksEvent.FLAG_SNARKS])
          snarks_wrapper.fire_snarks_event(event)
        wx.CallAfter(main_code)

      except (common.CompileSubsException) as err:
        # Parser failed in an uninteresting way.
        logging.error(str(err))
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: %s" % str(err)})

      except (Exception) as err:
        logging.exception(err)
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: The parser failed in an unexpected way."})

    t = killable_threading.WrapperThread()
    t.set_payload(threaded_code)
    t.start()
    global_config.get_cleanup_handler().add_thread(t)

    if (e is not None): e.Skip(False)  # Consume the event.
Ejemplo n.º 2
0
  def _on_export(self, e):
    config = self._snarks_wrapper.clone_config()
    snarks = self._snarks_wrapper.clone_snarks()

    if (len(snarks) == 0):
      user_cancelled = False
      d = wx.MessageDialog(self, "No snarks to export.\nThe result won't be very interesting.\nContinue?", "Are you sure?",
                           wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
      d.Center()  # Doesn't work.
      if (d.ShowModal() != wx.ID_YES):
        user_cancelled = True
      d.Destroy()
      if (user_cancelled is True): return

    if (self.show_log_nags is True):
      wx.GetApp().show_log_frame(self)

    def threaded_code(config=config, snarks=snarks, keep_alive_func=None, sleep_func=None):
      try:
        snarkutils.gui_postprocess_snarks(config, snarks)
        if (len(snarks) == 0):
          raise common.CompileSubsException("After postprocessing, no messages were left.")

        logging.info("Calling %s exporter..." % config.exporter_name)
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Calling %s exporter..." % config.exporter_name})
        snarkutils.export_snarks(config, snarks, keep_alive_func=None, sleep_func=None)

        logging.info("Export succeeded.")
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Export succeeded."})

      except (common.CompileSubsException) as err:
        # Exporter failed in an uninteresting way.
        logging.error(str(err))
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: %s" % str(err)})

      except (Exception) as err:
        logging.exception(err)
        wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: The exporter failed in an unexpected way."})

    t = killable_threading.WrapperThread()
    t.set_payload(threaded_code)
    t.start()
    global_config.get_cleanup_handler().add_thread(t)

    if (e is not None): e.Skip(False)  # Consume the event.
Ejemplo n.º 3
0
def main_gui():
  config = None
  snarks = []

  logging.info("Registering ctrl-c handler.")
  cleanup_handler = global_config.get_cleanup_handler()
  cleanup_handler.register()  # Must be called from main thread.
  # Warning: If the main thread gets totally blocked, it'll never notice sigint.
  sys.excepthook = create_exception_handler(logger, cleanup_handler)

  try:
    mygui = csgui.GuiApp(redirect=False, clearSigInt=False)
    cleanup_handler.add_gui(mygui)

    try:
      mygui.MainLoop()
    finally:
      mygui.done = True

  except (Exception) as err:
    logging.exception(err)

  finally:
    cleanup_handler.cleanup()