class configPanelBase(wx.Panel):
"A base class for configuration dialogs. Handles creation of settings, and popups"
- def __init__(self, parent):
+ def __init__(self, parent, changeCallback = None):
super(configPanelBase, self).__init__(parent)
self.settingControlList = []
self.popup.sizer = wx.BoxSizer()
self.popup.sizer.Add(self.popup.text, flag=wx.EXPAND|wx.ALL, border=1)
self.popup.SetSizer(self.popup.sizer)
+
+ self._callback = changeCallback
def CreateConfigTab(self, nb, name):
leftConfigPanel, rightConfigPanel, configPanel = self.CreateConfigPanel(nb)
setting.SetValue(setting.setting.getValue())
self.Update()
+ def _validate(self):
+ for setting in self.settingControlList:
+ setting._validate()
+ if self._callback is not None:
+ self._callback()
+
def getLabelColumnWidth(self, panel):
maxWidth = 0
for child in panel.GetChildren():
self.label.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
self.label.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseExit)
- if self.setting.getType() is types.FloatType and False:
- digits = 0
- while 1 / pow(10, digits) > defaultValue:
- digits += 1
- self.ctrl = floatspin.FloatSpin(panel, -1, value=float(getSettingFunc(configName)), increment=defaultValue, digits=digits, min_val=0.0)
- self.ctrl.Bind(floatspin.EVT_FLOATSPIN, self.OnSettingChange)
- flag = wx.EXPAND
- elif self.setting.getType() is types.BooleanType:
+ #if self.setting.getType() is types.FloatType and False:
+ # digits = 0
+ # while 1 / pow(10, digits) > defaultValue:
+ # digits += 1
+ # self.ctrl = floatspin.FloatSpin(panel, -1, value=float(getSettingFunc(configName)), increment=defaultValue, digits=digits, min_val=0.0)
+ # self.ctrl.Bind(floatspin.EVT_FLOATSPIN, self.OnSettingChange)
+ # 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.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange)
def OnSettingChange(self, e):
self.setting.setValue(self.GetValue())
+ self.panel.main._validate()
+
+ def _validate(self):
result, msg = self.setting.validate()
ctrl = self.ctrl
programmer = stk500v2.Stk500v2()
programmer.progressCallback = self.OnProgress
if self.port == 'AUTO':
- for self.port in machineCom.serialList():
+ for self.port in machineCom.serialList(True):
try:
programmer.connect(self.port)
break
self.fileMenu = wx.Menu()
i = self.fileMenu.Append(-1, 'Load model file...\tCTRL+L')
self.Bind(wx.EVT_MENU, lambda e: self._showModelLoadDialog(1), i)
- i = self.fileMenu.Append(-1, 'Prepare print...\tCTRL+R')
- self.Bind(wx.EVT_MENU, self.OnSlice, i)
i = self.fileMenu.Append(-1, 'Print...\tCTRL+P')
self.Bind(wx.EVT_MENU, self.OnPrint, i)
##Gui components##
self.simpleSettingsPanel = simpleMode.simpleModePanel(self.leftPane)
- self.normalSettingsPanel = normalSettingsPanel(self.leftPane)
+ self.normalSettingsPanel = normalSettingsPanel(self.leftPane, lambda : self.scene.sceneUpdated())
self.leftSizer = wx.BoxSizer(wx.VERTICAL)
self.leftSizer.Add(self.simpleSettingsPanel)
def OnLoadModel4(self, e):
self._showModelLoadDialog(4)
- def OnSlice(self, e):
- if len(self.filelist) < 1:
- wx.MessageBox('You need to load a file before you can prepare it.', 'Print error', wx.OK | wx.ICON_INFORMATION)
- return
- isSimple = profile.getPreference('startMode') == 'Simple'
- if isSimple:
- #save the current profile so we can put it back latter
- oldProfile = profile.getProfileString()
- self.simpleSettingsPanel.setupSlice()
- #Create a progress panel and add it to the window. The progress panel will start the Skein operation.
- spp = sliceProgressPanel.sliceProgressPanel(self, self, self.filelist)
- self.sizer.Add(spp, 0, flag=wx.EXPAND)
- self.sizer.Layout()
- newSize = self.GetSize()
- newSize.IncBy(0, spp.GetSize().GetHeight())
- if newSize.GetWidth() < wx.GetDisplaySize()[0]:
- self.SetSize(newSize)
- self.progressPanelList.append(spp)
- if isSimple:
- profile.loadProfileFromString(oldProfile)
-
def OnPrint(self, e):
if len(self.filelist) < 1:
wx.MessageBox('You need to load a file and prepare it before you can print.', 'Print error', wx.OK | wx.ICON_INFORMATION)
class normalSettingsPanel(configBase.configPanelBase):
"Main user interface window"
- def _addSettingsToPanels(self, category, left, right):
- count = len(profile.getSubCategoriesFor(category)) + len(profile.getSettingsForCategory(category))
-
- p = left
- n = 0
- for title in profile.getSubCategoriesFor(category):
- n += 1 + len(profile.getSettingsForCategory(category, title))
- if n > count / 2:
- p = right
- configBase.TitleRow(p, title)
- for s in profile.getSettingsForCategory(category, title):
- if s.checkConditions():
- configBase.SettingRow(p, s.getName())
-
- def __init__(self, parent):
- super(normalSettingsPanel, self).__init__(parent)
+ def __init__(self, parent, callback = None):
+ super(normalSettingsPanel, self).__init__(parent, callback)
#Main tabs
self.nb = wx.Notebook(self)
self.Bind(wx.EVT_SIZE, self.OnSize)
+ def _addSettingsToPanels(self, category, left, right):
+ count = len(profile.getSubCategoriesFor(category)) + len(profile.getSettingsForCategory(category))
+
+ p = left
+ n = 0
+ for title in profile.getSubCategoriesFor(category):
+ n += 1 + len(profile.getSettingsForCategory(category, title))
+ if n > count / 2:
+ p = right
+ configBase.TitleRow(p, title)
+ for s in profile.getSettingsForCategory(category, title):
+ if s.checkConditions():
+ configBase.SettingRow(p, s.getName())
+
def SizeLabelWidths(self, left, right):
leftWidth = self.getLabelColumnWidth(left)
rightWidth = self.getLabelColumnWidth(right)
except:
pass
-def serialList():
+def serialList(forAutoDetect=False):
baselist=[]
if os.name=="nt":
try:
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i=0
- while(1):
- baselist+=[_winreg.EnumValue(key,i)[1]]
+ while True:
+ values = _winreg.EnumValue(key, i)
+ if not forAutoDetect or 'USBSER' in values[0]:
+ baselist+=[_winreg.EnumValue(key,i)[1]]
i+=1
except:
pass
- baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*")
+ if forAutoDetect:
+ baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*")
+ baselist = filter(lambda s: not 'Bluetooth' in s, baselist)
+ else:
+ baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*")
prev = profile.getPreference('serial_port_auto')
if prev in baselist:
baselist.remove(prev)
if self._port == 'AUTO':
self._changeState(self.STATE_DETECT_SERIAL)
programmer = stk500v2.Stk500v2()
- self._log("Serial port list: %s" % (str(serialList())))
- for p in serialList():
+ self._log("Serial port list: %s" % (str(serialList(True))))
+ for p in serialList(True):
try:
self._log("Connecting to: %s" % (p))
programmer.connect(p)
self._process.terminate()
self._thread.join()
+ def getGCodeFilename(self):
+ return self._exportFilename
+
def runSlicer(self, scene):
self.abortSlicer()
self._callback(0.0, False)
f.write(mesh.vertexes.tostring())
pos = obj.getPosition() * 1000
pos += numpy.array([profile.getPreferenceFloat('machine_width') * 1000 / 2, profile.getPreferenceFloat('machine_depth') * 1000 / 2])
+ commandList += ['-m', ','.join(map(str, obj._matrix.getA().flatten()))]
commandList += ['-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]), '#']
self._objCount += 1
if self._objCount > 0: