From 0d2010d05f18a3f0484af267bbbffa3f9e24642f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 7 Apr 2022 21:32:27 -0700 Subject: [PATCH] Rename python-chordpro to igitar --- src/ukatali/configuredialog.py | 2 +- src/ukatali/lexer.py | 2 +- src/ukatali/mainwindow.py | 26 +++++++++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/ukatali/configuredialog.py b/src/ukatali/configuredialog.py index 08bf2de..2a1f0a5 100644 --- a/src/ukatali/configuredialog.py +++ b/src/ukatali/configuredialog.py @@ -2,7 +2,7 @@ from functools import partial from PyQt5 import QtCore, QtGui, QtWidgets -from chordpro.renderers.html import get_options, get_option_groups +from igitar.renderers.html import get_options, get_option_groups from ukatali.util import coerce_bool, convert_units diff --git a/src/ukatali/lexer.py b/src/ukatali/lexer.py index c692afb..85564ad 100644 --- a/src/ukatali/lexer.py +++ b/src/ukatali/lexer.py @@ -1,7 +1,7 @@ import re from PyQt5 import QtCore, QtGui, QtWidgets, Qsci -from chordpro.constants import KNOWN_DIRECTIVES, KNOWN_VERSE_TYPES +from igitar.constants import KNOWN_DIRECTIVES, KNOWN_VERSE_TYPES PALETTE_ROLES = { 'window': QtGui.QPalette.WindowText, diff --git a/src/ukatali/mainwindow.py b/src/ukatali/mainwindow.py index ff8be1b..246d7cb 100644 --- a/src/ukatali/mainwindow.py +++ b/src/ukatali/mainwindow.py @@ -2,8 +2,8 @@ from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci, QtPrintSupport -from chordpro import Song -from chordpro.renderers.html import render, get_options +from igitar import Song +from igitar.renderers.html import render, get_options from ukatali.configuredialog import ConfigureDialog from ukatali.lexer import ChordProLexer @@ -345,14 +345,17 @@ class MainWindow(QtWidgets.QMainWindow): options = self._get_render_options(self.is_lyrics_mode) text = self.file_editor.text() song = Song() - song.parse(text) - return render(song, options, extra_styles) + try: + song.parse(text) + return render(song, options, extra_styles) + except Exception: + return None def on_text_changed(self): """Update the preview when the text changes""" - # self.setWindowModified(True) html = self._render_song() - self.preview_view.setHtml(html) + if html: + self.preview_view.setHtml(html) def on_export_pdf_clicked(self): """Export the current song to PDF""" @@ -404,9 +407,14 @@ class MainWindow(QtWidgets.QMainWindow): # Export to HTML try: with filename.open('w') as html_file: - html_file.write(self._render_song()) - QtWidgets.QMessageBox.information(self, 'Export to HTML Successful', - 'Successfully exported to "{}"'.format(filename.name)) + html = self._render_song() + if html: + html_file.write(html) + QtWidgets.QMessageBox.information(self, 'Export to HTML Successful', + 'Successfully exported to "{}"'.format(filename.name)) + else: + QtWidgets.QMessageBox.critical(self, 'Error Exporting to HTML', + 'There was an error while exporting to HTML') except Exception as e: QtWidgets.QMessageBox.critical(self, 'Error Exporting to HTML', 'There was an error while exporting to HTML:\n{e}'.format(e=e))