|
@ -14,9 +14,9 @@ import os |
|
|
import time |
|
|
import time |
|
|
from copy import copy |
|
|
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.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 PyQt5 import uic |
|
|
from chordsheet.tableView import ChordTableView, BlockTableView |
|
|
from chordsheet.tableView import ChordTableView, BlockTableView |
|
|
from chordsheet.comboBox import MComboBox |
|
|
from chordsheet.comboBox import MComboBox |
|
@ -76,6 +76,9 @@ class MainWindow(QMainWindow): |
|
|
self.setCentralWidget(self.window.centralWidget) |
|
|
self.setCentralWidget(self.window.centralWidget) |
|
|
self.setMenuBar(self.window.menuBar) |
|
|
self.setMenuBar(self.window.menuBar) |
|
|
self.setWindowTitle("Chordsheet") |
|
|
self.setWindowTitle("Chordsheet") |
|
|
|
|
|
|
|
|
|
|
|
self.lastSubWindow = None |
|
|
|
|
|
self.currentSection = None |
|
|
|
|
|
|
|
|
if filename: |
|
|
if filename: |
|
|
try: |
|
|
try: |
|
@ -113,6 +116,14 @@ class MainWindow(QMainWindow): |
|
|
self.addDockWidget(Qt.RightDockWidgetArea, self.chordsw) |
|
|
self.addDockWidget(Qt.RightDockWidgetArea, self.chordsw) |
|
|
self.addDockWidget(Qt.RightDockWidgetArea, self.sectionsw) |
|
|
self.addDockWidget(Qt.RightDockWidgetArea, self.sectionsw) |
|
|
self.addDockWidget(Qt.RightDockWidgetArea, self.blocksw) |
|
|
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 |
|
|
# link all the UI elements |
|
|
self.window.mdiArea.subWindowActivated.connect(self.switchDocument) |
|
|
self.window.mdiArea.subWindowActivated.connect(self.switchDocument) |
|
@ -145,6 +156,14 @@ class MainWindow(QMainWindow): |
|
|
self.window.actionCopy.setShortcut(QKeySequence.Copy) |
|
|
self.window.actionCopy.setShortcut(QKeySequence.Copy) |
|
|
self.window.actionPaste.setShortcut(QKeySequence.Paste) |
|
|
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.psetup.widget().pageSizeComboBox.currentIndexChanged.connect( |
|
|
self.pageSizeAction) |
|
|
self.pageSizeAction) |
|
|
self.psetup.widget().documentUnitsComboBox.currentIndexChanged.connect( |
|
|
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.addItems(list(unitDict.keys())) |
|
|
self.psetup.widget().documentUnitsComboBox.setCurrentText( |
|
|
self.psetup.widget().documentUnitsComboBox.setCurrentText( |
|
|
list(unitDict.keys())[0]) |
|
|
list(unitDict.keys())[0]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.psetup.widget().fontComboBox.currentFontChanged.connect(self.fontChangeAction) |
|
|
self.psetup.widget().includedFontCheckBox.stateChanged.connect( |
|
|
self.psetup.widget().includedFontCheckBox.stateChanged.connect( |
|
|
self.includedFontAction) |
|
|
self.includedFontAction) |
|
|
|
|
|
|
|
@ -210,13 +230,17 @@ class MainWindow(QMainWindow): |
|
|
|
|
|
|
|
|
self.chordsw.widget().chordTableView.populate(doc.chordList) |
|
|
self.chordsw.widget().chordTableView.populate(doc.chordList) |
|
|
self.sectionsw.widget().sectionTableView.populate(doc.sectionList) |
|
|
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 |
|
|
# 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.blocksw.widget().blockTableView.populate( |
|
|
self.currentSection.blockList if self.currentSection else []) |
|
|
self.currentSection.blockList if self.currentSection else []) |
|
|
self.updateChordDict(doc) |
|
|
|
|
|
self.updateSectionDict(doc) |
|
|
|
|
|
|
|
|
|
|
|
def UIInitStyle(self, style): |
|
|
def UIInitStyle(self, style): |
|
|
""" |
|
|
""" |
|
@ -235,8 +259,7 @@ class MainWindow(QMainWindow): |
|
|
self.psetup.widget().topMarginLineEdit.setText(str(style.topMargin)) |
|
|
self.psetup.widget().topMarginLineEdit.setText(str(style.topMargin)) |
|
|
self.psetup.widget().bottomMarginLineEdit.setText(str(style.bottomMargin)) |
|
|
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().includedFontCheckBox.setChecked(True) |
|
|
|
|
|
|
|
|
self.psetup.widget().beatWidthLineEdit.setText(str(style.unitWidth)) |
|
|
self.psetup.widget().beatWidthLineEdit.setText(str(style.unitWidth)) |
|
@ -258,11 +281,28 @@ class MainWindow(QMainWindow): |
|
|
self.blocksw.widget().blockSectionComboBox.clear() |
|
|
self.blocksw.widget().blockSectionComboBox.clear() |
|
|
self.blocksw.widget().blockSectionComboBox.addItems( |
|
|
self.blocksw.widget().blockSectionComboBox.addItems( |
|
|
list(self.sectionDict.keys())) |
|
|
list(self.sectionDict.keys())) |
|
|
|
|
|
|
|
|
def switchDocument(self): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fontChangeAction(self): |
|
|
if self.window.mdiArea.currentSubWindow() is not None: |
|
|
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): |
|
|
def generateAction(self): |
|
|
if self.window.mdiArea.currentSubWindow() is not None: |
|
|
if self.window.mdiArea.currentSubWindow() is not None: |
|
@ -287,7 +327,7 @@ class MainWindow(QMainWindow): |
|
|
b.chord = None |
|
|
b.chord = None |
|
|
self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) |
|
|
self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) |
|
|
self.clearChordLineEdits() |
|
|
self.clearChordLineEdits() |
|
|
self.window.mdiArea.currentSubWindow().updateChordDict() |
|
|
|
|
|
|
|
|
self.updateChordDict(self.window.mdiArea.currentSubWindow().doc) |
|
|
|
|
|
|
|
|
def addChordAction(self): |
|
|
def addChordAction(self): |
|
|
success = False # initialise |
|
|
success = False # initialise |
|
@ -319,7 +359,7 @@ class MainWindow(QMainWindow): |
|
|
if success == True: # if chord was parsed properly |
|
|
if success == True: # if chord was parsed properly |
|
|
self.chordsw.widget().chordTableView.populate(self.window.mdiArea.currentSubWindow().doc.chordList) |
|
|
self.chordsw.widget().chordTableView.populate(self.window.mdiArea.currentSubWindow().doc.chordList) |
|
|
self.clearChordLineEdits() |
|
|
self.clearChordLineEdits() |
|
|
self.window.mdiArea.currentSubWindow().updateChordDict() |
|
|
|
|
|
|
|
|
self.updateChordDict(self.window.mdiArea.currentSubWindow().doc) |
|
|
|
|
|
|
|
|
def updateChordAction(self): |
|
|
def updateChordAction(self): |
|
|
success = False # see comments above |
|
|
success = False # see comments above |
|
@ -351,7 +391,7 @@ class MainWindow(QMainWindow): |
|
|
ChordNameWarningMessageBox().exec() |
|
|
ChordNameWarningMessageBox().exec() |
|
|
|
|
|
|
|
|
if success == True: |
|
|
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) |
|
|
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 |
|
|
# update the names of chords in all blocklists in case they've already been used |
|
|
for s in self.window.mdiArea.currentSubWindow().doc.sectionList: |
|
|
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.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) |
|
|
self.clearSectionLineEdits() |
|
|
self.clearSectionLineEdits() |
|
|
self.window.mdiArea.currentSubWindow().updateSectionDict() |
|
|
|
|
|
|
|
|
self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) |
|
|
|
|
|
|
|
|
def addSectionAction(self): |
|
|
def addSectionAction(self): |
|
|
self.window.mdiArea.currentSubWindow().updateSections() |
|
|
self.window.mdiArea.currentSubWindow().updateSections() |
|
@ -382,7 +422,7 @@ class MainWindow(QMainWindow): |
|
|
self.window.mdiArea.currentSubWindow().doc.sectionList.append(Section(name=sName)) |
|
|
self.window.mdiArea.currentSubWindow().doc.sectionList.append(Section(name=sName)) |
|
|
self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) |
|
|
self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) |
|
|
self.clearSectionLineEdits() |
|
|
self.clearSectionLineEdits() |
|
|
self.window.mdiArea.currentSubWindow().updateSectionDict() |
|
|
|
|
|
|
|
|
self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) |
|
|
else: |
|
|
else: |
|
|
# Section has no name or non unique, warn user |
|
|
# Section has no name or non unique, warn user |
|
|
SectionNameWarningMessageBox().exec() |
|
|
SectionNameWarningMessageBox().exec() |
|
@ -397,7 +437,7 @@ class MainWindow(QMainWindow): |
|
|
self.window.mdiArea.currentSubWindow().doc.sectionList[row].name = sName |
|
|
self.window.mdiArea.currentSubWindow().doc.sectionList[row].name = sName |
|
|
self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) |
|
|
self.sectionsw.widget().sectionTableView.populate(self.window.mdiArea.currentSubWindow().doc.sectionList) |
|
|
self.clearSectionLineEdits() |
|
|
self.clearSectionLineEdits() |
|
|
self.window.mdiArea.currentSubWindow().updateSectionDict() |
|
|
|
|
|
|
|
|
self.updateSectionDict(self.window.mdiArea.currentSubWindow().doc) |
|
|
else: |
|
|
else: |
|
|
# Section has no name or non unique, warn user |
|
|
# Section has no name or non unique, warn user |
|
|
SectionNameWarningMessageBox().exec() |
|
|
SectionNameWarningMessageBox().exec() |
|
@ -495,10 +535,11 @@ class MainWindow(QMainWindow): |
|
|
if sName: |
|
|
if sName: |
|
|
if self.window.mdiArea.currentSubWindow() is not None: |
|
|
if self.window.mdiArea.currentSubWindow() is not None: |
|
|
self.currentSection = self.sectionDict.get(sName, None) |
|
|
self.currentSection = self.sectionDict.get(sName, None) |
|
|
|
|
|
# self.window.mdiArea.currentSubWindow().currentSection = self.currentSection |
|
|
if self.currentSection is not None: |
|
|
if self.currentSection is not None: |
|
|
self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) |
|
|
self.blocksw.widget().blockTableView.populate(self.currentSection.blockList) |
|
|
else: |
|
|
else: |
|
|
self.currentSection = None |
|
|
|
|
|
|
|
|
pass # self.currentSection = None |
|
|
|
|
|
|
|
|
def blockClickedAction(self, index): |
|
|
def blockClickedAction(self, index): |
|
|
# set the controls to the values from the selected block |
|
|
# set the controls to the values from the selected block |
|
@ -537,7 +578,7 @@ class MainWindow(QMainWindow): |
|
|
self.window.mdiArea.addSubWindow(dw) |
|
|
self.window.mdiArea.addSubWindow(dw) |
|
|
self.UIInitDocument(dw.doc) |
|
|
self.UIInitDocument(dw.doc) |
|
|
self.UIInitStyle(dw.style) |
|
|
self.UIInitStyle(dw.style) |
|
|
self.currentSection = None |
|
|
|
|
|
|
|
|
# self.currentSection = None |
|
|
|
|
|
|
|
|
dw.show() |
|
|
dw.show() |
|
|
|
|
|
|
|
@ -618,6 +659,54 @@ class MainWindow(QMainWindow): |
|
|
except Exception: |
|
|
except Exception: |
|
|
pass |
|
|
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): |
|
|
def guitarVoicingAction(self): |
|
|
gdialog = GuitarDialog() |
|
|
gdialog = GuitarDialog() |
|
|
|
|
|
|
|
@ -666,9 +755,10 @@ class DocumentWindow(QMdiSubWindow): |
|
|
self.lastDoc = copy(self.doc) |
|
|
self.lastDoc = copy(self.doc) |
|
|
self.currentFilePath = filename |
|
|
self.currentFilePath = filename |
|
|
|
|
|
|
|
|
|
|
|
self.currentSection = None |
|
|
|
|
|
|
|
|
mw.updateChordDict(self.doc) |
|
|
mw.updateChordDict(self.doc) |
|
|
mw.updateSectionDict(self.doc) |
|
|
mw.updateSectionDict(self.doc) |
|
|
self.currentSection = None |
|
|
|
|
|
|
|
|
|
|
|
def UIFileLoader(self, ui_file): |
|
|
def UIFileLoader(self, ui_file): |
|
|
ui_file = QFile(ui_file) |
|
|
ui_file = QFile(ui_file) |
|
@ -696,13 +786,17 @@ class DocumentWindow(QMdiSubWindow): |
|
|
else: # if fileExt in [".xml", ".cml"]: |
|
|
else: # if fileExt in [".xml", ".cml"]: |
|
|
self.doc.loadXML(self.currentFilePath) |
|
|
self.doc.loadXML(self.currentFilePath) |
|
|
|
|
|
|
|
|
|
|
|
self.updatePreview() |
|
|
|
|
|
|
|
|
self.lastDoc = copy(self.doc) |
|
|
self.lastDoc = copy(self.doc) |
|
|
mw.setPath("workingPath", self.currentFilePath) |
|
|
mw.setPath("workingPath", self.currentFilePath) |
|
|
|
|
|
|
|
|
mw.updateChordDict(self.doc) |
|
|
mw.updateChordDict(self.doc) |
|
|
mw.updateSectionDict(self.doc) |
|
|
mw.updateSectionDict(self.doc) |
|
|
|
|
|
|
|
|
|
|
|
self.currentSection = (self.doc.sectionList[0] if self.doc.sectionList else None) |
|
|
|
|
|
|
|
|
self.updateTitleBar() |
|
|
self.updateTitleBar() |
|
|
self.updatePreview() |
|
|
|
|
|
|
|
|
|
|
|
def saveFile(self, filePath): |
|
|
def saveFile(self, filePath): |
|
|
""" |
|
|
""" |
|
|