chiark / gitweb /
Update code for translations, fix a few translation issues and add a few missing...
[cura.git] / Cura / gui / configBase.py
index e2cd0bddd166dd29fa79d96170a94960da81e1f2..3cf6a1d0eaf87abe149a241738330025173f4e21 100644 (file)
@@ -2,7 +2,6 @@ from __future__ import absolute_import
 from __future__ import division
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
-import platform
 import wx, wx.lib.stattext, types
 from wx.lib.agw import floatspin
 
@@ -133,7 +132,7 @@ class configPanelBase(wx.Panel):
                                size[0] = width
                                child.SetBestSize(size)
        
-class TitleRow():
+class TitleRow(object):
        def __init__(self, panel, name):
                "Add a title row to the configuration panel"
                sizer = panel.GetSizer()
@@ -144,8 +143,8 @@ class TitleRow():
                sizer.Add(wx.StaticLine(panel), (x+1,0), (1,3), flag=wx.EXPAND|wx.LEFT,border=10)
                sizer.SetRows(x + 2)
 
-class SettingRow():
-       def __init__(self, panel, configName, valueOverride = None):
+class SettingRow(object):
+       def __init__(self, panel, configName, valueOverride = None, index = None):
                "Add a setting to the configuration panel"
                sizer = panel.GetSizer()
                x = sizer.GetRows()
@@ -153,6 +152,7 @@ class SettingRow():
                flag = 0
 
                self.setting = profile.settingsDictionary[configName]
+               self.settingIndex = index
                self.validationMsg = ''
                self.panel = panel
 
@@ -169,25 +169,29 @@ class SettingRow():
                #       flag = wx.EXPAND
                if self.setting.getType() is types.BooleanType:
                        self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT)
-                       self.SetValue(self.setting.getValue())
+                       self.SetValue(self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange)
                elif valueOverride is not None and valueOverride is wx.Colour:
                        self.ctrl = wx.ColourPickerCtrl(panel, -1)
-                       self.SetValue(self.setting.getValue())
+                       self.SetValue(self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnSettingChange)
                elif type(self.setting.getType()) is list or valueOverride is not None:
-                       value = self.setting.getValue()
+                       value = self.setting.getValue(self.settingIndex)
                        choices = self.setting.getType()
                        if valueOverride is not None:
                                choices = valueOverride
+                       self._englishChoices = choices[:]
                        if value not in choices and len(choices) > 0:
                                value = choices[0]
+                       for n in xrange(0, len(choices)):
+                               choices[n] = _(choices[n])
+                       value = _(value)
                        self.ctrl = wx.ComboBox(panel, -1, value, choices=choices, style=wx.CB_DROPDOWN|wx.CB_READONLY)
                        self.ctrl.Bind(wx.EVT_COMBOBOX, self.OnSettingChange)
                        self.ctrl.Bind(wx.EVT_LEFT_DOWN, self.OnMouseExit)
                        flag = wx.EXPAND
                else:
-                       self.ctrl = wx.TextCtrl(panel, -1, self.setting.getValue())
+                       self.ctrl = wx.TextCtrl(panel, -1, self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
                        flag = wx.EXPAND
 
@@ -214,7 +218,7 @@ class SettingRow():
                e.Skip()
 
        def OnSettingChange(self, e):
-               self.setting.setValue(self.GetValue())
+               self.setting.setValue(self.GetValue(), self.settingIndex)
                self.panel.main._validate()
 
        def _validate(self):
@@ -237,6 +241,12 @@ class SettingRow():
        def GetValue(self):
                if isinstance(self.ctrl, wx.ColourPickerCtrl):
                        return str(self.ctrl.GetColour().GetAsString(wx.C2S_HTML_SYNTAX))
+               elif isinstance(self.ctrl, wx.ComboBox):
+                       value = str(self.ctrl.GetValue())
+                       for ret in self._englishChoices:
+                               if _(ret) == value:
+                                       return ret
+                       return value
                else:
                        return str(self.ctrl.GetValue())
 
@@ -250,18 +260,7 @@ class SettingRow():
                                self.ctrl.SetValue(float(value))
                        except ValueError:
                                pass
+               elif isinstance(self.ctrl, wx.ComboBox):
+                       self.ctrl.SetValue(_(value))
                else:
                        self.ctrl.SetValue(value)
-
-#Settings notify works as a validator, but instead of validating anything, it calls another function, which can use the value.
-# A bit hacky, bit it works.
-class settingNotify():
-       def __init__(self, setting, func):
-               self.setting = setting
-               self.setting.validators.append(self)
-               self.func = func
-       
-       def validate(self):
-               self.func()
-               return validators.SUCCESS, ''
-