Compare commits
3 Commits
8f58080045
...
79fa8777e9
Author | SHA1 | Date | |
---|---|---|---|
79fa8777e9 | |||
d6b77e13b6 | |||
42df7c9d81 |
@ -96,10 +96,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
icon = QtGui.QIcon.fromTheme('document-print')
|
icon = QtGui.QIcon.fromTheme('document-print')
|
||||||
self.print_action.setIcon(icon)
|
self.print_action.setIcon(icon)
|
||||||
self.print_action.setObjectName('print_action')
|
self.print_action.setObjectName('print_action')
|
||||||
self.export_action = QtWidgets.QAction(self)
|
self.export_pdf_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('document-export')
|
icon = QtGui.QIcon.fromTheme('application-pdf')
|
||||||
self.export_action.setIcon(icon)
|
self.export_pdf_action.setIcon(icon)
|
||||||
self.export_action.setObjectName('export_action')
|
self.export_pdf_action.setObjectName('export_pdf_action')
|
||||||
|
self.export_html_action = QtWidgets.QAction(self)
|
||||||
|
icon = QtGui.QIcon.fromTheme('text-html')
|
||||||
|
self.export_html_action.setIcon(icon)
|
||||||
|
self.export_html_action.setObjectName('export_html_action')
|
||||||
self.undo_action = QtWidgets.QAction(self)
|
self.undo_action = QtWidgets.QAction(self)
|
||||||
icon = QtGui.QIcon.fromTheme('edit-undo')
|
icon = QtGui.QIcon.fromTheme('edit-undo')
|
||||||
self.undo_action.setIcon(icon)
|
self.undo_action.setIcon(icon)
|
||||||
@ -137,7 +141,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.file_menu.addAction(self.save_action)
|
self.file_menu.addAction(self.save_action)
|
||||||
self.file_menu.addAction(self.save_as_action)
|
self.file_menu.addAction(self.save_as_action)
|
||||||
self.file_menu.addSeparator()
|
self.file_menu.addSeparator()
|
||||||
self.file_menu.addAction(self.export_action)
|
self.export_menu = self.file_menu.addMenu('')
|
||||||
|
self.export_menu.setObjectName('export_menu')
|
||||||
|
self.export_menu.addAction(self.export_pdf_action)
|
||||||
|
self.export_menu.addAction(self.export_html_action)
|
||||||
self.file_menu.addAction(self.print_action)
|
self.file_menu.addAction(self.print_action)
|
||||||
self.file_menu.addSeparator()
|
self.file_menu.addSeparator()
|
||||||
self.file_menu.addAction(self.exit_action)
|
self.file_menu.addAction(self.exit_action)
|
||||||
@ -157,7 +164,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.toolbar.addAction(self.open_action)
|
self.toolbar.addAction(self.open_action)
|
||||||
self.toolbar.addAction(self.save_action)
|
self.toolbar.addAction(self.save_action)
|
||||||
self.toolbar.addSeparator()
|
self.toolbar.addSeparator()
|
||||||
self.toolbar.addAction(self.export_action)
|
self.toolbar.addAction(self.export_pdf_action)
|
||||||
self.toolbar.addAction(self.print_action)
|
self.toolbar.addAction(self.print_action)
|
||||||
self.toolbar.addSeparator()
|
self.toolbar.addSeparator()
|
||||||
self.toolbar.addAction(self.undo_action)
|
self.toolbar.addAction(self.undo_action)
|
||||||
@ -176,10 +183,12 @@ 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)
|
||||||
self.export_action.triggered.connect(self.on_export_clicked)
|
self.export_pdf_action.triggered.connect(self.on_export_pdf_clicked)
|
||||||
|
self.export_html_action.triggered.connect(self.on_export_html_clicked)
|
||||||
self.print_action.triggered.connect(self.on_print_clicked)
|
self.print_action.triggered.connect(self.on_print_clicked)
|
||||||
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)
|
||||||
@ -187,7 +196,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
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'))
|
||||||
@ -209,9 +218,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.print_action.setText(_translate('MainWindow', '&Print'))
|
self.print_action.setText(_translate('MainWindow', '&Print'))
|
||||||
self.print_action.setToolTip(_translate('MainWindow', 'Print the current ChordPro file'))
|
self.print_action.setToolTip(_translate('MainWindow', 'Print the current ChordPro file'))
|
||||||
self.print_action.setShortcut(_translate('MainWindow', 'Ctrl+P'))
|
self.print_action.setShortcut(_translate('MainWindow', 'Ctrl+P'))
|
||||||
self.export_action.setText(_translate('MainWindow', '&Export...'))
|
self.export_menu.setTitle(_translate('MainWindow', '&Export'))
|
||||||
self.export_action.setToolTip(_translate('MainWindow', 'Export the current file as a different format'))
|
self.export_pdf_action.setText(_translate('MainWindow', 'Export to &PDF...'))
|
||||||
self.export_action.setShortcut(_translate('MainWindow', 'Ctrl+E'))
|
self.export_pdf_action.setToolTip(_translate('MainWindow', 'Export the current file as a PDF file'))
|
||||||
|
self.export_pdf_action.setShortcut(_translate('MainWindow', 'Ctrl+E'))
|
||||||
|
self.export_html_action.setText(_translate('MainWindow', 'Export to &HTML...'))
|
||||||
|
self.export_html_action.setToolTip(_translate('MainWindow', 'Export the current file as an HTML file'))
|
||||||
self.undo_action.setText(_translate('MainWindow', '&Undo'))
|
self.undo_action.setText(_translate('MainWindow', '&Undo'))
|
||||||
self.undo_action.setToolTip(_translate('MainWindow', 'Undo the last edit'))
|
self.undo_action.setToolTip(_translate('MainWindow', 'Undo the last edit'))
|
||||||
self.undo_action.setShortcut(_translate('MainWindow', 'Ctrl+Z'))
|
self.undo_action.setShortcut(_translate('MainWindow', 'Ctrl+Z'))
|
||||||
@ -235,6 +247,19 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
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'))
|
||||||
|
|
||||||
|
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"""
|
||||||
if self.settings.value('files/last-directory'):
|
if self.settings.value('files/last-directory'):
|
||||||
@ -252,6 +277,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"""
|
||||||
@ -260,6 +287,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"""
|
||||||
@ -313,10 +342,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
def on_export_clicked(self):
|
def on_export_pdf_clicked(self):
|
||||||
"""Export the current song to PDF"""
|
"""Export the current song to PDF"""
|
||||||
if self.filename:
|
if self.filename:
|
||||||
last_directory = str(Path(self.filename).with_suffix('.pdf'))
|
last_directory = str(Path(self.filename).with_suffix('.pdf'))
|
||||||
@ -347,6 +377,32 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
# Export to PDF
|
# Export to PDF
|
||||||
self.preview_view.page().printToPdf(str(filename), page_layout)
|
self.preview_view.page().printToPdf(str(filename), page_layout)
|
||||||
|
|
||||||
|
def on_export_html_clicked(self):
|
||||||
|
"""Export the current song to HTML"""
|
||||||
|
if self.filename:
|
||||||
|
last_directory = str(Path(self.filename).with_suffix('.html'))
|
||||||
|
elif self.settings.value('files/last-directory'):
|
||||||
|
last_directory = self.settings.value('files/last-directory')
|
||||||
|
else:
|
||||||
|
last_directory = ''
|
||||||
|
filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Export to HTML', last_directory,
|
||||||
|
filter='HTML files (.html)*')
|
||||||
|
if isinstance(filename, tuple):
|
||||||
|
filename = filename[0]
|
||||||
|
if not filename:
|
||||||
|
return
|
||||||
|
filename = Path(filename)
|
||||||
|
self.settings.setValue('files/last-directory', str(filename.parent))
|
||||||
|
# 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))
|
||||||
|
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))
|
||||||
|
|
||||||
def on_pdf_finished(self, filename, is_success):
|
def on_pdf_finished(self, filename, is_success):
|
||||||
"""A slot to notify the user when the PDF is done"""
|
"""A slot to notify the user when the PDF is done"""
|
||||||
if is_success:
|
if is_success:
|
||||||
|
Loading…
Reference in New Issue
Block a user