class SendToStationActionMixin(PopupCreator): def __init__(self, **kwargs): self.book = kwargs.pop('book') super(SendToStationActionMixin, self).__init__(**kwargs) self.scancenter, self.stations_list = self._get_data() popup_content = self._build_content() self.popup_args = { 'title': 'Send to another station in {}'.format(self.scancenter), 'content': popup_content, 'auto_dismiss': False, 'title_size': '18sp', 'size_hint_x': None, 'size_hint_y': 0.6, 'width': '400dp' } self.create_popup(**self.popup_args) popup_content.popup = self.popup @staticmethod def _get_data(): show_all = config.is_true('send_to_all_stations') sc, stations_list = btserver.get_adjacent_scanners(show_all) if not sc: raise Exception( 'Could not retrieve stations list. Please try again later.') return sc, stations_list def _build_content(self): selected_target_station = self.book.get_foldout_target() content = ScribeMessageGenericContent() for item in self.stations_list: active_value = selected_target_station == item selectable_option = RadioButton(text=item, group='scanners', active=active_value) content.ids._content.add_widget(selectable_option) content.ok_text = 'Send' content.ids._ok_button.background_color = [1, 0, 0, 1] content.trigger_func = self.do_action return content def do_action(self, popup, *args, **kwargs): target_scanner = None for button in popup.content.ids._content.children: if button.active: target_scanner = button.text if not target_scanner: self.action = ShowErrorAction( message='You need to select a station') self.action.display() return self.book.set_foldout_target(target_scanner) self.action = ShowInfoActionPopupMixin( message='Okay, upon [u]upload[/u] [b]{}[/b] ' 'will be sent to [b]{}[/b] for foldouts.'.format( self.book.name_human_readable(), target_scanner)) self.action.display() self.popup.dismiss()
def do_update(self, *args): result = self.update_manager.do_update( task_handler_class=GenericUIHandler) if not result: message = 'No update is available at this time.' self.action = ShowInfoActionPopupMixin(message=message) self.action.display()
def post_login(self, result, error): if error: self.action = ShowErrorAction( title='Login error', message=error, ) self.action.display() else: # here it calls update_config, and if we write successfully if self.update_config(result) is True: self.success = True success_message = "You are now logged in as: \n\n" + str( urllib.parse.unquote( result.get("cookies")["logged-in-user"])) + "." self.action = ShowInfoActionPopupMixin( message=success_message, on_popup_dismiss=self.post_login_confirmation) self.action.display()
def do_action(self, popup, *args, **kwargs): target_scanner = None for button in popup.content.ids._content.children: if button.active: target_scanner = button.text if not target_scanner: self.action = ShowErrorAction( message='You need to select a station') self.action.display() return self.book.set_foldout_target(target_scanner) self.action = ShowInfoActionPopupMixin( message='Okay, upon [u]upload[/u] [b]{}[/b] ' 'will be sent to [b]{}[/b] for foldouts.'.format( self.book.name_human_readable(), target_scanner)) self.action.display() self.popup.dismiss()
def show_next_states(self, book): book = self.get_book_object(book) message = 'Seeing as it is currently in\n[b]{}[/b] status,\n' \ '[b]{}[/b] can move to the following states next:\n\n'.format(book.get_status(human_readable=True), book.name_human_readable()) next_states = book.get_available_next_states(human_readable=True) for state in next_states: state_string = '[b]{}[/b]\n'.format(state) message += state_string self.action = ShowInfoActionPopupMixin(message=message, on_popup_dismiss=self._action_no_op_callback) self.action.display()
def action_button_press(self, *args): candidate_action = ACTIONS_BY_STATE[ self.update_manager.get_update_status()]['action'] candidate_action_hr = ACTION_NAMES[candidate_action] concrete_action = getattr(self, candidate_action) self.action = ColoredYesNoActionPopupMixin( action_function=concrete_action, title='Are you sure?', message='Do you want to {}?'.format(candidate_action_hr), ) self.action.display()
class LoginSection(BaseSection): load_img = Image(source=LOADING_IMAGE) success = BooleanProperty(False) en_next_button = False def __init__(self, **kwargs): self.task_scheduler = kwargs.pop('task_scheduler') super(LoginSection, self).__init__(**kwargs) def on_enter(self): super(LoginSection, self).on_enter() # Login with archive.org, get s3 keys, store them, done # main thread, called by _login_button def archive_login(self): email = self.ids['_login_email_input'].text password = self.ids['_login_password_input'].text task_handler = GenericUIHandler(task_type=IALoginTask, email=email, password=password, callback=self.post_login) self.task_scheduler.schedule(task_handler.task) def post_login(self, result, error): if error: self.action = ShowErrorAction( title='Login error', message=error, ) self.action.display() else: # here it calls update_config, and if we write successfully if self.update_config(result) is True: self.success = True success_message = "You are now logged in as: \n\n" + str( urllib.parse.unquote( result.get("cookies")["logged-in-user"])) + "." self.action = ShowInfoActionPopupMixin( message=success_message, on_popup_dismiss=self.post_login_confirmation) self.action.display() def post_login_confirmation(self, *args): self.root_widget.go_next() def before_next(self): self.schedule_rcs_download() return True @staticmethod def archive_signup(): webbrowser.open("https://archive.org/account/login.createaccount.php") @staticmethod def archive_forgot_pwd(): webbrowser.open("https://archive.org/account/login.forgotpw.php") # A little wrapper that updates the s3 configuration in scribe_config.yml def update_config(self, keys): config.set("s3/access_key", str(keys['s3']['access'])) config.set("s3/secret_key", str(keys['s3']['secret'])) # get email and escape @ email = urllib.parse.unquote(keys.get("cookies")["logged-in-user"]) config.set("email", email) config.set("cookie", str(keys.get("cookies")["logged-in-sig"])) return True def on_touch_down(self, touch): local_pos = self.to_local(*touch.pos) if self.ids['lb_forgot_pwd'].collide_point(*local_pos): self.archive_forgot_pwd() elif self.ids['lb_signup'].collide_point(*local_pos): self.archive_signup() super(LoginSection, self).on_touch_down(touch) def schedule_rcs_download(self): rcs_manager = self.root_widget.sections[3].children[0].rcs rcs_manager.attach_scheduler(self.task_scheduler) rcs_manager._do_sync() # delete s3 keys and account information from scribe_config.yml # main thread called by _logout_button def archive_logout(self): try: config.delete('s3') config.delete('email') config.delete('cookie') popup_success = Popup( title='Logged out', content=Label(text="You have logged out" + ". \n\nRestarting the application..."), auto_dismiss=True, size_hint=(None, None), size=(400, 200)) popup_success.open() restart_app() except: # if the keys didn't exist in the first place, a field was missing or whatever, cry. raise ScribeException('There was an error logging out.')
class UpdateWidget(Screen): update_status = StringProperty() action_button_icon = StringProperty('') action_button_text = StringProperty('') current_version = StringProperty() update_channel = StringProperty() candidate_version = StringProperty() build_tag = StringProperty() history = ListProperty() help_text = StringProperty() auto_update = BooleanProperty() def __init__(self, **kwargs): super(UpdateWidget, self).__init__(**kwargs) Clock.schedule_once(self._postponed_init) self.update_manager = UpdateManager() self.update_manager.subscribe(self._update_manager_event_handler) try: with open(join(NOTES_DIR, 'about_update_notes.txt')) as f: self.help_text = f.read() except Exception as e: print(e) def _postponed_init(self, *args): self.update_status = self.update_manager.get_update_status( human_readable=True) def _update_manager_event_handler(self, event, manager): Clock.schedule_once(self._update_properties) def _update_properties(self, *args): self.update_status = str( self.update_manager.get_update_status(human_readable=True)) self.current_version = self.update_manager.current_version or '--' self.candidate_version = self.update_manager.update_version or '--' self.update_channel = self.update_manager.update_channel or '--' self.auto_update = config.is_true('auto_update') self.action_button_icon = ACTIONS_BY_STATE[ self.update_manager.get_update_status()]['icon'] self.action_button_text = ACTIONS_BY_STATE[ self.update_manager.get_update_status()]['text'] def on_auto_update(self, screen, value): current_val = config.is_true('auto_update') if value != current_val: config.set('auto_update', value) def action_button_press(self, *args): candidate_action = ACTIONS_BY_STATE[ self.update_manager.get_update_status()]['action'] candidate_action_hr = ACTION_NAMES[candidate_action] concrete_action = getattr(self, candidate_action) self.action = ColoredYesNoActionPopupMixin( action_function=concrete_action, title='Are you sure?', message='Do you want to {}?'.format(candidate_action_hr), ) self.action.display() def do_update(self, *args): result = self.update_manager.do_update( task_handler_class=GenericUIHandler) if not result: message = 'No update is available at this time.' self.action = ShowInfoActionPopupMixin(message=message) self.action.display() def check_for_update(self, *args): self.update_manager.do_check_update( task_handler_class=GenericUIHandler) def restart_app(self, *args, **kwargs): restart_process()