Ejemplo n.º 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.
Ejemplo n.º 2
0
  def get_value(self):
    """Parses the field(s) into the Arg's native type.
    Disabled optional args have a value of None.

    :returns: The parsed result, and a list of error messages (which may be None).
    """
    if (self._toggle_check.IsChecked() is False):
      if (self._arg.multiple is True):
        return [], None
      else:
        return None, None

    results = []
    errors = []
    for field in self._value_fields:
      if (self._arg.choices is not None):
        choice = field.GetClientData(field.GetSelection())
        results.append(choice)
      else:
        value = field.GetValue()
        try:
          if (self._arg.type == arginfo.TIMEDELTA):
            results.append(common.delta_from_str(value))
          elif (self._arg.type == arginfo.DATETIME):
            if (value == "" or re.match("^0+-0+-0+$", value) is not None or re.match("^[0-9]{4}-[0-9]{2}-[0-9]{2}$", value) is None):
              raise ValueError("Date expected (####-##-##), not \"%s\"." % value)
            results.append(datetime.strptime(value, "%Y-%m-%d"))
          elif (self._arg.type == arginfo.BOOLEAN):
            if (value not in ["True","False"]):
              raise ValueError("Boolean expected (True/False), not \"%s\"." % value)
            results.append(True if (value == "True") else False)
          elif (self._arg.type == arginfo.INTEGER):
            if (re.match("^[0-9]+$", value) is None):
              raise ValueError("Integer expected, not \"%s\"." % value)
            results.append(int(value))
          elif (self._arg.type in [arginfo.URL, arginfo.FILE_OR_URL]):
            if (re.match("(?i)^[a-z]{2,}:", value) is None):
              raise ValueError("URI schema expected (abc:), not \"%s\"." % value)
            results.append(value)
          elif (self._arg.type in [arginfo.STRING, arginfo.HIDDEN_STRING, arginfo.FILE]):
            if (value == ""):
              raise ValueError("Empty strings are not allowed.")
            results.append(value)
          else:
            raise NotImplementedError("Unexpected arg type: %s" % self._arg.type)

        except (ValueError) as err:
          errors.append("While parsing arg %s: %s" % (self._arg.name, str(err)))
          results.append(None)

    if (len(errors) == 0): errors = None

    if (self._arg.multiple):
      return results, errors
    else:
      return results[0], errors
Ejemplo n.º 3
0
  def _on_delete(self, e):
    rows = self.fudge_grid.GetSelectedRows()
    if (not rows):
      self.statusbar.SetStatusText("No fudge selected.", self.STATUS_HELP)
    else:
      self._snarks_wrapper.checkout(self.__class__.__name__)
      config = self._snarks_wrapper.get_config()

      rows.reverse()
      for row in rows:
        doomed_user = self.fudge_table.GetValue(row, self.fudge_table.COL_USER)
        doomed_bookmark = common.delta_from_str(self.fudge_table.GetValue(row, self.fudge_table.COL_GLOBALLY_FUDGED_TIME))
        snarkutils.config_remove_user_fudge(config, doomed_user, doomed_bookmark)

      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)

    if (e is not None): e.Skip(False)  # Consume the event.