def post(self): required_fields = ('version', ) save_dict = {} for field in required_fields: save_dict[field] = self.get_argument(field) shelve_save(**save_dict) self.application.version = self.get_argument('version') self.redirect(self.request.path)
def on_closing(self): params = dict(last_state=self.root.state) coordinates = {'x': self.root.winfo_rootx(), 'y': self.root.winfo_rooty(), 'w': self.root.winfo_width(), 'h': self.root.winfo_height()} if self.root.state == 'main': params['main_coordinates'] = coordinates elif self.root.state == 'list': params['list_coordinates'] = coordinates shelve_save(**params) print('Exit') self.root.destroy()
def shelve_necessarry_fields(): fields = [ constants.APP_VERSION, constants.DATE_AFTER, constants.DATE_AT, constants.TIMER_AFTER_ACTION, constants.TIMER_AFTER_TIME, constants.TIMER_AT_ACTION, constants.TIMER_AT_DATETIME, constants.USER_NAME, constants.USER_PASSWORD ] logging.debug('Checking necessary shelve fields.\n' 'Necessary fields: %s', ','.join(fields)) shelve_dict = shelve_get_dict() for field in fields: if field not in shelve_dict: logging.debug('Shelve field %s not exists. Set as None' % field) shelve_save(**{field: None})
def login(self): self.loading = True self.root.after(0, self.run_loading) email = self.email.get() password = self.password.get() leo = GetLeoDict(email, password) self.loading = False if not leo.authorized: showinfo(config.app_name, 'Email or password incorrect', type='ok', icon='warning') return shelve_save(email=email, password=password) destroy(self.root) MainWindow(self.root, leo)
def on_closing(self): params = dict(last_state=self.root.state) coordinates = { 'x': self.root.winfo_rootx(), 'y': self.root.winfo_rooty(), 'w': self.root.winfo_width(), 'h': self.root.winfo_height() } if self.root.state == 'main': params['main_coordinates'] = coordinates elif self.root.state == 'list': params['list_coordinates'] = coordinates shelve_save(**params) print('Exit') self.root.destroy()
def clear_timer(self, event, notification_text=''): self.widget.notification_signal.emit(notification_text) if event == constants.DATE_AFTER: self.cancel_after_timer = False self.action_after_timer = 0 self.action_after_timer_do = None utils.shelve_save( **{ constants.TIMER_AFTER_TIME: None, constants.TIMER_AFTER_ACTION: None }) elif event == constants.DATE_AT: self.cancel_at_timer = False self.action_at_timer = 0 self.action_at_timer_do = None utils.shelve_save(**{ constants.TIMER_AT_DATETIME: None, constants.TIMER_AT_ACTION: None })
def setup_app(self): logging.debug('Setting up UI application...') self.setupUi(self) self.setWindowIcon(QIcon(config.app_icon_path)) self.hide_install_updates() logging.debug('Setting default date time for timers') self.action_after_time.setTime( QTime(*config.action_after_time_default)) self.action_after_time.setMinimumTime( QTime(*config.action_after_time_minimum)) self.action_at_datetime.setDateTime(self.run_from_dt) self.action_at_datetime.setMinimumDateTime(self.run_from_dt + datetime.timedelta( minutes=1)) self.action_at_datetime.setMaximumDateTime(self.run_from_dt + datetime.timedelta(7)) self.action_at_datetime.setDisplayFormat('MM/dd/yy hh:mm') if self.os_version == constants.DARWIN: self.action_after_select.removeItem(2) self.action_at_select.removeItem(2) elif self.os_version in (constants.LINUX, constants.LINUX2): self.action_at_select.removeItem(3) self.action_after_select.removeItem(3) logging.debug('Getting values from shelve for timers') timer_at = shelve_get(constants.TIMER_AT_DATETIME) timer_after = shelve_get(constants.TIMER_AFTER_TIME) self.callbacks = Callback(self) if timer_at: logging.debug('At timer exists in shelve file. \n' 'Timer at time: %s' % timer_at) if seconds_from_datetime(timer_at) > self.run_from_timestamp: logging.debug('Starting at timer gotten from shelve') threading.Thread(target=self.callbacks.start_timer, args=(constants.DATE_AT, timer_at, shelve_get(constants.TIMER_AT_ACTION)), daemon=True).start() self.callbacks.set_disabled_timer(constants.DATE_AT) else: logging.debug('Setting timer at to shelve as None') shelve_save( **{ constants.TIMER_AT_DATETIME: None, constants.TIMER_AT_ACTION: None }) if timer_after: logging.debug('After timer exists in shelve file. \n' 'Timer after time: %s' % timer_after) if seconds_from_datetime(timer_after, tm_format='%m/%d/%y %H:%M %S') > \ time.time(): seconds_to_action = seconds_from_datetime( timer_after, tm_format='%m/%d/%y %H:%M %S') - \ self.run_from_timestamp days_time_to_action = format_hours_minutes_from_seconds( seconds_to_action) self.callbacks.show_time_to_action(days_time_to_action) logging.debug('Starting after timer gotten from shelve') threading.Thread(target=self.callbacks.start_timer, args=(constants.DATE_AFTER, timer_after, shelve_get( constants.TIMER_AFTER_ACTION)), daemon=True).start() self.callbacks.set_disabled_timer(constants.DATE_AFTER) else: logging.debug('Setting timer after to shelve as None') shelve_save( **{ constants.TIMER_AFTER_TIME: None, constants.TIMER_AFTER_ACTION: None })
def start_timer(self, event, when, action): logging.debug('Starting %s timer.\n' 'Timeout date time: %s.\n' 'Action: %s' % (event, when, action)) canceled = False time_started = int(time.time()) if event == constants.DATE_AFTER: print(when) seconds_to_action = utils.seconds_from_datetime( when, tm_format='%m/%d/%y %H:%M %S') - time_started self.action_after_timer = seconds_to_action self.action_after_timer_do = action utils.shelve_save( **{ constants.TIMER_AFTER_TIME: when, constants.TIMER_AFTER_ACTION: action }) while self.action_after_timer > 0: if not self.cancel_after_timer: time.sleep(1) try: self.thread_lock.acquire() self.action_after_timer -= 1 days_time_to_action = utils.\ format_hours_minutes_from_seconds( self.action_after_timer) if not self.action_at_timer or ( self.action_at_timer > self.action_after_timer): self.widget.notification_signal.emit( constants.LABEL_NOTIFICATION_TEXT[action] % days_time_to_action) if not self.action_after_timer % 60: self.show_time_to_action(days_time_to_action) finally: self.thread_lock.release() else: canceled = True self.set_disabled_timer(constants.DATE_AFTER, False) break elif event == constants.DATE_AT: seconds_to_action = utils.seconds_from_datetime( when) - time_started print(seconds_to_action) if seconds_to_action < 0: self.widget.notification_signal.emit( constants.LABEL_NOTIFICATION_TEXT['time_less_zero']) self.set_disabled_timer(constants.DATE_AT, False) time.sleep(5) self.widget.notification_signal.emit('') return self.action_at_timer = seconds_to_action self.action_at_timer_do = action utils.shelve_save( **{ constants.TIMER_AT_DATETIME: when, constants.TIMER_AT_ACTION: action }) while self.action_at_timer > 0: if not self.cancel_at_timer: time.sleep(1) try: self.thread_lock.acquire() self.action_at_timer -= 1 days_time_to_action = utils.\ format_hours_minutes_from_seconds( self.action_at_timer) if not self.action_after_timer or ( self.action_after_timer > self.action_at_timer): self.widget.notification_signal.emit( constants.LABEL_NOTIFICATION_TEXT[action] % days_time_to_action) finally: self.thread_lock.release() else: canceled = True self.set_disabled_timer(constants.DATE_AT, False) break self.clear_timer(event) if not canceled: self.action_ontimer_timeout(event, action)