chiark / gitweb /
Tell user to connect and power on 3D printer before attempting to flash firmware
[cura.git] / Cura / gui / alterationPanel.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import wx, wx.stc
4
5 from Cura.gui.util import gcodeTextArea
6 from Cura.util import profile
7 #Panel to change the start & endcode of the gcode.
8 class alterationPanel(wx.Panel):
9         def __init__(self, parent, callback):
10                 wx.Panel.__init__(self, parent,-1)
11
12                 self.callback = callback
13                 self.alterationFileList = ['start.gcode', 'end.gcode']#, 'nextobject.gcode', 'replace.csv'
14                 if int(profile.getMachineSetting('extruder_amount')) > 1:
15                         self.alterationFileList += ['preSwitchExtruder.gcode', 'postSwitchExtruder.gcode']
16                         self.alterationFileList += ['start2.gcode', 'end2.gcode']
17                 if int(profile.getMachineSetting('extruder_amount')) > 2:
18                         self.alterationFileList += ['start3.gcode', 'end3.gcode']
19                 if int(profile.getMachineSetting('extruder_amount')) > 3:
20                         self.alterationFileList += ['start4.gcode', 'end4.gcode']
21                 if int(profile.getMachineSetting('extruder_amount')) > 4:
22                         self.alterationFileList += ['start5.gcode', 'end5.gcode']
23                 self.currentFile = None
24
25                 self.textArea = gcodeTextArea.GcodeTextArea(self)
26                 self.list = wx.ListBox(self, choices=self.alterationFileList, style=wx.LB_SINGLE)
27                 self.list.SetSelection(0)
28                 self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list)
29                 self.textArea.Bind(wx.EVT_KILL_FOCUS, self.OnFocusLost, self.textArea)
30                 self.textArea.Bind(wx.stc.EVT_STC_CHANGE, self.OnFocusLost, self.textArea)
31                 
32                 sizer = wx.GridBagSizer()
33                 sizer.Add(self.list, (0,0), span=(5,1), flag=wx.EXPAND)
34                 sizer.Add(self.textArea, (5,0), span=(5,1), flag=wx.EXPAND)
35                 sizer.AddGrowableCol(0)
36                 sizer.AddGrowableRow(0)
37                 sizer.AddGrowableRow(5)
38                 sizer.AddGrowableRow(6)
39                 sizer.AddGrowableRow(7)
40                 self.SetSizer(sizer)
41                 
42                 self.loadFile(self.alterationFileList[self.list.GetSelection()])
43                 self.currentFile = self.list.GetSelection()
44
45         def OnSelect(self, e):
46                 self.loadFile(self.alterationFileList[self.list.GetSelection()])
47                 self.currentFile = self.list.GetSelection()
48
49         def loadFile(self, filename):
50                 self.textArea.SetValue(profile.getAlterationFile(filename))
51
52         def OnFocusLost(self, e):
53                 if self.currentFile == self.list.GetSelection():
54                         profile.setAlterationFile(self.alterationFileList[self.list.GetSelection()], self.textArea.GetValue())
55                         self.callback()
56
57         def updateProfileToControls(self):
58                 self.OnSelect(None)