Compare commits
5 Commits
e9308b4c43
...
1a97bde040
Author | SHA1 | Date | |
---|---|---|---|
1a97bde040 | |||
54e0af1915 | |||
05802f6439 | |||
ee45264ebd | |||
79fa8777e9 |
@ -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()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
|
||||||
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
|
||||||
@ -19,6 +18,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
self.settings = QtCore.QSettings()
|
self.settings = QtCore.QSettings()
|
||||||
self.filename = None
|
self.filename = None
|
||||||
|
self.is_lyrics_mode = False
|
||||||
self.configure_dialog = ConfigureDialog(self)
|
self.configure_dialog = ConfigureDialog(self)
|
||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
@ -67,6 +67,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.preview_layout.setContentsMargins(0, 0, 0, 0)
|
self.preview_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
self.preview_layout.setSpacing(0)
|
self.preview_layout.setSpacing(0)
|
||||||
self.preview_layout.setObjectName('preview_layout')
|
self.preview_layout.setObjectName('preview_layout')
|
||||||
|
self.preview_toolbar = QtWidgets.QToolBar(self.preview_dock_contents)
|
||||||
|
self.preview_toolbar.setMovable(False)
|
||||||
|
self.preview_toolbar.setObjectName('preview_toolbar')
|
||||||
|
self.preview_layout.addWidget(self.preview_toolbar)
|
||||||
self.preview_view = QtWebEngineWidgets.QWebEngineView(self.preview_dock_contents)
|
self.preview_view = QtWebEngineWidgets.QWebEngineView(self.preview_dock_contents)
|
||||||
self.preview_view.setUrl(QtCore.QUrl('about:blank'))
|
self.preview_view.setUrl(QtCore.QUrl('about:blank'))
|
||||||
self.preview_view.setObjectName('preview_view')
|
self.preview_view.setObjectName('preview_view')
|
||||||
@ -74,6 +78,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.preview_dock.setWidget(self.preview_dock_contents)
|
self.preview_dock.setWidget(self.preview_dock_contents)
|
||||||
self.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.preview_dock)
|
self.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.preview_dock)
|
||||||
self.toolbar = QtWidgets.QToolBar(self)
|
self.toolbar = QtWidgets.QToolBar(self)
|
||||||
|
self.toolbar.setMovable(False)
|
||||||
self.toolbar.setObjectName('toolbar')
|
self.toolbar.setObjectName('toolbar')
|
||||||
self.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar)
|
self.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar)
|
||||||
self.new_action = QtWidgets.QAction(self)
|
self.new_action = QtWidgets.QAction(self)
|
||||||
@ -117,25 +122,25 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.cut_action.setIcon(icon)
|
self.cut_action.setIcon(icon)
|
||||||
self.cut_action.setObjectName('cut_action')
|
self.cut_action.setObjectName('cut_action')
|
||||||
self.copy_action = QtWidgets.QAction(self)
|
self.copy_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('edit-copy')
|
self.copy_action.setIcon(QtGui.QIcon.fromTheme('edit-copy'))
|
||||||
self.copy_action.setIcon(icon)
|
|
||||||
self.copy_action.setObjectName('copy_action')
|
self.copy_action.setObjectName('copy_action')
|
||||||
self.paste_action = QtWidgets.QAction(self)
|
self.paste_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('edit-paste')
|
self.paste_action.setIcon(QtGui.QIcon.fromTheme('edit-paste'))
|
||||||
self.paste_action.setIcon(icon)
|
|
||||||
self.paste_action.setObjectName('paste_action')
|
self.paste_action.setObjectName('paste_action')
|
||||||
self.configure_action = QtWidgets.QAction(self)
|
self.configure_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('configure')
|
self.configure_action.setIcon(QtGui.QIcon.fromTheme('configure'))
|
||||||
self.configure_action.setIcon(icon)
|
|
||||||
self.configure_action.setObjectName('configure_action')
|
self.configure_action.setObjectName('configure_action')
|
||||||
self.about_action = QtWidgets.QAction(self)
|
self.about_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('help-about')
|
self.about_action.setIcon(QtGui.QIcon.fromTheme('help-about'))
|
||||||
self.about_action.setIcon(icon)
|
|
||||||
self.about_action.setObjectName('about_action')
|
self.about_action.setObjectName('about_action')
|
||||||
self.exit_action = QtWidgets.QAction(self)
|
self.exit_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('application-exit')
|
self.exit_action.setIcon(QtGui.QIcon.fromTheme('application-exit'))
|
||||||
self.exit_action.setIcon(icon)
|
|
||||||
self.exit_action.setObjectName('exit_action')
|
self.exit_action.setObjectName('exit_action')
|
||||||
|
self.hide_chords_action = QtWidgets.QAction(self)
|
||||||
|
self.hide_chords_action.setCheckable(True)
|
||||||
|
self.hide_chords_action.setChecked(False)
|
||||||
|
self.hide_chords_action.setIcon(QtGui.QIcon.fromTheme('view-hidden'))
|
||||||
|
self.hide_chords_action.setObjectName('hide_chords_action')
|
||||||
self.file_menu.addAction(self.new_action)
|
self.file_menu.addAction(self.new_action)
|
||||||
self.file_menu.addAction(self.open_action)
|
self.file_menu.addAction(self.open_action)
|
||||||
self.file_menu.addAction(self.save_action)
|
self.file_menu.addAction(self.save_action)
|
||||||
@ -175,6 +180,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.toolbar.addAction(self.paste_action)
|
self.toolbar.addAction(self.paste_action)
|
||||||
self.toolbar.addSeparator()
|
self.toolbar.addSeparator()
|
||||||
self.toolbar.addAction(self.configure_action)
|
self.toolbar.addAction(self.configure_action)
|
||||||
|
self.preview_toolbar.addAction(self.hide_chords_action)
|
||||||
|
|
||||||
self.retranslate_ui()
|
self.retranslate_ui()
|
||||||
self.exit_action.triggered.connect(self.close)
|
self.exit_action.triggered.connect(self.close)
|
||||||
@ -183,6 +189,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.cut_action.triggered.connect(self.file_editor.cut)
|
self.cut_action.triggered.connect(self.file_editor.cut)
|
||||||
self.copy_action.triggered.connect(self.file_editor.copy)
|
self.copy_action.triggered.connect(self.file_editor.copy)
|
||||||
self.paste_action.triggered.connect(self.file_editor.paste)
|
self.paste_action.triggered.connect(self.file_editor.paste)
|
||||||
|
self.new_action.triggered.connect(self.on_new_clicked)
|
||||||
self.open_action.triggered.connect(self.on_open_clicked)
|
self.open_action.triggered.connect(self.on_open_clicked)
|
||||||
self.save_action.triggered.connect(self.on_save_clicked)
|
self.save_action.triggered.connect(self.on_save_clicked)
|
||||||
self.save_as_action.triggered.connect(self.on_save_as_clicked)
|
self.save_as_action.triggered.connect(self.on_save_as_clicked)
|
||||||
@ -192,10 +199,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.configure_action.triggered.connect(self.on_configure_clicked)
|
self.configure_action.triggered.connect(self.on_configure_clicked)
|
||||||
self.file_editor.textChanged.connect(self.on_text_changed)
|
self.file_editor.textChanged.connect(self.on_text_changed)
|
||||||
self.preview_view.page().pdfPrintingFinished.connect(self.on_pdf_finished)
|
self.preview_view.page().pdfPrintingFinished.connect(self.on_pdf_finished)
|
||||||
|
self.hide_chords_action.triggered.connect(self.on_hide_chords_clicked)
|
||||||
|
|
||||||
def retranslate_ui(self):
|
def retranslate_ui(self):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
self.setWindowTitle(_translate('MainWindow', 'Ukatali'))
|
self.setWindowTitle(_translate('MainWindow', 'Untitled') + '[*] - Ukatali')
|
||||||
self.file_menu.setTitle(_translate('MainWindow', '&File'))
|
self.file_menu.setTitle(_translate('MainWindow', '&File'))
|
||||||
self.edit_menu.setTitle(_translate('MainWindow', '&Edit'))
|
self.edit_menu.setTitle(_translate('MainWindow', '&Edit'))
|
||||||
self.settings_menu.setTitle(_translate('MainWindow', '&Settings'))
|
self.settings_menu.setTitle(_translate('MainWindow', '&Settings'))
|
||||||
@ -245,6 +253,20 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.exit_action.setText(_translate('MainWindow', 'E&xit'))
|
self.exit_action.setText(_translate('MainWindow', 'E&xit'))
|
||||||
self.exit_action.setToolTip(_translate('MainWindow', 'Quit Ukatali'))
|
self.exit_action.setToolTip(_translate('MainWindow', 'Quit Ukatali'))
|
||||||
self.exit_action.setShortcut(_translate('MainWindow', 'Alt+F4'))
|
self.exit_action.setShortcut(_translate('MainWindow', 'Alt+F4'))
|
||||||
|
self.hide_chords_action.setText(_translate('MainWindow', 'Hide Chords'))
|
||||||
|
|
||||||
|
def on_new_clicked(self):
|
||||||
|
"""Start a new file"""
|
||||||
|
if self.file_editor.isModified() and QtWidgets.QMessageBox.question(self, 'Save file?',
|
||||||
|
'The current file is not saved, do you '
|
||||||
|
'want to save it now?') \
|
||||||
|
== QtWidgets.QMessageBox.Yes:
|
||||||
|
self.on_save_clicked()
|
||||||
|
self.file_editor.setText('')
|
||||||
|
self.file_editor.setModified(False)
|
||||||
|
self.filename = ''
|
||||||
|
self.setWindowTitle('Untitled[*] - Ukatali')
|
||||||
|
self.setWindowModified(False)
|
||||||
|
|
||||||
def on_open_clicked(self):
|
def on_open_clicked(self):
|
||||||
"""Open the file"""
|
"""Open the file"""
|
||||||
@ -263,6 +285,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
self.settings.setValue('files/last-directory', str(file_path.parent))
|
self.settings.setValue('files/last-directory', str(file_path.parent))
|
||||||
self.file_editor.setText(file_path.open().read())
|
self.file_editor.setText(file_path.open().read())
|
||||||
|
self.setWindowTitle('{}[*] - Ukatali'.format(file_path.name))
|
||||||
|
self.setWindowModified(False)
|
||||||
|
|
||||||
def on_save_clicked(self):
|
def on_save_clicked(self):
|
||||||
"""Save the file"""
|
"""Save the file"""
|
||||||
@ -271,6 +295,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
else:
|
else:
|
||||||
with open(self.filename, 'w') as fd:
|
with open(self.filename, 'w') as fd:
|
||||||
fd.write(self.file_editor.text())
|
fd.write(self.file_editor.text())
|
||||||
|
self.setWindowTitle('{}[*] - Ukatali'.format(Path(self.filename).name))
|
||||||
|
self.setWindowModified(False)
|
||||||
|
|
||||||
def on_save_as_clicked(self):
|
def on_save_as_clicked(self):
|
||||||
"""Save the file"""
|
"""Save the file"""
|
||||||
@ -293,7 +319,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
if self.configure_dialog.exec() == QtWidgets.QDialog.Accepted and self.file_editor.text():
|
if self.configure_dialog.exec() == QtWidgets.QDialog.Accepted and self.file_editor.text():
|
||||||
self.on_text_changed()
|
self.on_text_changed()
|
||||||
|
|
||||||
def _get_render_options(self):
|
def _get_render_options(self, is_lyrics_mode=False):
|
||||||
"""Get all the render options from the settings"""
|
"""Get all the render options from the settings"""
|
||||||
options = {}
|
options = {}
|
||||||
self.settings.beginGroup('render')
|
self.settings.beginGroup('render')
|
||||||
@ -307,23 +333,24 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
elif details['type'] is bool:
|
elif details['type'] is bool:
|
||||||
value = coerce_bool(value)
|
value = coerce_bool(value)
|
||||||
options[name] = value
|
options[name] = value
|
||||||
|
if is_lyrics_mode and 'indent' in name:
|
||||||
|
options[name] = 0
|
||||||
|
elif is_lyrics_mode and 'is_hidden' in name:
|
||||||
|
options[name] = True
|
||||||
self.settings.endGroup()
|
self.settings.endGroup()
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def _render_song(self, extra_styles=None):
|
def _render_song(self, extra_styles=None):
|
||||||
"""Render the current song and return the HTML"""
|
"""Render the current song and return the HTML"""
|
||||||
options = self._get_render_options()
|
options = self._get_render_options(self.is_lyrics_mode)
|
||||||
text = self.file_editor.text()
|
text = self.file_editor.text()
|
||||||
song = Song()
|
song = Song()
|
||||||
song.parse(text)
|
song.parse(text)
|
||||||
if song.metadata.get('copyright'):
|
|
||||||
extra_styles = extra_styles or ''
|
|
||||||
extra_styles += os.linesep
|
|
||||||
extra_styles += '@page {{ @bottom-left {{ content: "{}"; }} }}'.format(song.metadata.get('copyright'))
|
|
||||||
return render(song, options, extra_styles)
|
return render(song, options, extra_styles)
|
||||||
|
|
||||||
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()
|
||||||
self.preview_view.setHtml(html)
|
self.preview_view.setHtml(html)
|
||||||
|
|
||||||
@ -392,16 +419,18 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
else:
|
else:
|
||||||
QtWidgets.QMessageBox.critical(self, 'Error Exporting to PDF', 'There was an error while exporting to PDF')
|
QtWidgets.QMessageBox.critical(self, 'Error Exporting to PDF', 'There was an error while exporting to PDF')
|
||||||
|
|
||||||
|
def on_print_finished(self, is_success):
|
||||||
|
print(is_success)
|
||||||
|
|
||||||
def on_print_clicked(self):
|
def on_print_clicked(self):
|
||||||
"""Print the current song"""
|
"""Print the current song"""
|
||||||
|
printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
|
||||||
def _on_print_finished(is_success):
|
|
||||||
print(is_success)
|
|
||||||
|
|
||||||
# print(QtPrintSupport.QPrinterInfo.defaultPrinterName())
|
|
||||||
# default_printer = QtPrintSupport.QPrinterInfo.defaultPrinter()
|
|
||||||
# print(default_printer)
|
|
||||||
printer = QtPrintSupport.QPrinter()
|
|
||||||
print_dialog = QtPrintSupport.QPrintDialog(printer, self.preview_view.page().view())
|
print_dialog = QtPrintSupport.QPrintDialog(printer, self.preview_view.page().view())
|
||||||
if print_dialog.exec() == QtWidgets.QDialog.Accepted:
|
if print_dialog.exec() == QtWidgets.QDialog.Accepted:
|
||||||
self.preview_view.page().print(printer, _on_print_finished)
|
self.preview_view.page().print(printer, self.on_print_finished)
|
||||||
|
|
||||||
|
def on_hide_chords_clicked(self, is_checked):
|
||||||
|
"""Hide the chords in the preview window"""
|
||||||
|
self.is_lyrics_mode = is_checked
|
||||||
|
if self.file_editor.text():
|
||||||
|
self.on_text_changed()
|
||||||
|
Loading…
Reference in New Issue
Block a user