1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
4 import ConfigParser as configparser
7 from Cura.util import profile
8 import cPickle as pickle
9 from Cura.util import resources
11 class simpleModePanel(wx.Panel):
12 "Main user interface window for Quickprint mode"
13 def __init__(self, parent, callback):
14 super(simpleModePanel, self).__init__(parent)
15 self._callback = callback
17 self._print_profile_options = []
18 self._print_material_options = []
20 printTypePanel = wx.Panel(self)
21 for filename in resources.getSimpleModeProfiles():
22 cp = configparser.ConfigParser()
24 name = os.path.basename(filename)
25 if cp.has_option('info', 'name'):
26 name = cp.get('info', 'name')
27 button = wx.RadioButton(printTypePanel, -1, name, style=wx.RB_GROUP if len(self._print_profile_options) == 0 else 0)
28 button.filename = filename
29 self._print_profile_options.append(button)
31 printMaterialPanel = wx.Panel(self)
32 for filename in resources.getSimpleModeMaterials():
33 cp = configparser.ConfigParser()
35 name = os.path.basename(filename)
36 if cp.has_option('info', 'name'):
37 name = cp.get('info', 'name')
38 button = wx.RadioButton(printMaterialPanel, -1, name, style=wx.RB_GROUP if len(self._print_material_options) == 0 else 0)
39 button.filename = filename
40 self._print_material_options.append(button)
41 if profile.getMachineSetting('gcode_flavor') == 'UltiGCode':
42 printMaterialPanel.Show(False)
44 self.printSupport = wx.CheckBox(self, -1, _("Print support structure"))
45 self.printBrim = wx.CheckBox(self, -1, _("Print Brim"))
47 sizer = wx.GridBagSizer()
50 sb = wx.StaticBox(printTypePanel, label=_("Select a quickprint profile:"))
51 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
52 for button in self._print_profile_options:
54 printTypePanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
55 printTypePanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
56 sizer.Add(printTypePanel, (0,0), flag=wx.EXPAND)
58 sb = wx.StaticBox(printMaterialPanel, label=_("Material:"))
59 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
60 for button in self._print_material_options:
62 printMaterialPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
63 printMaterialPanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
64 sizer.Add(printMaterialPanel, (1,0), flag=wx.EXPAND)
66 sb = wx.StaticBox(self, label=_("Other:"))
67 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
68 boxsizer.Add(self.printSupport)
69 boxsizer.Add(self.printBrim)
70 sizer.Add(boxsizer, (2,0), flag=wx.EXPAND)
72 for button in self._print_profile_options:
73 button.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
74 for button in self._print_material_options:
75 button.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
77 self.printSupport.Bind(wx.EVT_CHECKBOX, lambda e: self._callback())
78 self.printBrim.Bind(wx.EVT_CHECKBOX, lambda e: self._callback())
82 def getSavedSettings(self):
84 return pickle.loads(str(profile.getProfileSetting('simpleModeSettings')))
88 def loadSettings(self):
89 settings = self.getSavedSettings()
90 for item in settings.keys():
91 if hasattr(self, item):
92 getattr(self, item).SetValue(settings[item])
94 def saveSettings(self):
96 settingItems = ['printTypeHigh', 'printTypeNormal', 'printTypeLow', 'printTypeJoris',
97 'printMaterialHIPS', 'printMaterialABS', 'printMaterialPLA',
98 'printSupport', 'printBrim']
100 for item in settingItems:
101 if hasattr(self, item):
102 settings[item] = getattr(self, item).GetValue()
104 profile.putProfileSetting('simpleModeSettings', pickle.dumps(settings))
106 def getSettingOverrides(self):
108 for setting in profile.settingsList:
109 if not setting.isProfile():
111 settings[setting.getName()] = setting.getDefault()
113 for button in self._print_profile_options:
114 if button.GetValue():
115 cp = configparser.ConfigParser()
116 cp.read(button.filename)
117 for setting in profile.settingsList:
118 if setting.isProfile():
119 if cp.has_option('profile', setting.getName()):
120 settings[setting.getName()] = cp.get('profile', setting.getName())
121 if profile.getMachineSetting('gcode_flavor') != 'UltiGCode':
122 for button in self._print_material_options:
123 if button.GetValue():
124 cp = configparser.ConfigParser()
125 cp.read(button.filename)
126 for setting in profile.settingsList:
127 if setting.isProfile():
128 if cp.has_option('profile', setting.getName()):
129 settings[setting.getName()] = cp.get('profile', setting.getName())
132 if self.printSupport.GetValue():
133 settings['support'] = "Exterior Only"
136 def updateProfileToControls(self):