Compare commits

..

1 Commits

Author SHA1 Message Date
1a97bde040 Add a reset button 2021-09-08 09:13:51 -07:00
5 changed files with 46 additions and 70 deletions

View File

@ -1,51 +1,3 @@
[metadata]
name = ukatali
author = Raoul Snyman
author_email = raoul@snyman.info
description = A ChordPro GUI, written in Python and Qt5
long_description = file:README.rst
long_description_content_type = text/x-rst
url = https://git.snyman.info/raoul/ukatali
license = MIT
classifiers =
Development Status :: 3 - Alpha
Intended Audience :: End Users/Desktop
License :: OSI Approved :: MIT License
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Utilities
keywords =
music
chords
guitar
[options]
package_dir =
= src
packages = find:
python_requires = >=3.7
setup_requires =
setuptools_scm
install_requires =
igitar
PyQt5
PyQtWebEngine
QScintilla
[options.packages.find]
where = src
[options.entry_points]
console_scripts =
ukatali = ukatali.app:run_ukutali
[bdist_wheel]
universal = 1
[pep8] [pep8]
exclude=resources.py,vlc.py exclude=resources.py,vlc.py
max-line-length = 120 max-line-length = 120

View File

@ -1,2 +0,0 @@
from setuptools import setup
setup(use_scm_version=True, setup_requires=['setuptools_scm'])

View File

@ -2,7 +2,7 @@
from functools import partial from functools import partial
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from igitar.renderers.html import get_options, get_option_groups from chordpro.renderers.html import get_options, get_option_groups
from ukatali.util import coerce_bool, convert_units from ukatali.util import coerce_bool, convert_units
@ -83,6 +83,16 @@ class ConfigureDialog(QtWidgets.QDialog):
self.render_options_stack = QtWidgets.QStackedWidget(self) self.render_options_stack = QtWidgets.QStackedWidget(self)
self.render_options_stack.setObjectName("render_options_stack") self.render_options_stack.setObjectName("render_options_stack")
self.render_layout.addWidget(self.render_options_stack) self.render_layout.addWidget(self.render_options_stack)
self.render_reset_layout = QtWidgets.QHBoxLayout()
self.render_reset_layout.setObjectName('render_reset_layout')
self.render_reset_layout.setSpacing(0)
self.render_reset_layout.setContentsMargins(0, 0, 0, 0)
self.render_reset_layout.addStretch()
self.render_reset_button = QtWidgets.QPushButton(self.renderer_page)
self.render_reset_button.setIcon(QtGui.QIcon.fromTheme('edit-reset'))
self.render_reset_button.setObjectName('render_reset_button')
self.render_reset_layout.addWidget(self.render_reset_button)
self.render_layout.addLayout(self.render_reset_layout)
# Export settings # Export settings
self.export_page = QtWidgets.QWidget() self.export_page = QtWidgets.QWidget()
self.export_page.setObjectName('export_page') self.export_page.setObjectName('export_page')
@ -163,6 +173,7 @@ class ConfigureDialog(QtWidgets.QDialog):
self.export_margin_bottom_spinbox.valueChanged.connect(on_export_margin_bottom_changed) self.export_margin_bottom_spinbox.valueChanged.connect(on_export_margin_bottom_changed)
on_export_orientation_portait_clicked = partial(self._set_export_value, 'orientation') on_export_orientation_portait_clicked = partial(self._set_export_value, 'orientation')
self.export_orientation_portrait_radio.toggled.connect(on_export_orientation_portait_clicked) self.export_orientation_portrait_radio.toggled.connect(on_export_orientation_portait_clicked)
self.render_reset_button.clicked.connect(self.on_reset_button_clicked)
def retranslate_ui(self): def retranslate_ui(self):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
@ -173,6 +184,9 @@ class ConfigureDialog(QtWidgets.QDialog):
self.category_list_widget.item(3).setText(_translate('ConfigureDialog', 'PDF')) self.category_list_widget.item(3).setText(_translate('ConfigureDialog', 'PDF'))
self.export_orientation_portrait_radio.setText(_translate('ConfigureDialog', 'Portrait')) self.export_orientation_portrait_radio.setText(_translate('ConfigureDialog', 'Portrait'))
self.export_orientation_landscape_radio.setText(_translate('ConfigureDialog', 'Landscape')) self.export_orientation_landscape_radio.setText(_translate('ConfigureDialog', 'Landscape'))
self.render_reset_button.setText(_translate('ConfigureDialog', 'Reset values'))
self.render_reset_button.setToolTip(_translate('ConfigureDialog',
'Reset the values for this option to the defaults'))
def _set_option_value(self, name, value): def _set_option_value(self, name, value):
"""Set an option value""" """Set an option value"""
@ -192,6 +206,26 @@ class ConfigureDialog(QtWidgets.QDialog):
value = QtGui.QPageLayout.Portrait if value else QtGui.QPageLayout.Landscape value = QtGui.QPageLayout.Portrait if value else QtGui.QPageLayout.Landscape
self.export_values[name] = value self.export_values[name] = value
def on_reset_button_clicked(self):
"""Reset all the values for the current option group"""
current_group = self.render_options_combobox.currentText().replace(' ', '_').lower()
self.settings.beginGroup('render')
for name, details in get_options(current_group).items():
if name in self.option_values:
del self.option_values[name]
if self.settings.contains(name):
self.settings.remove(name)
if details['type'] is int:
self.option_widgets[name].setValue(details['default'])
elif details['type'] is bool:
self.option_widgets[name].setChecked(details['default'])
elif 'font' in name:
value = QtGui.QFont(details['default'])
self.option_widgets[name].setCurrentFont(value)
else:
self.option_widgets[name].setText(details['default'])
self.settings.endGroup()
def setup_options(self): def setup_options(self):
for group in get_option_groups(): for group in get_option_groups():
pretty_group = group.replace('_', ' ').title() pretty_group = group.replace('_', ' ').title()

