From 1fa4a67324671b6091b451daec9a4fd2b3291bc9 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sat, 13 Feb 2021 14:49:07 +0100 Subject: [PATCH] Use german note names when German locale is used --- engine/api.py | 2 +- engine/main.py | 16 ++++++++++++++++ qtgui/mainwindow.py | 1 + template/qtgui/mainwindow.py | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/engine/api.py b/engine/api.py index b286027..3e5c0e4 100644 --- a/engine/api.py +++ b/engine/api.py @@ -230,7 +230,7 @@ def updatePlayback(): cbox.Document.get_song().update_playback() def startEngine(nsmClient): - _templateStartEngine(nsmClient) + _templateStartEngine(nsmClient) #loads save files or creates empty structure. session.inLoopMode = None # remember if we are in loop mode or not. Positive value is None or a tuple with start and end diff --git a/engine/main.py b/engine/main.py index 3de7190..0b5cef9 100644 --- a/engine/main.py +++ b/engine/main.py @@ -66,6 +66,7 @@ class Data(template.engine.sequencer.Score): #Create three tracks with their first pattern activated, so 'play' after startup already produces sounding notes. This is less confusing for a new user. #self.tracks is created in the template. + self._emptyFile = True self.addTrack(name="Melody A", color="#ffff00") self.addTrack(name="Chords A", color="#0055ff") self.addTrack(name="Bass A", color="#00ff00") @@ -107,6 +108,19 @@ class Data(template.engine.sequencer.Score): self.sortTracks() self._duringFileLoadGroupIndicator = False + def setLanguageForEmptyFile(self, language): + """Only use in api.startEngine. Overrides the empty. + language is the summarized language string from Qt, like "German" which covers + de_DE, _AT and _CH. If another GUI is used in the future it needs to send these as well.""" + if self._emptyFile: + if language in simpleNoteNames: + logger.info("Setting language for empty / new file to " + language) + self.lastUsedNotenames = simpleNoteNames[language] + self.tracks[0].pattern.simpleNoteNames = simpleNoteNames[language] + self.tracks[1].pattern.simpleNoteNames = simpleNoteNames[language] + self.tracks[2].pattern.simpleNoteNames = simpleNoteNames[language] + #not drums. + def cacheOffsetInTicks(self): oneMeasureInTicks = (self.howManyUnits * self.whatTypeOfUnit) / self.subdivisions oneMeasureInTicks = int(oneMeasureInTicks) @@ -442,6 +456,8 @@ class Data(template.engine.sequencer.Score): else: self.globalOffsetTicks = 0 + self._emptyFile = False + #Tracks depend on the rest of the data already in place because they create a cache on creation. super().copyFromSerializedData(parentSession, serializedData, self) #Tracks, parentSession and tempoMap diff --git a/qtgui/mainwindow.py b/qtgui/mainwindow.py index 7f08220..1a30373 100644 --- a/qtgui/mainwindow.py +++ b/qtgui/mainwindow.py @@ -207,6 +207,7 @@ class MainWindow(TemplateMainWindow): #Toolbar, which needs the widgets above already established self._populateToolbar() + api.session.data.setLanguageForEmptyFile(language = QtCore.QLocale().languageToString(QtCore.QLocale().language())) #TODO: this is a hack because we access the session directly. But this is also a function tied to Qts language string. Two wrongs... self.start() #This shows the GUI, or not, depends on the NSM gui save setting. We need to call that after the menu, otherwise the about dialog will block and then we get new menu entries, which looks strange. #There is always a track. Forcing that to be active is better than having to hide all the pattern widgets, or to disable them. diff --git a/template/qtgui/mainwindow.py b/template/qtgui/mainwindow.py index 9c4149c..4e9ee7a 100644 --- a/template/qtgui/mainwindow.py +++ b/template/qtgui/mainwindow.py @@ -57,6 +57,7 @@ api.session.eventLoop = EventLoop() #Setup the translator before classes are set up. Otherwise we can't use non-template translation. #to test use LANGUAGE=de_DE.UTF-8 . not LANG= +#Language variants like de_AT.UTF-8 will be detected automatically and will result in Qt language detection as "German" language = QtCore.QLocale().languageToString(QtCore.QLocale().language()) logger.info("{}: Language set to {}".format(METADATA["name"], language)) if language in METADATA["supportedLanguages"]: