From 2b50fba71eab97f7507ce1c1241feec7e30b784b Mon Sep 17 00:00:00 2001 From: daid Date: Thu, 13 Feb 2014 09:40:53 +0100 Subject: [PATCH] Make the profile per machine. this code is becoming a mess... --- Cura/cura.py | 2 +- Cura/gui/mainWindow.py | 2 +- Cura/util/profile.py | 72 ++++++++++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Cura/cura.py b/Cura/cura.py index 36e487b2..e43c9123 100644 --- a/Cura/cura.py +++ b/Cura/cura.py @@ -42,7 +42,7 @@ def main(): elif options.profileini is not None: profile.loadProfile(options.profileini) else: - profile.loadProfile(profile.getDefaultProfilePath()) + profile.loadProfile(profile.getDefaultProfilePath(), True) if options.printfile is not None: from Cura.gui import printWindow diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index 9a21dd7b..97e9c6e3 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -552,7 +552,7 @@ class mainWindow(wx.Frame): aboutBox.Show() def OnClose(self, e): - profile.saveProfile(profile.getDefaultProfilePath()) + profile.saveProfile(profile.getDefaultProfilePath(), True) # Save the window position, size & state from the preferences file profile.putPreference('window_maximized', self.IsMaximized()) diff --git a/Cura/util/profile.py b/Cura/util/profile.py index ba2e4c1f..db538149 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -130,7 +130,7 @@ class setting(object): self._values[index] = unicode(value) def getValueIndex(self): - if self.isMachineSetting(): + if self.isMachineSetting() or self.isProfile(): global _selectedMachineIndex return _selectedMachineIndex return 0 @@ -496,36 +496,62 @@ def getAlternativeBasePaths(): def getDefaultProfilePath(): return os.path.join(getBasePath(), 'current_profile.ini') -def loadProfile(filename): +def loadProfile(filename, allMachines = False): + global settingsList #Read a configuration file as global config profileParser = ConfigParser.ConfigParser() try: profileParser.read(filename) except ConfigParser.ParsingError: return + if allMachines: + n = 0 + while profileParser.has_section('profile_%d' % (n)): + for set in settingsList: + if set.isPreference(): + continue + section = 'profile_%d' % (n) + if set.isAlteration(): + section = 'alterations_%d' % (n) + if profileParser.has_option(section, set.getName()): + set.setValue(unicode(profileParser.get(section, set.getName()), 'utf-8', 'replace'), n) + n += 1 + else: + for set in settingsList: + if set.isPreference(): + continue + section = 'profile' + if set.isAlteration(): + section = 'alterations' + if profileParser.has_option(section, set.getName()): + set.setValue(unicode(profileParser.get(section, set.getName()), 'utf-8', 'replace')) + +def saveProfile(filename, allMachines = False): global settingsList - for set in settingsList: - if set.isPreference(): - continue - section = 'profile' - if set.isAlteration(): - section = 'alterations' - if profileParser.has_option(section, set.getName()): - set.setValue(unicode(profileParser.get(section, set.getName()), 'utf-8', 'replace')) - -def saveProfile(filename): #Save the current profile to an ini file profileParser = ConfigParser.ConfigParser() - profileParser.add_section('profile') - profileParser.add_section('alterations') - global settingsList - for set in settingsList: - if set.isPreference() or set.isMachineSetting(): - continue - if set.isAlteration(): - profileParser.set('alterations', set.getName(), set.getValue().encode('utf-8')) - else: - profileParser.set('profile', set.getName(), set.getValue().encode('utf-8')) + if allMachines: + for set in settingsList: + if set.isPreference() or set.isMachineSetting(): + continue + for n in xrange(0, getMachineCount()): + if set.isAlteration(): + section = 'alterations_%d' % (n) + else: + section = 'profile_%d' % (n) + if not profileParser.has_section(section): + profileParser.add_section(section) + profileParser.set(section, set.getName(), set.getValue(n).encode('utf-8')) + else: + profileParser.add_section('profile') + profileParser.add_section('alterations') + for set in settingsList: + if set.isPreference() or set.isMachineSetting(): + continue + if set.isAlteration(): + profileParser.set('alterations', set.getName(), set.getValue().encode('utf-8')) + else: + profileParser.set('profile', set.getName(), set.getValue().encode('utf-8')) profileParser.write(open(filename, 'w')) @@ -1002,7 +1028,7 @@ def setAlterationFile(name, value): global settingsDictionary if name in settingsDictionary and settingsDictionary[name].isAlteration(): settingsDictionary[name].setValue(value) - saveProfile(getDefaultProfilePath()) + saveProfile(getDefaultProfilePath(), True) def isTagIn(tag, contents): contents = re.sub(';[^\n]*\n', '', contents) -- 2.30.2