def _update_fact(self, fact):
     """Update the a fact with values from edit dialog."""
     try:
         self._controler.store.facts.save(fact)
     except (ValueError, KeyError) as message:
         helpers.show_error(helpers.get_parent_window(self), message)
     else:
         self._controler.signal_handler.emit("facts-changed")
Beispiel #2
0
 def _update_fact(self, fact):
     """Update the a fact with values from edit dialog."""
     try:
         self._controler.store.facts.save(fact)
     except (ValueError, KeyError) as message:
         helpers.show_error(self, message)
     else:
         self._controler.signal_handler.emit('facts_changed')
Beispiel #3
0
 def _delete_fact(self, fact):
     """Delete fact from the backend. No further confirmation is required."""
     try:
         result = self._controler.store.facts.remove(fact)
     except (ValueError, KeyError) as error:
         helpers.show_error(self.get_toplevel(), error)
     else:
         self._controler.signal_handler.emit('facts_changed')
         return result
 def _delete_fact(self, fact):
     """Delete fact from the backend. No further confirmation is required."""
     try:
         result = self._controler.store.facts.remove(fact)
     except (ValueError, KeyError) as error:
         helpers.show_error(helpers.get_parent_window(self), error)
     else:
         self._controler.signal_handler.emit("facts-changed")
         return result
Beispiel #5
0
    def _on_cancel_button(self, button):
        """
        Triggerd when 'cancel' button clicked.

        Discard current *ongoing fact* without saving.
        """
        try:
            self._controler.store.facts.cancel_tmp_fact()
        except KeyError as err:
            helpers.show_error(self.get_toplevel(), err)
        else:
            self.emit('tracking-stopped')
Beispiel #6
0
    def _on_save_button(self, button):
        """
        Triggerd when 'save' button clicked.

        Save *ongoing fact* to storage.
        """
        try:
            self._controler.store.facts.stop_tmp_fact()
        except Exception as error:
            helpers.show_error(self.get_toplevel(), error)
        else:
            self.emit('tracking-stopped')
            # Inform the controller about the chance.
            self._controler.signal_handler.emit('facts-changed')
Beispiel #7
0
    def _on_start_tracking_button(self, button):
        """
        Start a new *ongoing fact*.

        Note:
            Whilst we accept the full ``raw_fact`` syntax, we ignore any ``Fact.end``
            information encoded in the string. Unlike legacy hamster we *only*
            deal with *ongoing facts* in this widget.
        """

        # [FIXME]
        # This should be done in one place only. And the hamster-lib. If at all
        # via hamster-lib.helpers.
        def complete_tmp_fact(fact):
            """Apply fallback logic in case no start time has been encoded."""
            if not fact.start:
                fact.start = datetime.datetime.now()
            # Make sure we dismiss any extracted end information.
            fact.end = None
            return fact

        raw_fact = _u(self.raw_fact_entry.props.text)

        try:
            fact = Fact.create_from_raw_fact(raw_fact)
        except Exception as error:
            helpers.show_error(helpers.get_parent_window(self), error)
        else:
            fact = complete_tmp_fact(fact)

            try:
                fact = self._controler.store.facts.save(fact)
            except Exception as error:
                helpers.show_error(self.get_top_level(), error)
            else:
                self.emit('tracking-started')
                self._controler.signal_handler.emit('facts-changed')
                self.reset()
Beispiel #8
0
    def _on_start_tracking_button(self, button):
        """
        Start a new *ongoing fact*.

        Note:
            Whilst we accept the full ``raw_fact`` syntax, we ignore any ``Fact.end``
            information encoded in the string. Unlike legacy hamster we *only*
            deal with *ongoing facts* in this widget.
        """
        # [FIXME]
        # This should be done in one place only. And the hamster-lib. If at all
        # via hamster-lib.helpers.
        def complete_tmp_fact(fact):
            """Apply fallback logic in case no start time has been encoded."""
            if not fact.start:
                fact.start = datetime.datetime.now()
            # Make sure we dismiss any extracted end information.
            fact.end = None
            return fact

        raw_fact = _u(self.raw_fact_entry.props.text)

        try:
            fact = Fact.create_from_raw_fact(raw_fact)
        except Exception as error:
            helpers.show_error(self.get_toplevel(), error)
        else:
            fact = complete_tmp_fact(fact)

            try:
                fact = self._controler.store.facts.save(fact)
            except Exception as error:
                helpers.show_error(self.get_top_level(), error)
            else:
                self.emit('tracking-started')
                self._controler.signal_handler.emit('facts-changed')
                self.reset()