コード例 #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