Пример #1
0
  def _on_edit_ok(self, e):
    assert (self._edited_row is not None)

    user, bookmark, fudge_amount = None, None, None

    try:
      user = self._edit_user_field.GetValue()
      if (len(user) == 0 or user == "@"): user = None
      bookmark = common.delta_from_str(self._edit_bookmark_field.GetValue())
      fudge_amount = common.delta_from_str(self._edit_fudge_field.GetValue())
    except (ValueError) as err:
      pass

    proceed = True
    for x,noun in [(user, "user"), (bookmark, "time"), (fudge_amount, "fudge amount")]:
      if (x is None):
        self.statusbar.SetStatusText("Error: Bad %s." % noun, self.STATUS_HELP)
        proceed = False
        break

    if (proceed is True):
      prev_row_count = self.fudge_table.GetNumberRows()

      self._snarks_wrapper.checkout(self.__class__.__name__)
      config = self._snarks_wrapper.get_config()
      if (self._edited_row != -1):
        # Remove the old user fudge that had been edited.
        doomed_user = self.fudge_table.GetValue(self._edited_row, self.fudge_table.COL_USER)
        doomed_bookmark = common.delta_from_str(self.fudge_table.GetValue(self._edited_row, self.fudge_table.COL_GLOBALLY_FUDGED_TIME))
        snarkutils.config_remove_user_fudge(config, doomed_user, doomed_bookmark)

      snarkutils.config_add_user_fudge(config, user, (bookmark, fudge_amount))
      snarkutils.gui_fudge_users(config, self._snarks_wrapper.get_snarks())
      self._snarks_wrapper.commit()

      new_event = common.SnarksEvent([common.SnarksEvent.FLAG_CONFIG_FUDGES, common.SnarksEvent.FLAG_SNARKS])
      self._snarks_wrapper.fire_snarks_event(new_event)

      self._on_edit_cancel(None)

      if (prev_row_count == 0):
        self.fudge_grid.AutoSizeColumn(self.fudge_table.COL_GLOBALLY_FUDGED_TIME)
        self.fudge_grid.AutoSizeColumn(self.fudge_table.COL_USER_FUDGE)

    if (e is not None): e.Skip(False)  # Consume the event.
Пример #2
0
  def _on_place_snark(self, e):
    """Adds a new fudge_users value to make the grabbed snark visible at the current video time.
    All config and snarks listeners will be notified of changes.
    """
    if (self._grabbed_snark is None):
      self.statusbar.SetStatusText("Error: No snark was grabbed.", self.STATUS_HELP)
    else:
      vlc_milliseconds = wx.GetApp().player_frame.get_vlc_time()
      if (vlc_milliseconds == -1):
        self.statusbar.SetStatusText("Error: VLC reported a bad time. Aborting placement.", self.STATUS_HELP)
        if (e is not None): e.Skip(False)  # Consume the event.
        return

      grabbed_snark = self._grabbed_snark
      self._grabbed_snark = None
      current_time = timedelta(seconds=(vlc_milliseconds//1000))
      fudge_delta = current_time - grabbed_snark["_globally fudged time"]
      fudge_tuple = (grabbed_snark["_globally fudged time"], fudge_delta)

      self._snarks_wrapper.checkout(self.__class__.__name__)
      snarkutils.config_add_user_fudge(self._snarks_wrapper.get_config(), grabbed_snark["user"], fudge_tuple)
      snarkutils.gui_fudge_users(self._snarks_wrapper.get_config(), self._snarks_wrapper.get_snarks())
      self._snarks_wrapper.commit()

      new_event = common.SnarksEvent([common.SnarksEvent.FLAG_CONFIG_FUDGES, common.SnarksEvent.FLAG_SNARKS])
      self._snarks_wrapper.fire_snarks_event(new_event)

      # Reselect the grabbed snark.
      for i in range(len(self._snarks)):
        snark = self._snarks[i]
        if (snark["user"] == grabbed_snark["user"] and snark["date"] == grabbed_snark["date"]):
          self.snark_grid.SelectRow(i, False)
          break

    self.grab_btn.Enable(True)
    self.place_btn.Enable(False)
    self.drop_btn.Enable(False)
    if (e is not None): e.Skip(False)  # Consume the event.