def reset(self, reset_counter=True): # keep = [] # if self.counts: # keep = [self.counts.max, self.counts.max_allowed] # del self.__counts if reset_counter: log("Resetting counter", 'counters') if self.counts is None: self.counts = EvernoteCounter() else: self.counts.reset() # if keep: # self.counts.max = keep[0] # self.counts.max_allowed = keep[1] if not self.__stopped: self.stop() self.__stopped = None self.__start = self.__time()
def __init__(self, max=None, interval=100, info=None, infoStr=None, automated=None, begin=True, label=None, display_initial_info=None, max_allowed=None, do_print=False, **kw): """ :type info : ActionInfo """ args = DictCaseInsensitive(kw, locals(), delete='kw infoStr info max self') simple_label = False self.counts = EvernoteCounter() self.__interval = interval self.__reported_progress = False if not isinstance(max, int): if hasattr(max, '__len__'): max = len(max) else: max = None self.counts.max = -1 if max is not None: self.counts.max = max args.max = self.counts.max if is_str(info): # noinspection PyTypeChecker info = ActionInfo(info, **args) elif infoStr and not info: info = ActionInfo(infoStr, **args) elif label and not info: simple_label = True if display_initial_info is None: display_initial_info = False info = ActionInfo(label, **args) elif label: info.Label = label if self.counts.max > 0 and info and (info.Max is None or info.Max < 1): info.Max = max self.counts.max_allowed = self.counts.max if max_allowed is None else max_allowed self.__did_break = True self.__do_print = do_print self.__info = info self.__action_initialized = False self.__action_attempted = self.hasActionInfo and (display_initial_info is not False) if self.__action_attempted: if self.info is None: log("Unexpected; Timer '%s' has no ActionInfo instance" % label, do_print=True) else: self.__action_initialized = self.info.displayInitialInfo( **args) is EvernoteAPIStatus.Initialized if begin: self.reset(False) log_blank(filename='counters') log(self.counts.fullSummary(self.name + ': Start'), 'counters')
def counts(self): if self.__counts is None: log("Init counter from property: " + repr(self.__counts), "counters") self.__counts = EvernoteCounter() return self.__counts