예제 #1
0
 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
예제 #2
0
 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()
예제 #3
0
 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()
예제 #4
0
    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))
예제 #5
0
 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)
예제 #6
0
    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)
예제 #7
0
    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()
예제 #8
0
    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)
예제 #9
0
 def _help_clicked(self, event):
     """
     show help message
     """
     if self.help:
         QMessageBox.information(self, self.title, self.help)
예제 #10
0
 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)