def convert(self, v): root: Path = v.root if not v.pattern: return [] try: pattern = compile_pattern(v.pattern) except (ReError, LookupError) as e: raise ParseError from e ret = [] for path in root.rglob('*'): match = pattern.search(str(path)) if not match: continue d = match.groupdict() show = d.get('show', v.default_show) season = d.get('season', v.default_season) episode = d.get('episode', v.default_episode) if None in (show, season, episode): continue season = int(season) episode = int(episode) ret.append( FileEpisode(show, season, episode, file=path, marks=Marks())) QMessageBox.information(self, 'result', f'{len(ret)} episodes to be added') return ret
def commit_parse(self): value = self.value() if not value.is_ok(): QMessageBox.critical(self, 'error parsing plaintext', value.details) else: self.owner.fill(value.value) self.close()
def apply_parse(self): value = self.value() if not value.is_ok(): QMessageBox.critical(self, 'error parsing plaintext', value.details) else: self.owner.fill(value.value) self.prep_for_show(clear_parse=False, clear_print=False) self.parse_edit.setFocus()
def save_file(self, *args): filename, _ = QFileDialog.getSaveFileName(self, 'save file', filter='text files (*.txt *.csv);;all files (*.*)') if not filename: return try: Path(filename).write_text(self.print_edit.toPlainText()) except IOError as e: QMessageBox.critical(self, 'could not write to file', str(e))
def _cancel_btn_clicked(self, *a): self.cancel_flag = True self.change_value() if self.close_on_confirm: value = self.value() if value.is_ok(): self.close() else: QMessageBox.critical(self, 'error parsing value', value.details)
def load_file(self, *args): filename, _ = QFileDialog.getOpenFileName(self, 'open file', filter='text files (*.txt *.csv);;all files (*.*)') if not filename: return try: text = Path(filename).read_text() except IOError as e: QMessageBox.critical(self, 'could not read file', str(e)) else: self.parse_edit.setPlainText(text)
def _detail_button_clicked(self, event): """ show details of the value """ value = self.value() if value.details: QMessageBox.information(self, value.type_details, value.details) if not value.is_ok(): offender: QWidget = reduce(lambda x, y: y, error_attrs(value.exception, 'offender'), None) if offender: offender.setFocus()
def _auto_btn_click(self, click_args): """ autofill the widget """ try: value = self.auto_func() except DoNotFill as e: if str(e): QMessageBox.critical(self, 'error during autofill', str(e)) return self.fill_value(value)
def _help_clicked(self, event): """ show help message """ if self.help: QMessageBox.information(self, self.title, self.help)
def make_project_changed(): v = self.make_project.value() if not v.is_ok(): QMessageBox.critical(self, 'error', v.details) else: self.switch_to_overview(v.value)