def __init__(self, model, view): self.model = model self.view = view assert isinstance(self.model, ValidationModel) events.subscribe(events.CHANGE_IMAGE, self.on_change_image) events.subscribe(events.IMG_LOADED, self.on_image_loaded) events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work) self.autoplay_manager = AutoplayManager(model) self.downloader = Downloader() self.image_loading_dialog_manager = ImageLoadingDialogManager(view)
def __init__(self, model, view): self.model = model self.view = view events.subscribe(events.CHANGE_IMAGE, self.on_change_image) events.subscribe(events.IMG_LOADED, self.on_image_loaded) events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work) self.autoplay_manager = AutoplayManager(model) self.image_loading_dialog_manager = ImageLoadingDialogManager(view)
class AbstractController(object): def __init__(self, model, view): self.model = model self.view = view events.subscribe(events.CHANGE_IMAGE, self.on_change_image) events.subscribe(events.IMG_LOADED, self.on_image_loaded) events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work) self.autoplay_manager = AutoplayManager(model) self.image_loading_dialog_manager = ImageLoadingDialogManager(view) def get_view(self): return self.view def display_current_image(self): try: self.view.display(self.model.get_current_cutout()) except ImageNotLoadedException as ex: self.image_loading_dialog_manager.wait_for_item(ex.requested_item) return False except NoWorkUnitException: return False self.view.update_displayed_data(self.model.get_reading_data(), self.model.get_header_data_list()) self.view.set_observation_status( self.model.get_current_obs_number() + 1, self.model.get_obs_count()) self.model.acknowledge_image_displayed() return True def on_reposition_source(self, new_x, new_y): try: self.model.update_current_source_location((new_x, new_y)) except ImageNotLoadedException: pass def on_image_loaded(self, event): displayable_item = event.data self.image_loading_dialog_manager.set_item_done(displayable_item) if displayable_item == self.model.get_current_displayable_item(): self.display_current_image() def on_change_image(self, event): if self.model.is_current_item_processed(): self.view.disable_source_validation() else: self.view.enable_source_validation() self.display_current_image() def on_no_available_work(self, event): self.view.hide_image_loading_dialog() if self.model.get_num_items_processed() == 0: self.view.show_empty_workload_dialog( self.model.get_working_directory()) self._do_exit() else: should_exit = self.view.all_processed_should_exit_prompt() if should_exit: self._do_exit() def on_use_singlet_view(self): self.model.use_singlets() self.view.use_singlets() self.display_current_image() def on_use_triplet_view(self): self.model.use_triplets() self.view.use_triplets() self.display_current_image() def on_enable_auto_sync(self): self.model.enable_synchronization() def on_disable_auto_sync(self): self.model.disable_synchronization() def on_enable_autoplay(self): self.autoplay_manager.start_autoplay() def on_disable_autoplay(self): self.autoplay_manager.stop_autoplay() def on_toggle_autoplay_key(self): """ The user has pressed the keybind for toggling autoplay. """ if self.autoplay_manager.is_running(): self.autoplay_manager.stop_autoplay() self.view.set_autoplay(False) else: self.autoplay_manager.start_autoplay() self.view.set_autoplay(True) def on_toggle_reticule_key(self): self.view.toggle_reticule() def on_show_keymappings(self): self.view.show_keymappings() def on_exit(self): self._do_exit() def _do_exit(self): self.autoplay_manager.stop_autoplay() self.view.close() self.model.exit() def on_next_obs(self): self.model.next_obs() def on_previous_obs(self): self.model.previous_obs() def on_accept(self): raise NotImplementedError() def on_reject(self): raise NotImplementedError() def on_reset_source_location(self): try: self.model.reset_current_source_location() self.view.refresh_markers() except ImageNotLoadedException: pass def on_reset_colormap(self): self.view.reset_colormap()
class AbstractController(object): def __init__(self, model, view): self.model = model self.view = view assert isinstance(self.model, ValidationModel) events.subscribe(events.CHANGE_IMAGE, self.on_change_image) events.subscribe(events.IMG_LOADED, self.on_image_loaded) events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work) self.autoplay_manager = AutoplayManager(model) self.downloader = Downloader() self.image_loading_dialog_manager = ImageLoadingDialogManager(view) def get_view(self): return self.view def display_current_image(self): try: self.view.display(self.model.get_current_cutout()) except ImageNotLoadedException as ex: self.image_loading_dialog_manager.wait_for_item(ex.requested_item) return False except NoWorkUnitException: return False self.view.update_displayed_data(self.model.get_reading_data(), self.model.get_header_data_list()) self.view.set_observation_status( self.model.get_current_obs_number() + 1, self.model.get_obs_count()) self.model.acknowledge_image_displayed() return True def on_reposition_source(self, new_x, new_y): try: self.model.update_current_source_location((new_x, new_y)) except ImageNotLoadedException: pass def on_image_loaded(self, event): displayable_item = event.data self.image_loading_dialog_manager.set_item_done(displayable_item) if displayable_item == self.model.get_current_displayable_item(): self.display_current_image() def on_change_image(self, event): if self.model.is_current_item_processed(): self.view.disable_source_validation() else: self.view.enable_source_validation() self.display_current_image() def on_no_available_work(self, event): self.view.hide_image_loading_dialog() if self.model.get_num_items_processed() == 0: self.view.show_empty_workload_dialog( self.model.get_working_directory()) self._do_exit() else: should_exit = self.view.all_processed_should_exit_prompt() if should_exit: self._do_exit() def on_use_singlet_view(self): self.model.use_singlets() self.view.use_singlets() self.display_current_image() def on_use_triplet_view(self): self.model.use_triplets() self.view.use_triplets() self.display_current_image() def on_enable_auto_sync(self): self.model.enable_synchronization() def on_disable_auto_sync(self): self.model.disable_synchronization() def on_enable_autoplay(self): self.autoplay_manager.start_autoplay() def on_disable_autoplay(self): self.autoplay_manager.stop_autoplay() def on_toggle_autoplay_key(self): """ The user has pressed the keybind for toggling autoplay. """ if self.autoplay_manager.is_running(): self.autoplay_manager.stop_autoplay() self.view.set_autoplay(False) else: self.autoplay_manager.start_autoplay() self.view.set_autoplay(True) def on_toggle_reticule_key(self): self.view.toggle_reticule() def on_show_keymappings(self): self.view.show_keymappings() def on_exit(self): self._do_exit() def _do_exit(self): self.autoplay_manager.stop_autoplay() self.view.close() self.model.exit() def on_load_comparison(self, research=False): raise NotImplementedError() def on_next_obs(self): self.model.next_obs() def on_previous_obs(self): self.model.previous_obs() def on_accept(self): raise NotImplementedError() def on_reject(self): raise NotImplementedError() def on_reset_source_location(self): try: self.model.reset_current_source_location() self.view.refresh_markers() except ImageNotLoadedException: pass def on_reset_colormap(self): self.view.reset_colormap()