chiark / gitweb /
Merge pull request #557 from GreatFruitOmsk/i18n
[cura.git] / Cura / gui / mainWindow.py
1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
3
4 import wx
5 import os
6 import webbrowser
7
8 from Cura.gui import configBase
9 from Cura.gui import expertConfig
10 from Cura.gui import alterationPanel
11 from Cura.gui import pluginPanel
12 from Cura.gui import preferencesDialog
13 from Cura.gui import configWizard
14 from Cura.gui import firmwareInstall
15 from Cura.gui import simpleMode
16 from Cura.gui import sceneView
17 from Cura.gui.util import dropTarget
18 #from Cura.gui.tools import batchRun
19 from Cura.gui.tools import pidDebugger
20 from Cura.gui.tools import minecraftImport
21 from Cura.util import profile
22 from Cura.util import version
23 from Cura.util import meshLoader
24 from Cura.util import resources
25
26 class mainWindow(wx.Frame):
27         def __init__(self):
28                 super(mainWindow, self).__init__(None, title='Cura - ' + version.getVersion())
29
30                 self.extruderCount = int(profile.getPreference('extruder_amount'))
31
32                 wx.EVT_CLOSE(self, self.OnClose)
33
34                 self.SetDropTarget(dropTarget.FileDropTarget(self.OnDropFiles, meshLoader.loadSupportedExtensions()))
35
36                 self.normalModeOnlyItems = []
37
38                 mruFile = os.path.join(profile.getBasePath(), 'mru_filelist.ini')
39                 self.config = wx.FileConfig(appName="Cura",
40                                                 localFilename=mruFile,
41                                                 style=wx.CONFIG_USE_LOCAL_FILE)
42
43                 self.ID_MRU_MODEL1, self.ID_MRU_MODEL2, self.ID_MRU_MODEL3, self.ID_MRU_MODEL4, self.ID_MRU_MODEL5, self.ID_MRU_MODEL6, self.ID_MRU_MODEL7, self.ID_MRU_MODEL8, self.ID_MRU_MODEL9, self.ID_MRU_MODEL10 = [wx.NewId() for line in xrange(10)]
44                 self.modelFileHistory = wx.FileHistory(10, self.ID_MRU_MODEL1)
45                 self.config.SetPath("/ModelMRU")
46                 self.modelFileHistory.Load(self.config)
47
48                 self.ID_MRU_PROFILE1, self.ID_MRU_PROFILE2, self.ID_MRU_PROFILE3, self.ID_MRU_PROFILE4, self.ID_MRU_PROFILE5, self.ID_MRU_PROFILE6, self.ID_MRU_PROFILE7, self.ID_MRU_PROFILE8, self.ID_MRU_PROFILE9, self.ID_MRU_PROFILE10 = [wx.NewId() for line in xrange(10)]
49                 self.profileFileHistory = wx.FileHistory(10, self.ID_MRU_PROFILE1)
50                 self.config.SetPath("/ProfileMRU")
51                 self.profileFileHistory.Load(self.config)
52
53                 self.menubar = wx.MenuBar()
54                 self.fileMenu = wx.Menu()
55                 i = self.fileMenu.Append(-1, _("Load model file...\tCTRL+L"))
56                 self.Bind(wx.EVT_MENU, lambda e: self.scene.showLoadModel(), i)
57                 i = self.fileMenu.Append(-1, _("Save model...\tCTRL+S"))
58                 self.Bind(wx.EVT_MENU, lambda e: self.scene.showSaveModel(), i)
59                 i = self.fileMenu.Append(-1, _("Clear platform"))
60                 self.Bind(wx.EVT_MENU, lambda e: self.scene.OnDeleteAll(e), i)
61
62                 self.fileMenu.AppendSeparator()
63                 i = self.fileMenu.Append(-1, _("Print...\tCTRL+P"))
64                 self.Bind(wx.EVT_MENU, lambda e: self.scene.showPrintWindow(), i)
65                 i = self.fileMenu.Append(-1, _("Save GCode..."))
66                 self.Bind(wx.EVT_MENU, lambda e: self.scene.showSaveGCode(), i)
67                 i = self.fileMenu.Append(-1, _("Show slice engine log..."))
68                 self.Bind(wx.EVT_MENU, lambda e: self.scene._showSliceLog(), i)
69
70                 self.fileMenu.AppendSeparator()
71                 i = self.fileMenu.Append(-1, _("Open Profile..."))
72                 self.normalModeOnlyItems.append(i)
73                 self.Bind(wx.EVT_MENU, self.OnLoadProfile, i)
74                 i = self.fileMenu.Append(-1, _("Save Profile..."))
75                 self.normalModeOnlyItems.append(i)
76                 self.Bind(wx.EVT_MENU, self.OnSaveProfile, i)
77                 i = self.fileMenu.Append(-1, _("Load Profile from GCode..."))
78                 self.normalModeOnlyItems.append(i)
79                 self.Bind(wx.EVT_MENU, self.OnLoadProfileFromGcode, i)
80                 self.fileMenu.AppendSeparator()
81                 i = self.fileMenu.Append(-1, _("Reset Profile to default"))
82                 self.normalModeOnlyItems.append(i)
83                 self.Bind(wx.EVT_MENU, self.OnResetProfile, i)
84
85                 self.fileMenu.AppendSeparator()
86                 i = self.fileMenu.Append(-1, _("Preferences...\tCTRL+,"))
87                 self.Bind(wx.EVT_MENU, self.OnPreferences, i)
88                 self.fileMenu.AppendSeparator()
89
90                 # Model MRU list
91                 modelHistoryMenu = wx.Menu()
92                 self.fileMenu.AppendMenu(wx.NewId(), _("&Recent Model Files"), modelHistoryMenu)
93                 self.modelFileHistory.UseMenu(modelHistoryMenu)
94                 self.modelFileHistory.AddFilesToMenu()
95                 self.Bind(wx.EVT_MENU_RANGE, self.OnModelMRU, id=self.ID_MRU_MODEL1, id2=self.ID_MRU_MODEL10)
96
97                 # Profle MRU list
98                 profileHistoryMenu = wx.Menu()
99                 self.fileMenu.AppendMenu(wx.NewId(), _("&Recent Profile Files"), profileHistoryMenu)
100                 self.profileFileHistory.UseMenu(profileHistoryMenu)
101                 self.profileFileHistory.AddFilesToMenu()
102                 self.Bind(wx.EVT_MENU_RANGE, self.OnProfileMRU, id=self.ID_MRU_PROFILE1, id2=self.ID_MRU_PROFILE10)
103
104                 self.fileMenu.AppendSeparator()
105                 i = self.fileMenu.Append(wx.ID_EXIT, _("Quit"))
106                 self.Bind(wx.EVT_MENU, self.OnQuit, i)
107                 self.menubar.Append(self.fileMenu, _("&File"))
108
109                 toolsMenu = wx.Menu()
110                 i = toolsMenu.Append(-1, _("Switch to quickprint..."))
111                 self.switchToQuickprintMenuItem = i
112                 self.Bind(wx.EVT_MENU, self.OnSimpleSwitch, i)
113                 i = toolsMenu.Append(-1, _("Switch to full settings..."))
114                 self.switchToNormalMenuItem = i
115                 self.Bind(wx.EVT_MENU, self.OnNormalSwitch, i)
116                 toolsMenu.AppendSeparator()
117                 #i = toolsMenu.Append(-1, 'Batch run...')
118                 #self.Bind(wx.EVT_MENU, self.OnBatchRun, i)
119                 #self.normalModeOnlyItems.append(i)
120                 if minecraftImport.hasMinecraft():
121                         i = toolsMenu.Append(-1, _("Minecraft import..."))
122                         self.Bind(wx.EVT_MENU, self.OnMinecraftImport, i)
123                 if version.isDevVersion():
124                         i = toolsMenu.Append(-1, _("PID Debugger..."))
125                         self.Bind(wx.EVT_MENU, self.OnPIDDebugger, i)
126                 self.menubar.Append(toolsMenu, _("Tools"))
127
128                 expertMenu = wx.Menu()
129                 i = expertMenu.Append(-1, _("Open expert settings..."))
130                 self.normalModeOnlyItems.append(i)
131                 self.Bind(wx.EVT_MENU, self.OnExpertOpen, i)
132                 expertMenu.AppendSeparator()
133                 if firmwareInstall.getDefaultFirmware() is not None:
134                         i = expertMenu.Append(-1, _("Install default Marlin firmware"))
135                         self.Bind(wx.EVT_MENU, self.OnDefaultMarlinFirmware, i)
136                 i = expertMenu.Append(-1, _("Install custom firmware"))
137                 self.Bind(wx.EVT_MENU, self.OnCustomFirmware, i)
138                 expertMenu.AppendSeparator()
139                 i = expertMenu.Append(-1, _("Run first run wizard..."))
140                 self.Bind(wx.EVT_MENU, self.OnFirstRunWizard, i)
141                 i = expertMenu.Append(-1, _("Run bed leveling wizard..."))
142                 self.Bind(wx.EVT_MENU, self.OnBedLevelWizard, i)
143                 if self.extruderCount > 1:
144                         i = expertMenu.Append(-1, _("Run head offset wizard..."))
145                         self.Bind(wx.EVT_MENU, self.OnHeadOffsetWizard, i)
146                 self.menubar.Append(expertMenu, _("Expert"))
147
148                 helpMenu = wx.Menu()
149                 i = helpMenu.Append(-1, _("Online documentation..."))
150                 self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('http://daid.github.com/Cura'), i)
151                 i = helpMenu.Append(-1, _("Report a problem..."))
152                 self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://github.com/daid/Cura/issues'), i)
153                 i = helpMenu.Append(-1, _("Check for update..."))
154                 self.Bind(wx.EVT_MENU, self.OnCheckForUpdate, i)
155                 i = helpMenu.Append(-1, _("Open YouMagine website..."))
156                 self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://www.youmagine.com/'), i)
157                 i = helpMenu.Append(-1, _("About Cura..."))
158                 self.Bind(wx.EVT_MENU, self.OnAbout, i)
159                 self.menubar.Append(helpMenu, _("Help"))
160                 self.SetMenuBar(self.menubar)
161
162                 self.splitter = wx.SplitterWindow(self, style = wx.SP_3D | wx.SP_LIVE_UPDATE)
163                 self.leftPane = wx.Panel(self.splitter, style=wx.BORDER_NONE)
164                 self.rightPane = wx.Panel(self.splitter, style=wx.BORDER_NONE)
165                 self.splitter.Bind(wx.EVT_SPLITTER_DCLICK, lambda evt: evt.Veto())
166
167                 ##Gui components##
168                 self.simpleSettingsPanel = simpleMode.simpleModePanel(self.leftPane, lambda : self.scene.sceneUpdated())
169                 self.normalSettingsPanel = normalSettingsPanel(self.leftPane, lambda : self.scene.sceneUpdated())
170
171                 self.leftSizer = wx.BoxSizer(wx.VERTICAL)
172                 self.leftSizer.Add(self.simpleSettingsPanel, 1)
173                 self.leftSizer.Add(self.normalSettingsPanel, 1, wx.EXPAND)
174                 self.leftPane.SetSizer(self.leftSizer)
175
176                 #Preview window
177                 self.scene = sceneView.SceneView(self.rightPane)
178
179                 #Main sizer, to position the preview window, buttons and tab control
180                 sizer = wx.BoxSizer()
181                 self.rightPane.SetSizer(sizer)
182                 sizer.Add(self.scene, 1, flag=wx.EXPAND)
183
184                 # Main window sizer
185                 sizer = wx.BoxSizer(wx.VERTICAL)
186                 self.SetSizer(sizer)
187                 sizer.Add(self.splitter, 1, wx.EXPAND)
188                 sizer.Layout()
189                 self.sizer = sizer
190
191                 self.updateProfileToControls()
192
193                 self.SetBackgroundColour(self.normalSettingsPanel.GetBackgroundColour())
194
195                 self.simpleSettingsPanel.Show(False)
196                 self.normalSettingsPanel.Show(False)
197
198                 # Set default window size & position
199                 self.SetSize((wx.Display().GetClientArea().GetWidth()/2,wx.Display().GetClientArea().GetHeight()/2))
200                 self.Centre()
201
202                 # Restore the window position, size & state from the preferences file
203                 try:
204                         if profile.getPreference('window_maximized') == 'True':
205                                 self.Maximize(True)
206                         else:
207                                 posx = int(profile.getPreference('window_pos_x'))
208                                 posy = int(profile.getPreference('window_pos_y'))
209                                 width = int(profile.getPreference('window_width'))
210                                 height = int(profile.getPreference('window_height'))
211                                 if posx > 0 or posy > 0:
212                                         self.SetPosition((posx,posy))
213                                 if width > 0 and height > 0:
214                                         self.SetSize((width,height))
215
216                         self.normalSashPos = int(profile.getPreference('window_normal_sash'))
217                 except:
218                         self.normalSashPos = 0
219                         self.Maximize(True)
220                 if self.normalSashPos < self.normalSettingsPanel.printPanel.GetBestSize()[0] + 5:
221                         self.normalSashPos = self.normalSettingsPanel.printPanel.GetBestSize()[0] + 5
222
223                 self.splitter.SplitVertically(self.leftPane, self.rightPane, self.normalSashPos)
224
225                 if wx.Display.GetFromPoint(self.GetPosition()) < 0:
226                         self.Centre()
227                 if wx.Display.GetFromPoint((self.GetPositionTuple()[0] + self.GetSizeTuple()[1], self.GetPositionTuple()[1] + self.GetSizeTuple()[1])) < 0:
228                         self.Centre()
229                 if wx.Display.GetFromPoint(self.GetPosition()) < 0:
230                         self.SetSize((800,600))
231                         self.Centre()
232
233                 self.updateSliceMode()
234
235         def updateSliceMode(self):
236                 isSimple = profile.getPreference('startMode') == 'Simple'
237
238                 self.normalSettingsPanel.Show(not isSimple)
239                 self.simpleSettingsPanel.Show(isSimple)
240                 self.leftPane.Layout()
241
242                 for i in self.normalModeOnlyItems:
243                         i.Enable(not isSimple)
244                 self.switchToQuickprintMenuItem.Enable(not isSimple)
245                 self.switchToNormalMenuItem.Enable(isSimple)
246
247                 # Set splitter sash position & size
248                 if isSimple:
249                         # Save normal mode sash
250                         self.normalSashPos = self.splitter.GetSashPosition()
251
252                         # Change location of sash to width of quick mode pane 
253                         (width, height) = self.simpleSettingsPanel.GetSizer().GetSize()
254                         self.splitter.SetSashPosition(width, True)
255
256                         # Disable sash
257                         self.splitter.SetSashSize(0)
258                 else:
259                         self.splitter.SetSashPosition(self.normalSashPos, True)
260                         # Enabled sash
261                         self.splitter.SetSashSize(4)
262                 self.scene.updateProfileToControls()
263
264         def OnPreferences(self, e):
265                 prefDialog = preferencesDialog.preferencesDialog(self)
266                 prefDialog.Centre()
267                 prefDialog.Show()
268
269         def OnDropFiles(self, files):
270                 if len(files) > 0:
271                         profile.setPluginConfig([])
272                         self.updateProfileToControls()
273                 self.scene.loadScene(files)
274
275         def OnModelMRU(self, e):
276                 fileNum = e.GetId() - self.ID_MRU_MODEL1
277                 path = self.modelFileHistory.GetHistoryFile(fileNum)
278                 # Update Model MRU
279                 self.modelFileHistory.AddFileToHistory(path)  # move up the list
280                 self.config.SetPath("/ModelMRU")
281                 self.modelFileHistory.Save(self.config)
282                 self.config.Flush()
283                 # Load Model
284                 profile.putPreference('lastFile', path)
285                 filelist = [ path ]
286                 self.scene.loadScene(filelist)
287
288         def addToModelMRU(self, file):
289                 self.modelFileHistory.AddFileToHistory(file)
290                 self.config.SetPath("/ModelMRU")
291                 self.modelFileHistory.Save(self.config)
292                 self.config.Flush()
293
294         def OnProfileMRU(self, e):
295                 fileNum = e.GetId() - self.ID_MRU_PROFILE1
296                 path = self.profileFileHistory.GetHistoryFile(fileNum)
297                 # Update Profile MRU
298                 self.profileFileHistory.AddFileToHistory(path)  # move up the list
299                 self.config.SetPath("/ProfileMRU")
300                 self.profileFileHistory.Save(self.config)
301                 self.config.Flush()
302                 # Load Profile  
303                 profile.loadProfile(path)
304                 self.updateProfileToControls()
305
306         def addToProfileMRU(self, file):
307                 self.profileFileHistory.AddFileToHistory(file)
308                 self.config.SetPath("/ProfileMRU")
309                 self.profileFileHistory.Save(self.config)
310                 self.config.Flush()                     
311
312         def updateProfileToControls(self):
313                 self.scene.updateProfileToControls()
314                 self.normalSettingsPanel.updateProfileToControls()
315                 self.simpleSettingsPanel.updateProfileToControls()
316
317         def OnLoadProfile(self, e):
318                 dlg=wx.FileDialog(self, _("Select profile file to load"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
319                 dlg.SetWildcard("ini files (*.ini)|*.ini")
320                 if dlg.ShowModal() == wx.ID_OK:
321                         profileFile = dlg.GetPath()
322                         profile.loadProfile(profileFile)
323                         self.updateProfileToControls()
324
325                         # Update the Profile MRU
326                         self.addToProfileMRU(profileFile)
327                 dlg.Destroy()
328
329         def OnLoadProfileFromGcode(self, e):
330                 dlg=wx.FileDialog(self, _("Select gcode file to load profile from"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
331                 dlg.SetWildcard("gcode files (*.gcode)|*.gcode;*.g")
332                 if dlg.ShowModal() == wx.ID_OK:
333                         gcodeFile = dlg.GetPath()
334                         f = open(gcodeFile, 'r')
335                         hasProfile = False
336                         for line in f:
337                                 if line.startswith(';CURA_PROFILE_STRING:'):
338                                         profile.loadProfileFromString(line[line.find(':')+1:].strip())
339                                         hasProfile = True
340                         if hasProfile:
341                                 self.updateProfileToControls()
342                         else:
343                                 wx.MessageBox(_("No profile found in GCode file.\nThis feature only works with GCode files made by Cura 12.07 or newer."), _("Profile load error"), wx.OK | wx.ICON_INFORMATION)
344                 dlg.Destroy()
345
346         def OnSaveProfile(self, e):
347                 dlg=wx.FileDialog(self, _("Select profile file to save"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
348                 dlg.SetWildcard("ini files (*.ini)|*.ini")
349                 if dlg.ShowModal() == wx.ID_OK:
350                         profileFile = dlg.GetPath()
351                         profile.saveProfile(profileFile)
352                 dlg.Destroy()
353
354         def OnResetProfile(self, e):
355                 dlg = wx.MessageDialog(self, _("This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?"), _("Profile reset"), wx.YES_NO | wx.ICON_QUESTION)
356                 result = dlg.ShowModal() == wx.ID_YES
357                 dlg.Destroy()
358                 if result:
359                         profile.resetProfile()
360                         self.updateProfileToControls()
361
362         def OnSimpleSwitch(self, e):
363                 profile.putPreference('startMode', 'Simple')
364                 self.updateSliceMode()
365
366         def OnNormalSwitch(self, e):
367                 profile.putPreference('startMode', 'Normal')
368                 self.updateSliceMode()
369
370         def OnDefaultMarlinFirmware(self, e):
371                 firmwareInstall.InstallFirmware()
372
373         def OnCustomFirmware(self, e):
374                 if profile.getPreference('machine_type').startswith('ultimaker'):
375                         wx.MessageBox(_("Warning: Installing a custom firmware does not guarantee that you machine will function correctly, and could damage your machine."), _("Firmware update"), wx.OK | wx.ICON_EXCLAMATION)
376                 dlg=wx.FileDialog(self, _("Open firmware to upload"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
377                 dlg.SetWildcard("HEX file (*.hex)|*.hex;*.HEX")
378                 if dlg.ShowModal() == wx.ID_OK:
379                         filename = dlg.GetPath()
380                         if not(os.path.exists(filename)):
381                                 return
382                         #For some reason my Ubuntu 10.10 crashes here.
383                         firmwareInstall.InstallFirmware(filename)
384
385         def OnFirstRunWizard(self, e):
386                 configWizard.configWizard()
387                 self.updateProfileToControls()
388
389         def OnBedLevelWizard(self, e):
390                 configWizard.bedLevelWizard()
391
392         def OnHeadOffsetWizard(self, e):
393                 configWizard.headOffsetWizard()
394
395         def OnExpertOpen(self, e):
396                 ecw = expertConfig.expertConfigWindow(lambda : self.scene.sceneUpdated())
397                 ecw.Centre()
398                 ecw.Show()
399
400         def OnMinecraftImport(self, e):
401                 mi = minecraftImport.minecraftImportWindow(self)
402                 mi.Centre()
403                 mi.Show(True)
404
405         def OnPIDDebugger(self, e):
406                 debugger = pidDebugger.debuggerWindow(self)
407                 debugger.Centre()
408                 debugger.Show(True)
409
410         def OnCheckForUpdate(self, e):
411                 newVersion = version.checkForNewerVersion()
412                 if newVersion is not None:
413                         if wx.MessageBox(_("A new version of Cura is available, would you like to download?"), _("New version available"), wx.YES_NO | wx.ICON_INFORMATION) == wx.YES:
414                                 webbrowser.open(newVersion)
415                 else:
416                         wx.MessageBox(_("You are running the latest version of Cura!"), _("Awesome!"), wx.ICON_INFORMATION)
417
418         def OnAbout(self, e):
419                 info = wx.AboutDialogInfo()
420                 info.SetName("Cura")
421                 info.SetDescription(_("End solution for Open Source Fused Filament Fabrication 3D printing."))
422                 info.SetWebSite('http://software.ultimaker.com/')
423                 info.SetCopyright(_("Copyright (C) David Braam"))
424                 info.SetLicence("""
425     This program is free software: you can redistribute it and/or modify
426     it under the terms of the GNU Affero General Public License as published by
427     the Free Software Foundation, either version 3 of the License, or
428     (at your option) any later version.
429
430     This program is distributed in the hope that it will be useful,
431     but WITHOUT ANY WARRANTY; without even the implied warranty of
432     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
433     GNU Affero General Public License for more details.
434
435     You should have received a copy of the GNU Affero General Public License
436     along with this program.  If not, see <http://www.gnu.org/licenses/>.
437 """)
438                 wx.AboutBox(info)
439
440         def OnClose(self, e):
441                 profile.saveProfile(profile.getDefaultProfilePath())
442
443                 # Save the window position, size & state from the preferences file
444                 profile.putPreference('window_maximized', self.IsMaximized())
445                 if not self.IsMaximized() and not self.IsIconized():
446                         (posx, posy) = self.GetPosition()
447                         profile.putPreference('window_pos_x', posx)
448                         profile.putPreference('window_pos_y', posy)
449                         (width, height) = self.GetSize()
450                         profile.putPreference('window_width', width)
451                         profile.putPreference('window_height', height)                  
452                         
453                         # Save normal sash position.  If in normal mode (!simple mode), get last position of sash before saving it...
454                         isSimple = profile.getPreference('startMode') == 'Simple'
455                         if not isSimple:
456                                 self.normalSashPos = self.splitter.GetSashPosition()
457                         profile.putPreference('window_normal_sash', self.normalSashPos)
458
459                 #HACK: Set the paint function of the glCanvas to nothing so it won't keep refreshing. Which keeps wxWidgets from quiting.
460                 print "Closing down"
461                 self.scene.OnPaint = lambda e : e
462                 self.scene._slicer.cleanup()
463                 self.Destroy()
464
465         def OnQuit(self, e):
466                 self.Close()
467
468 class normalSettingsPanel(configBase.configPanelBase):
469         "Main user interface window"
470         def __init__(self, parent, callback = None):
471                 super(normalSettingsPanel, self).__init__(parent, callback)
472
473                 #Main tabs
474                 self.nb = wx.Notebook(self)
475                 self.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
476                 self.GetSizer().Add(self.nb, 1, wx.EXPAND)
477
478                 (left, right, self.printPanel) = self.CreateDynamicConfigTab(self.nb, 'Basic')
479                 self._addSettingsToPanels('basic', left, right)
480                 self.SizeLabelWidths(left, right)
481                 
482                 (left, right, self.advancedPanel) = self.CreateDynamicConfigTab(self.nb, 'Advanced')
483                 self._addSettingsToPanels('advanced', left, right)
484                 self.SizeLabelWidths(left, right)
485
486                 #Plugin page
487                 self.pluginPanel = pluginPanel.pluginPanel(self.nb, callback)
488                 if len(self.pluginPanel.pluginList) > 0:
489                         self.nb.AddPage(self.pluginPanel, "Plugins")
490                 else:
491                         self.pluginPanel.Show(False)
492
493                 #Alteration page
494                 if profile.getPreference('gcode_flavor') == 'UltiGCode':
495                         self.alterationPanel = None
496                 else:
497                         self.alterationPanel = alterationPanel.alterationPanel(self.nb, callback)
498                         self.nb.AddPage(self.alterationPanel, "Start/End-GCode")
499
500                 self.Bind(wx.EVT_SIZE, self.OnSize)
501
502                 self.nb.SetSize(self.GetSize())
503                 self.UpdateSize(self.printPanel)
504                 self.UpdateSize(self.advancedPanel)
505
506         def _addSettingsToPanels(self, category, left, right):
507                 count = len(profile.getSubCategoriesFor(category)) + len(profile.getSettingsForCategory(category))
508
509                 p = left
510                 n = 0
511                 for title in profile.getSubCategoriesFor(category):
512                         n += 1 + len(profile.getSettingsForCategory(category, title))
513                         if n > count / 2:
514                                 p = right
515                         configBase.TitleRow(p, title)
516                         for s in profile.getSettingsForCategory(category, title):
517                                 if s.checkConditions():
518                                         configBase.SettingRow(p, s.getName())
519
520         def SizeLabelWidths(self, left, right):
521                 leftWidth = self.getLabelColumnWidth(left)
522                 rightWidth = self.getLabelColumnWidth(right)
523                 maxWidth = max(leftWidth, rightWidth)
524                 self.setLabelColumnWidth(left, maxWidth)
525                 self.setLabelColumnWidth(right, maxWidth)
526
527         def OnSize(self, e):
528                 # Make the size of the Notebook control the same size as this control
529                 self.nb.SetSize(self.GetSize())
530                 
531                 # Propegate the OnSize() event (just in case)
532                 e.Skip()
533                 
534                 # Perform out resize magic
535                 self.UpdateSize(self.printPanel)
536                 self.UpdateSize(self.advancedPanel)
537         
538         def UpdateSize(self, configPanel):
539                 sizer = configPanel.GetSizer()
540                 
541                 # Pseudocde
542                 # if horizontal:
543                 #     if width(col1) < best_width(col1) || width(col2) < best_width(col2):
544                 #         switch to vertical
545                 # else:
546                 #     if width(col1) > (best_width(col1) + best_width(col1)):
547                 #         switch to horizontal
548                 #
549                                 
550                 col1 = configPanel.leftPanel
551                 colSize1 = col1.GetSize()
552                 colBestSize1 = col1.GetBestSize()
553                 col2 = configPanel.rightPanel
554                 colSize2 = col2.GetSize()
555                 colBestSize2 = col2.GetBestSize()
556
557                 orientation = sizer.GetOrientation()
558                 
559                 if orientation == wx.HORIZONTAL:
560                         if (colSize1[0] <= colBestSize1[0]) or (colSize2[0] <= colBestSize2[0]):
561                                 configPanel.Freeze()
562                                 sizer = wx.BoxSizer(wx.VERTICAL)
563                                 sizer.Add(configPanel.leftPanel, flag=wx.EXPAND)
564                                 sizer.Add(configPanel.rightPanel, flag=wx.EXPAND)
565                                 configPanel.SetSizer(sizer)
566                                 #sizer.Layout()
567                                 configPanel.Layout()
568                                 self.Layout()
569                                 configPanel.Thaw()
570                 else:
571                         if max(colSize1[0], colSize2[0]) > (colBestSize1[0] + colBestSize2[0]):
572                                 configPanel.Freeze()
573                                 sizer = wx.BoxSizer(wx.HORIZONTAL)
574                                 sizer.Add(configPanel.leftPanel, proportion=1, border=35, flag=wx.EXPAND)
575                                 sizer.Add(configPanel.rightPanel, proportion=1, flag=wx.EXPAND)
576                                 configPanel.SetSizer(sizer)
577                                 #sizer.Layout()
578                                 configPanel.Layout()
579                                 self.Layout()
580                                 configPanel.Thaw()
581
582         def updateProfileToControls(self):
583                 super(normalSettingsPanel, self).updateProfileToControls()
584                 if self.alterationPanel is not None:
585                         self.alterationPanel.updateProfileToControls()
586                 self.pluginPanel.updateProfileToControls()