View File

@ -1,7 +1,7 @@
import re import re
from PyQt5 import QtCore, QtGui, QtWidgets, Qsci from PyQt5 import QtCore, QtGui, QtWidgets, Qsci
from igitar.constants import KNOWN_DIRECTIVES, KNOWN_VERSE_TYPES from chordpro.constants import KNOWN_DIRECTIVES, KNOWN_VERSE_TYPES
PALETTE_ROLES = { PALETTE_ROLES = {
'window': QtGui.QPalette.WindowText, 'window': QtGui.QPalette.WindowText,

View File

@ -2,8 +2,8 @@
from pathlib import Path from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci, QtPrintSupport from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci, QtPrintSupport
from igitar import Song from chordpro import Song
from igitar.renderers.html import render, get_options from chordpro.renderers.html import render, get_options
from ukatali.configuredialog import ConfigureDialog from ukatali.configuredialog import ConfigureDialog
from ukatali.lexer import ChordProLexer from ukatali.lexer import ChordProLexer
@ -345,16 +345,13 @@ class MainWindow(QtWidgets.QMainWindow):
options = self._get_render_options(self.is_lyrics_mode) options = self._get_render_options(self.is_lyrics_mode)
text = self.file_editor.text() text = self.file_editor.text()
song = Song() song = Song()
try:
song.parse(text) song.parse(text)
return render(song, options, extra_styles) return render(song, options, extra_styles)
except Exception:
return None
def on_text_changed(self): def on_text_changed(self):
"""Update the preview when the text changes""" """Update the preview when the text changes"""
# self.setWindowModified(True)
html = self._render_song() html = self._render_song()
if html:
self.preview_view.setHtml(html) self.preview_view.setHtml(html)
def on_export_pdf_clicked(self): def on_export_pdf_clicked(self):
@ -383,7 +380,7 @@ class MainWindow(QtWidgets.QMainWindow):
margin_top = float(self.settings.value('margin_top', 20)) margin_top = float(self.settings.value('margin_top', 20))
margin_bottom = float(self.settings.value('margin_bottom', 20)) margin_bottom = float(self.settings.value('margin_bottom', 20))
self.settings.endGroup() self.settings.endGroup()
margins = QtCore.QMarginsF(margin_left, margin_top, margin_right, margin_bottom) margins = QtCore.QMarginsF(QtCore.QMargins(margin_left, margin_top, margin_right, margin_bottom))
page_layout = QtGui.QPageLayout(page_size, orientation, margins, unit) page_layout = QtGui.QPageLayout(page_size, orientation, margins, unit)
# Export to PDF # Export to PDF
self.preview_view.page().printToPdf(str(filename), page_layout) self.preview_view.page().printToPdf(str(filename), page_layout)
@ -407,14 +404,9 @@ class MainWindow(QtWidgets.QMainWindow):
# Export to HTML # Export to HTML
try: try:
with filename.open('w') as html_file: with filename.open('w') as html_file:
html = self._render_song() html_file.write(self._render_song())
if html:
html_file.write(html)
QtWidgets.QMessageBox.information(self, 'Export to HTML Successful', QtWidgets.QMessageBox.information(self, 'Export to HTML Successful',
'Successfully exported to "{}"'.format(filename.name)) '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: except Exception as e:
QtWidgets.QMessageBox.critical(self, 'Error Exporting to HTML', QtWidgets.QMessageBox.critical(self, 'Error Exporting to HTML',
'There was an error while exporting to HTML:\n{e}'.format(e=e)) 'There was an error while exporting to HTML:\n{e}'.format(e=e))