diff --git a/gui.py b/gui.py index dc81a3d..baa08c7 100755 --- a/gui.py +++ b/gui.py @@ -14,9 +14,9 @@ import os import time from copy import copy -from PyQt5.QtWidgets import QApplication, QAction, QLabel, QDialogButtonBox, QDialog, QFileDialog, QMessageBox, QPushButton, QLineEdit, QCheckBox, QSpinBox, QDoubleSpinBox, QTableWidgetItem, QTabWidget, QComboBox, QWidget, QScrollArea, QMainWindow, QShortcut, QMdiSubWindow +from PyQt5.QtWidgets import QApplication, QAction, QLabel, QDialogButtonBox, QDialog, QFileDialog, QMessageBox, QPushButton, QLineEdit, QCheckBox, QFontComboBox, QSpinBox, QDoubleSpinBox, QTableWidgetItem, QTabWidget, QComboBox, QWidget, QScrollArea, QMainWindow, QShortcut, QMdiSubWindow from PyQt5.QtCore import QFile, QObject, Qt, pyqtSlot, QSettings -from PyQt5.QtGui import QPixmap, QImage, QKeySequence +from PyQt5.QtGui import QPixmap, QImage, QKeySequence, QFontInfo, QFont, QRawFont from PyQt5 import uic from chordsheet.tableView import ChordTableView, BlockTableView from chordsheet.comboBox import MComboBox @@ -76,6 +76,9 @@ class MainWindow(QMainWindow): self.setCentralWidget(self.window.centralWidget) self.setMenuBar(self.window.menuBar) self.setWindowTitle("Chordsheet") + + self.lastSubWindow = None + self.currentSection = None if filename: try: @@ -113,6 +116,14 @@ class MainWindow(QMainWindow): self.addDockWidget(Qt.RightDockWidgetArea, self.chordsw) self.addDockWidget(Qt.RightDockWidgetArea, self.sectionsw) self.addDockWidget(Qt.RightDockWidgetArea, self.blocksw) + + # Check all the boxes in the window menu + self.window.actionDocument_information.setChecked(True) + self.window.actionPage_setup.setChecked(True) + self.window.actionChords.setChecked(True) + self.window.actionSections.setChecked(True) + self.window.actionBlocks.setChecked(True) + self.window.actionPreview.setChecked(True) # link all the UI elements self.window.mdiArea.subWindowActivated.connect(self.switchDocument) @@ -145,6 +156,14 @@ class MainWindow(QMainWindow): self.window.actionCopy.setShortcut(QKeySequence.Copy) self.window.actionPaste.setShortcut(QKeySequence.Paste) + self.window.actionDocument_information.triggered.connect(self.menuWindowDocInfoAction) + self.window.actionPage_setup.triggered.connect(self.menuWindowPageSetupAction) + self.window.actionChords.triggered.connect(self.menuWindowChordsAction) + self.window.actionSections.triggered.connect(self.menuWindowSectionsAction) + self.window.actionBlocks.triggered.connect(self.menuWindowBlocksAction) + self.window.actionPreview.triggered.connect(self.menuWindowPreviewAction) + + self.psetup.widget().pageSizeComboBox.currentIndexChanged.connect( self.pageSizeAction) self.psetup.widget().documentUnitsComboBox.currentIndexChanged.connect( @@ -157,7 +176,8 @@ class MainWindow(QMainWindow): self.psetup.widget().documentUnitsComboBox.addItems(list(unitDict.keys())) self.psetup.widget().documentUnitsComboBox.setCurrentText( list(unitDict.keys())[0]) - + + self.psetup.widget().fontComboBox.currentFontChanged.connect(self.fontChangeAction) self.psetup.widget().includedFontCheckBox.stateChanged.connect( self.includedFontAction) @@ -210,13 +230,17 @@ class MainWindow(QMainWindow): self.chordsw.widget().chordTableView.populate(doc.chordList) self.sectionsw.widget().sectionTableView.populate(doc.sectionList) + + self.updateChordDict(doc) + self.updateSectionDict(doc) # populate the block table with the first section, account for a document with no sections - self.currentSection = doc.sectionList[0] if len( - doc.sectionList) else None + if self.currentSection is None: + self.currentSection = doc.sectionList[0] if doc.sectionList else None + else: + self.blocksw.widget().blockSectionComboBox.setCurrentText( + self.currentSection.name) self.blocksw.widget().blockTableView.populate( self.currentSection.blockList if self.currentSection else []) - self.updateChordDict(doc) - self.updateSectionDict(doc) def UIInitStyle(self, style): """ @@ -235,8 +259,7 @@ class MainWindow(QMainWindow): self.psetup.widget().topMarginLineEdit.setText(str(style.topMargin)) self.psetup.widget().bottomMarginLineEdit.setText(str(style.bottomMargin)) - - self.psetup.widget().fontComboBox.setDisabled(True) + # self.psetup.widget().fontComboBox.setDisabled(True) self.psetup.widget().includedFontCheckBox.setChecked(True) self.psetup.widget().beatWidthLineEdit.setText(str(style.unitWidth)) @@ -258,11 +281,28 @@ class MainWindow(QMainWindow): self.blocksw.widget().blockSectionComboBox.clear() self.blocksw.widget().blockSectionComboBox.addItems( list(self.sectionDict.keys())) - - def switchDocument(self): + + def fontChangeAction(self): if self.window.mdiArea.currentSubWindow() is not None: - self.UIInitDocument(self.window.mdiArea.currentSubWindow().doc) - self.UIInitStyle(self.window.mdiArea.currentSubWindow().style) + qFont = self.psetup.widget().fontComboBox.currentFont() + qFontReal = QRawFont.fromFont(qFont) + #fontInfo = QFontInfo(qFont) + #qFontReal = QRawFont(fontInfo.family()) + print(qFont.rawName()) + + + def switchDocument(self, curWindow): + if curWindow is not None: + if self.lastSubWindow is not None: + self.lastSubWindow.currentSection = self.currentSection + + self.UIInitDocument(curWindow.doc) + self.UIInitStyle(curWindow.style) + self.currentSection = curWindow.currentSection + if self.currentSection is not None: + self.blocksw.widget().blockSectionComboBox.setCurrentText( + self.currentSection.name) + self.lastSubWindow = curWindow def generateAction(self): if self.window.mdiArea.currentSubWindow() is not None: @@ -287,7 +327,7 @@ class MainWindow(QMainWindow): b.chord = None self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) self.clearChordLineEdits() - self.window.mdiArea.currentSubWindow().updateChordDict() + self.updateChordDict(self.window.mdiArea.currentSubWindow().doc) def addChordAction(self): success = False # initialise @@ -319,7 +359,7 @@ class MainWindow(QMainWindow): if success == True: # if chord was parsed properly self.chordsw.widget().chordTableView.populate(self.window.mdiArea.currentSubWindow().doc.chordList) self.clearChordLineEdits() - self.window.mdiArea.currentSubWindow().updateChordDict() + self.updateChordDict(self.window.mdiArea.currentSubWindow().doc) def updateChordAction(self): success = False # see comments above @@ -351,7 +391,7 @@ class MainWindow(QMainWindow): ChordNameWarningMessageBox().exec() if success == True: - self.window.mdiArea.currentSubWindow().updateChordDict() + self.updateChordDict(self.window.mdiArea.currentSubWindow().doc) self.chordsw.widget().chordTableView.populate(self.window.mdiArea.currentSubWindow().doc.chordList) # update the names of chords in all blocklists in case they've already been used for s in self.window.mdiArea.currentSubWindow().doc.sectionList: @@ -372,7 +412,7 @@ class MainWindow(QMainWindow): self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) self.clearSectionLineEdits() - self.window.mdiArea.currentSubWindow().updateSectionDict() + self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) def addSectionAction(self): self.window.mdiArea.currentSubWindow().updateSections() @@ -382,7 +422,7 @@ class MainWindow(QMainWindow): self.window.mdiArea.currentSubWindow().doc.sectionList.append(Section(name=sName)) self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) self.clearSectionLineEdits() - self.window.mdiArea.currentSubWindow().updateSectionDict() + self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) else: # Section has no name or non unique, warn user SectionNameWarningMessageBox().exec() @@ -397,7 +437,7 @@ class MainWindow(QMainWindow): self.window.mdiArea.currentSubWindow().doc.sectionList[row].name = sName self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) self.clearSectionLineEdits() - self.window.mdiArea.currentSubWindow().updateSectionDict() + self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) else: # Section has no name or non unique, warn user SectionNameWarningMessageBox().exec() @@ -495,10 +535,11 @@ class MainWindow(QMainWindow): if sName: if self.window.mdiArea.currentSubWindow() is not None: self.currentSection = self.sectionDict.get(sName, None) + # self.window.mdiArea.currentSubWindow().currentSection = self.currentSection if self.currentSection is not None: self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) else: - self.currentSection = None + pass # self.currentSection = None def blockClickedAction(self, index): # set the controls to the values from the selected block @@ -537,7 +578,7 @@ class MainWindow(QMainWindow): self.window.mdiArea.addSubWindow(dw) self.UIInitDocument(dw.doc) self.UIInitStyle(dw.style) - self.currentSection = None + # self.currentSection = None dw.show() @@ -618,6 +659,54 @@ class MainWindow(QMainWindow): except Exception: pass + + # self.docinfo = DocInfoDockWidget() + # self.psetup = PageSetupDockWidget() + # self.chordsw = ChordsDockWidget() + # self.sectionsw = SectionsDockWidget() + # self.blocksw = BlocksDockWidget() + # self.previeww = PreviewDockWidget() + + def menuWindowDocInfoAction(self): + if self.window.actionDocument_information.isChecked(): + self.docinfo.show() + else: + self.docinfo.hide() + + def menuWindowPageSetupAction(self): + if self.window.actionPage_setup.isChecked(): + self.psetup.show() + else: + self.psetup.hide() + + def menuWindowChordsAction(self): + if self.window.actionChords.isChecked(): + self.chordsw.show() + else: + self.chordsw.hide() + + + def menuWindowSectionsAction(self): + if self.window.actionSections.isChecked(): + self.sectionsw.show() + else: + self.sectionsw.hide() + + + def menuWindowBlocksAction(self): + if self.window.actionBlocks.isChecked(): + self.blocksw.show() + else: + self.blocksw.hide() + + + def menuWindowPreviewAction(self): + if self.window.actionPreview.isChecked(): + self.previeww.show() + else: + self.previeww.hide() + + def guitarVoicingAction(self): gdialog = GuitarDialog() @@ -666,9 +755,10 @@ class DocumentWindow(QMdiSubWindow): self.lastDoc = copy(self.doc) self.currentFilePath = filename + self.currentSection = None + mw.updateChordDict(self.doc) mw.updateSectionDict(self.doc) - self.currentSection = None def UIFileLoader(self, ui_file): ui_file = QFile(ui_file) @@ -696,13 +786,17 @@ class DocumentWindow(QMdiSubWindow): else: # if fileExt in [".xml", ".cml"]: self.doc.loadXML(self.currentFilePath) + self.updatePreview() + self.lastDoc = copy(self.doc) mw.setPath("workingPath", self.currentFilePath) mw.updateChordDict(self.doc) mw.updateSectionDict(self.doc) + + self.currentSection = (self.doc.sectionList[0] if self.doc.sectionList else None) + self.updateTitleBar() - self.updatePreview() def saveFile(self, filePath): """ diff --git a/preview.pdf b/preview.pdf index b51a7e9..e946d38 100644 Binary files a/preview.pdf and b/preview.pdf differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6971249 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +reportlab>=3.5.67 +PyMuPDF>=1.18.13 +PyQt5>=5.15.4 diff --git a/ui/blocks.ui b/ui/blocks.ui index 82ab355..5040468 100644 --- a/ui/blocks.ui +++ b/ui/blocks.ui @@ -6,193 +6,261 @@ 0 0 - 437 - 371 + 387 + 206 Blocks - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - - - - - QFormLayout::ExpandingFieldsGrow - - - - - Section - - - - - - - - 0 - 0 - - - - - + + + QFormLayout::ExpandingFieldsGrow + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Section + + - - + + - + 0 0 - - QAbstractItemView::NoEditTriggers + + + + + + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::InternalMove + + + Qt::TargetMoveAction + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Length - - true + + + + + + + + + + 0 + 0 + - - false + + Notes - - QAbstractItemView::InternalMove + + + + + + Chord - - Qt::TargetMoveAction + + + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + + + + + + 0 + 0 + - - QAbstractItemView::SingleSelection + + + + + + Qt::Horizontal - - QAbstractItemView::SelectRows + + QSizePolicy::MinimumExpanding - - false + + + 40 + 20 + - - false + + + + + + + + 6 + + + 6 + + + 0 + + + 6 + + + 6 + + + + + Remove block - - - - - Length - - - - - - - - - - - 0 - 0 - - - - Notes - - - - - - - Chord - - - - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - - - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 40 - 20 - - - - - + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 40 + 20 + + + + + + + + Update block + + - - - - - Remove block - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 40 - 20 - - - - - - - - Update block - - - - - - - Add block - - - - + + + true + + + Add block + + + false + + + false + + + false + + + false + + @@ -211,8 +279,6 @@ - blockSectionComboBox - blockTableView blockLengthLineEdit blockChordComboBox blockNotesLineEdit diff --git a/ui/chords.ui b/ui/chords.ui index 7f64fe4..40a4f67 100644 --- a/ui/chords.ui +++ b/ui/chords.ui @@ -6,65 +6,91 @@ 0 0 - 443 - 359 + 393 + 236 Chords - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - - - - - - 0 - 0 - - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - QAbstractItemView::InternalMove - - - Qt::IgnoreAction - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - false - - - false - - - + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::InternalMove + + + Qt::IgnoreAction + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + false + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + - - - - Chord name - - - + + 6 + @@ -82,6 +108,9 @@ + + + @@ -98,22 +127,6 @@ - - - - - 16777215 - 16777215 - - - - Editor... - - - - - - @@ -121,44 +134,23 @@ - - - - - - + + - Remove chord + Chord name - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - + + + - 40 - 20 + 16777215 + 16777215 - - - - - - Update chord - - - - - - Add chord + Editor... @@ -166,6 +158,62 @@ + + + + 6 + + + 6 + + + 0 + + + 6 + + + 6 + + + + + Remove chord + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 40 + 20 + + + + + + + + Update chord + + + + + + + Add chord + + + + + @@ -176,7 +224,6 @@ - chordTableView chordNameLineEdit guitarVoicingLineEdit guitarVoicingButton diff --git a/ui/docinfo.ui b/ui/docinfo.ui index 3f5b625..3c03418 100644 --- a/ui/docinfo.ui +++ b/ui/docinfo.ui @@ -9,8 +9,8 @@ 0 0 - 400 - 202 + 291 + 170 @@ -23,11 +23,29 @@ Document information + + 6 + + + 6 + + + 6 + + + 6 + QFormLayout::ExpandingFieldsGrow + + 6 + + + 6 + diff --git a/ui/document.ui b/ui/document.ui index 9ed6722..3577480 100644 --- a/ui/document.ui +++ b/ui/document.ui @@ -11,7 +11,7 @@ - Form + Unsaved diff --git a/ui/new.ui b/ui/new.ui index 60a8b94..eb82610 100644 --- a/ui/new.ui +++ b/ui/new.ui @@ -7,7 +7,7 @@ 0 0 1061 - 659 + 639 @@ -88,8 +88,21 @@ + + + Window + + + + + + + + + + @@ -166,6 +179,54 @@ About + + + true + + + Document information + + + + + true + + + Page setup + + + + + true + + + Chords + + + + + true + + + Sections + + + + + true + + + Blocks + + + + + true + + + Preview + + diff --git a/ui/preview.ui b/ui/preview.ui index 24e543a..712ac9d 100644 --- a/ui/preview.ui +++ b/ui/preview.ui @@ -6,7 +6,7 @@ 0 0 - 400 + 248 40 @@ -25,7 +25,10 @@ Preview - + + + 6 + 0 @@ -40,6 +43,12 @@ + + + 0 + 0 + + Update preview diff --git a/ui/psetup.ui b/ui/psetup.ui index 5ca2c8e..75ec37d 100644 --- a/ui/psetup.ui +++ b/ui/psetup.ui @@ -6,12 +6,12 @@ 0 0 - 400 - 500 + 257 + 271 - + 0 0 @@ -20,239 +20,262 @@ Page setup + + 6 + + + 6 + + + 6 + + + 6 + - - - - 0 - 0 - + + + 6 - - Page options - - - - - - - - Page size - - - - - - - - - - Document units - - - - - - - - - - Left margin - - - - - - - - 60 - 16777215 - - - - - - - - Top margin - - - - - - - - 60 - 16777215 - - - - - - - - Right margin - - - - - - - - 60 - 16777215 - - - - - - - - Bottom margin - - - - - - - - 60 - 16777215 - - - - - - - - - - - - - - 0 - 0 - - - - Font options - - - - - - - - - 40 - 16777215 - - - - Font - - - - - - - - 0 - 0 - - - - - - - - - - Use included FreeSans - - - - - - - - - - - 0 - 0 - - - - Text options - - - - - - - - Line spacing - - - - - - - - 70 - 0 - - - - - 70 - 16777215 - - - - - - - - - - - - - - 0 - 0 - - - - Block options - - - - - - - - Beat width - - - - - - - - 60 - 16777215 - - - - - - - - + + + + + 0 + 0 + + + + Line spacing + + + + + + + + 60 + 16777215 + + + + + + + + + 40 + 16777215 + + + + Font + + + + + + + + 60 + 16777215 + + + + + + + + + 60 + 16777215 + + + + + + + + + 70 + 0 + + + + + 70 + 16777215 + + + + + + + + + 60 + 16777215 + + + + + + + + + 70 + 26 + + + + true + + + true + + + + + + + + 0 + 0 + + + + + 16777215 + 16777194 + + + + Top margin + + + + + + + + 60 + 16777215 + + + + + + + + Page size + + + + + + + Units + + + + + + + + 0 + 0 + + + + Bottom margin + + + + + + + + 0 + 0 + + + + Left margin + + + + + + + + 0 + 0 + + + + Use FreeSans + + + true + + + + + + + + 0 + 0 + + + + Beat width + + + + + + + + 0 + 0 + + + + Right margin + + + + + + + true + + + + 70 + 26 + + + + true + + + true + + + + + + + + 16777215 + 26 + + + + + @@ -263,9 +286,9 @@ rightMarginLineEdit topMarginLineEdit bottomMarginLineEdit - lineSpacingDoubleSpinBox fontComboBox includedFontCheckBox + lineSpacingDoubleSpinBox beatWidthLineEdit diff --git a/ui/sections.ui b/ui/sections.ui index 9280c89..80d35d2 100644 --- a/ui/sections.ui +++ b/ui/sections.ui @@ -6,110 +6,148 @@ 0 0 - 431 - 325 + 405 + 170 Sections - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - - - - - - 0 - 0 - - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - QAbstractItemView::InternalMove - - - Qt::TargetMoveAction + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::InternalMove + + + Qt::TargetMoveAction + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + + + + + QFormLayout::ExpandingFieldsGrow + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Name - - QAbstractItemView::SingleSelection + + + + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Remove section - - QAbstractItemView::SelectRows + + + + + + Qt::Horizontal - - false + + QSizePolicy::MinimumExpanding - - false + + + 0 + 20 + - + - - - QFormLayout::ExpandingFieldsGrow + + + Update section - - - - Name - - - - - - - + - - - - - Remove section - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 0 - 20 - - - - - - - - Update section - - - - - - - Add section - - - - + + + Add section + +