class ScanListModel(ProgressListBoxModelFactory): def __init__(self, project_model, subject_model, database): ProgressListBoxModelFactory.__init__(self) self._database = database self._selected_scans = SelectedItemsModel() self._unselected_scans = SelectedItemsModel() self._subject_model = subject_model subject_model.list_items_model.add_listener(self._subject_list_changed) subject_model.selected_items_model.add_listener(self._subject_selection_changed) self._selected_scans.add_listener(self._scan_selection_changed) self._unselected_scans.add_listener(self._scan_unselection_changed) def _update_items(self, subject_list): subject_list = self._subject_model.selected_items_model.selected_items scan_records = [] self._database.clear_all_download_model_listeners() for subject in subject_list: session_map = subject.get_session_map() for session in session_map.values(): scan_map = session.get_scan_map() for scan in scan_map.values(): scan_records.append(ScanRecordModel(scan, subject.subject_label + ':' + scan.scan_id, self._database.get_scan_download_model(subject.project_id, subject.subject_id, scan.scan_id))) self.get_list_model().set_list_items(scan_records) def _subject_selection_changed(self, value): self._update_items(value) def _subject_list_changed(self, value): self._update_items([]) #ToDo: this is the list of selected subjects def _scan_selection_changed(self, scans): if len(scans) > 0: for scan in scans: if not self.database.is_scan_downloaded(scan.project_id, scan.subject_id, scan.scan_id): self.database.download_scan(scan.project_id, scan.subject_id, scan.scan_id) def _scan_unselection_changed(self, scans): scans_to_remove = [] for scan in scans: if self.database.is_scan_downloaded(scan.project_id, scan.subject_id, scan.scan_id): scans_to_remove.append(scan) if len(scans_to_remove) > 0: result = messagebox.askyesno("Delete downloaded scan", "Do you want to delete these scans from your computer?") if result: for scan in scans_to_remove: self.database.delete_scan(scan.project_id, scan.subject_id, scan.scan_id) self.scans.refresh_checks()
def __init__(self, project_model, subject_model, database): ProgressListBoxModelFactory.__init__(self) self._database = database self._selected_scans = SelectedItemsModel() self._unselected_scans = SelectedItemsModel() self._subject_model = subject_model subject_model.list_items_model.add_listener(self._subject_list_changed) subject_model.selected_items_model.add_listener(self._subject_selection_changed) self._selected_scans.add_listener(self._scan_selection_changed) self._unselected_scans.add_listener(self._scan_unselection_changed)