chiark / gitweb /
Merge tag '15.01-RC4' into upstream
[cura.git] / Cura / gui / simpleMode.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import wx
4 import ConfigParser as configparser
5 import os.path
6
7 from Cura.util import profile
8 import cPickle as pickle
9 from Cura.util import resources
10
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
16
17                 self._print_profile_options = []
18                 self._print_material_options = []
19
20                 printTypePanel = wx.Panel(self)
21                 for filename in resources.getSimpleModeProfiles():
22                         cp = configparser.ConfigParser()
23                         cp.read(filename)
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)
30
31                 printMaterialPanel = wx.Panel(self)
32                 for filename in resources.getSimpleModeMaterials():
33                         cp = configparser.ConfigParser()
34                         cp.read(filename)
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)
43
44                 self.printSupport = wx.CheckBox(self, -1, _("Print support structure"))
45                 self.printBrim = wx.CheckBox(self, -1, _("Print Brim"))
46
47                 sizer = wx.GridBagSizer()
48                 self.SetSizer(sizer)
49
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:
53                         boxsizer.Add(button)
54                 printTypePanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
55                 printTypePanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
56                 sizer.Add(printTypePanel, (0,0), flag=wx.EXPAND)
57
58                 sb = wx.StaticBox(printMaterialPanel, label=_("Material:"))
59                 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
60                 for button in self._print_material_options:
61                         boxsizer.Add(button)
62                 printMaterialPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
63                 printMaterialPanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
64                 sizer.Add(printMaterialPanel, (1,0), flag=wx.EXPAND)
65
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)
71
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())
76
77                 self.printSupport.Bind(wx.EVT_CHECKBOX, lambda e: self._callback())
78                 self.printBrim.Bind(wx.EVT_CHECKBOX, lambda e: self._callback())
79
80                 self.loadSettings()
81
82         def getSavedSettings(self):
83                 try:
84                         return pickle.loads(str(profile.getProfileSetting('simpleModeSettings')))
85                 except:
86                         return {}
87
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])
93
94         def saveSettings(self):
95                 settings = {}
96                 settingItems = ['printTypeHigh', 'printTypeNormal', 'printTypeLow', 'printTypeJoris',
97                                                 'printMaterialHIPS', 'printMaterialABS', 'printMaterialPLA',
98                                                 'printSupport', 'printBrim']
99
100                 for item in settingItems:
101                         if hasattr(self, item):
102                                 settings[item] = getattr(self, item).GetValue()
103
104                 profile.putProfileSetting('simpleModeSettings', pickle.dumps(settings))
105
106         def getSettingOverrides(self):
107                 settings = {}
108                 for setting in profile.settingsList:
109                         if not setting.isProfile():
110                                 continue
111                         settings[setting.getName()] = setting.getDefault()
112
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())
130
131
132                 if self.printSupport.GetValue():
133                         settings['support'] = "Exterior Only"
134                 return settings
135
136         def updateProfileToControls(self):
137                 pass