예제 #1
0
파일: misc.py 프로젝트: landonb/hamster-gtk
 def _on_daterange_button_clicked(self, button):
     """Callback for when the 'daterange' button is clicked."""
     parent = get_parent_window(self)
     dialog = DateRangeSelectDialog(parent)
     response = dialog.run()
     if response == Gtk.ResponseType.APPLY:
         parent._daterange = dialog.daterange
     dialog.destroy()
예제 #2
0
 def _on_about_button(self, button):
     """Bring up, process and shut down about dialog."""
     parent = get_parent_window(self)
     dialog = AboutDialog(parent)
     response = dialog.run()
     if response == Gtk.ResponseType.OK:
         pass
     dialog.destroy()
예제 #3
0
 def _on_about_button(self, button):
     """Bring up, process and shut down about dialog."""
     parent = get_parent_window(self)
     dialog = AboutDialog(parent)
     response = dialog.run()
     if response == Gtk.ResponseType.OK:
         pass
     dialog.destroy()
예제 #4
0
 def _update_fact(self, fact):
     """Update the a fact with values from edit dialog."""
     try:
         self._controller.store.facts.save(fact)
     except (ValueError, KeyError) as message:
         helpers.show_error(helpers.get_parent_window(self), message)
     else:
         self._controller.signal_handler.emit('facts-changed')
예제 #5
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(helpers.get_parent_window(self), message)
     else:
         self._controler.signal_handler.emit("facts-changed")
예제 #6
0
 def _on_daterange_button_clicked(self, button):
     """Callback for when the 'daterange' button is clicked."""
     parent = get_parent_window(self)
     dialog = DateRangeSelectDialog(parent)
     response = dialog.run()
     if response == Gtk.ResponseType.APPLY:
         parent._daterange = dialog.daterange
     dialog.destroy()
예제 #7
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(helpers.get_parent_window(self), error)
     else:
         self._controler.signal_handler.emit("facts-changed")
         return result
예제 #8
0
 def _delete_fact(self, fact):
     """Delete fact from the backend. No further confirmation is required."""
     try:
         result = self._controller.store.facts.remove(fact)
     except (ValueError, KeyError) as error:
         helpers.show_error(helpers.get_parent_window(self), error)
     else:
         self._controller.signal_handler.emit('facts-changed')
         return result
예제 #9
0
 def _on_activate(self, widget, row):
     """Callback trigger if a row is 'activated'."""
     edit_dialog = EditFactDialog(helpers.get_parent_window(self), row.fact)
     response = edit_dialog.run()
     if response == Gtk.ResponseType.CANCEL:
         pass
     elif response == Gtk.ResponseType.REJECT:
         self._delete_fact(edit_dialog._fact)
     elif response == Gtk.ResponseType.APPLY:
         self._update_fact(edit_dialog.updated_fact)
     edit_dialog.destroy()
예제 #10
0
 def _on_activate(self, widget, row):
     """Callback trigger if a row is 'activated'."""
     edit_dialog = EditFactDialog(helpers.get_parent_window(self), row.fact)
     response = edit_dialog.run()
     if response == Gtk.ResponseType.CANCEL:
         pass
     elif response == Gtk.ResponseType.REJECT:
         self._delete_fact(edit_dialog._fact)
     elif response == Gtk.ResponseType.APPLY:
         self._update_fact(edit_dialog.updated_fact)
     edit_dialog.destroy()
예제 #11
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(helpers.get_parent_window(self), err)
        else:
            self.emit('tracking-stopped')
예제 #12
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(helpers.get_parent_window(self), err)
        else:
            self.emit("tracking-stopped")
    def _on_choose_clicked(self, widget):
        """Open a dialog to select path and update entry widget with it."""
        toplevel = get_parent_window(self)

        dialog = Gtk.FileChooserDialog(_("Please choose a directory"), toplevel,
            Gtk.FileChooserAction.SAVE, (_("_Cancel"), Gtk.ResponseType.CANCEL,
                                         _("_Save"), Gtk.ResponseType.OK))
        dialog.set_filename(self.get_config_value())
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self._entry.set_text(_u(dialog.get_filename()))

        dialog.destroy()
예제 #14
0
 def _on_preferences_button(self, button):
     """Bring up, process and shut down preferences dialog."""
     def get_initial():
         """Return current values as a dict."""
         return self._app._config
     parent = get_parent_window(self)
     dialog = PreferencesDialog(parent, parent.app, get_initial())
     response = dialog.run()
     if response == Gtk.ResponseType.APPLY:
         config = dialog.get_config()
         self._app.save_config(config)
     else:
         pass
     dialog.destroy()
예제 #15
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(helpers.get_parent_window(self), error)
        else:
            self.emit('tracking-stopped')
            # Inform the controller about the chance.
            self._controler.signal_handler.emit('facts-changed')
예제 #16
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(helpers.get_parent_window(self), error)
        else:
            self.emit("tracking-stopped")
            # Inform the controller about the chance.
            self._controler.signal_handler.emit("facts-changed")
예제 #17
0
    def _on_choose_clicked(self, widget):
        """Open a dialog to select path and update entry widget with it."""
        toplevel = get_parent_window(self)

        dialog = Gtk.FileChooserDialog(_("Please choose a directory"),
                                       toplevel, Gtk.FileChooserAction.SAVE,
                                       (_("_Cancel"), Gtk.ResponseType.CANCEL,
                                        _("_Save"), Gtk.ResponseType.OK))
        dialog.set_filename(self.get_config_value())
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self._entry.set_text(_u(dialog.get_filename()))

        dialog.destroy()
