chiark / gitweb /
Make the profile per machine. this code is becoming a mess...
authordaid <daid303@gmail.com>
Thu, 13 Feb 2014 08:40:53 +0000 (09:40 +0100)
committerdaid <daid303@gmail.com>
Thu, 13 Feb 2014 08:40:53 +0000 (09:40 +0100)
Cura/cura.py
Cura/gui/mainWindow.py
Cura/util/profile.py

index 36e487b224fa8b0ffa13afe2269a1a2fa386f064..e43c91239af2a8ebfd6f9f77670d97a6139ee3b6 100644 (file)
@@ -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
index 9a21dd7bb8209313ebc665a7b461b41dcb01ac90..97e9c6e315152f34046832c4d08b2b2cc2aaa128 100644 (file)
@@ -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())
index ba2e4c1fb35cbdcd8ec3aab1ee05967e8a85d217..db5381499e341b6a774c91af2434e24eb8053f1f 100644 (file)
@@ -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)