コード例 #1
0
ファイル: gui.py プロジェクト: nwiltsie/pyhabit-cli
    def _validate_date(self, value, reason, widget, validation):
        """
        Validate that the date string can be parsed.

        Will clear the field if focus is lost and the date cannot be parsed,
        and enable the associated 'Update' button if it can.
        """
        if isinstance(widget, basestring):
            widget = self.nametowidget(widget)
        if reason in ['focusin', 'key']:
            return True
        elif reason == 'focusout':
            # Return True if the date parses
            try:
                new_dt = None
                if value:
                    new_dt = utils.parse_datetime(value)
                    widget.delete(0, 1000)
                    widget.insert(0, utils.format_date(new_dt))
                if new_dt != widget.original:
                    widget['background'] = 'green'
                elif new_dt and utils.is_past(new_dt):
                    widget['background'] = 'red'
                else:
                    widget['background'] = 'systemWindowBody'
                widget.after_idle(widget.config, {'validate': validation})
                return True
            except habitcli.utils.DateParseException:
                print "Invalid date entry,", value, ", deleting..."
                widget.delete(0, 1000)
                widget.after_idle(widget.config, {'validate': validation})
                return False
        # Return True for all other reasons
        else:
            return True
コード例 #2
0
ファイル: gui.py プロジェクト: nwiltsie/pyhabit-cli
 def _add_due_field(self, datum, row):
     """Add a due date field for the given todo."""
     due_date = datum.get_due_date()
     due_str = utils.format_date(due_date)
     due = tk.Entry(self, validate="all", validatecommand=self.val_date)
     due.insert(0, due_str)
     if utils.is_past(due_date):
         due['background'] = 'red'
     due.original = due_date
     due.grid(row=row, column=3, sticky="nsew")
     return due
コード例 #3
0
ファイル: gui.py プロジェクト: nwiltsie/pyhabit-cli
 def _add_plan_field(self, datum, row):
     """Add a plan date field for the given todo."""
     plan_date = datum.get_planning_date()
     plan_date_str = utils.format_date(plan_date)
     plan = tk.Entry(self, validate="all", validatecommand=self.val_date)
     plan.insert(0, plan_date_str)
     if utils.is_past(plan_date):
         plan['background'] = 'red'
     plan.original = plan_date
     plan.grid(row=row, column=2, sticky="nsew")
     return plan
コード例 #4
0
ファイル: gui.py プロジェクト: nwiltsie/pyhabit-cli
        def btn_callback():
            """Update the associated todo with the changed fields."""
            fragments = []
            updates = {}

            date_fmt_str = "%s:\n\tFrom: %s\n\tTo:     %s"

            # Changes in planning date
            if plan.get():
                old_plan = datum.get_planning_date()
                new_plan = utils.parse_datetime(plan.get())
                if new_plan != old_plan:
                    fragments.append(date_fmt_str %
                                     ('Plan Date',
                                      utils.format_date(old_plan),
                                      utils.format_date(new_plan)))
                    updates['plan'] = new_plan

            # Changes in due date
            if due.get():
                old_due = datum.get_due_date()
                new_due = utils.parse_datetime(due.get())
                if new_due != old_due:
                    fragments.append(date_fmt_str %
                                     ('Due Date',
                                      utils.format_date(old_due),
                                      utils.format_date(new_due)))
                    updates['due'] = new_due

            # Changes in tag
            old_tag = datum.get_primary_tag()
            new_tag = tag.get()
            if new_tag != old_tag:
                fragments.append("Tag:\n\tFrom: %s\n\tTo: %s" %
                                 (old_tag, new_tag))
                updates['tag'] = new_tag

            if fragments:
                message = "\n".join(fragments)
                if tkMessageBox.askyesno("Update %s?" %
                                         datum['text'], message):

                    if 'tag' in updates:
                        datum.set_primary_tag(updates['tag'])
                    if 'plan' in updates:
                        datum.set_planning_date(updates['plan'])
                    if 'due' in updates:
                        datum.set_due_date(updates['due'])

                    datum.update_db()

                    tag.original = datum.get_primary_tag()
                    tag.original = tag.original if tag.original else ""
                    tag.set(tag.original)
                    self._val_tag(tag.get(), tag)

                    plan.delete(0, 1000)
                    plan.original = datum.get_planning_date()
                    plan.insert(0, utils.format_date(plan.original))
                    self._validate_date(plan.get(), 'focusout', plan, 'all')

                    due.delete(0, 1000)
                    due.original = datum.get_due_date()
                    due.insert(0, utils.format_date(due.original))
                    self._validate_date(due.get(), 'focusout', due, 'all')

                    print datum['text'], "updated!"