예제 #18
0
    def _on_preferences_button(self, button):
        """Bring up, process and shut down preferences dialog."""
        def get_initial():
            """Return current values as a dict."""
            return self._app._config

        parent = get_parent_window(self)
        dialog = PreferencesDialog(parent, parent.app, get_initial())
        response = dialog.run()
        if response == Gtk.ResponseType.APPLY:
            config = dialog.get_config()
            self._app.save_config(config)
        else:
            pass
        dialog.destroy()
예제 #19
0
    def __init__(self, app, *args, **kwargs):
        """Setup widget."""
        super(TrackingScreen, self).__init__(*args, **kwargs)
        self._app = app

        self.main_window = helpers.get_parent_window(self)
        self.set_transition_type(Gtk.StackTransitionType.SLIDE_UP)
        self.set_transition_duration(1000)
        self.current_fact_view = CurrentFactBox(self._app.controller)
        self.current_fact_view.connect('tracking-stopped', self.update)
        self.start_tracking_view = StartTrackingBox(self._app)
        self.start_tracking_view.connect('tracking-started', self.update)
        self.add_titled(self.start_tracking_view, 'start tracking', _("Start Tracking"))
        self.add_titled(self.current_fact_view, 'ongoing fact', _("Show Ongoing Fact"))
        self.update()
        self.show_all()
예제 #20
0
    def __init__(self, app, *args, **kwargs):
        """Setup widget."""
        super(TrackingScreen, self).__init__()
        self.app = app

        self.main_window = helpers.get_parent_window(self)
        self.set_transition_type(Gtk.StackTransitionType.SLIDE_UP)
        self.set_transition_duration(1000)
        self.current_fact_view = CurrentFactBox(self.app.controler)
        self.current_fact_view.connect("tracking-stopped", self.update)
        self.start_tracking_view = StartTrackingBox(self.app.controler)
        self.start_tracking_view.connect("tracking-started", self.update)
        self.add_titled(self.start_tracking_view, "start tracking", _("Start Tracking"))
        self.add_titled(self.current_fact_view, "ongoing fact", _("Show Ongoing Fact"))
        self.update()
        self.show_all()
예제 #21
0
파일: misc.py 프로젝트: landonb/hamster-gtk
    def _on_export_button_clicked(self, button):
        """
        Trigger fact export if button clicked.

        This is the place to run extra logic about where to save/which format.
        ``parent._export_facts`` only deals with the actual export.
        """
        parent = get_parent_window(self)
        dialog = ExportDialog(parent)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            parent._export_facts(dialog.get_export_format(),
                                 dialog.get_filename())
        else:
            pass
        dialog.destroy()
예제 #22
0
    def _on_export_button_clicked(self, button):
        """
        Trigger fact export if button clicked.

        This is the place to run extra logic about where to save/which format.
        ``parent._export_facts`` only deals with the actual export.
        """
        parent = get_parent_window(self)
        dialog = Gtk.FileChooserDialog(_("Please Choose where to export to"), parent,
            Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                         Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        dialog.set_current_name('{}.csv'.format(_("hamster_export")))
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            target_path = dialog.get_filename()
            parent._export_facts(target_path)
        else:
            pass
        dialog.destroy()
예제 #23
0
    def _on_export_button_clicked(self, button):
        """
        Trigger fact export if button clicked.

        This is the place to run extra logic about where to save/which format.
        ``parent._export_facts`` only deals with the actual export.
        """
        parent = get_parent_window(self)
        dialog = Gtk.FileChooserDialog(
            _("Please Choose where to export to"), parent,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
             Gtk.ResponseType.OK))
        dialog.set_current_name('{}.csv'.format(_("hamster_export")))
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            target_path = dialog.get_filename()
            parent._export_facts(target_path)
        else:
            pass
        dialog.destroy()
예제 #24
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()
예제 #25
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()
예제 #26
0
 def _on_previous_daterange_button_clicked(self, button):
     """Callback for when the 'previous' button is clicked."""
     get_parent_window(self).apply_previous_daterange()
예제 #27
0
def test_get_parent_window(request):
    """Make sure the parent window of a widget placed in the window is determined correctly."""
    window = Gtk.Window()
    label = Gtk.Label('foo')
    window.add(label)
    assert helpers.get_parent_window(label) == window
예제 #28
0
def test_get_parent_window_standalone(request):
    """Make sure the parent window of a windowless widget is None."""
    label = Gtk.Label('foo')
    assert helpers.get_parent_window(label) is None
예제 #29
0
 def _on_next_daterange_button_clicked(self, button):
     """Callback for when the 'next' button is clicked."""
     get_parent_window(self).apply_next_daterange()
예제 #30
0
 def _on_overview_button(self, button):
     """Callback for overview button."""
     parent = get_parent_window(self)
     OverviewDialog(parent, parent.app)
예제 #31
0
 def _on_overview_button(self, button):
     """Callback for overview button."""
     parent = get_parent_window(self)
     OverviewDialog(parent, parent.app)
예제 #32
0
파일: misc.py 프로젝트: landonb/hamster-gtk
 def _on_next_daterange_button_clicked(self, button):
     """Callback for when the 'next' button is clicked."""
     get_parent_window(self).apply_next_daterange()
예제 #33
0
파일: misc.py 프로젝트: landonb/hamster-gtk
 def _on_previous_daterange_button_clicked(self, button):
     """Callback for when the 'previous' button is clicked."""
     get_parent_window(self).apply_previous_daterange()
예제 #34
0
def test_get_parent_window(request):
    """Make sure the parent window of a widget placed in the window is determined correctly."""
    window = Gtk.Window()
    label = Gtk.Label('foo')
    window.add(label)
    assert helpers.get_parent_window(label) == window
예제 #35
0
def test_get_parent_window_standalone(request):
    """Make sure the parent window of a windowless widget is None."""
    label = Gtk.Label('foo')
    assert helpers.get_parent_window(label) is None